Results 1 to 3 of 3

Thread: Mat4::translate bug?

  1. #1

    Default Mat4::translate bug?

    Hey, I think CL_Mat4::translate is wrong. (line 208 of matrix4x4.cpp)

    currently:

    Code:
    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:

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

  2. #2
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    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)

  3. #3
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Well spotted.

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

    however... http://www.opengl.org/discussion_boa...&Number=215629
    opengl stores it in the column major format.

    ... thinking of how to make it clearer

    By adding documentation
    Last edited by rombust; 01-29-2009 at 04:20 PM. Reason: update

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •