Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
csMatrix3 Class Reference

#include <opmatrix3.h>

Inheritance diagram for csMatrix3:
csXRotMatrix3 csXScaleMatrix3 csYRotMatrix3 csYScaleMatrix3 csZRotMatrix3 csZScaleMatrix3

Public Member Functions

 csMatrix3 ()
 Construct a matrix, initialized to be the identity. More...
 
 csMatrix3 (float am11, float am12, float am13, float am21, float am22, float am23, float am31, float am32, float am33)
 Construct a matrix and initialize it. More...
 
 csMatrix3 (const Quaternion &quat)
 Construct a matrix with a quaternion. More...
 
csVector3 Row1 () const
 Get the first row of this matrix as a vector. More...
 
csVector3 Row2 () const
 Get the second row of this matrix as a vector. More...
 
csVector3 Row3 () const
 Get the third row of this matrix as a vector. More...
 
csVector3 Col1 () const
 Get the first column of this matrix as a vector. More...
 
csVector3 Col2 () const
 Get the second column of this matrix as a vector. More...
 
csVector3 Col3 () const
 Get the third column of this matrix as a vector. More...
 
void Set (float m11, float m12, float m13, float m21, float m22, float m23, float m31, float m32, float m33)
 Set matrix values. More...
 
void Set (const Quaternion &quat)
 Initialize matrix with a quaternion. More...
 
csMatrix3operator+= (const csMatrix3 &m)
 Add another matrix to this matrix. More...
 
csMatrix3operator-= (const csMatrix3 &m)
 Subtract another matrix from this matrix. More...
 
csMatrix3operator*= (const csMatrix3 &m)
 Multiply another matrix with this matrix. More...
 
csMatrix3operator*= (float s)
 Multiply this matrix with a scalar. More...
 
csMatrix3operator/= (float s)
 Divide this matrix by a scalar. More...
 
csMatrix3 operator+ () const
 Unary + operator. More...
 
csMatrix3 operator- () const
 Unary - operator. More...
 
void Transpose ()
 Transpose this matrix. More...
 
csMatrix3 GetTranspose () const
 Return the transpose of this matrix. More...
 
csMatrix3 GetInverse () const
 Return the inverse of this matrix. More...
 
void Invert ()
 Invert this matrix. More...
 
float Determinant () const
 Compute the determinant of this matrix. More...
 
void Identity ()
 Set this matrix to the identity matrix. More...
 
bool IsIdentity () const
 Check if the matrix is identity. More...
 

Public Attributes

float m11
 
float m12
 
float m13
 
float m21
 
float m22
 
float m23
 
float m31
 
float m32
 
float m33
 

Friends

csMatrix3 operator+ (const csMatrix3 &m1, const csMatrix3 &m2)
 Add two matricies. More...
 
csMatrix3 operator- (const csMatrix3 &m1, const csMatrix3 &m2)
 Subtract two matricies. More...
 
csMatrix3 operator* (const csMatrix3 &m1, const csMatrix3 &m2)
 Multiply two matricies. More...
 
csVector3 operator* (const csMatrix3 &m, const csVector3 &v)
 Multiply a vector by a matrix (transform it). More...
 
csMatrix3 operator* (const csMatrix3 &m, float f)
 Multiply a matrix and a scalar. More...
 
csMatrix3 operator* (float f, const csMatrix3 &m)
 Multiply a matrix and a scalar. More...
 
csMatrix3 operator/ (const csMatrix3 &m, float f)
 Divide a matrix by a scalar. More...
 
bool operator== (const csMatrix3 &m1, const csMatrix3 &m2)
 Check if two matricies are equal. More...
 
bool operator!= (const csMatrix3 &m1, const csMatrix3 &m2)
 Check if two matricies are not equal. More...
 
bool operator< (const csMatrix3 &m, float f)
 Test if each component of a matrix is less than a small epsilon value. More...
 
bool operator> (float f, const csMatrix3 &m)
 Test if each component of a matrix is greater than a small epsilon value. More...
 

Detailed Description

A 3x3 matrix.

Definition at line 31 of file opmatrix3.h.

Constructor & Destructor Documentation

csMatrix3::csMatrix3 ( )
inline

Construct a matrix, initialized to be the identity.

Definition at line 40 of file opmatrix3.h.

Referenced by operator-().

