00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "CMatrix33.h"
00014 #include <math.h>
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 CMatrix33::CMatrix33(const float &f)
00032 {
00033 _11 = _12 = _13 =
00034 _21 = _22 = _23 =
00035 _31 = _31 = _33 = f;
00036 }
00037
00038 CMatrix33::CMatrix33(const float &f11, const float &f12, const float &f13,
00039 const float &f21, const float &f22, const float &f23,
00040 const float &f31, const float &f32, const float &f33)
00041 {
00042 _11 = f11; _12 = f12; _13 = f13;
00043 _21 = f21; _22 = f22; _23 = f23;
00044 _31 = f31; _32 = f32; _33 = f33;
00045 }
00046
00047 CMatrix33::CMatrix33(const CMatrix33 &other)
00048 {
00049 _11 = other._11; _12 = other._12; _13 = other._13;
00050 _21 = other._21; _22 = other._22; _23 = other._23;
00051 _31 = other._31; _32 = other._32; _33 = other._33;
00052 }
00053
00054 const CMatrix33 &CMatrix33::operator=(const CMatrix33 &other)
00055 {
00056 _11 = other._11; _12 = other._12; _13 = other._13;
00057 _21 = other._21; _22 = other._22; _23 = other._23;
00058 _31 = other._31; _32 = other._32; _33 = other._33;
00059
00060 return *this;
00061 }
00062
00063
00064 const CMatrix33 CMatrix33::operator*(const CMatrix33 &other) const
00065 {
00066 return CMatrix33(_11 * other._11 + _12 * other._21 + _13 * other._31,
00067 _11 * other._12 + _12 * other._22 + _13 * other._32,
00068 _11 * other._13 + _12 * other._23 + _13 * other._33,
00069
00070 _21 * other._11 + _22 * other._21 + _23 * other._31,
00071 _21 * other._12 + _22 * other._22 + _23 * other._32,
00072 _21 * other._13 + _22 * other._23 + _23 * other._33,
00073
00074 _31 * other._11 + _32 * other._21 + _33 * other._31,
00075 _31 * other._12 + _32 * other._22 + _33 * other._32,
00076 _31 * other._13 + _32 * other._23 + _33 * other._33);
00077 }
00078
00079 const CMatrix33 &CMatrix33::operator*=(const CMatrix33 &other)
00080 {
00081 Set(_11 * other._11 + _12 * other._21 + _13 * other._31,
00082 _11 * other._12 + _12 * other._22 + _13 * other._32,
00083 _11 * other._13 + _12 * other._23 + _13 * other._33,
00084
00085 _21 * other._11 + _22 * other._21 + _23 * other._31,
00086 _21 * other._12 + _22 * other._22 + _23 * other._32,
00087 _21 * other._13 + _22 * other._23 + _23 * other._33,
00088
00089 _31 * other._11 + _32 * other._21 + _33 * other._31,
00090 _31 * other._12 + _32 * other._22 + _33 * other._32,
00091 _31 * other._13 + _32 * other._23 + _33 * other._33);
00092
00093 return *this;
00094 }
00095
00096 const CVector3f CMatrix33::operator*(const CVector3f &v) const
00097 {
00098 return CVector3f(_11 * v.m_X + _12 * v.m_Y + _13 * v.m_Z,
00099 _21 * v.m_X + _22 * v.m_Y + _23 * v.m_Z,
00100 _31 * v.m_X + _32 * v.m_Y + _33 * v.m_Z);
00101 }
00102
00103 bool CMatrix33::operator==(const CMatrix33 &other) const
00104 {
00105 return _11 == other._11 && _12 == other._12 && _13 == other._13
00106 && _21 == other._21 && _22 == other._22 && _23 == other._23
00107 && _31 == other._31 && _32 == other._32 && _33 == other._33;
00108 }
00109
00110 bool CMatrix33::operator!=(const CMatrix33 &other) const
00111 {
00112 return _11 != other._11 || _12 != other._12 || _13 != other._13
00113 || _21 != other._21 || _22 != other._22 || _23 != other._23
00114 || _31 != other._31 || _32 != other._32 || _33 != other._33;
00115 }
00116
00117 void CMatrix33::Set(const float &f)
00118 {
00119 _11 = _12 = _13 =
00120 _21 = _22 = _23 =
00121 _31 = _31 = _33 = f;
00122 }
00123
00124 void CMatrix33::Set(const float &f11, const float &f12, const float &f13,
00125 const float &f21, const float &f22, const float &f23,
00126 const float &f31, const float &f32, const float &f33)
00127 {
00128 _11 = f11; _12 = f12; _13 = f13;
00129 _21 = f21; _22 = f22; _23 = f23;
00130 _31 = f31; _32 = f32; _33 = f33;
00131 }
00132
00133 void CMatrix33::Identity()
00134 {
00135 _11 = 1.0f; _12 = 0.0f; _13 = 0.0f;
00136 _21 = 0.0f; _22 = 1.0f; _23 = 0.0f;
00137 _31 = 0.0f; _32 = 0.0f; _33 = 1.0f;
00138 }
00139
00140 void CMatrix33::Transpose()
00141 {
00142 float f;
00143
00144 f = _12;
00145 _12 = _21;
00146 _21 = f;
00147
00148 f = _13;
00149 _13 = _31;
00150 _31 = f;
00151
00152 f = _23;
00153 _23 = _32;
00154 _32 = f;
00155 }
00156
00157 void CMatrix33::TransposeFrom(const CMatrix33 &m)
00158 {
00159 _11 = m._11; _12 = m._21; _13 = m._31;
00160 _21 = m._12; _22 = m._22; _23 = m._32;
00161 _31 = m._13; _32 = m._23; _33 = m._33;
00162 }
00163
00164
00165 void CMatrix33::Multiply(const CMatrix33 &first, const CMatrix33 &second)
00166 {
00167 _11 = first._11 * second._11 + first._12 * second._21 + first._13 * second._31;
00168 _12 = first._11 * second._12 + first._12 * second._22 + first._13 * second._32;
00169 _13 = first._11 * second._13 + first._12 * second._23 + first._13 * second._33;
00170
00171 _21 = first._21 * second._11 + first._22 * second._21 + first._23 * second._31;
00172 _22 = first._21 * second._12 + first._22 * second._22 + first._23 * second._32;
00173 _23 = first._21 * second._13 + first._22 * second._23 + first._23 * second._33;
00174
00175 _31 = first._31 * second._11 + first._32 * second._21 + first._33 * second._31;
00176 _32 = first._31 * second._12 + first._32 * second._22 + first._33 * second._32;
00177 _33 = first._31 * second._13 + first._32 * second._23 + first._33 * second._33;
00178 }
00179
00180 void CMatrix33::Scaling(const float &fX, const float &fY, const float &fZ)
00181 {
00182 _11 = fX; _12 = 0.0f; _13 = 0.0f;
00183 _21 = 0.0f; _22 = fY; _23 = 0.0f;
00184 _31 = 0.0f; _32 = 0.0f; _33 = fZ;
00185 }
00186
00187 void CMatrix33::Scaling(const CVector3f &vScale)
00188 {
00189 _11 = vScale.m_X; _12 = 0.0f; _13 = 0.0f;
00190 _21 = 0.0f; _22 = vScale.m_Y; _23 = 0.0f;
00191 _31 = 0.0f; _32 = 0.0f; _33 = vScale.m_Z;
00192 }
00193
00194 void CMatrix33::RotationX(const float &fRad)
00195 {
00196 _11 = 1.0f; _12 = 0.0f; _13 = 0.0f;
00197 _21 = 0.0f; _22 = cos(fRad); _23 = sin(fRad);
00198 _31 = 0.0f; _32 = -_23; _33 = _22;
00199 }
00200
00201 void CMatrix33::RotationY(const float &fRad)
00202 {
00203 _11 = cos(fRad); _12 = 0.0f; _13 = -sin(fRad);
00204 _21 = 0.0f; _22 = 1.0f; _23 = 0.0f;
00205 _31 = -_13; _32 = 0.0f; _33 = _11;
00206 }
00207
00208 void CMatrix33::RotationZ(const float &fRad)
00209 {
00210 _11 = cos(fRad); _12 = sin(fRad); _13 = 0.0f;
00211 _21 = -_12; _22 = _11; _23 = 0.0f;
00212 _31 = 0.0f; _32 = 0.0f; _33 = 1.0f;
00213 }
00214
00215 void CMatrix33::RotationZXY(const float &fX, const float &fY, const float &fZ)
00216 {
00217 float sinx = sin(fX);
00218 float siny = sin(fY);
00219 float sinz = sin(fZ);
00220 float cosx = cos(fX);
00221 float cosy = cos(fY);
00222 float cosz = cos(fZ);
00223
00224 _11 = cosy*cosz - sinx*siny*sinz; _12 = cosy*sinz + sinx*siny*cosz; _13 = -cosx*siny;
00225 _21 =-cosx*sinz; _22 = cosx*cosz; _23 = sinx;
00226 _31 = siny*cosz + sinx*cosy*sinz; _32 = siny*sinz - sinx*cosy*cosz;_33 = cosx*cosy;
00227 }
00228
00229 void CMatrix33::RotationZXY(const CVector3f &vRotation)
00230 {
00231 float sinx = sin(vRotation.m_X);
00232 float siny = sin(vRotation.m_Y);
00233 float sinz = sin(vRotation.m_Z);
00234 float cosx = cos(vRotation.m_X);
00235 float cosy = cos(vRotation.m_Y);
00236 float cosz = cos(vRotation.m_Z);
00237
00238 _11 = cosy*cosz - sinx*siny*sinz; _12 = cosy*sinz + sinx*siny*cosz; _13 = -cosx*siny;
00239 _21 =-cosx*sinz; _22 = cosx*cosz; _23 = sinx;
00240 _31 = siny*cosz + sinx*cosy*sinz; _32 = siny*sinz - sinx*cosy*cosz;_33 = cosx*cosy;
00241 }
00242
00243 const CVector3f CMatrix33::GetZXYRotationVector()
00244 {
00245 CVector3f rot;
00246 rot.m_Z = atan2(-_21, _22);
00247
00248
00249
00250
00251
00252 rot.m_X = asin(_23);
00253 rot.m_Y = atan2(-_13, _33);
00254
00255 return rot;
00256 }
00257
00258 void CMatrix33::Log(word wTargetLog) const
00259 {
00260
00261
00262
00263
00264
00265
00266
00267 }