Rendering Engine 0.2.0
Modular Graphics Rendering Engine | v0.2.0
Loading...
Searching...
No Matches
scene_component.cpp
Go to the documentation of this file.
1#include "scene_component.hpp"
2
3namespace rendering_engine
4{
5
7 :
8 mPosition{ 0.0f },
9 mRotation{ 1.0f, 0.0f, 0.0f, 0.0f },
10 mEulerRotation{ 0.0f },
11 mScale{ 1.0f, 1.0f, 1.0f },
12 mWorldMatrix{ 1.0f }
13{
14}
15
17{
18 // T * R * S
19 mWorldMatrix = glm::translate(glm::mat4(1.0f), mPosition) * glm::toMat4(mRotation) * glm::scale(glm::mat4(1.0f), mScale);
20}
21const glm::mat4& SceneComponent::GetWorldMatrix() const
22{
23 return mWorldMatrix;
24}
25
26void SceneComponent::SetPosition(const glm::vec3& position)
27{
28 mPosition = position;
30}
31
32void SceneComponent::SetRotation(const glm::quat& rotation)
33{
34 mRotation = rotation;
35 mEulerRotation = glm::eulerAngles(rotation); // radians
37}
38
39/*
40Pitch rotate around Right vector (0.0f, 1.0f, 0.0f)
41Roll rotate around Forward vector (1.0f, 0.0f, 0.0f)
42Yaw rotate around Up vector (0.0f, 0.0f, 1.0f)
43*/
44void SceneComponent::SetRotation(const glm::vec3& rotation)
45{
46 mEulerRotation = glm::radians(rotation);
47 mRotation = glm::angleAxis(-rotation.y, axes::UpVector)// Yaw
48 * glm::angleAxis(-rotation.x, axes::RightVector) // Pitch
49 * glm::angleAxis(-rotation.z, axes::ForwardVector);// Roll
51}
52
53void SceneComponent::SetScale(const glm::vec3& scale)
54{
55 mScale = scale;
57}
58
60{
61 return glm::rotate(mRotation, axes::ForwardVector);
62}
63
64glm::vec3 SceneComponent::GetRight() const
65{
66 return glm::rotate(mRotation, axes::RightVector);
67}
68
69glm::vec3 SceneComponent::GetUp() const
70{
71 return glm::rotate(mRotation, axes::UpVector);
72}
73
74
75
76} //rendering_engine
glm::vec3 GetRight() const
Returns the right (local Y+) direction vector in world space.
void UpdateWorldMatrix()
Updates the world transformation matrix from the current position, rotation, and scale.
const glm::mat4 & GetWorldMatrix() const
Returns the world transformation matrix (model matrix).
void SetRotation(const glm::quat &rotation)
Sets the rotation using a quaternion.
SceneComponent()
Constructs a SceneComponent with default transform (origin, identity rotation, unit scale).
void SetPosition(const glm::vec3 &position)
Sets the position of the component in world space.
glm::vec3 GetForward() const
Returns the forward (local X+) direction vector in world space.
void SetScale(const glm::vec3 &scale)
Sets the scale for each dimension.
glm::vec3 GetUp() const
Returns the up (local Z+) direction vector in world space.
static const glm::vec3 UpVector
static const glm::vec3 RightVector
static const glm::vec3 ForwardVector