41  : m11(1), m12(0), m13(0),
42  m21(0), m22(1), m23(0),
43  m31(0), m32(0), m33(1)
44  {}
csMatrix3::csMatrix3 ( float  am11,
float  am12,
float  am13,
float  am21,
float  am22,
float  am23,
float  am31,
float  am32,
float  am33 
)
inline

Construct a matrix and initialize it.

Definition at line 47 of file opmatrix3.h.

50  : m11(am11), m12(am12), m13(am13),
51  m21(am21), m22(am22), m23(am23),
52  m31(am31), m32(am32), m33(am33)
53  {}
csMatrix3::csMatrix3 ( const Quaternion quat)
inlineexplicit

Construct a matrix with a quaternion.

Definition at line 56 of file opmatrix3.h.

References Set().

56 { Set (quat); }

Member Function Documentation

csVector3 csMatrix3::Col1 ( ) const
inline

Get the first column of this matrix as a vector.

Definition at line 68 of file opmatrix3.h.

References m11, m21, and m31.

68 { return csVector3 (m11,m21,m31); }
csVector3 csMatrix3::Col2 ( ) const
inline

Get the second column of this matrix as a vector.

Definition at line 71 of file opmatrix3.h.

References m12, m22, and m32.

71 { return csVector3 (m12,m22,m32); }
csVector3 csMatrix3::Col3 ( ) const
inline

Get the third column of this matrix as a vector.

Definition at line 74 of file opmatrix3.h.

References m13, m23, and m33.

74 { return csVector3 (m13,m23,m33); }
float csMatrix3::Determinant ( ) const

Compute the determinant of this matrix.

Definition at line 104 of file opmatrix3.cpp.

References m11, m12, m13, m21, m22, m23, m31, m32, and m33.

105 {
106  return
107  m11 * (m22*m33 - m23*m32)
108  -m12 * (m21*m33 - m23*m31)
109  +m13 * (m21*m32 - m22*m31);
110 }
csMatrix3 csMatrix3::GetInverse ( ) const
inline

Return the inverse of this matrix.

Definition at line 121 of file opmatrix3.h.

References float, m11, m12, m13, m21, m22, m23, m31, m32, and m33.

Referenced by csReversibleTransform::csReversibleTransform(), Invert(), csReversibleTransform::SetO2T(), and csReversibleTransform::SetT2O().

122  {
123  csMatrix3 C(
124  (m22*m33 - m23*m32), -(m12*m33 - m13*m32), (m12*m23 - m13*m22),
125  -(m21*m33 - m23*m31), (m11*m33 - m13*m31), -(m11*m23 - m13*m21),
126  (m21*m32 - m22*m31), -(m11*m32 - m12*m31), (m11*m22 - m12*m21) );
127  float s = (float)1./(m11*C.m11 + m12*C.m21 + m13*C.m31);
128 
129  C *= s;
130 
131  return C;
132  }
csMatrix3 csMatrix3::GetTranspose ( ) const

Return the transpose of this matrix.

Definition at line 94 of file opmatrix3.cpp.

References m11, m12, m13, m21, m22, m23, m31, m32, and m33.

Referenced by csOrthoTransform::SetO2T(), and csOrthoTransform::SetT2O().

95 {
96  csMatrix3 t;
97  t.m12 = m21; t.m21 = m12;
98  t.m13 = m31; t.m31 = m13;
99  t.m23 = m32; t.m32 = m23;
100  t.m11 = m11; t.m22 = m22; t.m33 = m33;
101  return t;
102 }
void csMatrix3::Identity ( )

Set this matrix to the identity matrix.

Definition at line 73 of file opmatrix3.cpp.

References m11, m12, m13, m21, m22, m23, m31, m32, and m33.

74 {
75  m11 = m22 = m33 = 1.0;
76  m12 = m13 = m21 = m23 = m31 = m32 = 0.0;
77 }
void csMatrix3::Invert ( )
inline

Invert this matrix.

Definition at line 135 of file opmatrix3.h.

References GetInverse().

135 { *this = GetInverse (); }
bool csMatrix3::IsIdentity ( ) const

Check if the matrix is identity.

Definition at line 79 of file opmatrix3.cpp.

References m11, m12, m13, m21, m22, m23, m31, m32, and m33.

