Nebula
Loading...
Searching...
No Matches
transform44.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
12#include "math/mat4.h"
13#include "math/vec3.h"
14#include "math/quat.h"
15
16//------------------------------------------------------------------------------
17namespace Math
18{
20{
21public:
25 transform44(const transform44& rhs) = default;
27 bool operator==(const transform44& rhs) const;
29 void loadu(const scalar* ptr);
31 void storeu(scalar* ptr) const;
33 void setposition(const vec3& p);
35 void setposition(const point& p);
37 const point& getposition() const;
39 void setrotate(const quat& r);
41 const quat& getrotate() const;
43 void setscale(const vec3& s);
45 const vec3& getscale() const;
47 void setrotatepivot(const point& p);
49 const point& getrotatepivot() const;
51 void setscalepivot(const point& p);
53 const point& getscalepivot() const;
55 void setoffset(const mat4& m);
57 const mat4& getoffset() const;
59 const mat4& getmatrix();
61 bool isdirty() const;
62
63private:
71 bool isDirty;
73};
74
75//------------------------------------------------------------------------------
78inline
80 position(0.0f, 0.0f, 0.0f),
81 rotate(0.0f, 0.0f, 0.0f, 1.0f),
82 scale(1.0f, 1.0f, 1.0f),
83 rotatePivot(0.0f, 0.0f, 0.0f),
84 scalePivot(0.0f, 0.0f, 0.0f),
85 offset(mat4()),
86 isDirty(false),
87 offsetValid(false)
88{
89 // empty
90}
91
92//------------------------------------------------------------------------------
95inline bool
97{
98 return (this->position == rhs.position) && (this->rotate == rhs.rotate) && (this->scale == rhs.scale) && (this->rotatePivot == rhs.rotatePivot) && (this->scalePivot == rhs.scalePivot) && (this->matrix == rhs.matrix);
99}
100
101//------------------------------------------------------------------------------
104__forceinline void
106{
107 this->position.loadu(ptr);
108 this->rotate.loadu(ptr + 4);
109 this->scale.loadu(ptr + 8);
110 this->rotatePivot.loadu(ptr + 12);
111 this->scalePivot.loadu(ptr + 16);
112 this->offset.loadu(ptr + 20);
113}
114
115//------------------------------------------------------------------------------
118__forceinline void
120{
121 this->position.storeu(ptr);
122 this->rotate.storeu(ptr + 4);
123 this->scale.storeu(ptr + 8);
124 this->rotatePivot.storeu(ptr + 12);
125 this->scalePivot.storeu(ptr + 16);
126 this->offset.storeu(ptr + 20);
127}
128
129//------------------------------------------------------------------------------
132inline void
134{
135 this->position = p;
136 this->isDirty = true;
137}
138
139//------------------------------------------------------------------------------
142inline void
144{
145 this->position = xyz(Math::vec4(p));
146 this->isDirty = true;
147}
148
149//------------------------------------------------------------------------------
152inline const point&
154{
155 return this->position;
156}
157
158//------------------------------------------------------------------------------
161inline void
163{
164 this->rotate = r;
165 this->isDirty = true;
166}
167
168//------------------------------------------------------------------------------
171inline const quat&
173{
174 return this->rotate;
175}
176
177//------------------------------------------------------------------------------
180inline void
182{
183 this->scale = s;
184 this->isDirty = true;
185}
186
187//------------------------------------------------------------------------------
190inline const vec3&
192{
193 return this->scale;
194}
195
196//------------------------------------------------------------------------------
199inline void
201{
202 this->rotatePivot = p;
203 this->isDirty = true;
204}
205
206//------------------------------------------------------------------------------
209inline const point&
211{
212 return this->rotatePivot;
213}
214
215//------------------------------------------------------------------------------
218inline void
220{
221 this->scalePivot = p;
222 this->isDirty = true;
223}
224
225//------------------------------------------------------------------------------
228inline const point&
230{
231 return this->scalePivot;
232}
233
234//------------------------------------------------------------------------------
237inline void
239{
240 this->offset = m;
241 this->offsetValid = true;
242 this->isDirty = true;
243}
244
245//------------------------------------------------------------------------------
248inline const mat4&
250{
251 return this->offset;
252}
253
254//------------------------------------------------------------------------------
257inline const mat4&
259{
260 if (this->isDirty)
261 {
262 quat ident;
263 this->matrix = transformation(xyz(this->scalePivot), ident, this->scale, xyz(this->rotatePivot), this->rotate, xyz(this->position));
264 if (this->offsetValid)
265 {
266 this->matrix = this->offset * this->matrix;
267 }
268 this->isDirty = false;
269 }
270 return this->matrix;
271}
272
273//------------------------------------------------------------------------------
276inline bool
278{
279 return this->isDirty;
280}
281
282} // namespace Math
283//------------------------------------------------------------------------------
284
285
A 4x4 matrix which is described by translation, rotation and scale.
Definition transform44.h:20
void setscalepivot(const point &p)
set optional scale pivot
Definition transform44.h:219
transform44()
constructor
Definition transform44.h:79
point position
Definition transform44.h:64
mat4 offset
Definition transform44.h:69
const mat4 & getmatrix()
get resulting 4x4 matrix
Definition transform44.h:258
const point & getrotatepivot() const
get optional rotate pivot
Definition transform44.h:210
void setoffset(const mat4 &m)
set optional offset matrix
Definition transform44.h:238
bool isdirty() const
return true if the transformation matrix is dirty
Definition transform44.h:277
void storeu(scalar *ptr) const
write content to unaligned memory through the write cache
Definition transform44.h:119
void setscale(const vec3 &s)
set scale
Definition transform44.h:181
vec3 scale
Definition transform44.h:66
bool operator==(const transform44 &rhs) const
equality operator
Definition transform44.h:96
void setposition(const vec3 &p)
set position
Definition transform44.h:133
point scalePivot
Definition transform44.h:68
bool isDirty
Definition transform44.h:71
point rotatePivot
Definition transform44.h:67
quat rotate
Definition transform44.h:65
transform44(const transform44 &rhs)=default
constructor
const vec3 & getscale() const
get scale
Definition transform44.h:191
mat4 matrix
Definition transform44.h:70
void loadu(const scalar *ptr)
load content from unaligned memory
Definition transform44.h:105
const point & getposition() const
get position
Definition transform44.h:153
const mat4 & getoffset() const
get optional offset matrix
Definition transform44.h:249
void setrotate(const quat &r)
set rotate
Definition transform44.h:162
bool offsetValid
Definition transform44.h:72
void setrotatepivot(const point &p)
set optional rotate pivot
Definition transform44.h:200
const point & getscalepivot() const
get optional scale pivot
Definition transform44.h:229
const quat & getrotate() const
get rotate
Definition transform44.h:172
Different curves.
Definition angularpfeedbackloop.h:17
float scalar
Definition scalar.h:45
mat4 transformation(const vec3 &scalingCenter, const quat &scalingRotation, const vec3 &scale, const vec3 &rotationCenter, const quat &rotation, const vec3 &trans)
Definition mat4.cc:199
vec3 rotate(quat const &q, vec3 const &v)
Rotate a vector by a quaternion.
Definition quat.h:547
__forceinline vec3 xyz(const point &v)
Definition point.h:528
A 4x4 single point precision float matrix.
Definition mat4.h:49
void loadu(const scalar *ptr)
load content from unaligned memory
Definition mat4.h:215
void storeu(scalar *ptr) const
write content to unaligned memory through the write cache
Definition mat4.h:250
Represents a 3D point in space.
Definition point.h:22
void storeu(scalar *ptr) const
write content to unaligned memory through the write cache
Definition point.h:222
void loadu(const scalar *ptr)
load content from unaligned memory
Definition point.h:202
A quaternion is usually used to represent an orientation in 3D space.
Definition quat.h:30
void storeu(scalar *ptr) const
write content to unaligned memory through the write cache
Definition quat.h:183
void loadu(const scalar *ptr)
load content from unaligned memory
Definition quat.h:163
A 3D vector.
Definition vec3.h:40
void loadu(const scalar *ptr)
load content from unaligned memory
Definition vec3.h:173
void storeu(scalar *ptr) const
write content to unaligned memory through the write cache
Definition vec3.h:196
A 4D vector.
Definition vec4.h:24
bool operator==(const TiXmlString &a, const TiXmlString &b)
Definition tinystr.h:272
#define NEBULA_ALIGN16
Definition types.h:181