View Full Version : Is this correct code to translate a matrix?

skippyj777

08-23-2000, 10:49 AM

Will this code translate the given matrix the same as glTranslate would? The matrix is as follows:

00 01 02 03

04 05 06 07

08 09 10 11

12 13 14 15

procedure OogleMatrixTranslate(var m: OOGLE_MATRIXF; x, y, z: Single);

begin

m[12] := m[12] + x;

m[13] := m[13] + y;

m[14] := m[14] + z;

end;

Remember that glTranslate computes a transformation matrix and multiplies the current modelview matrix by it.

no, that's not the same.

if you translate by direct modification of the translational part of the modelview, you will translate in a coordinate frame aligned with the eye-space.

instead, if you multiply the current modelview matrix by a translation matrix, you'll get your translation operate into object-space.

this is the log of some lines of gl code:

glLoadIdentity();

modelview matrix xlt: 0.000000 0.000000 0.000000

glRotatef(45,1,1,0);

modelview matrix xlt: 0.000000 0.000000 0.000000

glTranslatef(100,200,300);

modelview matrix xlt: 264.644623 35.355347 262.132019

note that translation value of mv matrix is NOT what has been passed to glTranslate.

Another thing: you should be modifying the last _column_ of your matrix, not your last row. ie:

[ 0 0 0 x ]

[ 0 0 0 y ]

[ 0 0 0 z ]

[ 0 0 0 1 ]

where the values go into x, y & z respectively. (remember: you POST multiply your modelview matrix, not pre multiply)

cheers

John

Kilam Malik

08-24-2000, 01:32 AM

Depends on how you organize your matrix. But it's correct, when he sets the values 12, 13 and 14 in the array he gets from openGL. This is the translation vector. So OpenGL organizes it column-based in this array.

Kilam.

skippyj777

08-24-2000, 05:54 AM

Column-based, meaning my diagram should have looked like:

00 04 08 12

01 05 09 13

02 06 10 14

03 07 11 15

Is this what you mean by column-based?

skippyj777

08-24-2000, 05:56 AM

How should my code translate a modelview matrix the correct way (I want to work on the matrix itself, directly)?

Kilam Malik

08-24-2000, 08:15 AM

Yep, thats what I mean with column based.

I alter my matrix the same way. I have to rotate a part on the screen with my mouse.

I achieve this by multiplying the rotationmatrix of my delta rotation in this from on the existing rotation. For this I read out the matrix from openGL, multiply it with my own matrix and then give it back to openGL.

Kilam.

skippyj777

08-25-2000, 12:53 PM

What I wanted was an algorithm that will take a modelview matrix and a xyz translation, and translate the modelview matrix. I just want to work with the matrix and translation numbers, not with the current matrix or gl functions or any of that.

skippyj777

08-25-2000, 12:56 PM

Would it be creating a translation matrix as John said, and then post-multiplying the modelview matrix by the new translation matrix? I already have a function that multiplies to matricies together.

procedure OogleMatrixTranslate(var m: OOGLE_MATRIXF; x, y, z: Single);

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.