80 {
81  return (m11 == 1.0) && (m22 == 1.0) && (m33 == 1.0)
82  && (m12 == 0.0) && (m13 == 0.0) && (m21 == 0.0)
83  && (m23 == 0.0) && (m31 == 0.0) && (m32 == 0.0);
84 }
csMatrix3 & csMatrix3::operator*= ( const csMatrix3 m)

Multiply another matrix with this matrix.

Definition at line 45 of file opmatrix3.cpp.

References m11, m12, m13, m21, m22, m23, m31, m32, and m33.

46 {
47  float old_m11 = m11;
48  m11 = m11*m.m11 + m12*m.m21 + m13*m.m31;
49  float old_m12 = m12;
50  m12 = old_m11*m.m12 + m12*m.m22 + m13*m.m32;
51  m13 = old_m11*m.m13 + old_m12*m.m23 + m13*m.m33;
52  float old_m21 = m21;
53  m21 = m21*m.m11 + m22*m.m21 + m23*m.m31;
54  float old_m22 = m22;
55  m22 = old_m21*m.m12 + m22*m.m22 + m23*m.m32;
56  m23 = old_m21*m.m13 + old_m22*m.m23 + m23*m.m33;
57  float old_m31 = m31;
58  m31 = m31*m.m11 + m32*m.m21 + m33*m.m31;
59  float old_m32 = m32;
60  m32 = old_m31*m.m12 + m32*m.m22 + m33*m.m32;
61  m33 = old_m31*m.m13 + old_m32*m.m23 + m33*m.m33;
62  return *this;
63 }
csMatrix3 & csMatrix3::operator*= ( float  s)

Multiply this matrix with a scalar.

Definition at line 65 of file opmatrix3.cpp.

References m11, m12, m13, m21, m22, m23, m31, m32, and m33.

66 {
67  m11 *= s; m12 *= s; m13 *= s;
68  m21 *= s; m22 *= s; m23 *= s;
69  m31 *= s; m32 *= s; m33 *= s;
70  return *this;
71 }
csMatrix3 csMatrix3::operator+ ( ) const
inline

Unary + operator.

Definition at line 105 of file opmatrix3.h.

105 { return *this; }
csMatrix3 & csMatrix3::operator+= ( const csMatrix3 m)

Add another matrix to this matrix.

Definition at line 29 of file opmatrix3.cpp.

References m11, m12, m13, m21, m22, m23, m31, m32, and m33.

30 {
31  m11 += m.m11; m12 += m.m12; m13 += m.m13;
32  m21 += m.m21; m22 += m.m22; m23 += m.m23;
33  m31 += m.m31; m32 += m.m32; m33 += m.m33;
34  return *this;
35 }
csMatrix3 csMatrix3::operator- ( ) const
inline

Unary - operator.

Definition at line 107 of file opmatrix3.h.

References csMatrix3(), m11, m12, m13, m21, m22, m23, m31, m32, and m33.

108  {
109  return csMatrix3(-m11,-m12,-m13,
110  -m21,-m22,-m23,
111  -m31,-m32,-m33);
112  }
csMatrix3 & csMatrix3::operator-= ( const csMatrix3 m)

Subtract another matrix from this matrix.

Definition at line 37 of file opmatrix3.cpp.

References m11, m12, m13, m21, m22, m23, m31, m32, and m33.

38 {
39  m11 -= m.m11; m12 -= m.m12; m13 -= m.m13;
40  m21 -= m.m21; m22 -= m.m22; m23 -= m.m23;
41  m31 -= m.m31; m32 -= m.m32; m33 -= m.m33;
42  return *this;
43 }
csMatrix3& csMatrix3::operator/= ( float  s)

Divide this matrix by a scalar.

csVector3 csMatrix3::Row1 ( ) const
inline

Get the first row of this matrix as a vector.

Definition at line 59 of file opmatrix3.h.

References m11, m12, and m13.

Referenced by csOPCODECollider::Collide().

59 { return csVector3 (m11,m12,m13); }
csVector3 csMatrix3::Row2 ( ) const
inline

Get the second row of this matrix as a vector.

Definition at line 62 of file opmatrix3.h.

References m21, m22, and m23.

Referenced by csOPCODECollider::Collide().

62 { return csVector3 (m21,m22,m23); }
csVector3 csMatrix3::Row3 ( ) const
inline

