comparison engine/core/util/math/matrix.h @ 58:9ec572a5a944

reworked matrix vector multiplication, patch by yonibear
author spq@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 14 Jul 2008 16:39:27 +0000
parents 90005975cdbb
children 16c2b3ee59ce
comparison
equal deleted inserted replaced
57:47979f9dce55 58:9ec572a5a944
208 } 208 }
209 209
210 /** Transform given point using this matrix 210 /** Transform given point using this matrix
211 */ 211 */
212 inline PointType3D<T> operator* (const PointType3D<T>& vec) { 212 inline PointType3D<T> operator* (const PointType3D<T>& vec) {
213 PointType3D<T> ret(T(0)); 213 return PointType3D<T> (
214 for (register unsigned j = 0; j < 3; ++j) 214 vec.x * m0 + vec.y * m4 + vec.z * m8 + m12,
215 for (register unsigned i = 0; i < 3; ++i) 215 vec.x * m1 + vec.y * m5 + vec.z * m9 + m13,
216 ret.val[j] += vec.val[i]*m[j+i*4]; //scale and rotate disregarding w scaling 216 vec.x * m2 + vec.y * m6 + vec.z * m10 + m14
217 217 );
218 for (register unsigned i = 0; i < 3; ++i)
219 ret.val[i] += m[i+3*4]; //translate
220
221 //do w scaling
222 T w = m[15];
223 for (register unsigned i = 0; i < 3; ++i)
224 w += vec.val[i]*m[3+i*4];
225
226 register T resip = 1/w;
227
228 for (register unsigned i = 0; i < 3; ++i)
229 ret[i] *= resip;
230
231 return ret;
232 } 218 }
233 219
234 /** Direct access to the matrix elements, just remember they are in column major format!! 220 /** Direct access to the matrix elements, just remember they are in column major format!!
235 */ 221 */
236 inline T& operator[] (int ind) { 222 inline T& operator[] (int ind) {