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?
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?