Get the third row of this matrix as a vector.

Definition at line 65 of file opmatrix3.h.

References m31, m32, and m33.

Referenced by csOPCODECollider::Collide().

65 { return csVector3 (m31,m32,m33); }
void csMatrix3::Set ( float  m11,
float  m12,
float  m13,
float  m21,
float  m22,
float  m23,
float  m31,
float  m32,
float  m33 
)
inline

Set matrix values.

Definition at line 77 of file opmatrix3.h.

References m11, m12, m13, m21, m22, m23, m31, m32, and m33.

Referenced by csMatrix3().

void csMatrix3::Set ( const Quaternion quat)

Initialize matrix with a quaternion.

Definition at line 112 of file opmatrix3.cpp.

References m11, m12, m13, m21, m22, m23, m31, m32, m33, Quaternion::s, Quaternion::v, x, y, and z.

113 {
114  float s;
115  float xs, ys, zs;
116  float wx, wy, wz;
117  float xx, xy, xz;
118  float yy, yz, zz;
119  float x = quat.v.i;
120  float y = quat.v.j;
121  float z = quat.v.k;
122  float w = quat.s;
123 
124  // For unit Quat, just set s = 2 or set xs = x + x, etc.
125  s = 2 / (x * x + y * y + z * z + w * w );
126 
127  xs = x * s; ys = y * s; zs = z * s;
128  wx = w * xs; wy = w * ys; wz = w * zs;
129  xx = x * xs; xy = x * ys; xz = x * zs;
130  yy = y * ys; yz = y * zs; zz = z * zs;
131 
132  m11 = 1.0f - (yy + zz);
133  m12 = xy + wz;
134  m13 = xz - wy;
135  m21 = xy - wz;
136  m22 = 1.0f - (xx + zz);
137  m23 = yz + wx;
138  m31 = xz + wy;
139  m32 = yz - wx;
140  m33 = 1.0f - (xx + yy);
141 }
void csMatrix3::Transpose ( )

Transpose this matrix.

Definition at line 86 of file opmatrix3.cpp.

References m12, m13, m21, m23, m31, and m32.

87 {
88  float swap;
89  swap = m12; m12 = m21; m21 = swap;
90  swap = m13; m13 = m31; m31 = swap;
91  swap = m23; m23 = m32; m32 = swap;
92 }

Friends And Related Function Documentation

bool operator!= ( const csMatrix3 m1,
const csMatrix3 m2 
)
friend

Check if two matricies are not equal.

Definition at line 201 of file opmatrix3.cpp.

202 {
203  if (m1.m11 != m2.m11 || m1.m12 != m2.m12 || m1.m13 != m2.m13) return true;
204  if (m1.m21 != m2.m21 || m1.m22 != m2.m22 || m1.m23 != m2.m23) return true;
205  if (m1.m31 != m2.m31 || m1.m32 != m2.m32 || m1.m33 != m2.m33) return true;
206  return false;
207 }
csMatrix3 operator* ( const csMatrix3 m1,
const csMatrix3 m2 
)
friend

Multiply two matricies.

Definition at line 157 of file opmatrix3.cpp.

158 {
159  return csMatrix3 (
160  m1.m11*m2.m11 + m1.m12*m2.m21 + m1.m13*m2.m31,
161  m1.m11*m2.m12 + m1.m12*m2.m22 + m1.m13*m2.m32,
162  m1.m11*m2.m13 + m1.m12*m2.m23 + m1.m13*m2.m33,
163  m1.m21*m2.m11 + m1.m22*m2.m21 + m1.m23*m2.m31,
164  m1.m21*m2.m12 + m1.m22*m2.m22 + m1.m23*m2.m32,
165  m1.m21*m2.m13 + m1.m22*m2.m23 + m1.m23*m2.m33,
166  m1.m31*m2.m11 + m1.m32*m2.m21 + m1.m33*m2.m31,
167  m1.m31*m2.m12 + m1.m32*m2.m22 + m1.m33*m2.m32,
168  m1.m31*m2.m13 + m1.m32*m2.m23 + m1.m33*m2.m33 );
169 }
csVector3 operator* ( const csMatrix3 m,
const csVector3 v 
)
friend

Multiply a vector by a matrix (transform it).

