Enzo
Loading...
Searching...
No Matches
Transform.h
1#pragma once
2
3#include "Engine/Core/Types.h"
4#include <Eigen/Geometry>
5#include <numbers>
6
7namespace enzo::attr {
8class Attribute;
9}
10
11namespace enzo {
12
26class Transform
27{
28 public:
29 using Affine = Eigen::Transform<floatT, 3, Eigen::Affine>;
30
32 Transform() : xform_(Affine::Identity()) {}
33
35 explicit Transform(const Matrix4& matrix) : xform_(matrix) {}
36
37 // Factories
38
46 static Transform fromAttribute(const attr::Attribute& attribute, Offset offset);
47
56 static Transform lookAt(const Vector3& translation, const Vector3& forward, const Vector3& up);
57
58 // Builders compose in the current local frame, so the first call is applied
59 // to a point first and later calls wrap it.
60
62 Transform& translate(const Vector3& offset)
63 {
64 xform_.translate(offset);
65 return *this;
66 }
67
69 Transform& rotateEuler(const Vector3& degrees)
70 {
71 const Vector3 radians = degrees * (std::numbers::pi / 180.0);
72 xform_.rotate(
73 Eigen::AngleAxis<floatT>(radians.z(), Vector3::UnitZ()) *
74 Eigen::AngleAxis<floatT>(radians.y(), Vector3::UnitY()) *
75 Eigen::AngleAxis<floatT>(radians.x(), Vector3::UnitX())
76 );
77 return *this;
78 }
79
81 Transform& scale(const Vector3& factors)
82 {
83 xform_.scale(factors);
84 return *this;
85 }
86
88 Transform& scale(floatT uniform)
89 {
90 xform_.scale(uniform);
91 return *this;
92 }
93
96 {
97 xform_ = xform_ * other.xform_;
98 return *this;
99 }
100
105 Vector3 operator*(const Vector3& point) const { return xform_ * point; }
106
107 const Matrix4& getMatrix() const { return xform_.matrix(); }
108
109 private:
110 Affine xform_;
111};
112
113} // namespace enzo
Basic attribute, parameter, and node types for Enzo.
size_t Offset
enzo::Offset is the internal discontinuous index of an element in a given AttributeOwner.
Definition Types.h:100
An affine transform that composes translation, rotation, and scale.
Transform & rotateEuler(const Vector3 &degrees)
Rotates in X, then Y, then Z, with angles given in degrees.
Definition Transform.h:69
Transform & scale(const Vector3 &factors)
Scales each local axis independently.
Definition Transform.h:81
Transform & compose(const Transform &other)
Composes another transform into this one in the local frame.
Definition Transform.h:95
Transform & translate(const Vector3 &offset)
Moves the local origin by an offset.
Definition Transform.h:62
Vector3 operator*(const Vector3 &point) const
Applies the transform to a point.
Definition Transform.h:105
Transform()
Constructs an identity transform.
Definition Transform.h:32
static Transform lookAt(const Vector3 &translation, const Vector3 &forward, const Vector3 &up)
Builds an orientation frame that points down a forward axis.
Definition Transform.cpp:23
Transform(const Matrix4 &matrix)
Wraps an existing matrix.
Definition Transform.h:35
static Transform fromAttribute(const attr::Attribute &attribute, Offset offset)
Reads a transform from a single attribute value.
Definition Transform.cpp:6
Transform & scale(floatT uniform)
Scales all local axes by the same factor.
Definition Transform.h:88
Containers for geometry data.