PDA

View Full Version : Mat4::translate bug?



CrazyFrazee
01-28-2009, 05:59 PM
Hey, I think CL_Mat4::translate is wrong. (line 208 of matrix4x4.cpp)

currently:


template<typename Type>
CL_Mat4<Type> CL_Mat4<Type>::translate(Type x, Type y, Type z)
{
CL_Mat4<Type> translate_matrix = identity();
translate_matrix.matrix[0+3*4] = x;
translate_matrix.matrix[1+3*4] = y;
translate_matrix.matrix[2+3*4] = z;
return translate_matrix;
}

That's setting the bottom row, but the mult by vector in cl_vector.h (line 811) expects the translation to be on the right column:


template<typename Type>
CL_Vec4<Type> operator * (const CL_Vec4<Type>& v, const CL_Mat4<Type>& matrix)
{
return CL_Vec4<Type>(
matrix[0*4+0]*v.x + matrix[0*4+1]*v.y + matrix[0*4+2]*v.z + matrix[0*4+3]*v.w,
matrix[1*4+0]*v.x + matrix[1*4+1]*v.y + matrix[1*4+2]*v.z + matrix[1*4+3]*v.w,
matrix[2*4+0]*v.x + matrix[2*4+1]*v.y + matrix[2*4+2]*v.z + matrix[2*4+3]*v.w,
matrix[3*4+0]*v.x + matrix[3*4+1]*v.y + matrix[3*4+2]*v.z + matrix[3*4+3]*v.w);
}

That seem right?

rombust
01-28-2009, 08:19 PM
I will have a look tomorrow.

I thought, i have done a test for matrix translate and multiplication, maybe i have forgotten to write one.

(The test should be in Tests/Core/Math)

rombust
01-29-2009, 03:52 PM
Well spotted.

Looking at http://msdn.microsoft.com/en-us/library/dd368646(VS.85).aspx
It looks like it is wrong

however... http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=215629
opengl stores it in the column major format.

... thinking of how to make it clearer

By adding documentation :)