Definition at line 154 of file opmatrix3.h.

155  {
156  return csVector3 (m.m11*v.x + m.m12*v.y + m.m13*v.z,
157  m.m21*v.x + m.m22*v.y + m.m23*v.z,
158  m.m31*v.x + m.m32*v.y + m.m33*v.z);
159  }
csMatrix3 operator* ( const csMatrix3 m,
float  f 
)
friend

Multiply a matrix and a scalar.

Definition at line 171 of file opmatrix3.cpp.

172 {
173  return csMatrix3 (m.m11*f, m.m12*f, m.m13*f,
174  m.m21*f, m.m22*f, m.m23*f,
175  m.m31*f, m.m32*f, m.m33*f);
176 }
csMatrix3 operator* ( float  f,
const csMatrix3 m 
)
friend

Multiply a matrix and a scalar.

Definition at line 178 of file opmatrix3.cpp.

179 {
180  return csMatrix3 (m.m11*f, m.m12*f, m.m13*f,
181  m.m21*f, m.m22*f, m.m23*f,
182  m.m31*f, m.m32*f, m.m33*f);
183 }
csMatrix3 operator+ ( const csMatrix3 m1,
const csMatrix3 m2 
)
friend

Add two matricies.

Definition at line 144 of file opmatrix3.cpp.

145 {
146  return csMatrix3 (m1.m11+m2.m11, m1.m12+m2.m12, m1.m13+m2.m13,
147  m1.m21+m2.m21, m1.m22+m2.m22, m1.m23+m2.m23,
148  m1.m31+m2.m31, m1.m32+m2.m32, m1.m33+m2.m33);
149 }
csMatrix3 operator- ( const csMatrix3 m1,
const csMatrix3 m2 
)
friend

Subtract two matricies.

Definition at line 151 of file opmatrix3.cpp.

152 {
153  return csMatrix3 (m1.m11-m2.m11, m1.m12-m2.m12, m1.m13-m2.m13,
154  m1.m21-m2.m21, m1.m22-m2.m22, m1.m23-m2.m23,
155  m1.m31-m2.m31, m1.m32-m2.m32, m1.m33-m2.m33);
156 }
csMatrix3 operator/ ( const csMatrix3 m,
float  f 
)
friend

Divide a matrix by a scalar.

Definition at line 185 of file opmatrix3.cpp.

186 {
187  float inv_f = 1 / f;
188  return csMatrix3 (m.m11*inv_f, m.m12*inv_f, m.m13*inv_f,
189  m.m21*inv_f, m.m22*inv_f, m.m23*inv_f,
190  m.m31*inv_f, m.m32*inv_f, m.m33*inv_f);
191 }
bool operator< ( const csMatrix3 m,
float  f 
)
friend

Test if each component of a matrix is less than a small epsilon value.

Definition at line 209 of file opmatrix3.cpp.

210 {
211  return ABS(m.m11)<f && ABS(m.m12)<f && ABS(m.m13)<f &&
212  ABS(m.m21)<f && ABS(m.m22)<f && ABS(m.m23)<f &&
213  ABS(m.m31)<f && ABS(m.m32)<f && ABS(m.m33)<f;
214 }
bool operator== ( const csMatrix3 m1,
const csMatrix3 m2 
)
friend

Check if two matricies are equal.

Definition at line 193 of file opmatrix3.cpp.

194 {
195  if (m1.m11 != m2.m11 || m1.m12 != m2.m12 || m1.m13 != m2.m13) return false;
196  if (m1.m21 != m2.m21 || m1.m22 != m2.m22 || m1.m23 != m2.m23) return false;
197  if (m1.m31 != m2.m31 || m1.m32 != m2.m32 || m1.m33 != m2.m33) return false;
198  return true;
199 }
bool operator> ( float  f,
const csMatrix3 m 
)
friend

Test if each component of a matrix is greater than a small epsilon value.

Definition at line 216 of file opmatrix3.cpp.

217 {
218  return ABS(m.m11)<f && ABS(m.m12)<f && ABS(m.m13)<f &&
219  ABS(m.m21)<f && ABS(m.m22)<f && ABS(m.m23)<f &&
220  ABS(m.m31)<f && ABS(m.m32)<f && ABS(m.m33)<f;
221 }

Member Data Documentation


The documentation for this class was generated from the following files: