Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
Actor.cpp
Go to the documentation of this file.
2
8
9#include <GLFW/glfw3.h>
10#include <plog/Log.h>
11
12namespace EngineCore {
16
18 }
19
21 PLOGI << "Begin play";
22 // Initialize all components
23 for (auto& component : components) {
24 component->beginPlay();
25 }
26 }
27
28 void Actor::tick(double deltaTime) {
29 Entity::tick(deltaTime);
30
31 // Tick components
32 for (auto& component : components) {
33 if (component->canTick()) {
34 component->tick(deltaTime);
35 }
36 }
37 }
38
40 for (auto& component : components) {
41 component->endPlay();
42 }
43
44 if (sceneNode.has_value())
45 {
47 }
48 }
49
50 glm::vec3 Actor::getActorLocation() const {
52 if (sceneNode.has_value()) {
53 return Ecs::TransformOperators::getPosition( sceneNode.value()->getWorldMatrix() );
54 }
55 return glm::vec3(0.0f);
56 }
57
58 glm::vec3 Actor::getActorRotation() const {
59 if (sceneNode.has_value()) {
60 return Ecs::TransformOperators::getRotationEuler( sceneNode.value()->getWorldMatrix() );
61 }
62 return glm::vec3(0.0f);
63 }
64
65 glm::vec3 Actor::getActorScale() const {
66 if (sceneNode.has_value()) {
67 return Ecs::TransformOperators::getScale( sceneNode.value()->getWorldMatrix() );
68 }
69 return glm::vec3(0.0f);
70 }
71
72 void Actor::setActorLocation(const glm::vec3 newLocation) {
73 if (sceneNode.has_value()) {
74 sceneNode.value()->setWorldPosition(newLocation);
75 }
76 }
77
78 void Actor::setActorRotation(glm::vec3 newRotation) {
79 if (sceneNode.has_value()) {
80 sceneNode.value()->setWorldRotation(newRotation);
81 }
82 }
83
84 void Actor::rotateActor(glm::vec3 deltaRotation) {
85 if (sceneNode.has_value()) {
86 sceneNode.value()->rotateWorld(deltaRotation);
87 }
88 }
89
90 void Actor::setActorScale(glm::vec3 newScale) {
91 if (sceneNode.has_value()) {
92 sceneNode.value()->setWorldScale(newScale);
93 }
94 }
95
96 glm::mat4 Actor::getWorldTransform() const {
97 if (sceneNode.has_value()) {
98 return sceneNode.value()->getWorldMatrix();
99 }
100 return glm::mat4(1.0f);
101 }
102
104 const auto managedMeshComponent = owningScene->getSceneManager()->registerGameObject(meshComponent);
105 meshComponents.push_back(meshComponent);
106 return managedMeshComponent;
107 }
108
110 meshComponents.erase(std::ranges::find(meshComponents, meshComponent));
111 delete meshComponent;
112 meshComponent = nullptr;
113 }
114
115 std::vector<MeshComponent *> Actor::getMeshComponents() const {
116 return meshComponents;
117 }
118
122
124 TRACY_ZONE_SCOPED_NAMED("Cleaning Mesh Components");
125 for (auto& component : components) {
126 component->endPlay();
127 }
128 components.clear();
129 }
130
132 return owningScene;
133 }
134
135 std::shared_ptr<SceneNode> Actor::getSceneNode() const
136 {
137 return sceneNode.value();
138 }
139} // namespace EngineCore
#define FUNCTION_NOT_IMPLEMENTED_F
#define TRACY_ZONE_SCOPED_FUNCTION
#define TRACY_ZONE_SCOPED_NAMED(name)
static entt::registry & get()
Gets the registry for all components.
static glm::vec3 getPosition(const glm::mat4 &matrix)
static glm::vec3 getScale(const glm::mat4 &matrix)
static glm::vec3 getRotationEuler(const glm::mat4 &matrix)
friend class Scene
Definition Actor.h:25
std::vector< MeshComponent * > meshComponents
Definition Actor.h:128
void cleanupComponents()
Definition Actor.cpp:123
std::vector< MeshComponent * > getMeshComponents() const
Definition Actor.cpp:115
Actor(std::shared_ptr< SceneNode > sceneNode, Scene *owningScene)
Definition Actor.cpp:13
void setActorLocation(glm::vec3 newLocation)
Set the new world location for this actor.
Definition Actor.cpp:72
Scene * getOwningScene() const
Get the pointer to the scene this entity is a part of.
Definition Actor.cpp:131
virtual void beginPlay()
Gets executed when the actor is spawned into the world.
Definition Actor.cpp:20
MeshComponent * registerMeshComponent(MeshComponent *meshComponent)
Definition Actor.cpp:103
void tick(double deltaTime) override
Executed every frame.
Definition Actor.cpp:28
void setActorScale(glm::vec3 newScale)
sets the world scale for this actor
Definition Actor.cpp:90
void initComponents()
Definition Actor.cpp:119
void setActorRotation(glm::vec3 newRotation)
Sets the world rotation.
Definition Actor.cpp:78
Scene * owningScene
Definition Actor.h:149
glm::vec3 getActorScale() const
Scales the actor to world scale.
Definition Actor.cpp:65
glm::mat4 getWorldTransform() const
Gets the model matrix.
Definition Actor.cpp:96
glm::vec3 getActorLocation() const
Gets the actors location in the world.
Definition Actor.cpp:50
virtual void endPlay()
Definition Actor.cpp:39
glm::vec3 getActorRotation() const
Gets the actors rotation in the world.
Definition Actor.cpp:58
std::shared_ptr< SceneNode > getSceneNode() const
Getter for the scene graph node for this object.
Definition Actor.cpp:135
std::optional< std::shared_ptr< SceneNode > > sceneNode
Definition Actor.h:131
void rotateActor(glm::vec3 deltaRotation)
Applies an incremental rotation to the actor using quaternion multiplication. Use this instead of get...
Definition Actor.cpp:84
void unregisterMeshComponent(MeshComponent *meshComponent)
Definition Actor.cpp:109
EngineCore::Engine * getEngineModule()
gets the pointer to the engine object
Definition Engine.cpp:1140
static EngineManager & getInstance()
gets a reference to the engine manager
Definition Engine.cpp:1135
entt::entity data
Definition Entity.h:177
void tick(double deltaTime) override
Executes every frame if tick is enabled.
Definition Entity.cpp:31
std::vector< std::shared_ptr< LogicComponent > > components
List of all logical components.
Definition Entity.h:175
A component which can be attached as many times to an actor as one wants. It makes it possible to ren...
Log category system implementation.