3DCoat Core API
The 3DCoat API documentation.
Loading...
Searching...
No Matches
cMat3.h
1#pragma once
2
6class APICALL cMat3 {
7public:
8 enum EZeroCtor { ZeroCtor };
9 enum EIdentityCtor { IdentityCtor };
10 enum ERowsCtor { RowsCtor };
11 enum EColsCtor { ColsCtor };
12
13 cMat3();
14 cMat3(const EZeroCtor);
15 cMat3(const EIdentityCtor);
16 cMat3(const ERowsCtor, const cVec3 &Row0, const cVec3 &Row1, const cVec3 &Row2);
17 cMat3(const EColsCtor, const cVec3 &Col0, const cVec3 &Col1, const cVec3 &Col2);
18 cMat3(const float _00, const float _01, const float _02,
19 const float _10, const float _11, const float _12,
20 const float _20, const float _21, const float _22);
21 cMat3(const cMat3& v) { memcpy(this, &v, sizeof(v)); }
22
23 void Copy(const float *Float9);
24 void CopyTransposed(const float *Float9);
25
26 void SetZero();
27 void SetIdentity();
28
29 const cVec3 & GetRow(const int Index) const;
30 const cVec3 & GetRow0() const;
31 const cVec3 & GetRow1() const;
32 const cVec3 & GetRow2() const;
33
34 cVec3 & Row(const int Index);
35 cVec3 & Row0();
36 cVec3 & Row1();
37 cVec3 & Row2();
38
39 void SetRow(const int Index, const cVec3 &);
40 void SetRow0(const cVec3 &);
41 void SetRow1(const cVec3 &);
42 void SetRow2(const cVec3 &);
43
44 void SetRow(const int Index, const float X, const float Y, const float Z);
45 void SetRow0(const float X, const float Y, const float Z);
46 void SetRow1(const float X, const float Y, const float Z);
47 void SetRow2(const float X, const float Y, const float Z);
48
49 const cVec3 GetCol(const int Index) const;
50 const cVec3 GetCol0() const;
51 const cVec3 GetCol1() const;
52 const cVec3 GetCol2() const;
53
54 void SetCol(const int Index, const cVec3 &);
55 void SetCol0(const cVec3 &);
56 void SetCol1(const cVec3 &);
57 void SetCol2(const cVec3 &);
58
59 void SetCol(const int Index, const float X, const float Y, const float Z);
60 void SetCol0(const float X, const float Y, const float Z);
61 void SetCol1(const float X, const float Y, const float Z);
62 void SetCol2(const float X, const float Y, const float Z);
63
64 void SetElem(int Row, int Col, float Value);
65 float GetElem(const int Row, const int Col) const;
66 float & Elem(const int Row, const int Col);
67
68 const cVec3 & operator [] (const int Row) const;
69 cVec3 & operator [] (const int Row);
70
71 float operator () (const int Row, const int Col) const;
72 float & operator () (const int Row, const int Col);
73
74 float Trace() const;
75 float Determinant() const;
76
77 bool operator == (const cMat3 &) const;
78 static bool Equals(const cMat3 &, const cMat3 &, const float Eps = cMath::MatrixEpsilon);
79
80 bool IsZero(const float Eps = cMath::MatrixEpsilon) const;
81 bool IsIdentity(const float Eps = cMath::MatrixEpsilon) const;
82 bool IsSymmetric(const float Eps = cMath::MatrixEpsilon) const;
83 bool IsOrthonormal(const float Eps = cMath::MatrixEpsilon) const;
84
85 const cMat3 operator - () const;
86
87 cMat3& operator += (const cMat3 &R);
88 cMat3& operator -= (const cMat3 &R);
89 cMat3& operator *= (const cMat3 &R);
90 cMat3& operator *= (const float);
91 cMat3& operator /= (const float);
92
93 const cMat3 operator + (const cMat3 &R) const;
94 const cMat3 operator - (const cMat3 &R) const;
95 const cMat3 operator * (const cMat3 &R) const;
96 const cMat3 operator * (const float) const;
97 friend const cMat3 operator * (const float, const cMat3 &);
98 const cMat3 operator / (const float) const;
99
100 void Add(const cMat3 &R);
101 void Sub(const cMat3 &R);
102 void Mul(const cMat3 &R);
103 void Mul(const float s);
104
105 static const cMat3 Add(const cMat3 &L, const cMat3 &R);
106 static const cMat3 Sub(const cMat3 &L, const cMat3 &R);
107 static const cMat3 Mul(const cMat3 &L, const cMat3 &R);
108 static const cMat3 Mul(const cMat3 &L, const float s);
109 static const cVec3 Mul(const cMat3 &L, const cVec3 &vc);
110
111 static const cMat3 Zero;
112 static const cMat3 Identity;
113
114 static const cMat3 Transpose(const cMat3 &);
115 void Transpose();
116
117 static bool Invert(const cMat3 &Fm, cMat3 *To);
118 bool Invert() { return Invert(*this, this); }
119
120 static const cMat3 OrthoNormalize(const cMat3 &Src);
121 void OrthoNormalize();
122
123 static const cMat3 Rotation(const cVec3 &Axis, const float Angle);
124 static const cMat3 RotationX(const float Angle);
125 static const cMat3 RotationY(const float Angle);
126 static const cMat3 RotationZ(const float Angle);
127 static const cMat3 RotationXYZ(const float Pitch, const float Yaw, const float Roll);
128 static const cMat3 EulerZYX(const float eulerX, const float eulerY, const float eulerZ);
129
130 static const cMat3 Scaling(const float XYZ);
131 static const cMat3 Scaling(const float X, const float Y);
132 static const cMat3 Scaling(const float X, const float Y, const float Z);
133 static const cMat3 Scaling(const cVec2 &XY);
134 static const cMat3 Scaling(const cVec3 &XYZ);
135
136 const float * ToFloatPtr() const;
137 float * ToFloatPtr();
138 const cMat4 ToMat4() const;
139 const cQuat ToQuat() const;
140
141 void ToVectors(cVec3 *Forward, cVec3 *Right = nullptr, cVec3 *Up = nullptr) const;
142 static const cMat3 FromVectors(const cVec3 &Forward, const cVec3 &Right, const cVec3 &Up);
143 static const cMat3 FromForward(const cVec3& Forward);
144 const cVec3 ToForward() const;
145 const cVec3 ToRight() const;
146 const cVec3 ToUp() const;
147
148 const cAngles ToAngles() const;
149
150 std::tuple<float, float, float, float, float, float, float, float, float> __getstate__();
151 void __setstate__(const std::tuple<float, float, float, float, float, float, float, float, float>& state);
152 const std::string __repr__() const;
153
154private:
155 cVec3 m_Rows[3];
156};
157
158// cMat3.ctor : ()
159inline cMat3::cMat3() {
160}
161
162// cMat3.ctor : (const EZeroCtor)
163inline cMat3::cMat3(const EZeroCtor) {
164 m_Rows[0].SetZero();
165 m_Rows[1].SetZero();
166 m_Rows[2].SetZero();
167}
168
169// cMat3.ctor : (const EIdentityCtor)
170inline cMat3::cMat3(const EIdentityCtor) {
171 m_Rows[0].Set(1.0f, 0.0f, 0.0f);
172 m_Rows[1].Set(0.0f, 1.0f, 0.0f);
173 m_Rows[2].Set(0.0f, 0.0f, 1.0f);
174}
175
176// cMat3.ctor : (const ERowsCtor, const cVec3 &, const cVec3 &, const cVec3 &)
177inline cMat3::cMat3(const ERowsCtor, const cVec3 &Row0, const cVec3 &Row1, const cVec3 &Row2) {
178 m_Rows[0] = Row0;
179 m_Rows[1] = Row1;
180 m_Rows[2] = Row2;
181}
182
183// cMat3.ctor : (const EColsCtor, const cVec3 &, const cVec3 &, const cVec3 &)
184inline cMat3::cMat3(const EColsCtor, const cVec3 &Col0, const cVec3 &Col1, const cVec3 &Col2) {
185 m_Rows[0].Set(Col0.x, Col1.x, Col2.x);
186 m_Rows[1].Set(Col0.y, Col1.y, Col2.y);
187 m_Rows[2].Set(Col0.z, Col1.z, Col2.z);
188}
189
190// cMat3.ctor
191inline cMat3::cMat3(const float _00, const float _01, const float _02,
192 const float _10, const float _11, const float _12,
193 const float _20, const float _21, const float _22) {
194 m_Rows[0].Set(_00, _01, _02);
195 m_Rows[1].Set(_10, _11, _12);
196 m_Rows[2].Set(_20, _21, _22);
197}
198
199// cMat3::Copy
200inline void cMat3::Copy(const float *Float9) {
201 m_Rows[0].Set(Float9[0], Float9[1], Float9[2]);
202 m_Rows[1].Set(Float9[3], Float9[4], Float9[5]);
203 m_Rows[2].Set(Float9[6], Float9[7], Float9[8]);
204}
205
206// cMat3::CopyTransposed
207inline void cMat3::CopyTransposed(const float *Float9) {
208 m_Rows[0].Set(Float9[0], Float9[3], Float9[6]);
209 m_Rows[1].Set(Float9[1], Float9[4], Float9[7]);
210 m_Rows[2].Set(Float9[2], Float9[5], Float9[8]);
211}
212
213// cMat3::SetZero
214inline void cMat3::SetZero() {
215 m_Rows[0].SetZero();
216 m_Rows[1].SetZero();
217 m_Rows[2].SetZero();
218}
219
220// cMat3::SetIdentity
221inline void cMat3::SetIdentity() {
222 m_Rows[0].Set(1.0f, 0.0f, 0.0f);
223 m_Rows[1].Set(0.0f, 1.0f, 0.0f);
224 m_Rows[2].Set(0.0f, 0.0f, 1.0f);
225}
226
227// cMat3::GetRow : const cVec3 & (const int) const
228inline const cVec3 & cMat3::GetRow(const int Index) const {
229 cAssert(Index >= 0 && Index < 3);
230 return m_Rows[Index];
231}
232
233// cMat3::GetRow0 : const cVec3 & () const
234inline const cVec3 & cMat3::GetRow0() const {
235 return m_Rows[0];
236}
237
238// cMat3::GetRow1 : const cVec3 & () const
239inline const cVec3 & cMat3::GetRow1() const {
240 return m_Rows[1];
241}
242
243// cMat3::GetRow2 : const cVec3 & () const
244inline const cVec3 & cMat3::GetRow2() const {
245 return m_Rows[2];
246}
247
248// cMat3::Row : cVec3 & (const int)
249inline cVec3 & cMat3::Row(const int Index) {
250 cAssert(Index >= 0 && Index < 3);
251 return m_Rows[Index];
252}
253
254// cMat3::Row0 : cVec3 & ()
255inline cVec3 & cMat3::Row0() {
256 return m_Rows[0];
257}
258
259// cMat3::Row1 : cVec3 & ()
260inline cVec3 & cMat3::Row1() {
261 return m_Rows[1];
262}
263
264// cMat3::Row2 : cVec3 & ()
265inline cVec3 & cMat3::Row2() {
266 return m_Rows[2];
267}
268
269// cMat3::SetRow : void (const int, const cVec3 &)
270inline void cMat3::SetRow(const int Index, const cVec3 &r) {
271 cAssert(Index >= 0 && Index < 3);
272 m_Rows[Index] = r;
273}
274
275// cMat3::SetRow0 : void (const cVec3 &)
276inline void cMat3::SetRow0(const cVec3 &r) {
277 m_Rows[0] = r;
278}
279
280// cMat3::SetRow1 : void (const cVec3 &)
281inline void cMat3::SetRow1(const cVec3 &r) {
282 m_Rows[1] = r;
283}
284
285// cMat3::SetRow2 : void (const cVec3 &)
286inline void cMat3::SetRow2(const cVec3 &r) {
287 m_Rows[2] = r;
288}
289
290// cMat3::SetRow : void (const int, const float, const float, const float)
291inline void cMat3::SetRow(const int Index, const float X, const float Y, const float Z) {
292 cAssert(Index >= 0 && Index < 3);
293 m_Rows[Index].Set(X, Y, Z);
294}
295
296// cMat3::SetRow0 : void (const float, const float, const float)
297inline void cMat3::SetRow0(const float X, const float Y, const float Z) {
298 m_Rows[0].Set(X, Y, Z);
299}
300
301// cMat3::SetRow1 : void (const float, const float, const float)
302inline void cMat3::SetRow1(const float X, const float Y, const float Z) {
303 m_Rows[1].Set(X, Y, Z);
304}
305
306// cMat3::SetRow2 : void(const float, const float, const float)
307inline void cMat3::SetRow2(const float X, const float Y, const float Z) {
308 m_Rows[2].Set(X, Y, Z);
309}
310
311// cMat3::GetCol : const cVec3 (const int) const
312inline const cVec3 cMat3::GetCol(const int Index) const {
313 cAssert(Index >= 0 && Index < 3);
314 return cVec3(m_Rows[0][Index], m_Rows[1][Index], m_Rows[2][Index]);
315}
316
317// cMat3::GetCol0 : const cVec3 () const
318inline const cVec3 cMat3::GetCol0() const {
319 return cVec3(m_Rows[0].x, m_Rows[1].x, m_Rows[2].x);
320}
321
322// cMat3::GetCol1 : const cVec3 () const
323inline const cVec3 cMat3::GetCol1() const {
324 return cVec3(m_Rows[0].y, m_Rows[1].y, m_Rows[2].y);
325}
326
327// cMat3::GetCol2 : const cVec3 () const
328inline const cVec3 cMat3::GetCol2() const {
329 return cVec3(m_Rows[0].z, m_Rows[1].z, m_Rows[2].z);
330}
331
332// cMat3::SetCol : void (const int, const cVec3 &)
333inline void cMat3::SetCol(const int Index, const cVec3 &u) {
334 cAssert(Index >= 0 && Index < 3);
335 m_Rows[0][Index] = u.x;
336 m_Rows[1][Index] = u.y;
337 m_Rows[2][Index] = u.z;
338}
339
340// cMat3::SetCol0 : void (const cVec3 &)
341inline void cMat3::SetCol0(const cVec3 &u) {
342 m_Rows[0].x = u.x;
343 m_Rows[1].x = u.y;
344 m_Rows[2].x = u.z;
345}
346
347// cMat3::SetCol1 : void (const cVec3 &)
348inline void cMat3::SetCol1(const cVec3 &u) {
349 m_Rows[0].y = u.x;
350 m_Rows[1].y = u.y;
351 m_Rows[2].y = u.z;
352}
353
354// cMat3::SetCol2 : void (const cVec3 &)
355inline void cMat3::SetCol2(const cVec3 &u) {
356 m_Rows[0].z = u.x;
357 m_Rows[1].z = u.y;
358 m_Rows[2].z = u.z;
359}
360
361// cMat3::SetCol : void (const int, const float, const float, const float)
362inline void cMat3::SetCol(const int Index, const float X, const float Y, const float Z) {
363 cAssert(Index >= 0 && Index < 3);
364 m_Rows[0][Index] = X;
365 m_Rows[1][Index] = Y;
366 m_Rows[2][Index] = Z;
367}
368
369// cMat3::SetCol0 : void (const float, const float, const float)
370inline void cMat3::SetCol0(const float X, const float Y, const float Z) {
371 m_Rows[0].x = X;
372 m_Rows[1].x = Y;
373 m_Rows[2].x = Z;
374}
375
376// cMat3::SetCol1 : void (const float, const float, const float)
377inline void cMat3::SetCol1(const float X, const float Y, const float Z) {
378 m_Rows[0].y = X;
379 m_Rows[1].y = Y;
380 m_Rows[2].y = Z;
381}
382
383// cMat3::SetCol2 : void (const float, const float, const float)
384inline void cMat3::SetCol2(const float X, const float Y, const float Z) {
385 m_Rows[0].z = X;
386 m_Rows[1].z = Y;
387 m_Rows[2].z = Z;
388}
389
390// cMat3::GetElem : float (const int, const int) const
391inline void cMat3::SetElem(int Row, int Col, float Value) {
392 cAssert(Row >= 0 && Row < 3);
393 cAssert(Col >= 0 && Col < 3);
394 m_Rows[Row][Col] = Value;
395}
396
397// cMat3::GetElem : float (const int, const int) const
398inline float cMat3::GetElem(const int Row, const int Col) const {
399 cAssert(Row >= 0 && Row < 3);
400 cAssert(Col >= 0 && Col < 3);
401 return m_Rows[Row][Col];
402}
403
404// cMat3::Elem : float & (const int, const int)
405inline float & cMat3::Elem(const int Row, const int Col) {
406 cAssert(Row >= 0 && Row < 3);
407 cAssert(Col >= 0 && Col < 3);
408 return m_Rows[Row][Col];
409}
410
411// cMat3::operator [] : const cVec3 & (const int) const
412inline const cVec3 & cMat3::operator [] (const int Row) const {
413 cAssert(Row >= 0 && Row < 3);
414 return m_Rows[Row];
415}
416
417// cMat3::operator [] : cVec3 & (const int)
418inline cVec3 & cMat3::operator [] (const int Row) {
419 cAssert(Row >= 0 && Row < 3);
420 return m_Rows[Row];
421}
422
423// cMat3::operator () : float (const int, const int) const
424inline float cMat3::operator () (const int Row, const int Col) const {
425 cAssert(Row >= 0 && Row < 3);
426 cAssert(Col >= 0 && Col < 3);
427 return m_Rows[Row][Col];
428}
429
430// cMat3::operator () : float & (const int, const int)
431inline float & cMat3::operator () (const int Row, const int Col) {
432 cAssert(Row >= 0 && Row < 3);
433 cAssert(Col >= 0 && Col < 3);
434 return m_Rows[Row][Col];
435}
436
437// cMat3::Trace
438inline float cMat3::Trace() const {
439 return m_Rows[0][0] + m_Rows[1][1] + m_Rows[2][2];
440}
441
442// cMat3::operator == : bool(const cMat3 &) const
443inline bool cMat3::operator == (const cMat3 &u) const {
444 return cMat3::Equals( *this, u );
445}
446
447// cMat3::Equals
448inline bool cMat3::Equals(const cMat3 &P, const cMat3 &Q, const float Eps) {
449 if(cVec3::Equals(P[0], Q[0]) && cVec3::Equals(P[1], Q[1]) && cVec3::Equals(P[2], Q[2])) {
450 return true;
451 }
452 return false;
453}
454
455// cMat3::operator - : const cMat3 () const
456inline const cMat3 cMat3::operator - () const {
457 return Mul(*this, -1.0f);
458}
459
460//-----------------------------------------------------------------------------
461// cMat3::Add : void (const cMat3 &)
462//-----------------------------------------------------------------------------
463inline void cMat3::Add(const cMat3 &R) {
464 float *l = reinterpret_cast<float *>(this);
465 const float *r = reinterpret_cast<const float *>(&R);
466
467 for(int i = 0; i < 9; i++) {
468 *l++ += *r++;
469 }
470} // cMat3::Add
471
472// cMat3::operator += : void (const cMat3 &)
473inline cMat3& cMat3::operator += (const cMat3 &R) {
474 Add(R);
475 return *this;
476}
477
478//-----------------------------------------------------------------------------
479// cMat3::Add : const cMat3 (const cMat3 &, const cMat3 &)
480//-----------------------------------------------------------------------------
481inline const cMat3 cMat3::Add(const cMat3 &L, const cMat3 &R) {
482 const float *l = reinterpret_cast<const float *>(&L);
483 const float *r = reinterpret_cast<const float *>(&R);
484 cMat3 S;
485 float *s = reinterpret_cast<float *>(&S);
486
487 for(int i = 0; i < 9; i++) {
488 *s++ = *l++ + *r++;
489 }
490 return S;
491}
492
493// cMat3::operator + : const cMat3 (const cMat3 &) const
494inline const cMat3 cMat3::operator + (const cMat3 &R) const {
495 return Mul(*this, R);
496}
497
498//-----------------------------------------------------------------------------
499// cMat3::Sub : void (const cMat3 &)
500//-----------------------------------------------------------------------------
501inline void cMat3::Sub(const cMat3 &R) {
502 float *l = reinterpret_cast<float *>(this);
503 const float *r = reinterpret_cast<const float *>(&R);
504
505 for(int i = 0; i < 9; i++) {
506 *l++ -= *r++;
507 }
508} // cMat3::Sub
509
510// cMat3::operator -= : void (const cMat3 &)
511inline cMat3& cMat3::operator -= (const cMat3 &R) {
512 Sub(R);
513 return *this;
514}
515
516//-----------------------------------------------------------------------------
517// cMat3::Sub : const cMat3 (const cMat3 &, const cMat3 &)
518//-----------------------------------------------------------------------------
519inline const cMat3 cMat3::Sub(const cMat3 &L, const cMat3 &R) {
520 const float *l = reinterpret_cast<const float *>(&L);
521 const float *r = reinterpret_cast<const float *>(&R);
522 cMat3 D;
523 float *d = reinterpret_cast<float *>(&D);
524
525 for(int i = 0; i < 9; i++) {
526 *d++ = *l++ - *r++;
527 }
528 return D;
529} // cMat3::Sub
530
531inline const cMat3 cMat3::operator - (const cMat3 &R) const {
532 return Sub(*this, R);
533}
534
535//-----------------------------------------------------------------------------
536// cMat3::Mul : void (const cMat3 &)
537//-----------------------------------------------------------------------------
538inline void cMat3::Mul(const cMat3 &R) {
539 float *l = reinterpret_cast<float *>(this);
540 const float *r = reinterpret_cast<const float *>(&R);
541
542 float t[3];
543 for(int i = 0; i < 3; i++) {
544 for(int j = 0; j < 3; j++) {
545 t[j] = l[0] * r[0 * 3 + j] + l[1] * r[1 * 3 + j] + l[2] * r[2 * 3 + j];
546 }
547 l[0] = t[0];
548 l[1] = t[1];
549 l[2] = t[2];
550 l += 3;
551 }
552} // cMat3::Mul
553
554// cMat3::Mul : void (const float)
555inline void cMat3::Mul(const float s) {
556 float *l = (float *)this;
557 for(int i = 0; i < 9; i++) {
558 *l++ *= s;
559 }
560}
561
562// cMat3::operator *= : void (const cMat3 &)
563inline cMat3& cMat3::operator *= (const cMat3 &R) {
564 Mul(R);
565 return *this;
566}
567
568// cMat3::operator *= : void (const float)
569inline cMat3& cMat3::operator *= (const float s) {
570 Mul(s);
571 return *this;
572}
573
574// cMat3::operator /=
575inline cMat3& cMat3::operator /= (const float s) {
576 float is = 1.0f / s;
577 Mul(is);
578 return *this;
579}
580
581//-----------------------------------------------------------------------------
582// cMat3::Mul : const cMat3 (const cMat3 &, const cMat3 &)
583//-----------------------------------------------------------------------------
584inline const cMat3 cMat3::Mul(const cMat3 &L, const cMat3 &R) {
585 cMat3 M;
586 const float *l = reinterpret_cast<const float *>(&L);
587 const float *r = reinterpret_cast<const float *>(&R);
588 float *m = reinterpret_cast<float *>(&M);
589
590 for(int i = 0; i < 3; i++) {
591 for(int j = 0; j < 3; j++) {
592 *m = l[0] * r[0 * 3 + j] + l[1] * r[1 * 3 + j] + l[2] * r[2 * 3 + j];
593 m++;
594 }
595 l += 3;
596 }
597 return M;
598} // cMat3::Mul
599
600// cMat3::Mul : const cMat3 (const cMat3 &, const float)
601inline const cMat3 cMat3::Mul(const cMat3 &L, const float s) {
602 cMat3 M;
603 const float *l = (const float *)&L;
604 float *m = (float *)&M;
605
606 for(int i = 0; i < 9; i++) {
607 *m++ = *l++ * s;
608 }
609 return M;
610}
611
612inline const cVec3 cMat3::Mul(const cMat3 &L, const cVec3 &vc){
613 cVec3 res_vec;
614
615 res_vec.x = L.m_Rows[0].x *vc.x + L.m_Rows[0].y *vc.y + L.m_Rows[0].z *vc.z;
616 res_vec.y = L.m_Rows[1].x *vc.x + L.m_Rows[1].y *vc.y + L.m_Rows[1].z *vc.z;
617 res_vec.z = L.m_Rows[2].x *vc.x + L.m_Rows[2].y *vc.y + L.m_Rows[2].z *vc.z;
618
619 return res_vec;
620}
621
622// cMat3::operator * : const cMat3 (const cMat3 &) const
623inline const cMat3 cMat3::operator * (const cMat3 &R) const {
624 return Mul(*this, R);
625}
626
627// cMat3::operator * : const cMat3 (const float) const
628inline const cMat3 cMat3::operator * (const float s) const {
629 return Mul(*this, s);
630}
631
632// cMat3::operator /
633inline const cMat3 cMat3::operator / (const float s) const {
634 float is = 1.0f / s;
635 return Mul(*this, is);
636}
637
638// operator * : const cMat3 (const float, const cMat3 &)
639inline const cMat3 operator * (const float s, const cMat3 &R) {
640 return cMat3::Mul(R, s);
641}
642
643// cMat3::IsZero
644inline bool cMat3::IsZero(const float Eps) const {
645 return Equals(*this, Zero, Eps);
646}
647
648// cMat3::IsIdentity
649inline bool cMat3::IsIdentity(const float Eps) const {
650 return Equals(*this, Identity, Eps);
651}
652
653// cMat3::IsSymmetric
654inline bool cMat3::IsSymmetric(const float Eps) const {
655 if(!cMath::Equals(m_Rows[2][0], m_Rows[0][2], Eps)) {
656 return false;
657 }
658 if(!cMath::Equals(m_Rows[2][1], m_Rows[1][2], Eps)) {
659 return false;
660 }
661 if(!cMath::Equals(m_Rows[1][0], m_Rows[0][1], Eps)) {
662 return false;
663 }
664 return true;
665}
666
667// cMat3::IsOrthonormal
668inline bool cMat3::IsOrthonormal(const float Eps) const {
669 return cMath::IsOne(Determinant(), Eps);
670}
671
672// cMat3::ToFloatPtr() : const float * () const
673inline const float * cMat3::ToFloatPtr() const {
674 return m_Rows[0].ToFloatPtr();
675}
676
677// cMat3::ToFloatPtr() : float * ()
678inline float * cMat3::ToFloatPtr() {
679 return m_Rows[0].ToFloatPtr();
680}
681
682// cMat3::Transpose : const cMat3 (const cMat3 &)
683inline const cMat3 cMat3::Transpose(const cMat3 &M) {
684 cMat3 T;
685 for(int i = 0; i < 3; i++) {
686 T.SetRow(i, M.GetCol(i));
687 }
688 return T;
689}
690
691// cMat3::Transpose : void ()
692inline void cMat3::Transpose() {
693 cMath::Swap(m_Rows[0][1], m_Rows[1][0]);
694 cMath::Swap(m_Rows[0][2], m_Rows[2][0]);
695 cMath::Swap(m_Rows[1][2], m_Rows[2][1]);
696}
697
698// cMat3::OrthoNormalize : const cMat3 (const cMat3 &)
699inline const cMat3 cMat3::OrthoNormalize(const cMat3 &Src) {
700 cMat3 O = Src;
701 O.m_Rows[0].Normalize();
702 O.m_Rows[2] = cVec3::Cross(O.m_Rows[0], O.m_Rows[1]).ToNormal();
703 O.m_Rows[1] = cVec3::Cross(O.m_Rows[2], O.m_Rows[0]).ToNormal();
704 return O;
705}
706
707// cMat3::OrthoNormalize : void ()
708inline void cMat3::OrthoNormalize() {
709 m_Rows[0].Normalize();
710 m_Rows[2] = cVec3::Cross(m_Rows[0], m_Rows[1]).ToNormal();
711 m_Rows[1] = cVec3::Cross(m_Rows[2], m_Rows[0]).ToNormal();
712}
713
714//*****************************************************************************
715// cVec2 & cMat3
716//*****************************************************************************
717
718// cVec2::Transform : const cVec2 (const cVec2 &, const cMat3 &)
719inline const cVec2 cVec2::Transform(const cVec2 &u, const cMat3 &R) {
720 cVec2 r;
721 r.x = u.x * R(0, 0) + u.y * R(1, 0);
722 r.y = u.x * R(0, 1) + u.y * R(1, 1);
723 return r;
724}
725
726// cVec2::Transform : void (const cMat3 &)
727inline void cVec2::Transform(const cMat3 &R) {
728 *this = Transform(*this, R);
729}
730
731// cVec2::operator *= : void (const cMat3 &)
732inline void cVec2::operator *= (const cMat3 &R) {
733 *this = Transform(*this, R);
734}
735
736// cVec2::operator * : const cVec2 (const cMat3 &) const
737inline const cVec2 cVec2::operator * (const cMat3 &R) const {
738 return Transform(*this, R);
739}
740
741//*****************************************************************************
742// cVec3 & cMat3
743//*****************************************************************************
744
745// cVec3::Transform : const cVec3 (const cVec3 &, const cMat3 &)
746inline const cVec3 cVec3::Transform(const cVec3 &u, const cMat3 &R) {
747 cVec3 r;
748 r.x = u.x * R(0, 0) + u.y * R(1, 0) + u.z * R(2, 0);
749 r.y = u.x * R(0, 1) + u.y * R(1, 1) + u.z * R(2, 1);
750 r.z = u.x * R(0, 2) + u.y * R(1, 2) + u.z * R(2, 2);
751 return r;
752}
753
754// cVec3::Transform : void (const cMat3 &)
755inline void cVec3::Transform(const cMat3 &R) {
756 *this = Transform(*this, R);
757}
758
759// cVec3::operator *= : void (const cMat3 &)
760inline cVec3& cVec3::operator *= (const cMat3 &R) {
761 *this = Transform(*this, R);
762 return *this;
763}
764
765
766// cVec3::operator * : const cVec3 (const cMat3 &) const
767inline const cVec3 cVec3::operator * (const cMat3 &R) const {
768 return Transform(*this, R);
769}
770
771
772
773
774::std::ostream& operator<<( ::std::ostream&, const cMat3& );
The 3D-matrix, refer it as coat::mat3 in the Core API.
Definition cMat3.h:6
The 4D-matrix, refer it as coat::mat4 in the Core API.
Definition cMat4.h:6
The 2D-vector, refer it as coat::vec2 in the Core API.
Definition cVec2.h:9
The 3D-vector, refer it as coat::vec3 in the Core API.
Definition cVec3.h:10