7 #include "VectorMathDecl.h"
22 v2 (
float x,
float y );
25 void Set (
const v2& src );
26 void Set (
float x,
float y );
32 void SetX (
float data );
33 void SetY (
float data );
38 static v2 Add (
const v2& src1,
const v2& src2 );
39 static v2 Sub (
const v2& src1,
const v2& src2 );
40 static v2 Mul (
const v2& src1,
const v2& src2 );
41 static v2 Div (
const v2& src1,
const v2& src2 );
43 static v2 Scale (
const v2& src1,
float scale );
44 static v2 InvScale (
const v2& src1,
float scale );
46 static v2 Neg (
const v2& src );
47 static v2 Abs(
const v2& src);
49 static float Dot (
const v2& src1,
const v2& src2 );
51 static v2 Lerp (
const v2& src1,
const v2& src2,
float ratio );
53 float Length ()
const;
54 float LengthSq ()
const;
57 bool operator== (
const v2 &rhs)
const;
58 bool operator!= (
const v2 &rhs)
const;
60 v2 operator - ( )
const;
62 v2 operator + (
const v2& rhs )
const;
63 v2 operator - (
const v2& rhs )
const;
64 v2 operator * (
const v2& rhs )
const;
65 v2 operator / (
const v2& rhs )
const;
66 v2 operator * (
const float rhs )
const;
67 v2 operator / (
const float rhs )
const;
69 v2& operator += (
const v2& rhs );
70 v2& operator -= (
const v2& rhs );
71 v2& operator *= (
const v2& rhs );
72 v2& operator /= (
const v2& rhs );
74 v2& operator *= (
const float rhs );
75 v2& operator /= (
const float rhs );
77 static v2 Min(
const v2& src1,
const v2& src2 );
78 static v2 Max(
const v2& src1,
const v2& src2 );
79 static bool IsFinite(
const v2& v);
82 static const v2 Zero();
83 static const v2 One();
86 v2 operator * (
const float lhs,
const v2& rhs);
96 dv2 (
double x,
double y );
99 void Set (
const dv2& src );
100 void Set (
double x,
double y );
103 double GetX ()
const;
104 double GetY ()
const;
106 void SetX (
double data );
107 void SetY (
double data );
112 static dv2 Add (
const dv2& src1,
const dv2& src2 );
113 static dv2 Sub (
const dv2& src1,
const dv2& src2 );
114 static dv2 Mul (
const dv2& src1,
const dv2& src2 );
115 static dv2 Div (
const dv2& src1,
const dv2& src2 );
117 static dv2 Scale (
const dv2& src1,
double scale );
118 static dv2 InvScale (
const dv2& src1,
double scale );
120 static dv2 Neg (
const dv2& src );
122 static double Dot (
const dv2& src1,
const dv2& src2 );
124 static dv2 Lerp (
const dv2& src1,
const dv2& src2,
double ratio );
126 double Length ()
const;
127 double LengthSq ()
const;
130 static v2 ToSingle(
const dv2& src);
133 dv2 operator - ( )
const;
135 dv2 operator + (
const dv2& rhs )
const;
136 dv2 operator - (
const dv2& rhs )
const;
137 dv2 operator * (
const dv2& rhs )
const;
138 dv2 operator / (
const dv2& rhs )
const;
139 dv2 operator * (
const double rhs )
const;
140 dv2 operator / (
const double rhs )
const;
142 dv2& operator += (
const dv2& rhs );
143 dv2& operator -= (
const dv2& rhs );
144 dv2& operator *= (
const dv2& rhs );
145 dv2& operator /= (
const dv2& rhs );
147 dv2& operator *= (
const double rhs );
148 dv2& operator /= (
const double rhs );
150 static dv2 Min(
const dv2& src1,
const dv2& src2 );
151 static dv2 Max(
const dv2& src1,
const dv2& src2 );
152 static bool IsFinite(
const dv2& v);
154 static const dv2 Zero();
155 static const dv2 One();
158 dv2 operator * (
const double lhs,
const dv2& );
177 v3 (
const v3& src );
178 v3 (
float x,
float y,
float z );
179 v3 (
const float* pSrc );
180 v3 (
const v4& src );
181 v3& operator= (
const v3& rhs);
183 void Set (
float x,
float y,
float z );
190 void SetX (
float data );
191 void SetY (
float data );
192 void SetZ (
float data );
198 static v3 Add (
const v3& src1,
const v3& src2 );
199 static v3 Sub (
const v3& src1,
const v3& src2 );
200 static v3 Mul (
const v3& src1,
const v3& src2 );
201 static v3 Div (
const v3& src1,
const v3& src2 );
203 static v3 Scale (
const v3& src1,
float scale );
204 static v3 InvScale (
const v3& src1,
float scale );
206 static v3 Neg (
const v3& src );
208 static float Dot (
const v3& src1,
const v3& src2 );
209 static v3 Cross (
const v3& src1,
const v3& src2 );
211 static v3 Lerp (
const v3& src1,
const v3& src2,
float ratio );
213 static v3 Mul (
const v3& src,
const m33& matrix );
214 static v3 Mul (
const v3& src,
const m44& matrix );
215 static v3 MulRotate (
const v3& src,
const m44& matrix );
216 static v3 Clamped (
const v3& src,
float maxLength);
217 static v3 Abs(
const v3& src);
218 inline float SquareDistanceTo(
const v3& a )
const;
220 float Length ()
const;
221 float LengthSq ()
const;
224 bool operator== (
const v3 &rhs)
const;
225 bool operator!= (
const v3 &rhs)
const;
227 v3 operator - ( )
const;
229 v3 operator + (
const v3& rhs )
const;
230 v3 operator - (
const v3& rhs )
const;
231 v3 operator * (
const v3& rhs )
const;
232 v3 operator / (
const v3& rhs )
const;
233 v3 operator * (
const float rhs )
const;
234 v3 operator / (
const float rhs )
const;
236 v3& operator += (
const v3& rhs );
237 v3& operator -= (
const v3& rhs );
238 v3& operator *= (
const v3& rhs );
239 v3& operator /= (
const v3& rhs );
241 v3& operator *= (
const float rhs );
242 v3& operator /= (
const float rhs );
244 static v3 Min(
const v3& src1,
const v3& src2 );
245 static v3 Max(
const v3& src1,
const v3& src2 );
246 static bool IsFinite(
const v3& v);
248 static const v3 Zero();
249 static const v3 One();
252 v3 operator * (
const float lhs,
const v3& rhs);
267 dv3 ( ) : x(0.0), y(0.0), z(0.0) {};
270 dv3 (
double x,
double y,
double z );
271 dv3 (
const double* pSrc );
272 dv3 (
const v4& src );
274 dv3 (
const v3& src );
276 void Set (
double x,
double y,
double z );
279 double GetX ()
const;
280 double GetY ()
const;
281 double GetZ ()
const;
283 void SetX (
double data );
284 void SetY (
double data );
285 void SetZ (
double data );
291 static dv3 Add (
const dv3& src1,
const dv3& src2 );
292 static dv3 Sub (
const dv3& src1,
const dv3& src2 );
293 static dv3 Mul (
const dv3& src1,
const dv3& src2 );
294 static dv3 Div (
const dv3& src1,
const dv3& src2 );
296 static dv3 Add (
const dv3& src1,
const v3& src2 );
297 static dv3 Sub (
const dv3& src1,
const v3& src2 );
298 static dv3 Mul (
const dv3& src1,
const v3& src2 );
299 static dv3 Div (
const dv3& src1,
const v3& src2 );
301 static dv3 Scale (
const dv3& src1,
double scale );
302 static dv3 InvScale (
const dv3& src1,
double scale );
304 static dv3 Neg (
const dv3& src );
306 static double Dot (
const dv3& src1,
const dv3& src2 );
307 static dv3 Cross (
const dv3& src1,
const dv3& src2 );
309 static dv3 Lerp (
const dv3& src1,
const dv3& src2,
double ratio );
311 static dv3 Mul (
const dv3& src,
const m33& matrix );
312 static dv3 Mul (
const dv3& src,
const m44& matrix );
313 static dv3 MulRotate (
const dv3& src,
const m44& matrix );
314 static dv3 Mul (
const dv3& src,
const dm33& matrix);
315 static dv3 Mul (
const dv3& src,
const dm44& matrix );
316 static dv3 MulRotate (
const dv3& src,
const dm44& matrix );
318 static v3 ToSingle(
const dv3& src);
319 static dv3 FromSingle(
const v3& src);
321 inline double SquareDistanceTo(
const dv3& a)
const;
323 double Length ()
const;
324 double LengthSq ()
const;
329 dv3 operator - ( )
const;
331 dv3 operator + (
const dv3& rhs )
const;
332 dv3 operator - (
const dv3& rhs )
const;
333 dv3 operator * (
const dv3& rhs )
const;
334 dv3 operator / (
const dv3& rhs )
const;
335 dv3 operator * (
const double rhs )
const;
336 dv3 operator / (
const double rhs )
const;
338 dv3& operator += (
const dv3& rhs );
339 dv3& operator -= (
const dv3& rhs );
340 dv3& operator *= (
const dv3& rhs );
341 dv3& operator /= (
const dv3& rhs );
343 dv3& operator *= (
const double rhs );
344 dv3& operator /= (
const double rhs );
346 dv3 operator + (
const v3& rhs )
const;
347 dv3 operator - (
const v3& rhs )
const;
348 dv3 operator * (
const v3& rhs )
const;
349 dv3 operator / (
const v3& rhs )
const;
350 dv3 operator * (
const float rhs )
const;
351 dv3 operator / (
const float rhs )
const;
353 dv3& operator += (
const v3& rhs );
354 dv3& operator -= (
const v3& rhs );
355 dv3& operator *= (
const v3& rhs );
356 dv3& operator /= (
const v3& rhs );
358 static dv3 Min(
const dv3& src1,
const dv3& src2 );
359 static dv3 Max(
const dv3& src1,
const dv3& src2 );
360 static bool IsFinite(
const dv3& v);
363 static const dv3 Zero();
364 static const dv3 One();
367 dv3 operator * (
const double lhs,
const dv3& rhs);
386 v4 (
const v4& src );
387 v4 (
float x,
float y,
float z,
float w );
388 v4 (
const v3& src,
float w );
390 void Set (
float x,
float y,
float z,
float w );
398 void SetX (
float data );
399 void SetY (
float data );
400 void SetZ (
float data );
401 void SetW (
float data );
408 void Load (
const float* pSrc );
409 void Store (
float* pDest )
const;
412 static v4 Add (
const v4& src1,
const v4& src2 );
413 static v4 Sub (
const v4& src1,
const v4& src2 );
414 static v4 Mul (
const v4& src1,
const v4& src2 );
415 static v4 Div (
const v4& src1,
const v4& src2 );
416 static v4 Dot (
const v4& src1,
const v4& src2 );
418 static v4 Lerp (
const v4& src1,
const v4& src2,
float ratio );
420 static v4 Mul (
const v4& src,
const m44& matrix );
421 static v4 MulTransposed (
const v4& src,
const m44& matrix );
422 static v4 Neg(
const v4& src);
425 v4 LengthSq ()
const;
428 bool operator== (
const v4 &rhs)
const;
429 bool operator!= (
const v4 &rhs)
const;
431 v4 operator - ()
const;
433 v4 operator + (
const v4& rhs )
const;
434 v4 operator - (
const v4& rhs )
const;
435 v4 operator * (
const v4& rhs )
const;
436 v4 operator / (
const v4& rhs )
const;
437 v4 operator * (
const float rhs )
const;
438 v4 operator / (
const float rhs )
const;
440 v4& operator += (
const v4& rhs );
441 v4& operator -= (
const v4& rhs );
442 v4& operator *= (
const v4& rhs );
443 v4& operator /= (
const v4& rhs );
445 v4& operator *= (
const float rhs );
446 v4& operator /= (
const float rhs );
448 static v4 Min(
const v4& src1,
const v4& src2 );
449 static v4 Max(
const v4& src1,
const v4& src2 );
450 static bool IsFinite(
const v4& v);
452 const static v4 Zero();
453 const static v4 One();
476 dv4 (
double x,
double y,
double z,
double w );
477 dv4 (
const double* pSrc );
478 dv4 (
const v3& src );
480 dv4 (
const dv3& src,
double w );
481 dv4 (
const v4& src );
483 void Set (
double x,
double y,
double z,
double w );
487 double GetX ()
const;
488 double GetY ()
const;
489 double GetZ ()
const;
490 double GetW ()
const;
492 void SetX (
double data );
493 void SetY (
double data );
494 void SetZ (
double data );
495 void SetW (
double data );
502 static dv4 Add (
const dv4& src1,
const dv4& src2 );
503 static dv4 Sub (
const dv4& src1,
const dv4& src2 );
504 static dv4 Mul (
const dv4& src1,
const dv4& src2 );
505 static dv4 Div (
const dv4& src1,
const dv4& src2 );
507 static dv4 Add (
const dv4& src1,
const v4& src2 );
508 static dv4 Sub (
const dv4& src1,
const v4& src2 );
509 static dv4 Mul (
const dv4& src1,
const v4& src2 );
510 static dv4 Div (
const dv4& src1,
const v4& src2 );
512 static dv4 Scale (
const dv4& src1,
double scale );
513 static dv4 InvScale (
const dv4& src1,
double scale );
515 static dv4 Neg (
const dv4& src );
517 static double Dot (
const dv4& src1,
const dv4& src2 );
519 static dv4 Lerp (
const dv4& src1,
const dv4& src2,
double ratio );
521 static dv4 Mul (
const dv4& src,
const m44& matrix );
522 static dv4 MulTransposed (
const dv4& src,
const m44& matrix );
524 static v4 ToSingle(
const dv4& src);
525 static dv4 FromSingle(
const v4& src);
527 double Length ()
const;
528 double LengthSq ()
const;
533 dv4 operator - ( )
const;
535 dv4 operator + (
const dv4& rhs )
const;
536 dv4 operator - (
const dv4& rhs )
const;
537 dv4 operator * (
const dv4& rhs )
const;
538 dv4 operator / (
const dv4& rhs )
const;
539 dv4 operator * (
const double rhs )
const;
540 dv4 operator / (
const double rhs )
const;
542 dv4& operator += (
const dv4& rhs );
543 dv4& operator -= (
const dv4& rhs );
544 dv4& operator *= (
const dv4& rhs );
545 dv4& operator /= (
const dv4& rhs );
547 dv4& operator *= (
const double rhs );
548 dv4& operator /= (
const double rhs );
550 dv4 operator + (
const v4& rhs )
const;
551 dv4 operator - (
const v4& rhs )
const;
552 dv4 operator * (
const v4& rhs )
const;
553 dv4 operator / (
const v4& rhs )
const;
554 dv4 operator * (
const float rhs )
const;
555 dv4 operator / (
const float rhs )
const;
557 dv4& operator += (
const v4& rhs );
558 dv4& operator -= (
const v4& rhs );
559 dv4& operator *= (
const v4& rhs );
560 dv4& operator /= (
const v4& rhs );
562 static dv4 Min(
const dv4& src1,
const dv4& src2 );
563 static dv4 Max(
const dv4& src1,
const dv4& src2 );
564 static bool IsFinite(
const dv4& v);
566 static const dv4 Zero();
567 static const dv4 One();
581 static void Transpose (
m33& dst,
const m33& src );
584 static bool Decompose (
const m33& src,
v3& outScale,
Quaternion& outRotation);
586 void SetRow (
int row,
const v3& data );
587 void SetFromBasis(
const v3& right,
const v3& up,
const v3& forward);
588 v3 GetRow (
int row )
const;
590 void Scale (
float scale );
591 void Scale (
const v3& scale );
593 void RotateX (
float theta );
594 void RotateY (
float theta );
595 void RotateZ (
float theta );
596 void Rotate (
float x,
float y,
float z );
597 void Rotate (
const v3& axis,
float angle );
599 static void Inverse (
m33& dst,
const m33& src );
600 static void Mul (
m33& dst,
const m33& src1,
const m33& src2 );
601 void Mul (
const float scale );
605 static m33 CreateIdentity();
611 double _11, _12, _13;
612 double _21, _22, _23;
613 double _31, _32, _33;
626 static void Transpose (
dm33& dst,
const dm33& src );
631 void SetRow (
int row,
const dv3& data );
632 void SetFromBasis(
const dv3& right,
const dv3& up,
const dv3& forward);
633 dv3 GetRow (
int row )
const;
635 void Scale (
double scale );
636 void Scale (
const dv3& scale );
638 void RotateX (
double theta );
639 void RotateY (
double theta );
640 void RotateZ (
double theta );
641 void Rotate (
double x,
double y,
double z );
642 void Rotate (
const dv3& axis,
double angle );
644 static void Inverse (
dm33& dst,
const dm33& src );
645 static void Mul (
dm33& dst,
const dm33& src1,
const dm33& src2 );
646 void Mul (
const double scale );
662 m44 (
const v4& row0,
const v4& row1,
const v4& row2,
const v4& row3 );
663 m44 (
float values[16]);
664 void SetRow (
int row,
const v4& data ) { m_rows[row] = data; }
665 void SetFromBasis(
const v3& right,
const v3& up,
const v3& forward,
const v3& pos);
666 const v4& GetRow (
int row )
const {
return m_rows[row]; }
668 void Load (
const float* pSrc );
669 void Store (
float* pDest )
const;
671 bool operator== (
const m44 &rhs)
const;
672 bool operator!= (
const m44 &rhs)
const;
675 bool IsIdentity ()
const;
676 void Scale (
float scale );
677 void Scale (
const v3& scale );
679 void OrthProjection (
float left,
float right,
float top,
float bottom,
float near,
float far,
float scale);
680 void Projection (
float fovyRadians,
float aspect,
float nearZ,
float farZ);
682 void RotateX (
float theta );
683 void RotateY (
float theta );
684 void RotateZ (
float theta );
685 void Rotate (
float x,
float y,
float z );
686 void Rotate (
const v3& axis,
float angle );
688 bool Decompose (
v3& outScale,
Quaternion& outRotation,
v3& outTranslation);
689 static bool Decompose (
const m44& src,
v3& outScale,
Quaternion& outRotation,
v3& outTranslation);
691 static void Transpose (
m44& dst,
const m44& src );
692 static void Inverse (
m44& dst,
const m44& src );
693 static void OrthoInverse(
m44& dst,
const m44& src );
694 static void Mul (
m44& dst,
const m44& src1,
const m44& src2 );
695 void Mul (
const float scale );
696 static void Lerp (
m44& dst,
const m44& from,
const m44& to,
float t );
698 static float Determinant33(
const m44& src);
700 static const m44 Zero();
702 static m44 CreateIdentity();
703 static m44 CreateTranslate(
const v3& translate);
704 static m44 CreateScale(
const v3& scale);
705 static m44 CreateFromRowMajorElements(
const float* pRowMajorElements );
722 dm44 (
const dv4& row0,
const dv4& row1,
const dv4& row2,
const dv4& row3 );
723 void SetRow (
int row,
const dv4& data ) { m_rows[row] = data; }
724 void SetFromBasis(
const dv3& right,
const dv3& up,
const dv3& forward,
const dv3& pos);
725 const dv4& GetRow (
int row )
const {
return m_rows[row]; }
728 void Scale (
double scale );
729 void Scale (
const dv3& scale );
731 void OrthProjection (
double left,
double right,
double top,
double bottom,
double near,
double far,
double scale);
732 void Projection (
double fovyRadians,
double aspect,
double nearZ,
double farZ);
734 void RotateX (
double theta );
735 void RotateY (
double theta );
736 void RotateZ (
double theta );
737 void Rotate (
double x,
double y,
double z );
738 void Rotate (
const dv3& axis,
double angle );
740 bool Decompose (
dv3& outScale,
Quaternion& outRotation,
dv3& outTranslation);
741 static bool Decompose (
const dm44& src,
dv3& outScale,
Quaternion& outRotation,
dv3& outTranslation);
743 static void Transpose (
dm44& dst,
const dm44& src );
744 static void Inverse (
dm44& dst,
const dm44& src );
745 static void OrthoInverse(
dm44& dst,
const dm44& src );
746 static void Mul (
dm44& dst,
const dm44& src1,
const dm44& src2 );
747 void Mul (
const double scale );
753 inline v2::v2(
const v2& src )
759 inline v2::v2(
float _x,
float _y )
765 inline v2::v2(
float* pSrc )
771 inline void v2::Set(
const v2& src )
777 inline void v2::Set(
float _x,
float _y )
783 inline void v2::SetZero()
789 inline v2 v2::SplatX()
const
794 inline v2 v2::SplatY()
const
799 inline float v2::GetX()
const
804 inline float v2::GetY()
const
809 inline void v2::SetX(
float data )
814 inline void v2::SetY(
float data )
820 inline v2 v2::Add(
const v2& src1,
const v2& src2 )
822 return v2(src1.x + src2.x, src1.y + src2.y);
825 inline v2 v2::Sub(
const v2& src1,
const v2& src2 )
827 return v2(src1.x - src2.x, src1.y - src2.y);
830 inline v2 v2::Mul(
const v2& src1,
const v2& src2 )
832 return v2(src1.x * src2.x, src1.y * src2.y);
835 inline v2 v2::Div(
const v2& src1,
const v2& src2 )
837 return v2(src1.x / src2.x, src1.y / src2.y);
840 inline float v2::Dot(
const v2& src1,
const v2& src2 )
842 float dot = src1.x * src2.x + src1.y * src2.y;
846 inline v2 v2::Lerp(
const v2& src1,
const v2& src2,
float ratio )
848 v2 temp = src2 * ratio;
849 temp += src1 * (1.0f - ratio);
854 inline v2 v2::Scale(
const v2& src,
float scale )
856 return v2(src.x * scale, src.y * scale);
859 inline v2 v2::InvScale(
const v2& src,
float scale )
861 return v2(src.x / scale, src.y / scale);
864 inline float v2::Length()
const
866 float dot = x * x + y * y;
867 float length = Math::Sqrtf(dot);
871 inline float v2::LengthSq()
const
873 return Dot(*
this, *
this);
876 inline v2 v2::Norm()
const
878 float dot = x * x + y * y;
879 float length = Math::Sqrtf(dot);
880 return v2(x/length, y/length);
883 inline v2 v2::Neg(
const v2& src)
885 return v2(-src.x, -src.y);
888 inline v2 v2::Abs(
const v2& src)
890 return v2(Math::Abs(src.x), Math::Abs(src.y));
893 inline bool v2::operator== (
const v2 &rhs)
const
895 return (x == rhs.x) && (y == rhs.y);
898 inline bool v2::operator!= (
const v2 &rhs)
const
900 return (x != rhs.x) || (y != rhs.y);
903 inline v2 v2::operator - ()
const
908 inline v2 v2::operator + (
const v2& rhs )
const
910 return Add(*
this, rhs);
913 inline v2 v2::operator - (
const v2& rhs )
const
915 return Sub(*
this, rhs);
918 inline v2 v2::operator * (
const v2& rhs )
const
920 return Mul(*
this, rhs);
923 inline v2 v2::operator * (
const float rhs )
const
925 return Scale(*
this, rhs);
928 inline v2 operator * (
const float lhs,
const v2& rhs)
930 return v2::Scale(rhs, lhs);
933 inline v2 v2::operator / (
const v2& rhs )
const
935 return Div(*
this, rhs);
938 inline v2 v2::operator / (
const float rhs )
const
940 return InvScale(*
this, rhs);
943 inline v2& v2::operator += (
const v2& rhs )
945 *
this = Add(*
this, rhs);
949 inline v2& v2::operator -= (
const v2& rhs )
951 *
this = Sub(*
this, rhs);
955 inline v2& v2::operator *= (
const v2& rhs )
957 *
this = Mul(*
this, rhs);
961 inline v2& v2::operator /= (
const v2& rhs )
963 *
this = Div(*
this, rhs);
967 inline v2& v2::operator *= (
const float rhs )
974 inline v2& v2::operator /= (
const float rhs )
982 inline v2 v2::Min(
const v2& src1,
const v2& src2 )
984 return v2( src1.x < src2.x ? src1.x : src2.x,
985 src1.y < src2.y ? src1.y : src2.y );
988 inline v2 v2::Max(
const v2& src1,
const v2& src2 )
990 return v2( src1.x > src2.x ? src1.x : src2.x,
991 src1.y > src2.y ? src1.y : src2.y );
994 inline dv2::dv2(
const dv2& src )
1000 inline dv2::dv2(
double _x,
double _y )
1006 inline dv2::dv2(
double* pSrc )
1012 inline void dv2::Set(
const dv2& src )
1018 inline void dv2::Set(
double _x,
double _y )
1024 inline void dv2::SetZero()
1030 inline dv2 dv2::SplatX()
const
1035 inline dv2 dv2::SplatY()
const
1040 inline double dv2::GetX()
const
1045 inline double dv2::GetY()
const
1050 inline void dv2::SetX(
double data )
1055 inline void dv2::SetY(
double data )
1061 inline dv2 dv2::Add(
const dv2& src1,
const dv2& src2 )
1063 return dv2(src1.x + src2.x, src1.y + src2.y);
1066 inline dv2 dv2::Sub(
const dv2& src1,
const dv2& src2 )
1068 return dv2(src1.x - src2.x, src1.y - src2.y);
1071 inline dv2 dv2::Mul(
const dv2& src1,
const dv2& src2 )
1073 return dv2(src1.x * src2.x, src1.y * src2.y);
1076 inline dv2 dv2::Div(
const dv2& src1,
const dv2& src2 )
1078 return dv2(src1.x / src2.x, src1.y / src2.y);
1081 inline double dv2::Dot(
const dv2& src1,
const dv2& src2 )
1083 double dot = src1.x * src2.x + src1.y * src2.y;
1087 inline dv2 dv2::Lerp(
const dv2& src1,
const dv2& src2,
double ratio )
1089 dv2 temp = src2 * ratio;
1090 temp += src1 * (1.0f - ratio);
1095 inline dv2 dv2::Scale(
const dv2& src,
double scale )
1097 return dv2(src.x * scale, src.y * scale);
1100 inline dv2 dv2::InvScale(
const dv2& src,
double scale )
1102 return dv2(src.x / scale, src.y / scale);
1105 inline double dv2::Length()
const
1107 double dot = x * x + y * y;
1108 double length = Math::Sqrtd(dot);
1112 inline double dv2::LengthSq()
const
1114 return Dot(*
this, *
this);
1117 inline dv2 dv2::Norm()
const
1119 double invMagnitude = 1.0 / Length();
1120 return dv2(x * invMagnitude, y * invMagnitude);
1123 inline v2 dv2::ToSingle(
const dv2& src)
1125 return v2(static_cast<float>(src.x), static_cast<float>(src.y));
1128 inline v2 dv2::ToSingle()
const
1130 return ToSingle(*
this);
1133 inline dv2 dv2::Neg(
const dv2& src)
1135 return dv2(-src.x, -src.y);
1138 inline dv2 dv2::operator - ()
const
1143 inline dv2 dv2::operator + (
const dv2& rhs )
const
1145 return Add(*
this, rhs);
1148 inline dv2 dv2::operator - (
const dv2& rhs )
const
1150 return Sub(*
this, rhs);
1153 inline dv2 dv2::operator * (
const dv2& rhs )
const
1155 return Mul(*
this, rhs);
1158 inline dv2 dv2::operator * (
const double rhs )
const
1160 return Scale(*
this, rhs);
1163 inline dv2 operator * (
const double lhs,
const dv2& rhs )
1165 return dv2::Scale(rhs, lhs);
1168 inline dv2 dv2::operator / (
const dv2& rhs )
const
1170 return Div(*
this, rhs);
1173 inline dv2 dv2::operator / (
const double rhs )
const
1175 return InvScale(*
this, rhs);
1178 inline dv2& dv2::operator += (
const dv2& rhs )
1180 *
this = Add(*
this, rhs);
1184 inline dv2& dv2::operator -= (
const dv2& rhs )
1186 *
this = Sub(*
this, rhs);
1190 inline dv2& dv2::operator *= (
const dv2& rhs )
1192 *
this = Mul(*
this, rhs);
1196 inline dv2& dv2::operator /= (
const dv2& rhs )
1198 *
this = Div(*
this, rhs);
1202 inline dv2& dv2::operator *= (
const double rhs )
1209 inline dv2& dv2::operator /= (
const double rhs )
1217 inline dv2 dv2::Min(
const dv2& src1,
const dv2& src2 )
1219 return dv2( src1.x < src2.x ? src1.x : src2.x,
1220 src1.y < src2.y ? src1.y : src2.y );
1223 inline dv2 dv2::Max(
const dv2& src1,
const dv2& src2 )
1225 return dv2( src1.x > src2.x ? src1.x : src2.x,
1226 src1.y > src2.y ? src1.y : src2.y );
1229 inline v3::v3(
const v3& src )
1236 inline v3::v3(
float _x,
float _y,
float _z )
1243 inline v3::v3(
const float* pSrc )
1250 inline v3::v3(
const v4& src)
1257 inline v3& v3::operator= (
const v3& rhs)
1265 inline bool v3::operator== (
const v3 &rhs)
const
1267 return (x == rhs.x) && (y == rhs.y) && (z == rhs.z);
1270 inline bool v3::operator!= (
const v3 &rhs)
const
1272 return (x != rhs.x) || (y != rhs.y) || (z != rhs.z);
1275 inline void v3::Set(
float _x,
float _y,
float _z )
1282 inline void v3::SetZero()
1289 inline v3 v3::SplatX()
const
1294 inline v3 v3::SplatY()
const
1299 inline v3 v3::SplatZ()
const
1304 inline float v3::GetX()
const
1309 inline float v3::GetY()
const
1314 inline float v3::GetZ()
const
1319 inline void v3::SetX(
float data )
1324 inline void v3::SetY(
float data )
1329 inline void v3::SetZ(
float data )
1334 inline v3 v3::Add(
const v3& src1,
const v3& src2 )
1336 return v3(src1.x + src2.x, src1.y + src2.y, src1.z + src2.z);
1339 inline v3 v3::Sub(
const v3& src1,
const v3& src2 )
1341 return v3(src1.x - src2.x, src1.y - src2.y, src1.z - src2.z);
1344 inline v3 v3::Mul(
const v3& src1,
const v3& src2 )
1346 return v3(src1.x * src2.x, src1.y * src2.y, src1.z * src2.z);
1349 inline v3 v3::Div(
const v3& src1,
const v3& src2 )
1351 return v3(src1.x / src2.x, src1.y / src2.y, src1.z / src2.z);
1354 inline float v3::Dot(
const v3& src1,
const v3& src2 )
1357 float dot = src1.x * src2.x + src1.y * src2.y + src1.z * src2.z;
1362 inline v3 v3::Lerp(
const v3& src1,
const v3& src2,
float ratio )
1364 v3 temp = src2 * ratio;
1365 temp += src1 * (1.0f - ratio);
1370 inline v3 v3::Cross(
const v3& src1,
const v3& src2 )
1372 return v3( src1.y * src2.z - src1.z * src2.y,
1373 src1.z * src2.x - src1.x * src2.z,
1374 src1.x * src2.y - src1.y * src2.x );
1377 inline v3 v3::Mul (
const v3& src,
const m33& matrix)
1385 "vld1.32 {d0, d1}, [%1] \n\t"
1386 "vld1.32 {d2, d3}, [%0], %3 \n\t"
1387 "vld1.32 {d4, d5}, [%0], %3 \n\t"
1388 "vld1.32 {d6, d7}, [%0], %3 \n\t"
1390 "vmul.f32 q9, q1, d0[0] \n\t"
1391 "vmla.f32 q9, q2, d0[1] \n\t"
1392 "vmla.f32 q9, q3, d1[0] \n\t"
1393 "vmov.f32 q0, q9 \n\t"
1395 "vst1.32 d0, [%2]! \n\t"
1396 "fsts s2, [%2] \n\t"
1398 :
"+r"(&matrix),
"+r"(&src),
"+r"(destVector),
"+r"(tmp):
1399 :
"q0",
"q9",
"q10",
"q11",
"q12",
"q13",
"memory"
1407 tempMatrix.x = matrix._11*src.x + matrix._21*src.y + matrix._31*src.z;
1408 tempMatrix.y = matrix._12*src.x + matrix._22*src.y + matrix._32*src.z;
1409 tempMatrix.z = matrix._13*src.x + matrix._23*src.y + matrix._33*src.z;
1417 inline v3 v3::Mul(
const v3& src,
const m44& matrix )
1419 float x = matrix.m_rows[0].x * src.x + matrix.m_rows[1].x * src.y + matrix.m_rows[2].x * src.z + matrix.m_rows[3].x;
1420 float y = matrix.m_rows[0].y * src.x + matrix.m_rows[1].y * src.y + matrix.m_rows[2].y * src.z + matrix.m_rows[3].y;
1421 float z = matrix.m_rows[0].z * src.x + matrix.m_rows[1].z * src.y + matrix.m_rows[2].z * src.z + matrix.m_rows[3].z;
1426 inline v3 v3::MulRotate(
const v3& src,
const m44& matrix )
1428 float x = matrix.m_rows[0].x * src.x + matrix.m_rows[1].x * src.y + matrix.m_rows[2].x * src.z;
1429 float y = matrix.m_rows[0].y * src.x + matrix.m_rows[1].y * src.y + matrix.m_rows[2].y * src.z;
1430 float z = matrix.m_rows[0].z * src.x + matrix.m_rows[1].z * src.y + matrix.m_rows[2].z * src.z;
1435 inline v3 v3::Clamped(
const v3& src,
float maxLength)
1437 float length = src.Length();
1438 v3 result = (length > maxLength) ? v3::Scale(src, maxLength/length) : src;
1442 inline v3 v3::Abs(
const v3& src)
1444 return v3(Math::Abs(src.x), Math::Abs(src.y), Math::Abs(src.z));
1447 inline v3 v3::Scale(
const v3& src,
float scale )
1449 return v3(src.x * scale, src.y * scale, src.z * scale);
1452 inline v3 v3::InvScale(
const v3& src,
float scale )
1454 return v3(src.x / scale, src.y / scale, src.z / scale);
1457 inline float v3::Length()
const
1459 float dot = x * x + y * y + z * z;
1460 float length = Math::Sqrtf(dot);
1464 inline float v3::LengthSq()
const
1466 return Dot(*
this, *
this);
1469 inline float v3::SquareDistanceTo(
const v3& a )
const
1474 return dx*dx + dy*dy + dz*dz;
1477 inline v3 v3::Norm()
const
1479 float dot = x * x + y * y + z * z;
1480 float length = Math::Sqrtf(dot);
1481 return v3(x/length, y/length, z/length);
1484 inline v3 v3::Neg(
const v3& src)
1486 return v3(-src.x, -src.y, -src.z);
1489 inline v3 v3::operator - ()
const
1494 inline v3 v3::operator + (
const v3& rhs )
const
1496 return Add(*
this, rhs);
1499 inline v3 v3::operator - (
const v3& rhs )
const
1501 return Sub(*
this, rhs);
1504 inline v3 v3::operator * (
const v3& rhs )
const
1506 return Mul(*
this, rhs);
1509 inline v3 v3::operator * (
const float rhs )
const
1511 return Scale(*
this, rhs);
1514 inline v3 operator * (
const float lhs,
const v3& rhs )
1516 return v3::Scale(rhs, lhs);
1519 inline v3 v3::operator / (
const v3& rhs )
const
1521 return Div(*
this, rhs);
1524 inline v3 v3::operator / (
const float rhs )
const
1526 return InvScale(*
this, rhs);
1529 inline v3& v3::operator += (
const v3& rhs )
1531 *
this = Add(*
this, rhs);
1535 inline v3& v3::operator -= (
const v3& rhs )
1537 *
this = Sub(*
this, rhs);
1541 inline v3& v3::operator *= (
const v3& rhs )
1543 *
this = Mul(*
this, rhs);
1547 inline v3& v3::operator /= (
const v3& rhs )
1549 *
this = Div(*
this, rhs);
1553 inline v3& v3::operator *= (
const float rhs )
1561 inline v3& v3::operator /= (
const float rhs )
1570 inline v3 v3::Min(
const v3& src1,
const v3& src2 )
1572 return v3( src1.x < src2.x ? src1.x : src2.x,
1573 src1.y < src2.y ? src1.y : src2.y,
1574 src1.z < src2.z ? src1.z : src2.z );
1577 inline v3 v3::Max(
const v3& src1,
const v3& src2 )
1579 return v3( src1.x > src2.x ? src1.x : src2.x,
1580 src1.y > src2.y ? src1.y : src2.y,
1581 src1.z > src2.z ? src1.z : src2.z );
1584 inline dv3::dv3(
const dv3& src )
1591 inline dv3::dv3(
double _x,
double _y,
double _z )
1598 inline dv3::dv3(
const double* pSrc )
1605 inline dv3::dv3(
const v4& src)
1612 inline dv3::dv3(
const dv4& src)
1619 inline dv3::dv3(
const v3& src)
1626 inline void dv3::Set(
double _x,
double _y,
double _z )
1633 inline void dv3::SetZero()
1640 inline dv3 dv3::SplatX()
const
1642 return dv3(x, x, x);
1645 inline dv3 dv3::SplatY()
const
1647 return dv3(y, y, y);
1650 inline dv3 dv3::SplatZ()
const
1652 return dv3(z, z, z);
1655 inline double dv3::GetX()
const
1660 inline double dv3::GetY()
const
1665 inline double dv3::GetZ()
const
1670 inline void dv3::SetX(
double data )
1675 inline void dv3::SetY(
double data )
1680 inline void dv3::SetZ(
double data )
1685 inline dv3 dv3::Add(
const dv3& src1,
const dv3& src2 )
1687 return dv3(src1.x + src2.x, src1.y + src2.y, src1.z + src2.z);
1690 inline dv3 dv3::Sub(
const dv3& src1,
const dv3& src2 )
1692 return dv3(src1.x - src2.x, src1.y - src2.y, src1.z - src2.z);
1695 inline dv3 dv3::Mul(
const dv3& src1,
const dv3& src2 )
1697 return dv3(src1.x * src2.x, src1.y * src2.y, src1.z * src2.z);
1700 inline dv3 dv3::Div(
const dv3& src1,
const dv3& src2 )
1702 return dv3(src1.x / src2.x, src1.y / src2.y, src1.z / src2.z);
1705 inline dv3 dv3::Add(
const dv3& src1,
const v3& src2 )
1707 return dv3(src1.x + src2.x, src1.y + src2.y, src1.z + src2.z);
1710 inline dv3 dv3::Sub(
const dv3& src1,
const v3& src2 )
1712 return dv3(src1.x - src2.x, src1.y - src2.y, src1.z - src2.z);
1715 inline dv3 dv3::Mul(
const dv3& src1,
const v3& src2 )
1717 return dv3(src1.x * src2.x, src1.y * src2.y, src1.z * src2.z);
1720 inline dv3 dv3::Div(
const dv3& src1,
const v3& src2 )
1722 return dv3(src1.x / src2.x, src1.y / src2.y, src1.z / src2.z);
1725 inline double dv3::Dot(
const dv3& src1,
const dv3& src2 )
1727 #if MATH_NEON && !TARGET_IPHONE_SIMULATOR
1731 "vld1.32 {d2}, [%0] \n\t"
1732 "flds s6, [%0, #8] \n\t"
1733 "vld1.32 {d4}, [%1] \n\t"
1734 "flds s10, [%1, #8] \n\t"
1736 "vmul.f32 d0, d2, d4 \n\t"
1737 "vpadd.f32 d0, d0, d0 \n\t"
1738 "vmla.f32 d0, d3, d5 \n\t"
1740 "vstr.32 d0, [%2] \n\t"
1742 ::
"r"(&src1),
"r"(&src2),
"=r"(ret)
1743 :
"d0",
"d1",
"d2",
"d3",
"d4",
"d5"
1749 double dot = src1.x * src2.x + src1.y * src2.y + src1.z * src2.z;
1754 inline dv3 dv3::Lerp(
const dv3& src1,
const dv3& src2,
double ratio )
1756 dv3 temp = src2 * ratio;
1757 temp += src1 * (1.0f - ratio);
1762 inline dv3 dv3::Cross(
const dv3& src1,
const dv3& src2 )
1764 return dv3( src1.y * src2.z - src1.z * src2.y,
1765 src1.z * src2.x - src1.x * src2.z,
1766 src1.x * src2.y - src1.y * src2.x );
1769 inline dv3 dv3::Mul (
const dv3& src,
const m33& matrix)
1777 "vld1.32 {d0, d1}, [%1] \n\t"
1778 "vld1.32 {d2, d3}, [%0], %3 \n\t"
1779 "vld1.32 {d4, d5}, [%0], %3 \n\t"
1780 "vld1.32 {d6, d7}, [%0], %3 \n\t"
1782 "vmul.f32 q9, q1, d0[0] \n\t"
1783 "vmla.f32 q9, q2, d0[1] \n\t"
1784 "vmla.f32 q9, q3, d1[0] \n\t"
1785 "vmov.f32 q0, q9 \n\t"
1787 "vst1.32 d0, [%2]! \n\t"
1788 "fsts s2, [%2] \n\t"
1790 :
"+r"(&matrix),
"+r"(&src),
"+r"(destVector),
"+r"(tmp):
1791 :
"q0",
"q9",
"q10",
"q11",
"q12",
"q13",
"memory"
1799 tempMatrix.x = matrix._11*src.x + matrix._21*src.y + matrix._31*src.z;
1800 tempMatrix.y = matrix._12*src.x + matrix._22*src.y + matrix._32*src.z;
1801 tempMatrix.z = matrix._13*src.x + matrix._23*src.y + matrix._33*src.z;
1809 inline dv3 dv3::Mul(
const dv3& src,
const m44& matrix )
1811 double x = matrix.m_rows[0].x * src.x + matrix.m_rows[1].x * src.y + matrix.m_rows[2].x * src.z + matrix.m_rows[3].x;
1812 double y = matrix.m_rows[0].y * src.x + matrix.m_rows[1].y * src.y + matrix.m_rows[2].y * src.z + matrix.m_rows[3].y;
1813 double z = matrix.m_rows[0].z * src.x + matrix.m_rows[1].z * src.y + matrix.m_rows[2].z * src.z + matrix.m_rows[3].z;
1815 return dv3(x, y, z);
1818 inline dv3 dv3::MulRotate(
const dv3& src,
const m44& matrix )
1820 double x = matrix.m_rows[0].x * src.x + matrix.m_rows[1].x * src.y + matrix.m_rows[2].x * src.z;
1821 double y = matrix.m_rows[0].y * src.x + matrix.m_rows[1].y * src.y + matrix.m_rows[2].y * src.z;
1822 double z = matrix.m_rows[0].z * src.x + matrix.m_rows[1].z * src.y + matrix.m_rows[2].z * src.z;
1824 return dv3(x, y, z);
1827 inline dv3 dv3::Mul(
const dv3& src,
const dm33& matrix)
1829 double x = matrix._11 * src.x + matrix._21 * src.y + matrix._31 * src.z;
1830 double y = matrix._12 * src.x + matrix._22 * src.y + matrix._32 * src.z;
1831 double z = matrix._13 * src.x + matrix._23 * src.y + matrix._33 * src.z;
1833 return dv3(x, y, z);
1837 inline dv3 dv3::Mul(
const dv3& src,
const dm44& matrix )
1839 double x = matrix.m_rows[0].x * src.x + matrix.m_rows[1].x * src.y + matrix.m_rows[2].x * src.z + matrix.m_rows[3].x;
1840 double y = matrix.m_rows[0].y * src.x + matrix.m_rows[1].y * src.y + matrix.m_rows[2].y * src.z + matrix.m_rows[3].y;
1841 double z = matrix.m_rows[0].z * src.x + matrix.m_rows[1].z * src.y + matrix.m_rows[2].z * src.z + matrix.m_rows[3].z;
1843 return dv3(x, y, z);
1846 inline dv3 dv3::MulRotate(
const dv3& src,
const dm44& matrix )
1848 double x = matrix.m_rows[0].x * src.x + matrix.m_rows[1].x * src.y + matrix.m_rows[2].x * src.z;
1849 double y = matrix.m_rows[0].y * src.x + matrix.m_rows[1].y * src.y + matrix.m_rows[2].y * src.z;
1850 double z = matrix.m_rows[0].z * src.x + matrix.m_rows[1].z * src.y + matrix.m_rows[2].z * src.z;
1852 return dv3(x, y, z);
1855 inline v3 dv3::ToSingle(
const dv3& src)
1857 return v3(static_cast<float>(src.x), static_cast<float>(src.y), static_cast<float>(src.z));
1860 inline dv3 dv3::FromSingle(
const v3& src)
1862 return dv3(src.GetX(), src.GetY(), src.GetZ());
1865 inline dv3 dv3::Scale(
const dv3& src,
double scale )
1867 return dv3(src.x * scale, src.y * scale, src.z * scale);
1870 inline dv3 dv3::InvScale(
const dv3& src,
double scale )
1872 return dv3(src.x / scale, src.y / scale, src.z / scale);
1875 inline double dv3::SquareDistanceTo(
const dv3& a)
const
1877 double dx = a.x - x;
1878 double dy = a.y - y;
1879 double dz = a.z - z;
1880 return dx*dx + dy*dy + dz*dz;
1883 inline double dv3::Length()
const
1885 double dot = x * x + y * y + z * z;
1886 double length = Math::Sqrtd(dot);
1890 inline double dv3::LengthSq()
const
1892 return Dot(*
this, *
this);
1895 inline dv3 dv3::Norm()
const
1897 double invMagnitude = 1.0 / Length();
1898 return dv3(x * invMagnitude, y * invMagnitude, z * invMagnitude);
1901 inline dv3& dv3::Normalise()
1907 inline v3 dv3::ToSingle()
const
1909 return ToSingle(*
this);
1912 inline dv3 dv3::Neg(
const dv3& src)
1914 return dv3(-src.x, -src.y, -src.z);
1917 inline dv3 dv3::operator - ()
const
1922 inline dv3 dv3::operator + (
const v3& rhs )
const
1924 return Add(*
this, rhs);
1927 inline dv3 dv3::operator - (
const v3& rhs )
const
1929 return Sub(*
this, rhs);
1932 inline dv3 dv3::operator * (
const v3& rhs )
const
1934 return Mul(*
this, rhs);
1937 inline dv3 dv3::operator * (
const float rhs )
const
1939 return Scale(*
this, rhs);
1942 inline dv3 operator * (
const double lhs,
const dv3& rhs)
1944 return dv3::Scale(rhs, lhs);
1947 inline dv3 dv3::operator / (
const v3& rhs )
const
1949 return Div(*
this, rhs);
1952 inline dv3 dv3::operator / (
const float rhs )
const
1954 return InvScale(*
this, rhs);
1957 inline dv3& dv3::operator += (
const v3& rhs )
1959 *
this = Add(*
this, rhs);
1963 inline dv3& dv3::operator -= (
const v3& rhs )
1965 *
this = Sub(*
this, rhs);
1969 inline dv3& dv3::operator *= (
const v3& rhs )
1971 *
this = Mul(*
this, rhs);
1975 inline dv3& dv3::operator /= (
const v3& rhs )
1977 *
this = Div(*
this, rhs);
1982 inline dv3 dv3::operator + (
const dv3& rhs )
const
1984 return Add(*
this, rhs);
1987 inline dv3 dv3::operator - (
const dv3& rhs )
const
1989 return Sub(*
this, rhs);
1992 inline dv3 dv3::operator * (
const dv3& rhs )
const
1994 return Mul(*
this, rhs);
1997 inline dv3 dv3::operator * (
const double rhs )
const
1999 return Scale(*
this, rhs);
2002 inline dv3 dv3::operator / (
const dv3& rhs )
const
2004 return Div(*
this, rhs);
2007 inline dv3 dv3::operator / (
const double rhs )
const
2009 return InvScale(*
this, rhs);
2012 inline dv3& dv3::operator += (
const dv3& rhs )
2014 *
this = Add(*
this, rhs);
2018 inline dv3& dv3::operator -= (
const dv3& rhs )
2020 *
this = Sub(*
this, rhs);
2024 inline dv3& dv3::operator *= (
const dv3& rhs )
2026 *
this = Mul(*
this, rhs);
2030 inline dv3& dv3::operator /= (
const dv3& rhs )
2032 *
this = Div(*
this, rhs);
2036 inline dv3& dv3::operator *= (
const double rhs )
2044 inline dv3& dv3::operator /= (
const double rhs )
2053 inline dv3 dv3::Min(
const dv3& src1,
const dv3& src2 )
2055 return dv3( src1.x < src2.x ? src1.x : src2.x,
2056 src1.y < src2.y ? src1.y : src2.y,
2057 src1.z < src2.z ? src1.z : src2.z );
2060 inline dv3 dv3::Max(
const dv3& src1,
const dv3& src2 )
2062 return dv3( src1.x > src2.x ? src1.x : src2.x,
2063 src1.y > src2.y ? src1.y : src2.y,
2064 src1.z > src2.z ? src1.z : src2.z );
2072 inline v4::v4(
const v4& src )
2080 inline v4::v4(
float _x,
float _y,
float _z,
float _w )
2088 inline v4::v4(
const v3& src,
float _w )
2096 inline void v4::Set(
float _x,
float _y,
float _z,
float _w )
2104 inline void v4::SetZero()
2112 inline float v4::GetX()
const
2117 inline float v4::GetY()
const
2122 inline float v4::GetZ()
const
2127 inline float v4::GetW()
const
2132 inline void v4::SetX(
float data )
2137 inline void v4::SetY(
float data )
2142 inline void v4::SetZ(
float data )
2147 inline void v4::SetW(
float data )
2152 inline v4 v4::SplatX()
const
2154 return v4(x, x, x, x);
2157 inline v4 v4::SplatY()
const
2159 return v4(y, y, y, y);
2162 inline v4 v4::SplatZ()
const
2164 return v4(z, z, z, z);
2167 inline v4 v4::SplatW()
const
2169 return v4(w, w, w, w);
2172 inline void v4::Load(
const float* pSrc )
2180 inline void v4::Store(
float* pDest )
const
2191 inline v4 v4::Add(
const v4& src1,
const v4& src2 )
2193 return v4(src1.x + src2.x, src1.y + src2.y, src1.z + src2.z, src1.w + src2.w);
2196 inline v4 v4::Sub(
const v4& src1,
const v4& src2 )
2198 return v4(src1.x - src2.x, src1.y - src2.y, src1.z - src2.z, src1.w - src2.w);
2200 inline v4 v4::Mul(
const v4& src1,
const v4& src2 )
2202 return v4(src1.x * src2.x, src1.y * src2.y, src1.z * src2.z, src1.w * src2.w);
2205 inline v4 v4::Div(
const v4& src1,
const v4& src2 )
2207 return v4(src1.x / src2.x, src1.y / src2.y, src1.z / src2.z, src1.w / src2.w);
2210 inline v4 v4::Dot(
const v4& src1,
const v4& src2 )
2212 float dot = src1.x * src2.x + src1.y * src2.y + src1.z * src2.z + src1.w * src2.w;
2213 return v4(dot, dot, dot, dot);
2216 inline v4 v4::Lerp(
const v4& src1,
const v4& src2,
float ratio )
2218 v4 temp = src2 * ratio;
2219 temp += src1 * (1.0f - ratio);
2224 inline v4 v4::Neg(
const v4& src)
2226 return v4(-src.x, -src.y, -src.z, -src.w);
2229 inline bool v4::operator== (
const v4 &rhs)
const
2231 return (x == rhs.x) && (y == rhs.y) && (z == rhs.z) && (w == rhs.w);
2234 inline bool v4::operator!= (
const v4 &rhs)
const
2236 return (x != rhs.x) || (y != rhs.y) || (z != rhs.z) || (w != rhs.w);
2239 inline v4 v4::operator - ()
const
2244 inline v4 v4::operator + (
const v4& rhs )
const
2246 return Add(*
this, rhs);
2249 inline v4 v4::operator - (
const v4& rhs )
const
2251 return Sub(*
this, rhs);
2254 inline v4 v4::operator * (
const v4& rhs )
const
2256 return Mul(*
this, rhs);
2259 inline v4 v4::operator / (
const v4& rhs )
const
2261 return Div(*
this, rhs);
2264 inline v4 v4::operator * (
const float rhs )
const
2266 return v4(x * rhs, y * rhs, z * rhs, w * rhs);
2269 inline v4 v4::operator / (
const float rhs )
const
2271 return v4(x / rhs, y / rhs, z / rhs, w / rhs);
2274 inline v4& v4::operator += (
const v4& rhs )
2276 *
this = Add(*
this, rhs);
2280 inline v4& v4::operator -= (
const v4& rhs )
2282 *
this = Sub(*
this, rhs);
2286 inline v4& v4::operator *= (
const v4& rhs )
2288 *
this = Mul(*
this, rhs);
2292 inline v4& v4::operator /= (
const v4& rhs )
2294 *
this = Div(*
this, rhs);
2298 inline v4& v4::operator *= (
const float rhs )
2308 inline v4& v4::operator /= (
const float rhs )
2318 inline v4 v4::Min(
const v4& src1,
const v4& src2 )
2320 return v4( src1.x < src2.x ? src1.x : src2.x,
2321 src1.y < src2.y ? src1.y : src2.y,
2322 src1.z < src2.z ? src1.z : src2.z,
2323 src1.w < src2.w ? src1.w : src2.w);
2326 inline v4 v4::Max(
const v4& src1,
const v4& src2 )
2328 return v4( src1.x > src2.x ? src1.x : src2.x,
2329 src1.y > src2.y ? src1.y : src2.y,
2330 src1.z > src2.z ? src1.z : src2.z,
2331 src1.w > src2.w ? src1.w : src2.w);
2334 inline v4 v4::Mul(
const v4& src,
const m44& matrix )
2336 float x = matrix.m_rows[0].x * src.x + matrix.m_rows[1].x * src.y + matrix.m_rows[2].x * src.z + matrix.m_rows[3].x * src.w;
2337 float y = matrix.m_rows[0].y * src.x + matrix.m_rows[1].y * src.y + matrix.m_rows[2].y * src.z + matrix.m_rows[3].y * src.w;
2338 float z = matrix.m_rows[0].z * src.x + matrix.m_rows[1].z * src.y + matrix.m_rows[2].z * src.z + matrix.m_rows[3].z * src.w;
2339 float w = matrix.m_rows[0].w * src.x + matrix.m_rows[1].w * src.y + matrix.m_rows[2].w * src.z + matrix.m_rows[3].w * src.w;
2341 return v4(x, y, z, w);
2344 inline v4 v4::MulTransposed(
const v4& src,
const m44& matrix )
2346 float x = matrix.m_rows[0].x * src.x + matrix.m_rows[0].y * src.y + matrix.m_rows[0].z * src.z + matrix.m_rows[0].w * src.w;
2347 float y = matrix.m_rows[1].x * src.x + matrix.m_rows[1].y * src.y + matrix.m_rows[1].z * src.z + matrix.m_rows[1].w * src.w;
2348 float z = matrix.m_rows[2].x * src.x + matrix.m_rows[2].y * src.y + matrix.m_rows[2].z * src.z + matrix.m_rows[2].w * src.w;
2349 float w = matrix.m_rows[3].x * src.x + matrix.m_rows[3].y * src.y + matrix.m_rows[3].z * src.z + matrix.m_rows[3].w * src.w;
2351 return v4(x, y, z, w);
2354 inline v4 v4::Length()
const
2356 float dot = x * x + y * y + z * z + w * w;
2357 float length = Math::Sqrtf(dot);
2358 return v4(length, length, length, length);
2361 inline v4 v4::LengthSq()
const
2363 return Dot(*
this, *
this);
2367 inline dv4::dv4(
const dv4& src )
2375 inline dv4::dv4(
const dv3& src,
double _w )
2383 inline dv4::dv4(
double _x,
double _y,
double _z,
double _w )
2391 inline dv4::dv4(
const double* pSrc )
2399 inline dv4::dv4(
const v4& src)
2407 inline dv4::dv4(
const v3& src)
2415 inline void dv4::Set(
double _x,
double _y,
double _z ,
double _w )
2423 inline void dv4::SetZero()
2431 inline dv4 dv4::SplatX()
const
2433 return dv4(x, x, x, x);
2436 inline dv4 dv4::SplatY()
const
2438 return dv4(y, y, y, y);
2441 inline dv4 dv4::SplatZ()
const
2443 return dv4(z, z, z, z);
2446 inline dv4 dv4::SplatW()
const
2448 return dv4(w, w, w, w);
2451 inline double dv4::GetX()
const
2456 inline double dv4::GetY()
const
2461 inline double dv4::GetZ()
const
2466 inline double dv4::GetW()
const
2471 inline void dv4::SetX(
double data )
2476 inline void dv4::SetY(
double data )
2481 inline void dv4::SetZ(
double data )
2486 inline void dv4::SetW(
double data )
2491 inline dv4 dv4::Add(
const dv4& src1,
const dv4& src2 )
2493 return dv4(src1.x + src2.x, src1.y + src2.y, src1.z + src2.z, src1.w + src2.w);
2496 inline dv4 dv4::Sub(
const dv4& src1,
const dv4& src2 )
2498 return dv4(src1.x - src2.x, src1.y - src2.y, src1.z - src2.z, src1.w - src2.w);
2501 inline dv4 dv4::Mul(
const dv4& src1,
const dv4& src2 )
2503 return dv4(src1.x * src2.x, src1.y * src2.y, src1.z * src2.z, src1.w * src2.w);
2506 inline dv4 dv4::Div(
const dv4& src1,
const dv4& src2 )
2508 return dv4(src1.x / src2.x, src1.y / src2.y, src1.z / src2.z, src1.w / src2.w);
2511 inline dv4 dv4::Add(
const dv4& src1,
const v4& src2 )
2513 return dv4(src1.x + src2.x, src1.y + src2.y, src1.z + src2.z, src1.w + src2.w);
2516 inline dv4 dv4::Sub(
const dv4& src1,
const v4& src2 )
2518 return dv4(src1.x - src2.x, src1.y - src2.y, src1.z - src2.z, src1.w - src2.w);
2521 inline dv4 dv4::Mul(
const dv4& src1,
const v4& src2 )
2523 return dv4(src1.x * src2.x, src1.y * src2.y, src1.z * src2.z, src1.w * src2.w);
2526 inline dv4 dv4::Div(
const dv4& src1,
const v4& src2 )
2528 return dv4(src1.x / src2.x, src1.y / src2.y, src1.z / src2.z, src1.w / src2.w);
2531 inline double dv4::Dot(
const dv4& src1,
const dv4& src2 )
2533 double dot = src1.x * src2.x + src1.y * src2.y + src1.z * src2.z + src1.w * src2.w;
2537 inline dv4 dv4::Lerp(
const dv4& src1,
const dv4& src2,
double ratio )
2539 dv4 temp = src2 * ratio;
2540 temp += src1 * (1.0 - ratio);
2544 inline dv4 dv4::Mul(
const dv4& src,
const m44& matrix )
2546 double x = matrix.m_rows[0].x * src.x + matrix.m_rows[1].x * src.y + matrix.m_rows[2].x * src.z + matrix.m_rows[3].x * src.w;
2547 double y = matrix.m_rows[0].y * src.x + matrix.m_rows[1].y * src.y + matrix.m_rows[2].y * src.z + matrix.m_rows[3].y * src.w;
2548 double z = matrix.m_rows[0].z * src.x + matrix.m_rows[1].z * src.y + matrix.m_rows[2].z * src.z + matrix.m_rows[3].z * src.w;
2549 double w = matrix.m_rows[0].w * src.x + matrix.m_rows[1].w * src.y + matrix.m_rows[2].w * src.z + matrix.m_rows[3].w * src.w;
2551 return dv4(x, y, z, w);
2554 inline dv4 dv4::MulTransposed(
const dv4& src,
const m44& matrix )
2556 double x = matrix.m_rows[0].x * src.x + matrix.m_rows[0].y * src.y + matrix.m_rows[0].z * src.z + matrix.m_rows[0].w * src.w;
2557 double y = matrix.m_rows[1].x * src.x + matrix.m_rows[1].y * src.y + matrix.m_rows[1].z * src.z + matrix.m_rows[1].w * src.w;
2558 double z = matrix.m_rows[2].x * src.x + matrix.m_rows[2].y * src.y + matrix.m_rows[2].z * src.z + matrix.m_rows[2].w * src.w;
2559 double w = matrix.m_rows[3].x * src.x + matrix.m_rows[3].y * src.y + matrix.m_rows[3].z * src.z + matrix.m_rows[3].w * src.w;
2561 return dv4(x, y, z, w);
2564 inline v4 dv4::ToSingle(
const dv4& src)
2566 return v4(static_cast<float>(src.x), static_cast<float>(src.y), static_cast<float>(src.z), static_cast<float>(src.w));
2569 inline dv4 dv4::FromSingle(
const v4& src)
2571 return dv4(src.GetX(), src.GetY(), src.GetZ(), src.GetW());
2574 inline dv4 dv4::Scale(
const dv4& src,
double scale )
2576 return dv4(src.x * scale, src.y * scale, src.z * scale, src.w * scale);
2579 inline dv4 dv4::InvScale(
const dv4& src,
double scale )
2581 return dv4(src.x / scale, src.y / scale, src.z / scale, src.w / scale);
2584 inline double dv4::Length()
const
2586 double dot = x * x + y * y + z * z + w * w;
2587 double length = Math::Sqrtd(dot);
2591 inline double dv4::LengthSq()
const
2593 return Dot(*
this, *
this);
2596 inline dv4 dv4::Norm()
const
2598 double invMagnitude = 1.0 / Length();
2599 return dv4(x * invMagnitude, y * invMagnitude, z * invMagnitude, w * invMagnitude);
2602 inline dv4& dv4::Normalise()
2608 inline v4 dv4::ToSingle()
const
2610 return ToSingle(*
this);
2613 inline dv4 dv4::Neg(
const dv4& src)
2615 return dv4(-src.x, -src.y, -src.z, -src.w);
2618 inline dv4 dv4::operator - ()
const
2623 inline dv4 dv4::operator + (
const v4& rhs )
const
2625 return Add(*
this, rhs);
2628 inline dv4 dv4::operator - (
const v4& rhs )
const
2630 return Sub(*
this, rhs);
2633 inline dv4 dv4::operator * (
const v4& rhs )
const
2635 return Mul(*
this, rhs);
2638 inline dv4 dv4::operator * (
const float rhs )
const
2640 return Scale(*
this, rhs);
2643 inline dv4 dv4::operator / (
const v4& rhs )
const
2645 return Div(*
this, rhs);
2648 inline dv4 dv4::operator / (
const float rhs )
const
2650 return InvScale(*
this, rhs);
2653 inline dv4& dv4::operator += (
const v4& rhs )
2655 *
this = Add(*
this, rhs);
2659 inline dv4& dv4::operator -= (
const v4& rhs )
2661 *
this = Sub(*
this, rhs);
2665 inline dv4& dv4::operator *= (
const v4& rhs )
2667 *
this = Mul(*
this, rhs);
2671 inline dv4& dv4::operator /= (
const v4& rhs )
2673 *
this = Div(*
this, rhs);
2678 inline dv4 dv4::operator + (
const dv4& rhs )
const
2680 return Add(*
this, rhs);
2683 inline dv4 dv4::operator - (
const dv4& rhs )
const
2685 return Sub(*
this, rhs);
2688 inline dv4 dv4::operator * (
const dv4& rhs )
const
2690 return Mul(*
this, rhs);
2693 inline dv4 dv4::operator * (
const double rhs )
const
2695 return Scale(*
this, rhs);
2698 inline dv4 dv4::operator / (
const dv4& rhs )
const
2700 return Div(*
this, rhs);
2703 inline dv4 dv4::operator / (
const double rhs )
const
2705 return InvScale(*
this, rhs);
2708 inline dv4& dv4::operator += (
const dv4& rhs )
2710 *
this = Add(*
this, rhs);
2714 inline dv4& dv4::operator -= (
const dv4& rhs )
2716 *
this = Sub(*
this, rhs);
2720 inline dv4& dv4::operator *= (
const dv4& rhs )
2722 *
this = Mul(*
this, rhs);
2726 inline dv4& dv4::operator /= (
const dv4& rhs )
2728 *
this = Div(*
this, rhs);
2732 inline dv4& dv4::operator *= (
const double rhs )
2741 inline dv4& dv4::operator /= (
const double rhs )
2750 inline dv4 dv4::Min(
const dv4& src1,
const dv4& src2 )
2752 return dv4( src1.x < src2.x ? src1.x : src2.x,
2753 src1.y < src2.y ? src1.y : src2.y,
2754 src1.z < src2.z ? src1.z : src2.z,
2755 src1.w < src2.w ? src1.w : src2.w );
2758 inline dv4 dv4::Max(
const dv4& src1,
const dv4& src2 )
2760 return dv4( src1.x > src2.x ? src1.x : src2.x,
2761 src1.y > src2.y ? src1.y : src2.y,
2762 src1.z > src2.z ? src1.z : src2.z,
2763 src1.w > src2.w ? src1.w : src2.w );
2767 inline void m33::Identity()
2769 _11 = 1.0f; _12 = 0.0f; _13 = 0.0f;
2770 _21 = 0.0f; _22 = 1.0f; _23 = 0.0f;
2771 _31 = 0.0f; _32 = 0.0f; _33 = 1.0f;
2774 inline m33 m33::CreateIdentity()
2777 newMatrix.Identity();
2781 inline void m33::Transpose( m33& dst,
const m33& src )
2798 inline void m33::SetRow (
int row,
const v3& data )
2818 Eegeo_ASSERT(
false,
"row out of range");
2822 inline void m33::SetFromBasis(
const v3& right,
const v3& up,
const v3& forward)
2835 inline v3 m33::GetRow (
int row )
const
2840 return v3(_11, _12, _13);
2842 return v3(_21, _22, _23);
2844 return v3(_31, _32, _33);
2846 Eegeo_ASSERT(
false,
"row out of range");
2851 inline void m33::Scale(
float scale)
2853 _11 = scale; _12 = 0.0f; _13 = 0.0f;
2854 _21 = 0.0f; _22 = scale; _23 = 0.0f;
2855 _31 = 0.0f; _32 = 0.0f; _33 = scale;
2858 inline void m33::Scale(
const v3& s)
2860 _11 = s.GetX(); _12 = 0.0f; _13 = 0.0f;
2861 _21 = 0.0f; _22 = s.GetY(); _23 = 0.0f;
2862 _31 = 0.0f; _32 = 0.0f; _33 = s.GetZ();
2865 inline void m33::RotateX(
float theta)
2869 float sin = Math::Sin(theta);
2870 float cos = Math::Cos(theta);
2872 SetRow(1, v3(0.0f, cos, -sin));
2873 SetRow(2, v3(0.0f, sin, cos));
2876 inline void m33::RotateY(
float theta)
2880 float sin = Math::Sin(theta);
2881 float cos = Math::Cos(theta);
2883 SetRow(0, v3(cos, 0.0f, -sin));
2884 SetRow(2, v3(sin, 0.0f , cos));
2887 inline void m33::RotateZ(
float theta)
2891 float sin = Math::Sin(theta);
2892 float cos = Math::Cos(theta);
2894 SetRow(0, v3(cos, -sin, 0.0f));
2895 SetRow(1, v3(sin, cos, 0.0f));
2898 inline void m33::Rotate(
float x,
float y,
float z )
2908 Mul(temp, tempZ, tempY);
2909 Mul(*
this, temp, tempX);
2912 inline void m33::Rotate(
const v3& axis,
float angle )
2914 float c = Math::Cos(angle);
2915 float s = Math::Sin(angle);
2918 float x = axis.GetX();
2919 float y = axis.GetY();
2920 float z = axis.GetZ();
2922 SetRow(0, v3( (t*x*x) + c, (t*y*x) - (s*z), (t*z*x) + (s*y)));
2923 SetRow(1, v3((t*x*y) + (s*z), (t*y*y) + c, (t*z*y) - (s*x)));
2924 SetRow(2, v3((t*x*z) - (s*y), (t*y*z) + (s*x), (t*z*z) + c));
2927 inline void m33::Mul( m33& dest,
const m33& src1,
const m33& src2 )
2931 const v3& src1row0 = src1.GetRow(0);
2932 const v3& src1row1 = src1.GetRow(1);
2933 const v3& src1row2 = src1.GetRow(2);
2935 for(
int i = 0; i < 3; i++)
2937 const v3& src2rowI = src2.GetRow(i);
2939 float x = src2rowI.x * src1row0.x +
2940 src2rowI.y * src1row1.x +
2941 src2rowI.z * src1row2.x;
2943 float y = src2rowI.x * src1row0.y +
2944 src2rowI.y * src1row1.y +
2945 src2rowI.z * src1row2.y;
2947 float z = src2rowI.x * src1row0.z +
2948 src2rowI.y * src1row1.z +
2949 src2rowI.z * src1row2.z;
2951 temp.SetRow(i, v3(x, y, z));
2954 memcpy(&dest, &temp,
sizeof(dest));
2957 inline void m33::Mul(
const float scale )
2970 inline m44 m33::ToM44()
const
2973 m.m_rows[0].Set(_11, _12, _13, 0.f);
2974 m.m_rows[1].Set(_21, _22, _23, 0.f);
2975 m.m_rows[2].Set(_31, _32, _33, 0.f);
2976 m.m_rows[3].Set(0.f, 0.f, 0.f, 1.f);
2980 inline m44 m44::CreateIdentity()
2983 newMatrix.Identity();
2987 inline m44 m44::CreateTranslate(
const v3& translate)
2989 m44 m(CreateIdentity());
2990 m.m_rows[3] = v4(translate, 1.f);
2994 inline m44 m44::CreateScale(
const v3& scale)
3001 inline m44 m44::CreateFromRowMajorElements(
const float* pRowMajorElements )
3005 matrix.SetRow(0,
Eegeo::v4(pRowMajorElements[0], pRowMajorElements[1], pRowMajorElements[2], pRowMajorElements[3]));
3006 matrix.SetRow(1,
Eegeo::v4(pRowMajorElements[4], pRowMajorElements[5], pRowMajorElements[6], pRowMajorElements[7]));
3007 matrix.SetRow(2,
Eegeo::v4(pRowMajorElements[8], pRowMajorElements[9], pRowMajorElements[10], pRowMajorElements[11]));
3008 matrix.SetRow(3,
Eegeo::v4(pRowMajorElements[12], pRowMajorElements[13], pRowMajorElements[14], pRowMajorElements[15]));
3013 inline m44::m44(
const v4& row0,
const v4& row1,
const v4& row2,
const v4& row3 )
3021 inline m44::m44(
float values[16])
3023 m_rows[0] = v4(values[0], values[1], values[2], values[3]);
3024 m_rows[1] = v4(values[4], values[5], values[6], values[7]);
3025 m_rows[2] = v4(values[8], values[9], values[10], values[11]);
3026 m_rows[3] = v4(values[12], values[13], values[14], values[15]);
3029 inline void m44::SetFromBasis(
const v3& right,
const v3& up,
const v3& forward,
const v3& pos)
3031 m_rows[0].Set(right.x, right.y, right.z, 0.f);
3032 m_rows[1].Set(up.x, up.y, up.z, 0.f);
3033 m_rows[2].Set(forward.x, forward.y, forward.z, 0.f);
3034 m_rows[3].Set(pos.x, pos.y, pos.z, 1.f);
3037 inline void m44::Load(
const float* pSrc )
3039 m_rows[0].Load(&pSrc[0]);
3040 m_rows[1].Load(&pSrc[4]);
3041 m_rows[2].Load(&pSrc[8]);
3042 m_rows[3].Load(&pSrc[12]);
3045 inline void m44::Store(
float* pDest )
const
3047 GetRow(0).Store(&pDest[0]);
3048 GetRow(1).Store(&pDest[4]);
3049 GetRow(2).Store(&pDest[8]);
3050 GetRow(3).Store(&pDest[12]);
3053 inline bool m44::operator== (
const m44 &rhs)
const
3055 return (m_rows[0] == rhs.m_rows[0]) &&
3056 (m_rows[1] == rhs.m_rows[1]) &&
3057 (m_rows[2] == rhs.m_rows[2]) &&
3058 (m_rows[3] == rhs.m_rows[3]);
3061 inline bool m44::operator!= (
const m44 &rhs)
const
3063 return (m_rows[0] != rhs.m_rows[0]) ||
3064 (m_rows[1] != rhs.m_rows[1]) ||
3065 (m_rows[2] != rhs.m_rows[2]) ||
3066 (m_rows[3] != rhs.m_rows[3]);
3069 inline void m44::Identity()
3071 m_rows[0].x = 1.0f; m_rows[0].y = 0.0f; m_rows[0].z = 0.0f; m_rows[0].w = 0.0f;
3072 m_rows[1].x = 0.0f; m_rows[1].y = 1.0f; m_rows[1].z = 0.0f; m_rows[1].w = 0.0f;
3073 m_rows[2].x = 0.0f; m_rows[2].y = 0.0f; m_rows[2].z = 1.0f; m_rows[2].w = 0.0f;
3074 m_rows[3].x = 0.0f; m_rows[3].y = 0.0f; m_rows[3].z = 0.0f; m_rows[3].w = 1.0f;
3077 inline bool m44::IsIdentity()
const
3081 (m_rows[0].x == 1.0f) && (m_rows[0].y == 0.0f) && (m_rows[0].z == 0.0f) && (m_rows[0].w == 0.0f) &&
3082 (m_rows[1].x == 0.0f) && (m_rows[1].y == 1.0f) && (m_rows[1].z == 0.0f) && (m_rows[1].w == 0.0f) &&
3083 (m_rows[2].x == 0.0f) && (m_rows[2].y == 0.0f) && (m_rows[2].z == 1.0f) && (m_rows[2].w == 0.0f) &&
3084 (m_rows[3].x == 0.0f) && (m_rows[3].y == 0.0f) && (m_rows[3].z == 0.0f) && (m_rows[3].w == 1.0f)
3088 inline void m44::Scale(
float scale)
3090 m_rows[0].x = scale; m_rows[0].y = 0.0f; m_rows[0].z = 0.0f; m_rows[0].w = 0.0f;
3091 m_rows[1].x = 0.0f; m_rows[1].y = scale; m_rows[1].z = 0.0f; m_rows[1].w = 0.0f;
3092 m_rows[2].x = 0.0f; m_rows[2].y = 0.0f; m_rows[2].z = scale; m_rows[2].w = 0.0f;
3093 m_rows[3].x = 0.0f; m_rows[3].y = 0.0f; m_rows[3].z = 0.0f; m_rows[3].w = 1.0f;
3096 inline void m44::Scale(
const v3& scale)
3098 m_rows[0] = v4(scale.GetX(), 0.0f, 0.0f, 0.0f);
3099 m_rows[1] = v4( 0.0f, scale.GetY(), 0.0f, 0.0f);
3100 m_rows[2] = v4( 0.0f, 0.0f, scale.GetZ(), 0.0f);
3101 m_rows[3] = v4( 0.0f, 0.0f, 0.0f, 1.0f);
3104 inline void m44::RotateX(
float theta)
3108 float sin = Math::Sin(theta);
3109 float cos = Math::Cos(theta);
3111 m_rows[1] = v4(0.0f, cos, -sin, 0.0f);
3112 m_rows[2] = v4(0.0f, sin, cos, 0.0f);
3115 inline void m44::RotateY(
float theta)
3119 float sin = Math::Sin(theta);
3120 float cos = Math::Cos(theta);
3122 m_rows[0] = v4( cos, 0.0f,-sin, 0.0f);
3123 m_rows[2] = v4( sin, 0.0f, cos, 0.0f);
3126 inline void m44::RotateZ(
float theta)
3130 float sin = Math::Sin(theta);
3131 float cos = Math::Cos(theta);
3133 m_rows[0] = v4(cos, -sin, 0.0f, 0.0f);
3134 m_rows[1] = v4(sin, cos, 0.0f, 0.0f);
3137 inline void m44::Rotate(
float x,
float y,
float z )
3148 Mul(temp, tempZ, tempY);
3149 Mul(*
this, temp, tempX);
3152 inline void m44::Rotate(
const v3& axis,
float angle )
3154 float c = Math::Cos(angle);
3155 float s = Math::Sin(angle);
3158 float x = axis.GetX();
3159 float y = axis.GetY();
3160 float z = axis.GetZ();
3162 SetRow(0, v4( (t*x*x) + c, (t*y*x) - (s*z), (t*z*x) + (s*y), 0.0f));
3163 SetRow(1, v4((t*x*y) + (s*z), (t*y*y) + c, (t*z*y) - (s*x), 0.0f));
3164 SetRow(2, v4((t*x*z) - (s*y), (t*y*z) + (s*x), (t*z*z) + c, 0.0f));
3165 SetRow(3, v4(0.0f, 0.0f, 0.0f, 1.0f));
3168 inline void m44::Transpose(m44& dst,
const m44& src)
3172 v4 r0 = temp.GetRow(0);
3173 v4 r1 = temp.GetRow(1);
3174 v4 r2 = temp.GetRow(2);
3175 v4 r3 = temp.GetRow(3);
3177 dst.SetRow(0, v4(r0.x, r1.x, r2.x, r3.x));
3178 dst.SetRow(1, v4(r0.y, r1.y, r2.y, r3.y));
3179 dst.SetRow(2, v4(r0.z, r1.z, r2.z, r3.z));
3180 dst.SetRow(3, v4(r0.w, r1.w, r2.w, r3.w));
3183 inline void m44::OrthoInverse(m44& dst,
const m44& src)
3185 v3 trans = v3(src.GetRow(3));
3191 dst.SetRow(3, zero);
3193 Transpose(dst, dst);
3195 trans = -v3::MulRotate(trans, dst);
3197 dst.SetRow(3, v4(trans, 1.0f));
3200 inline void m44::Mul( m44& dest,
const m44& src1,
const m44& src2 )
3203 for(
int i = 0; i < 4; i++)
3205 temp.m_rows[i].x = src2.m_rows[i].x * src1.m_rows[0].x + src2.m_rows[i].y * src1.m_rows[1].x + src2.m_rows[i].z * src1.m_rows[2].x + src2.m_rows[i].w * src1.m_rows[3].x;
3206 temp.m_rows[i].y = src2.m_rows[i].x * src1.m_rows[0].y + src2.m_rows[i].y * src1.m_rows[1].y + src2.m_rows[i].z * src1.m_rows[2].y + src2.m_rows[i].w * src1.m_rows[3].y;
3207 temp.m_rows[i].z = src2.m_rows[i].x * src1.m_rows[0].z + src2.m_rows[i].y * src1.m_rows[1].z + src2.m_rows[i].z * src1.m_rows[2].z + src2.m_rows[i].w * src1.m_rows[3].z;
3208 temp.m_rows[i].w = src2.m_rows[i].x * src1.m_rows[0].w + src2.m_rows[i].y * src1.m_rows[1].w + src2.m_rows[i].z * src1.m_rows[2].w + src2.m_rows[i].w * src1.m_rows[3].w;
3212 memcpy(&dest, &temp,
sizeof(dest));
3215 inline void m44::Lerp( m44& dst,
const m44& from,
const m44& to,
float t )
3217 for (
int i = 0; i < 4; ++i)
3221 Eegeo::v4 dest = Eegeo::v4::Lerp(va, vb, t);
3222 dst.SetRow(i, dest);
3226 inline void m44::Mul(
const float scale )
3228 for(
int i = 0; i < 4; i++)
3230 m_rows[i].x *= scale;
3231 m_rows[i].y *= scale;
3232 m_rows[i].z *= scale;
3233 m_rows[i].w *= scale;
3238 inline dm44::dm44(
const dv4& row0,
const dv4& row1,
const dv4& row2,
const dv4& row3 )
3246 inline void dm44::SetFromBasis(
const dv3& right,
const dv3& up,
const dv3& forward,
const dv3& pos)
3248 m_rows[0].Set(right.GetX(), right.GetY(), right.GetZ(), 0.0);
3249 m_rows[1].Set(up.GetX(), up.GetY(), up.GetZ(), 0.0);
3250 m_rows[2].Set(forward.GetX(), forward.GetY(), forward.GetZ(), 0.0);
3251 m_rows[3].Set(pos.GetX(), pos.GetY(), pos.GetZ(), 1.0);
3254 inline void dm44::Identity()
3256 m_rows[0].x = 1.0f; m_rows[0].y = 0.0f; m_rows[0].z = 0.0f; m_rows[0].w = 0.0f;
3257 m_rows[1].x = 0.0f; m_rows[1].y = 1.0f; m_rows[1].z = 0.0f; m_rows[1].w = 0.0f;
3258 m_rows[2].x = 0.0f; m_rows[2].y = 0.0f; m_rows[2].z = 1.0f; m_rows[2].w = 0.0f;
3259 m_rows[3].x = 0.0f; m_rows[3].y = 0.0f; m_rows[3].z = 0.0f; m_rows[3].w = 1.0f;
3262 inline void dm44::Scale(
double scale)
3264 m_rows[0].x = scale; m_rows[0].y = 0.0f; m_rows[0].z = 0.0f; m_rows[0].w = 0.0f;
3265 m_rows[1].x = 0.0f; m_rows[1].y = scale; m_rows[1].z = 0.0f; m_rows[1].w = 0.0f;
3266 m_rows[2].x = 0.0f; m_rows[2].y = 0.0f; m_rows[2].z = scale; m_rows[2].w = 0.0f;
3267 m_rows[3].x = 0.0f; m_rows[3].y = 0.0f; m_rows[3].z = 0.0f; m_rows[3].w = 1.0f;
3270 inline void dm44::Scale(
const dv3& scale)
3272 m_rows[0] = dv4(scale.GetX(), 0.0f, 0.0f, 0.0f);
3273 m_rows[1] = dv4( 0.0f, scale.GetY(), 0.0f, 0.0f);
3274 m_rows[2] = dv4( 0.0f, 0.0f, scale.GetZ(), 0.0f);
3275 m_rows[3] = dv4( 0.0f, 0.0f, 0.0f, 1.0f);
3278 inline void dm44::RotateX(
double theta)
3282 double sin = std::sin(theta);
3283 double cos = std::cos(theta);
3285 m_rows[1] = dv4(0.0f, cos, -sin, 0.0f);
3286 m_rows[2] = dv4(0.0f, sin, cos, 0.0f);
3289 inline void dm44::RotateY(
double theta)
3293 double sin = std::sin(theta);
3294 double cos = std::cos(theta);
3296 m_rows[0] = dv4( cos, 0.0f,-sin, 0.0f);
3297 m_rows[2] = dv4( sin, 0.0f, cos, 0.0f);
3300 inline void dm44::RotateZ(
double theta)
3304 double sin = std::sin(theta);
3305 double cos = std::cos(theta);
3307 m_rows[0] = dv4(cos, -sin, 0.0f, 0.0f);
3308 m_rows[1] = dv4(sin, cos, 0.0f, 0.0f);
3311 inline void dm44::Rotate(
double x,
double y,
double z )
3322 Mul(temp, tempZ, tempY);
3323 Mul(*
this, temp, tempX);
3326 inline void dm44::Rotate(
const dv3& axis,
double angle )
3328 double c = std::cos(angle);
3329 double s = std::sin(angle);
3330 double t = 1.0f - c;
3332 double x = axis.GetX();
3333 double y = axis.GetY();
3334 double z = axis.GetZ();
3336 SetRow(0, dv4( (t*x*x) + c, (t*y*x) - (s*z), (t*z*x) + (s*y), 0.0f));
3337 SetRow(1, dv4((t*x*y) + (s*z), (t*y*y) + c, (t*z*y) - (s*x), 0.0f));
3338 SetRow(2, dv4((t*x*z) - (s*y), (t*y*z) + (s*x), (t*z*z) + c, 0.0f));
3339 SetRow(3, dv4(0.0f, 0.0f, 0.0f, 1.0f));
3342 inline void dm44::Transpose(dm44& dst,
const dm44& src)
3346 dv4 r0 = temp.GetRow(0);
3347 dv4 r1 = temp.GetRow(1);
3348 dv4 r2 = temp.GetRow(2);
3349 dv4 r3 = temp.GetRow(3);
3351 dst.SetRow(0, dv4(r0.x, r1.x, r2.x, r3.x));
3352 dst.SetRow(1, dv4(r0.y, r1.y, r2.y, r3.y));
3353 dst.SetRow(2, dv4(r0.z, r1.z, r2.z, r3.z));
3354 dst.SetRow(3, dv4(r0.w, r1.w, r2.w, r3.w));
3357 inline void dm44::OrthoInverse(dm44& dst,
const dm44& src)
3359 dv3 trans = dv3(src.GetRow(3));
3365 dst.SetRow(3, zero);
3367 Transpose(dst, dst);
3369 trans = -dv3::MulRotate(trans, dst);
3371 dst.SetRow(3, dv4(trans, 1.0f));
3374 inline void dm44::Mul( dm44& dest,
const dm44& src1,
const dm44& src2 )
3377 for(
int i = 0; i < 4; i++)
3379 temp.m_rows[i].x = src2.m_rows[i].x * src1.m_rows[0].x + src2.m_rows[i].y * src1.m_rows[1].x + src2.m_rows[i].z * src1.m_rows[2].x + src2.m_rows[i].w * src1.m_rows[3].x;
3380 temp.m_rows[i].y = src2.m_rows[i].x * src1.m_rows[0].y + src2.m_rows[i].y * src1.m_rows[1].y + src2.m_rows[i].z * src1.m_rows[2].y + src2.m_rows[i].w * src1.m_rows[3].y;
3381 temp.m_rows[i].z = src2.m_rows[i].x * src1.m_rows[0].z + src2.m_rows[i].y * src1.m_rows[1].z + src2.m_rows[i].z * src1.m_rows[2].z + src2.m_rows[i].w * src1.m_rows[3].z;
3382 temp.m_rows[i].w = src2.m_rows[i].x * src1.m_rows[0].w + src2.m_rows[i].y * src1.m_rows[1].w + src2.m_rows[i].z * src1.m_rows[2].w + src2.m_rows[i].w * src1.m_rows[3].w;
3386 memcpy(&dest, &temp,
sizeof(dest));
3389 inline void dm44::Mul(
const double scale )
3391 for(
int i = 0; i < 4; i++)
3393 m_rows[i].x *= scale;
3394 m_rows[i].y *= scale;
3395 m_rows[i].z *= scale;
3396 m_rows[i].w *= scale;
3400 inline void dm33::Identity()
3402 _11 = 1.0; _12 = 0.0; _13 = 0.0;
3403 _21 = 0.0; _22 = 1.0; _23 = 0.0;
3404 _31 = 0.0; _32 = 0.0; _33 = 1.0;
3407 inline void dm33::Transpose( dm33& dst,
const dm33& src )
3424 inline void dm33::SetRow (
int row,
const dv3& data )
3444 Eegeo_ASSERT(
false,
"row out of range");
3448 inline void dm33::SetFromBasis(
const dv3& right,
const dv3& up,
const dv3& forward)
3461 inline dv3 dm33::GetRow (
int row )
const
3466 return dv3(_11, _12, _13);
3468 return dv3(_21, _22, _23);
3470 return dv3(_31, _32, _33);
3472 Eegeo_ASSERT(
false,
"row out of range");
3477 inline void dm33::Scale(
double scale)
3479 _11 = scale; _12 = 0.0; _13 = 0.0;
3480 _21 = 0.0; _22 = scale; _23 = 0.0;
3481 _31 = 0.0; _32 = 0.0; _33 = scale;
3484 inline void dm33::Scale(
const dv3& s)
3486 _11 = s.GetX(); _12 = 0.0; _13 = 0.0;
3487 _21 = 0.0; _22 = s.GetY(); _23 = 0.0;
3488 _31 = 0.0; _32 = 0.0; _33 = s.GetZ();
3491 inline void dm33::RotateX(
double theta)
3495 double sin = std::sin(theta);
3496 double cos = std::cos(theta);
3498 SetRow(1, dv3(0.0, cos, -sin));
3499 SetRow(2, dv3(0.0, sin, cos));
3502 inline void dm33::RotateY(
double theta)
3506 double sin = std::sin(theta);
3507 double cos = std::cos(theta);
3509 SetRow(0, dv3(cos, 0.0, -sin));
3510 SetRow(2, dv3(sin, 0.0 , cos));
3513 inline void dm33::RotateZ(
double theta)
3517 double sin = std::sin(theta);
3518 double cos = std::cos(theta);
3520 SetRow(0, dv3(cos, -sin, 0.0));
3521 SetRow(1, dv3(sin, cos, 0.0));
3524 inline void dm33::Rotate(
double x,
double y,
double z )
3534 Mul(temp, tempZ, tempY);
3535 Mul(*
this, temp, tempX);
3538 inline void dm33::Rotate(
const dv3& axis,
double angle )
3540 double c = std::cos(angle);
3541 double s = std::sin(angle);
3544 double x = axis.GetX();
3545 double y = axis.GetY();
3546 double z = axis.GetZ();
3548 SetRow(0, dv3( (t*x*x) + c, (t*y*x) - (s*z), (t*z*x) + (s*y)));
3549 SetRow(1, dv3((t*x*y) + (s*z), (t*y*y) + c, (t*z*y) - (s*x)));
3550 SetRow(2, dv3((t*x*z) - (s*y), (t*y*z) + (s*x), (t*z*z) + c));
3553 inline void dm33::Mul( dm33& dest,
const dm33& src1,
const dm33& src2 )
3557 const dv3& src1row0 = src1.GetRow(0);
3558 const dv3& src1row1 = src1.GetRow(1);
3559 const dv3& src1row2 = src1.GetRow(2);
3561 for(
int i = 0; i < 3; i++)
3563 const dv3& src2rowI = src2.GetRow(i);
3565 double x = src2rowI.x * src1row0.x +
3566 src2rowI.y * src1row1.x +
3567 src2rowI.z * src1row2.x;
3569 double y = src2rowI.x * src1row0.y +
3570 src2rowI.y * src1row1.y +
3571 src2rowI.z * src1row2.y;
3573 double z = src2rowI.x * src1row0.z +
3574 src2rowI.y * src1row1.z +
3575 src2rowI.z * src1row2.z;
3577 temp.SetRow(i, dv3(x, y, z));
3580 memcpy(&dest, &temp,
sizeof(dest));
3583 inline void dm33::Mul(
const double scale )