Translation Matrix - Urgent Please

Dear friends…

I know that to set the translation matrix we can use the function glTranslatef() by passing to it the value of tx, ty and tz.

I have an assignment to set the translation matrix manually without using the glTranslate() function. What I am doing is this:

  1. Define that the matrix in use is the GL_MODEVIEW matrix.
  2. Load the identity matrix into this matrix.
  3. Declare this matrix:
    float t1[16] = { 1.0, 0.0, 0.0, 175.0,
    0.0, 1.0, 0.0, 125.0,
    0.0, 0.0, 1.0, 100.0,
    0.0, 0.0, 0.0, 1.0 };
  4. Use the glMultMatrix() function like this:
    glMultiMatrix(t1);
  5. The previous four steps must postmultiply the identity matrix with the t1
    matrix which gives as a reslut the t1 matrix in the GL_MODEVIEW matrix.
  6. Draw some shapes that must be translated according to the t1 matrix.

The problem here is the out drawing is not seems to be translated, actually I get a strange output.

Please can anyone help me with this.

Thanks in advance for your help…

Your matrix is transposed. The correct translation matrix is


float t1[16] = { 1.0, 0.0, 0.0, 0.0,
                 0.0, 1.0, 0.0, 0.0,
                 0.0, 0.0, 1.0, 0.0,
                 175.0, 125.0, 100.0, 1.0 };

Pay attention to what the matrix looks like that OpenGL wants, how it’s elements are layed out in memory, and how that corresponds to a flat array.

And instead of glLoadIdentity(); glMultMatrix(t1) you can simply use glLoadMatrix(t1).

There’s always the glLoadTransposeMatrix functions if you don’t want to bother with transposing the data in system memory.

Dear friends…

Thanks a lot for your help, I don’t know how I forgot this small thing, I will try to solve it now.

Thanks…