5#include <glm/gtc/matrix_transform.hpp>
14 std::shared_ptr<SceneNode> sceneNode,
73 for (
auto entity : view) {
87 PLOGD <<
"Camera set as active";
111 return glm::mat4(1.0f);
116 return glm::inverse(
sceneNode_->getWorldMatrix());
149 props->aspectRatio = aspectRatio;
161 props->nearPlane = nearPlane;
173 props->farPlane = farPlane;
180 return glm::vec3(0.0f);
182 const auto& worldMatrix =
sceneNode_->getWorldMatrix();
183 return glm::vec3(worldMatrix[3]);
188 return glm::vec3(0.0f, 0.0f, -1.0f);
190 const auto& worldMatrix =
sceneNode_->getWorldMatrix();
192 return -glm::normalize(glm::vec3(worldMatrix[2]));
197 return glm::vec3(1.0f, 0.0f, 0.0f);
199 const auto& worldMatrix =
sceneNode_->getWorldMatrix();
201 return glm::normalize(glm::vec3(worldMatrix[0]));
206 return glm::vec3(0.0f, 1.0f, 0.0f);
208 const auto& worldMatrix =
sceneNode_->getWorldMatrix();
210 return glm::normalize(glm::vec3(worldMatrix[1]));
216 float fovRadians = glm::radians(
fov_);
217 float tanHalfFov = glm::tan(fovRadians * 0.5f);
static entt::registry & get()
Gets the registry for all components.
A camera component that provides view and projection matrices based on its SceneNode transform....
void endPlay() override
Called when the component is removed or the game ends.
bool isActive() const
Checks if this camera is currently the active camera.
entt::entity cameraEntity_
void setAspectRatio(float aspectRatio)
Sets the aspect ratio (width / height)
glm::vec3 getForwardVector() const
Gets the forward direction vector of the camera.
glm::mat4 cachedProjectionMatrix_
glm::mat4 getProjectionMatrix() const
Gets the projection matrix based on FOV, aspect ratio, and clipping planes.
CameraComponent(Scene *owningScene, std::shared_ptr< SceneNode > sceneNode, float fov=60.0f, float nearPlane=0.01f, float farPlane=1000.0f)
Constructs a camera component with default parameters.
glm::mat4 getViewProjectionMatrix() const
Gets the combined view-projection matrix.
glm::vec3 getWorldPosition() const
Gets the camera's world position from its scene node.
glm::vec3 getUpVector() const
Gets the up direction vector of the camera.
glm::vec3 getRightVector() const
Gets the right direction vector of the camera.
void setActive(bool active)
Sets this camera as the active camera for rendering.
glm::mat4 getViewMatrix() const
Gets the view matrix computed from the camera's world transform.
void setFov(float fov)
Sets the vertical field of view.
void updateProjectionMatrix()
void tick(double deltaTime) override
Called every frame if ticking is enabled.
void beginPlay() override
Called when the component is added to the scene or the game starts.
void setNearPlane(float nearPlane)
Sets the near clipping plane distance.
std::shared_ptr< SceneNode > sceneNode_
void setFarPlane(float farPlane)
Sets the far clipping plane distance.
virtual void endPlay()
Called when the component is removed or the game ends.
void setCanTick(bool enable)
Enables or disables ticking for this component.
virtual void beginPlay()
Called when the component is added to the scene or the game starts.
LogicComponent(Scene *owningScene)
A scene is the overarching structure which can spawn actors.
Log category system implementation.
static CameraComponent * s_activeCamera
bool hasActiveCamera()
Checks if there is an active camera set.
CameraComponent * getActiveCamera()
Gets the currently active camera.
Tag for the active camera in the scene.
Camera properties for projection matrix calculation.
float fov
Vertical field of view in degrees.