00001 // Implementation des matrices de transformation 3D 00002 00003 #ifndef __J2K__Matrice44_CPP__ 00004 #define __J2K__Matrice44_CPP__ 00005 00006 #include <j2k/Fred/3d/Matrice44.hpp> 00007 00008 // Multiplication de la matrice par une autre matrice 44. 00009 void Matrice44::multiplyByMatrix( const Matrice44&& m ) { 00010 00011 realtype tmp_xx = xx * m.xx + xy * m.yx + 00012 xz * m.zx + xw * m.wx; 00013 00014 realtype tmp_xy = xx * m.xy + xy * m.yy + 00015 xz * m.zy + xw * m.wy; 00016 00017 realtype tmp_xz = xx * m.xz + xy * m.yz + 00018 xz * m.zz + xw * m.wz; 00019 00020 realtype tmp_xw = xx * m.xw + xy * m.yw + 00021 xz * m.zw + xw * m.ww; 00022 00023 realtype tmp_yx = yx * m.xx + yy * m.yx + 00024 yz * m.zx + yw * m.wx; 00025 00026 realtype tmp_yy = yx * m.xy + yy * m.yy + 00027 yz * m.zy + yw * m.wy; 00028 00029 realtype tmp_yz = yx * m.xz + yy * m.yz + 00030 yz * m.zz + yw * m.wz; 00031 00032 realtype tmp_yw = yx * m.xw + yy * m.yw + 00033 yz * m.zw + yw * m.ww; 00034 00035 realtype tmp_zx = zx * m.xx + zy * m.yx + 00036 zz * m.zx + zw * m.wx; 00037 00038 realtype tmp_zy = zx * m.xy + zy * m.yy + 00039 zz * m.zy + zw * m.wy; 00040 00041 realtype tmp_zz = zx * m.xz + zy * m.yz + 00042 zz * m.zz + zw * m.wz; 00043 00044 realtype tmp_zw = zx * m.xw + zy * m.yw + 00045 zz * m.zw + zw * m.ww; 00046 00047 realtype tmp_wx = wx * m.xx + wy * m.yx + 00048 wz * m.zx + ww * m.wx; 00049 00050 realtype tmp_wy = wx * m.xy + wy * m.yy + 00051 wz * m.zy + ww * m.wy; 00052 00053 realtype tmp_wz = wx * m.xz + wy * m.yz + 00054 wz * m.zz + ww * m.wz; 00055 00056 realtype tmp_ww = wx * m.xw + wy * m.yw + 00057 wz * m.zw + ww * m.ww; 00058 00059 xx = tmp_xx; 00060 xy = tmp_xy; 00061 xz = tmp_xz; 00062 xw = tmp_xw; 00063 00064 yx = tmp_yx; 00065 yy = tmp_yy; 00066 yz = tmp_yz; 00067 yw = tmp_yw; 00068 00069 zx = tmp_zx; 00070 zy = tmp_zy; 00071 zz = tmp_zz; 00072 zw = tmp_zw; 00073 00074 wx = tmp_wx; 00075 wy = tmp_wy; 00076 wz = tmp_wz; 00077 ww = tmp_ww; 00078 } 00079 00080 void Matrice44::CopyFrom( const Matrice44&& m ) { 00081 xx = m.xx; 00082 xy = m.xy; 00083 xz = m.xz; 00084 xw = m.xw; 00085 00086 yx = m.yx; 00087 yy = m.yy; 00088 yz = m.yz; 00089 yw = m.yw; 00090 00091 zx = m.zx; 00092 zy = m.zy; 00093 zz = m.zz; 00094 zw = m.zw; 00095 00096 wx = m.wx; 00097 wy = m.wy; 00098 wz = m.wz; 00099 ww = m.ww; 00100 } 00101 00102 //Initialisation de la matrice identitée. 00103 void Matrice44::setIdentity() { 00104 setNull(); 00105 xx = yy = zz = ww = 1; 00106 } 00107 00108 // Initialisation de la matrice nulle. 00109 void Matrice44::setNull () 00110 { 00111 xx = xy = xz = xw = 0; 00112 yx = yy = yz = yw = 0; 00113 zx = zy = zz = zw = 0; 00114 wx = wy = wz = ww = 0; 00115 } 00116 00117 // Initialisation de la matrice de translation X. 00118 void Matrice44::setTranslateX( realtype x ) 00119 { 00120 wx = x; 00121 } 00122 00123 // Initialisation de la matrice de translation Y. 00124 void Matrice44::setTranslateY( realtype y ) 00125 { 00126 wy = y; 00127 } 00128 00129 // Initialisation de la matrice de translation Z. 00130 void Matrice44::setTranslateZ( realtype z ) 00131 { 00132 wz = z; 00133 } 00134 00135 // Initialisation de la matrice de rotation x. 00136 void Matrice44::setRotateX( realtype cos, realtype sin ) 00137 { 00138 setIdentity(); 00139 yy = cos; 00140 yz = sin; 00141 zz = cos; 00142 zy = -sin; 00143 } 00144 00145 // Initialisation de la matrice de rotation y. 00146 void Matrice44::setRotateY( realtype cos, realtype sin ) 00147 { 00148 setIdentity(); 00149 xx = cos; 00150 xz = -sin; 00151 zz = cos; 00152 zx = sin; 00153 } 00154 00155 // Initialisation de la matrice de rotation Z. 00156 void Matrice44::setRotateZ( realtype cos, realtype sin ) 00157 { 00158 setIdentity(); 00159 xx = cos; 00160 xy = sin; 00161 yy = cos; 00162 yx = -sin; 00163 } 00164 00165 // Initialisation de la matrice de changement d'echelle X. 00166 void Matrice44::setScaleX( realtype s) 00167 { 00168 xx = s; 00169 } 00170 00171 // Initialisation de la matrice de changement d'echelle Y. 00172 void Matrice44::setScaleY( realtype s) 00173 { 00174 yy = s; 00175 } 00176 00177 // Initialisation de la matrice de changement d'echelle Z. 00178 void Matrice44::setScaleZ( realtype s) 00179 { 00180 zz = s; 00181 } 00182 00183 // La matrice est elle la matrice identitée. 00184 BOOL Matrice44::isIdentity() 00185 { 00186 return ( xx == 1 && xy == 0 && xz == 0 && xw == 0 && 00187 yx == 0 && yy == 1 && yz == 0 && yw == 0 && 00188 zx == 0 && zy == 0 && zz == 1 && zw == 0 && 00189 wx == 0 && wy == 0 && wz == 0 && ww == 1 00190 ); 00191 } 00192 00193 #endif