12 #ifndef __ICEMATRIX4X4_H__ 13 #define __ICEMATRIX4X4_H__ 19 #define MATRIX4X4_EPSILON (1.0e-7f) 31 float m10,
float m11,
float m12,
float m13,
32 float m20,
float m21,
float m22,
float m23,
33 float m30,
float m31,
float m32,
float m33)
35 m[0][0] = m00; m[0][1] = m01; m[0][2] = m02; m[0][3] = m03;
36 m[1][0] = m10; m[1][1] = m11; m[1][2] = m12; m[1][3] = m13;
37 m[2][0] = m20; m[2][1] = m21; m[2][2] = m22; m[2][3] = m23;
38 m[3][0] = m30; m[3][1] = m31; m[3][2] = m32; m[3][3] = m33;
47 float m10,
float m11,
float m12,
48 float m20,
float m21,
float m22)
50 m[0][0] = m00; m[0][1] = m01; m[0][2] = m02;
51 m[1][0] = m10; m[1][1] = m11; m[1][2] = m12;
52 m[2][0] = m20; m[2][1] = m21; m[2][2] = m22;
57 float m10,
float m11,
float m12,
float m13,
58 float m20,
float m21,
float m22,
float m23,
59 float m30,
float m31,
float m32,
float m33)
61 m[0][0] = m00; m[0][1] = m01; m[0][2] = m02; m[0][3] = m03;
62 m[1][0] = m10; m[1][1] = m11; m[1][2] = m12; m[1][3] = m13;
63 m[2][0] = m20; m[2][1] = m21; m[2][2] = m22; m[2][3] = m23;
64 m[3][0] = m30; m[3][1] = m31; m[3][2] = m32; m[3][3] = m33;
103 inline_ void SetTrans(
float tx,
float ty,
float tz) { m[3][0]=tx; m[3][1]=ty; m[3][2]=tz; }
109 inline_ void SetScale(
float sx,
float sy,
float sz) { m[0][0]=sx; m[1][1]=sy; m[2][2]=sz; }
113 m[0][0] *= p.
x; m[1][0] *= p.
y; m[2][0] *= p.
z;
114 m[0][1] *= p.
x; m[1][1] *= p.
y; m[2][1] *= p.
z;
115 m[0][2] *= p.
x; m[1][2] *= p.
y; m[2][2] *= p.
z;
118 void Scale(
float sx,
float sy,
float sz)
120 m[0][0] *= sx; m[1][0] *= sy; m[2][0] *= sz;
121 m[0][1] *= sx; m[1][1] *= sy; m[2][1] *= sz;
122 m[0][2] *= sx; m[1][2] *= sy; m[2][2] *= sz;
168 inline_ float Trace()
const {
return m[0][0] + m[1][1] + m[2][2] + m[3][3]; }
179 if(
IR(m[0][1])!=0)
return false;
180 if(
IR(m[0][2])!=0)
return false;
181 if(
IR(m[0][3])!=0)
return false;
183 if(
IR(m[1][0])!=0)
return false;
185 if(
IR(m[1][2])!=0)
return false;
186 if(
IR(m[1][3])!=0)
return false;
188 if(
IR(m[2][0])!=0)
return false;
189 if(
IR(m[2][1])!=0)
return false;
191 if(
IR(m[2][3])!=0)
return false;
193 if(
IR(m[3][0])!=0)
return false;
194 if(
IR(m[3][1])!=0)
return false;
195 if(
IR(m[3][2])!=0)
return false;
214 void RotX(
float angle) {
float Cos = cosf(angle), Sin = sinf(angle); Identity(); m[1][1] = m[2][2] = Cos; m[2][1] = -Sin; m[1][2] = Sin; }
216 void RotY(
float angle) {
float Cos = cosf(angle), Sin = sinf(angle); Identity(); m[0][0] = m[2][2] = Cos; m[2][0] = Sin; m[0][2] = -Sin; }
218 void RotZ(
float angle) {
float Cos = cosf(angle), Sin = sinf(angle); Identity(); m[0][0] = m[1][1] = Cos; m[1][0] = -Sin; m[0][1] = Sin; }
226 IR(m[1][0]) ^=
IR(m[0][1]);
IR(m[0][1]) ^=
IR(m[1][0]);
IR(m[1][0]) ^=
IR(m[0][1]);
227 IR(m[2][0]) ^=
IR(m[0][2]);
IR(m[0][2]) ^=
IR(m[2][0]);
IR(m[2][0]) ^=
IR(m[0][2]);
228 IR(m[3][0]) ^=
IR(m[0][3]);
IR(m[0][3]) ^=
IR(m[3][0]);
IR(m[3][0]) ^=
IR(m[0][3]);
229 IR(m[1][2]) ^=
IR(m[2][1]);
IR(m[2][1]) ^=
IR(m[1][2]);
IR(m[1][2]) ^=
IR(m[2][1]);
230 IR(m[1][3]) ^=
IR(m[3][1]);
IR(m[3][1]) ^=
IR(m[1][3]);
IR(m[1][3]) ^=
IR(m[3][1]);
231 IR(m[2][3]) ^=
IR(m[3][2]);
IR(m[3][2]) ^=
IR(m[2][3]);
IR(m[2][3]) ^=
IR(m[3][2]);
237 float Determinant()
const;
247 m[0][0], m[0][1], m[0][2],
248 m[1][0], m[1][1], m[1][2],
249 m[2][0], m[2][1], m[2][2]);
252 operator Quat()
const;
261 m[0][0]+mat.
m[0][0], m[0][1]+mat.
m[0][1], m[0][2]+mat.
m[0][2], m[0][3]+mat.
m[0][3],
262 m[1][0]+mat.
m[1][0], m[1][1]+mat.
m[1][1], m[1][2]+mat.
m[1][2], m[1][3]+mat.
m[1][3],
263 m[2][0]+mat.
m[2][0], m[2][1]+mat.
m[2][1], m[2][2]+mat.
m[2][2], m[2][3]+mat.
m[2][3],
264 m[3][0]+mat.
m[3][0], m[3][1]+mat.
m[3][1], m[3][2]+mat.
m[3][2], m[3][3]+mat.
m[3][3]);
271 m[0][0]-mat.
m[0][0], m[0][1]-mat.
m[0][1], m[0][2]-mat.
m[0][2], m[0][3]-mat.
m[0][3],
272 m[1][0]-mat.
m[1][0], m[1][1]-mat.
m[1][1], m[1][2]-mat.
m[1][2], m[1][3]-mat.
m[1][3],
273 m[2][0]-mat.
m[2][0], m[2][1]-mat.
m[2][1], m[2][2]-mat.
m[2][2], m[2][3]-mat.
m[2][3],
274 m[3][0]-mat.
m[3][0], m[3][1]-mat.
m[3][1], m[3][2]-mat.
m[3][2], m[3][3]-mat.
m[3][3]);
281 m[0][0]*mat.
m[0][0] + m[0][1]*mat.
m[1][0] + m[0][2]*mat.
m[2][0] + m[0][3]*mat.
m[3][0],
282 m[0][0]*mat.
m[0][1] + m[0][1]*mat.
m[1][1] + m[0][2]*mat.
m[2][1] + m[0][3]*mat.
m[3][1],
283 m[0][0]*mat.
m[0][2] + m[0][1]*mat.
m[1][2] + m[0][2]*mat.
m[2][2] + m[0][3]*mat.
m[3][2],
284 m[0][0]*mat.
m[0][3] + m[0][1]*mat.
m[1][3] + m[0][2]*mat.
m[2][3] + m[0][3]*mat.
m[3][3],
286 m[1][0]*mat.
m[0][0] + m[1][1]*mat.
m[1][0] + m[1][2]*mat.
m[2][0] + m[1][3]*mat.
m[3][0],
287 m[1][0]*mat.
m[0][1] + m[1][1]*mat.
m[1][1] + m[1][2]*mat.
m[2][1] + m[1][3]*mat.
m[3][1],
288 m[1][0]*mat.
m[0][2] + m[1][1]*mat.
m[1][2] + m[1][2]*mat.
m[2][2] + m[1][3]*mat.
m[3][2],
289 m[1][0]*mat.
m[0][3] + m[1][1]*mat.
m[1][3] + m[1][2]*mat.
m[2][3] + m[1][3]*mat.
m[3][3],
291 m[2][0]*mat.
m[0][0] + m[2][1]*mat.
m[1][0] + m[2][2]*mat.
m[2][0] + m[2][3]*mat.
m[3][0],
292 m[2][0]*mat.
m[0][1] + m[2][1]*mat.
m[1][1] + m[2][2]*mat.
m[2][1] + m[2][3]*mat.
m[3][1],
293 m[2][0]*mat.
m[0][2] + m[2][1]*mat.
m[1][2] + m[2][2]*mat.
m[2][2] + m[2][3]*mat.
m[3][2],
294 m[2][0]*mat.
m[0][3] + m[2][1]*mat.
m[1][3] + m[2][2]*mat.
m[2][3] + m[2][3]*mat.
m[3][3],
296 m[3][0]*mat.
m[0][0] + m[3][1]*mat.
m[1][0] + m[3][2]*mat.
m[2][0] + m[3][3]*mat.
m[3][0],
297 m[3][0]*mat.
m[0][1] + m[3][1]*mat.
m[1][1] + m[3][2]*mat.
m[2][1] + m[3][3]*mat.
m[3][1],
298 m[3][0]*mat.
m[0][2] + m[3][1]*mat.
m[1][2] + m[3][2]*mat.
m[2][2] + m[3][3]*mat.
m[3][2],
299 m[3][0]*mat.
m[0][3] + m[3][1]*mat.
m[1][3] + m[3][2]*mat.
m[2][3] + m[3][3]*mat.
m[3][3]);
308 return Point( m[0][0]*v.
x + m[0][1]*v.
y + m[0][2]*v.
z + m[0][3],
309 m[1][0]*v.
x + m[1][1]*v.
y + m[1][2]*v.
z + m[1][3],
310 m[2][0]*v.
x + m[2][1]*v.
y + m[2][2]*v.
z + m[2][3] );
317 m[0][0]*s, m[0][1]*s, m[0][2]*s, m[0][3]*s,
318 m[1][0]*s, m[1][1]*s, m[1][2]*s, m[1][3]*s,
319 m[2][0]*s, m[2][1]*s, m[2][2]*s, m[2][3]*s,
320 m[3][0]*s, m[3][1]*s, m[3][2]*s, m[3][3]*s);
327 s*mat.
m[0][0], s*mat.
m[0][1], s*mat.
m[0][2], s*mat.
m[0][3],
328 s*mat.
m[1][0], s*mat.
m[1][1], s*mat.
m[1][2], s*mat.
m[1][3],
329 s*mat.
m[2][0], s*mat.
m[2][1], s*mat.
m[2][2], s*mat.
m[2][3],
330 s*mat.
m[3][0], s*mat.
m[3][1], s*mat.
m[3][2], s*mat.
m[3][3]);
339 m[0][0]*s, m[0][1]*s, m[0][2]*s, m[0][3]*s,
340 m[1][0]*s, m[1][1]*s, m[1][2]*s, m[1][3]*s,
341 m[2][0]*s, m[2][1]*s, m[2][2]*s, m[2][3]*s,
342 m[3][0]*s, m[3][1]*s, m[3][2]*s, m[3][3]*s);
349 s/mat.
m[0][0], s/mat.
m[0][1], s/mat.
m[0][2], s/mat.
m[0][3],
350 s/mat.
m[1][0], s/mat.
m[1][1], s/mat.
m[1][2], s/mat.
m[1][3],
351 s/mat.
m[2][0], s/mat.
m[2][1], s/mat.
m[2][2], s/mat.
m[2][3],
352 s/mat.
m[3][0], s/mat.
m[3][1], s/mat.
m[3][2], s/mat.
m[3][3]);
358 m[0][0]+=mat.
m[0][0]; m[0][1]+=mat.
m[0][1]; m[0][2]+=mat.
m[0][2]; m[0][3]+=mat.
m[0][3];
359 m[1][0]+=mat.
m[1][0]; m[1][1]+=mat.
m[1][1]; m[1][2]+=mat.
m[1][2]; m[1][3]+=mat.
m[1][3];
360 m[2][0]+=mat.
m[2][0]; m[2][1]+=mat.
m[2][1]; m[2][2]+=mat.
m[2][2]; m[2][3]+=mat.
m[2][3];
361 m[3][0]+=mat.
m[3][0]; m[3][1]+=mat.
m[3][1]; m[3][2]+=mat.
m[3][2]; m[3][3]+=mat.
m[3][3];
368 m[0][0]-=mat.
m[0][0]; m[0][1]-=mat.
m[0][1]; m[0][2]-=mat.
m[0][2]; m[0][3]-=mat.
m[0][3];
369 m[1][0]-=mat.
m[1][0]; m[1][1]-=mat.
m[1][1]; m[1][2]-=mat.
m[1][2]; m[1][3]-=mat.
m[1][3];
370 m[2][0]-=mat.
m[2][0]; m[2][1]-=mat.
m[2][1]; m[2][2]-=mat.
m[2][2]; m[2][3]-=mat.
m[2][3];
371 m[3][0]-=mat.
m[3][0]; m[3][1]-=mat.
m[3][1]; m[3][2]-=mat.
m[3][2]; m[3][3]-=mat.
m[3][3];
381 m[0][0] = TempRow.
x*mat.
m[0][0] + TempRow.
y*mat.
m[1][0] + TempRow.
z*mat.
m[2][0] + TempRow.
w*mat.
m[3][0];
382 m[0][1] = TempRow.
x*mat.
m[0][1] + TempRow.
y*mat.
m[1][1] + TempRow.
z*mat.
m[2][1] + TempRow.
w*mat.
m[3][1];
383 m[0][2] = TempRow.
x*mat.
m[0][2] + TempRow.
y*mat.
m[1][2] + TempRow.
z*mat.
m[2][2] + TempRow.
w*mat.
m[3][2];
384 m[0][3] = TempRow.
x*mat.
m[0][3] + TempRow.
y*mat.
m[1][3] + TempRow.
z*mat.
m[2][3] + TempRow.
w*mat.
m[3][3];
387 m[1][0] = TempRow.
x*mat.
m[0][0] + TempRow.
y*mat.
m[1][0] + TempRow.
z*mat.
m[2][0] + TempRow.
w*mat.
m[3][0];
388 m[1][1] = TempRow.
x*mat.
m[0][1] + TempRow.
y*mat.
m[1][1] + TempRow.
z*mat.
m[2][1] + TempRow.
w*mat.
m[3][1];
389 m[1][2] = TempRow.
x*mat.
m[0][2] + TempRow.
y*mat.
m[1][2] + TempRow.
z*mat.
m[2][2] + TempRow.
w*mat.
m[3][2];
390 m[1][3] = TempRow.
x*mat.
m[0][3] + TempRow.
y*mat.
m[1][3] + TempRow.
z*mat.
m[2][3] + TempRow.
w*mat.
m[3][3];
393 m[2][0] = TempRow.
x*mat.
m[0][0] + TempRow.
y*mat.
m[1][0] + TempRow.
z*mat.
m[2][0] + TempRow.
w*mat.
m[3][0];
394 m[2][1] = TempRow.
x*mat.
m[0][1] + TempRow.
y*mat.
m[1][1] + TempRow.
z*mat.
m[2][1] + TempRow.
w*mat.
m[3][1];
395 m[2][2] = TempRow.
x*mat.
m[0][2] + TempRow.
y*mat.
m[1][2] + TempRow.
z*mat.
m[2][2] + TempRow.
w*mat.
m[3][2];
396 m[2][3] = TempRow.
x*mat.
m[0][3] + TempRow.
y*mat.
m[1][3] + TempRow.
z*mat.
m[2][3] + TempRow.
w*mat.
m[3][3];
399 m[3][0] = TempRow.
x*mat.
m[0][0] + TempRow.
y*mat.
m[1][0] + TempRow.
z*mat.
m[2][0] + TempRow.
w*mat.
m[3][0];
400 m[3][1] = TempRow.
x*mat.
m[0][1] + TempRow.
y*mat.
m[1][1] + TempRow.
z*mat.
m[2][1] + TempRow.
w*mat.
m[3][1];
401 m[3][2] = TempRow.
x*mat.
m[0][2] + TempRow.
y*mat.
m[1][2] + TempRow.
z*mat.
m[2][2] + TempRow.
w*mat.
m[3][2];
402 m[3][3] = TempRow.
x*mat.
m[0][3] + TempRow.
y*mat.
m[1][3] + TempRow.
z*mat.
m[2][3] + TempRow.
w*mat.
m[3][3];
410 m[0][0]*=s; m[0][1]*=s; m[0][2]*=s; m[0][3]*=s;
411 m[1][0]*=s; m[1][1]*=s; m[1][2]*=s; m[1][3]*=s;
412 m[2][0]*=s; m[2][1]*=s; m[2][2]*=s; m[2][3]*=s;
413 m[3][0]*=s; m[3][1]*=s; m[3][2]*=s; m[3][3]*=s;
421 m[0][0]*=s; m[0][1]*=s; m[0][2]*=s; m[0][3]*=s;
422 m[1][0]*=s; m[1][1]*=s; m[1][2]*=s; m[1][3]*=s;
423 m[2][0]*=s; m[2][1]*=s; m[2][2]*=s; m[2][3]*=s;
424 m[3][0]*=s; m[3][1]*=s; m[3][2]*=s; m[3][3]*=s;
439 dest.
x = rot.
m[3][0] + source.
x * rot.
m[0][0] + source.
y * rot.
m[1][0] + source.
z * rot.
m[2][0];
440 dest.
y = rot.
m[3][1] + source.
x * rot.
m[0][1] + source.
y * rot.
m[1][1] + source.
z * rot.
m[2][1];
441 dest.
z = rot.
m[3][2] + source.
x * rot.
m[0][2] + source.
y * rot.
m[1][2] + source.
z * rot.
m[2][2];
447 dest.
x = source.
x * rot.
m[0][0] + source.
y * rot.
m[1][0] + source.
z * rot.
m[2][0];
448 dest.
y = source.
x * rot.
m[0][1] + source.
y * rot.
m[1][1] + source.
z * rot.
m[2][1];
449 dest.
z = source.
x * rot.
m[0][2] + source.
y * rot.
m[1][2] + source.
z * rot.
m[2][2];
454 #endif // __ICEMATRIX4X4_H__ inline_ void SetTrans(const HPoint &p)
Sets the translation part of the matrix, from a HPoint.
inline_ Matrix4x4 operator-(const Matrix4x4 &mat) const
Operator for Matrix4x4 Minus = Matrix4x4 - Matrix4x4;.
inline_ void SetRow(const udword r, const Point &p)
Sets a row.
#define IR(x)
Integer representation of a floating-point value.
inline_ Matrix4x4 operator*(const Matrix4x4 &mat) const
Operator for Matrix4x4 Mul = Matrix4x4 * Matrix4x4;.
inline_ void Copy(const Matrix4x4 &source)
Copy from a Matrix4x4.
inline_ Matrix4x4 & operator*=(float s)
Operator for Matrix4x4 *= float;.
inline_ void SetTrans(const Point &p)
Sets the translation part of the matrix, from a Point.
inline_ void GetCol(const udword c, HPoint &p) const
Returns a column.
inline_ void GetRow(const udword r, Point &p) const
Returns a row.
inline_ Matrix4x4 & Set(float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, float m20, float m21, float m22, float m23, float m30, float m31, float m32, float m33)
Assign values.
void RotY(float angle)
Sets a rotation matrix around the Y axis.
inline_ ~Matrix4x4()
Destructor.
inline_ Matrix4x4 operator*(float s) const
Operator for Matrix4x4 Scale = Matrix4x4 * float;.
inline_ HPoint & operator[](int row)
inline_ friend Matrix4x4 operator*(float s, const Matrix4x4 &mat)
Operator for Matrix4x4 Scale = float * Matrix4x4;.
inline_ void SetRow(const udword r, const HPoint &p)
Sets a row.
inline_ bool IsIdentity() const
Checks for identity.
void Scale(const Point &p)
Scales from a Point. Each row is multiplied by a component.
int BOOL
Another boolean type.
inline_ const HPoint & GetRow(const udword r) const
Returns a row.
unsigned int udword
sizeof(udword) must be 4
inline_ Matrix4x4 & Set(float m00, float m01, float m02, float m10, float m11, float m12, float m20, float m21, float m22)
Assign values (rotation only)
inline_ Matrix4x4 & operator/=(float s)
Operator for Matrix4x4 /= float;.
inline_ void TransformPoint4x3(Point &dest, const Point &source, const Matrix4x4 &rot)
Quickly rotates & translates a vector, using the 4x3 part of a 4x4 matrix.
inline_ Matrix4x4(float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, float m20, float m21, float m22, float m23, float m30, float m31, float m32, float m33)
Constructor from 16 values.
def j(str, encoding="cp932")
inline_ Matrix4x4 operator/(float s) const
Operator for Matrix4x4 Div = Matrix4x4 / float;.
Matrix4x4 & operator*=(const Matrix4x4 &mat)
Operator for Matrix4x4 *= Matrix4x4;.
inline_ friend Matrix4x4 operator/(float s, const Matrix4x4 &mat)
Operator for Matrix4x4 Div = float / Matrix4x4;.
inline_ Matrix4x4 & operator-=(const Matrix4x4 &mat)
Operator for Matrix4x4 -= Matrix4x4;.
inline_ void Zero()
Clears the matrix.
void RotZ(float angle)
Sets a rotation matrix around the Z axis.
inline_ void TransformPoint3x3(Point &dest, const Point &source, const Matrix4x4 &rot)
Quickly rotates a vector, using the 3x3 part of a 4x4 matrix.
inline_ void SetScale(const Point &p)
Sets the scale from a Point. The point is put on the diagonal.
inline_ bool IsValidFloat(float value)
inline_ void SetCol(const udword c, const HPoint &p)
Sets a column.
inline_ float Trace() const
Computes the trace. The trace is the sum of the 4 diagonal components.
inline_ void SetScale(float sx, float sy, float sz)
Sets the scale from floats. Values are put on the diagonal.
inline_ void SetCol(const udword c, const Point &p)
Sets a column.
inline_ Matrix4x4()
Empty constructor.
ICEMATHS_API void InvertPRMatrix(Matrix4x4 &dest, const Matrix4x4 &src)
inline_ void CopyMemory(void *dest, const void *src, udword size)
inline_ void GetTrans(Point &p) const
Gets the translation part of the matrix.
float w
Cast a HPoint to a Point. w is discarded.
inline_ HPoint & GetRow(const udword r)
Returns a row.
void Transpose()
Transposes the matrix.
inline_ void GetCol(const udword c, Point &p) const
Returns a column.
inline_ Matrix4x4 & operator+=(const Matrix4x4 &mat)
Operator for Matrix4x4 += Matrix4x4;.
#define IEEE_1_0
integer representation of 1.0
inline_ void ZeroMemory(void *addr, udword size)
inline_ Matrix4x4 operator+(const Matrix4x4 &mat) const
Operator for Matrix4x4 Plus = Matrix4x4 + Matrix4x4;.
inline_ void Identity()
Sets the identity matrix.
inline_ BOOL IsValid() const
Checks matrix validity.
void RotX(float angle)
Sets a rotation matrix around the X axis.
void Scale(float sx, float sy, float sz)
Scales from floats. Each row is multiplied by a value.
inline_ const HPoint & GetTrans() const
Returns the translation part of the matrix.
inline_ void GetRow(const udword r, HPoint &p) const
Returns a row.
inline_ Point operator*(const Point &v) const
Operator for Point Mul = Matrix4x4 * Point;.
inline_ void SetTrans(float tx, float ty, float tz)
Sets the translation part of the matrix, from floats.
inline_ Matrix4x4(const Matrix4x4 &mat)
Copy constructor.
inline_ const HPoint & operator[](int row) const
inline_ HPoint operator*(const HPoint &v) const
Operator for HPoint Mul = Matrix4x4 * HPoint;.
inline_ float Trace3x3() const
Computes the trace of the upper 3x3 matrix.