Fillwave  10.0.0
Entity.h
1 #pragma once
2 
3 /*
4  * The MIT License (MIT)
5  *
6  * Copyright (c) 2018 Filip Wasil and Fillwave community members
7  *
8  * Permission is hereby granted, free of charge, to any person
9  * obtaining a copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
12  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included
15  * in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
18  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23 
24 #include <flw/cmn/IPickable.h>
25 #include <flw/cmn/scene/ICamera.h>
26 #include <flw/flc/renderers/IRenderable.h>
27 #include <flw/cmn/scene/Moveable.h>
28 #include <flw/flf/models/base/TreePtr.h>
29 
30 namespace flw {
31 namespace flf {
32 class Entity;
33 class EventHandler;
34 class Event;
35 enum class EEventType;
36 }
37 
38 namespace flc {
39 class Program;
40 }
41 
42 namespace flf {
43 
48 class Entity : public flc::IRenderable, public IPickable, public Moveable, public TreePtr<Entity> {
49 public:
50  Entity();
51 
52  ~Entity() override;
53 
54  Entity& operator=(Entity &&);
55 
56  Entity(Entity &&obj);
57 
58  /* Flags */
59  bool isPSC();
60 
61  bool isPSR();
62 
63  /* Callbacks */
64  void handleEvent(const Event& event);
65 
66  /* Model */
67  glm::mat4 getPhysicsMMC();
68 
69  /* Physics */
70  void setTransformation(glm::mat4 modelMatrix);
71 
72  /* Callbacks */
73  void attachHandler(std::function<void(const Event&)>&& h, EEventType eventType);
74 
75  void detachHandlers();
76 
77  /* Parent */
78  void updateMatrixTree();
79 
80  void updateParentMatrix(glm::mat4 &parent);
81 
82  void updateParentRotation(glm::quat &rotation);
83 
84  /* IPickable */
85  void assignColor(const glm::vec3& color) override;
86 
87  void unpick() override;
88 
89  void stepInTime(float timeSinceLastFrameInSeconds);
90 
91  virtual void onPicked() override;
92 
93  virtual void onUnpicked() override;
94 
95  /* IDrawable */
96  void drawFR(ICamera &camera) override;
97  void drawPBRP(ICamera &camera) override;
98  void drawDR(ICamera &camera) override;
99  void drawDepth(ICamera &camera) override;
100  void drawDepthColor(ICamera &camera, glm::vec3 &position) override;
101  void drawAOG(ICamera &camera) override;
102  void drawAOC(ICamera &camera) override;
103  void drawOcclusionBox(ICamera &camera) override;
104  void drawPicking(ICamera &camera) override;
105 
106  /* IRenderable */
107  void updateRenderer(flc::IRenderer &renderer) override;
108  bool getRenderItem(flc::RenderItem &item) override;
109 
110  /* Animations */
111  virtual bool isAnimated() const;
112 
113  /* Log */
114  virtual void log() const;
115 
116 protected:
117  /* MMC - Model Matrix Cache */
118  glm::mat4 mPhysicsMMC;
119 
120  bool mChildrenPropagateEvent;
121  bool mParentRefresh;
122  vec<EventHandler> mEventHandlers;
123 
124  bool mPSC;
125  bool mPSR;
126 };
127 
128 } /* flf */
129 } /* flw */
Definition: Aliases.h:30
Base for all renderers.
Definition: IRenderer.h:42
Base for all Scene nodes.
Definition: Entity.h:48
Pickable Interface.
Definition: IPickable.h:33
Event.
Definition: Event.h:154
Encapsulates renderable objects. To be used with IRenderer.
Definition: IRenderable.h:36
Base for every object which has a 3D position.
Definition: Moveable.h:43
Basic tree template class. Enables attaching and detaching nodes.
Definition: TreePtr.h:41
Single draw item structure.
Definition: RenderItem.h:33
Stores camera view parameters.
Definition: ICamera.h:32