t
Loading...
Searching...
No Matches
Object3D.hpp
1#include "math/EulerRotation.hpp"
2#include "math/Matrix4x4.hpp"
3#include "math/Vector3.hpp"
4#include <functional>
5#include <optional>
6#include <vector>
7
8#ifndef OBJECT3D_HPP
9#define OBJECT3D_HPP
10
11namespace t {
12
24class Object3D {
25public:
26 virtual ~Object3D() = default;
27
28 std::optional<std::reference_wrapper<Object3D>> parent;
33 0, 0, 0);
35 0, 0, 0, EulerRotationOrder::Xyz);
38 1, 1, 1);
51 std::vector<std::reference_wrapper<Object3D>>
61 virtual bool isMesh() const { return false; }
62
70 virtual bool isLight() const { return false; }
71
78 children.push_back(child);
79 child.parent = *this;
80
81 return *this;
82 }
83
84 // Object3D &lookAt(const Vector3 &target);
85 // Object3D &lookAt(const Object3D &target);
86
97 Object3D &translate(double x, double y, double z) {
98 this->localPosition += Vector3(x, y, z);
99 return *this;
100 }
101
112 Object3D &rotate(double x, double y, double z, EulerRotationOrder order) {
113 this->localRotation.copy(this->localRotation +
114 EulerRotation(x, y, z, order));
115 return *this;
116 }
117
127 Object3D &scale(double x, double y, double z) {
128 this->localScale *= Vector3(x, y, z);
129 return *this;
130 }
131
132 // Vector3 getWorldPosition() const;
133 // EulerRotation getWorldRotation() const;
134 // Vector3 getWorldScale();
135
148
149 localMatrix.copy(translationMatrix * rotationMatrix * scaleMatrix);
150 return *this;
151 }
152
164 if (parent) {
165 modelMatrix.copy(parent.value().get().modelMatrix * this->localMatrix);
166 } else {
168 }
169
170 return *this;
171 }
172};
173
174} // namespace t
175
176#endif // OBJECT3D_HPP
The Euler rotation class.
Definition EulerRotation.hpp:17
EulerRotation & copy(const EulerRotation &source)
Copies another Euler rotation into this Euler rotation.
Definition EulerRotation.hpp:42
The matrix class.
Definition Matrix4x4.hpp:35
static Matrix4x4 fromTranslation(const Vector3 &distance)
Returns a translation matrix for the specified translation for post-multiplication ( where is the h...
Definition Matrix4x4.hpp:79
static Matrix4x4 identity()
Returns a identity matrix.
Definition Matrix4x4.hpp:45
static Matrix4x4 fromRotation(const EulerRotation &angle)
Returns a rotation matrix for the specified rotation for post-multiplication ( where is the homogen...
Definition Matrix4x4.hpp:99
static Matrix4x4 fromScale(const Vector3 &scaleFactor)
Returns a scale matrix for the specified scale factor.
Definition Matrix4x4.hpp:133
Matrix4x4 & copy(const Matrix4x4 &source)
Copies the elements of another matrix into this matrix.
Definition Matrix4x4.hpp:189
The 3D object class.
Definition Object3D.hpp:24
Vector3 localPosition
The position of this 3D object relative to its parent.
Definition Object3D.hpp:32
virtual bool isLight() const
Returns whether this 3D object is a light.
Definition Object3D.hpp:70
Vector3 up
The vector pointing to the up direction in object space.
Definition Object3D.hpp:30
Object3D & rotate(double x, double y, double z, EulerRotationOrder order)
Rotates this 3D object by the specified angles around the x, y, and z axes in local space.
Definition Object3D.hpp:112
Matrix4x4 modelMatrix
The model matrix of this 3D object, transformating local space to world space.
Definition Object3D.hpp:46
Vector3 localScale
The scale of this 3D object relative to its parent.
Definition Object3D.hpp:37
Matrix4x4 localMatrix
The matrix of the local transformation of this 3D object.
Definition Object3D.hpp:39
std::optional< std::reference_wrapper< Object3D > > parent
The parent of this 3D object.
Definition Object3D.hpp:28
Object3D & scale(double x, double y, double z)
Scales this 3D object by the specified amounts along the x, y, and z axes in local space.
Definition Object3D.hpp:127
virtual bool isMesh() const
Returns whether this 3D object is a mesh.
Definition Object3D.hpp:61
Object3D & updateLocalMatrix()
Updates the local transformation matrix of this 3D object.
Definition Object3D.hpp:144
Object3D & add(Object3D &child)
Adds another 3D object as a child of this 3D object.
Definition Object3D.hpp:77
std::vector< std::reference_wrapper< Object3D > > children
The children of this 3D object.
Definition Object3D.hpp:52
Object3D & translate(double x, double y, double z)
Translates this 3D object by the specified amounts along the x, y, and z axes in local space.
Definition Object3D.hpp:97
Object3D & updateModelMatrix()
Updates the model matrix of this 3D object.
Definition Object3D.hpp:163
EulerRotation localRotation
The rotation of this 3D object relative to its parent.
Definition Object3D.hpp:34
The 3D vector class.
Definition Vector3.hpp:20
#define DEFAULT_UP
The default up direction.
Definition constants.hpp:50
The t software 3D graphics library namespace.
Definition algorithms.hpp:12
EulerRotationOrder
The Euler rotation order.
Definition constants.hpp:19