Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / 3D Theory & Graphics / How does glTranslated work with GL_MODELVIEW Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
cipherx

April 18, 2005, 08:53 AM

Hi,

I was trying to skip glulookAt for once and build the ModelView matrix myself. Well I did manage to build it, but I just don't understand how glTranslated works with GL_MODELVIEW. Here is what I am doing... I have built my ModelView matrix as follows
| 11 12 13 0 |
| 21 22 23 0 |
| 31 32 33 0 |
| 0 0 0 1 |

Then I call glLoadMatrixf and then glTranslated with the inverse of the eye position. This works fine, but the main reason as to why I built the matrix on my own in the first place is so that I did not have to call
glGetFloatv(GL_MODELVIEW_MATRIX, modl) ;
again to get the frustrum planes.

As far as I understood glTranslated just transforms all drawing done after it has been called. This should mean that the resulting matrix should be

| 11 12 13 -eye.x |
| 21 22 23 -eye.y |
| 31 32 33 -eye.z |
| 0 0 0 1 |

But this does not work. I'm sure I have not understood the inner workings of glTranslated properly. Please can someone correct me.

Thanks,

- Sid

 
nih_co

April 18, 2005, 11:08 AM

Your assumption of translate functions is incorrect.

when translating you are multiplying the current matrix by a translation matrix. this takes place in the form:

[ 11 12 13 q ][ 1 0 0 x ] [ 11 12 13 (11*x+12*y+13*z+q*1) ]
[ 21 22 23 r ][ 0 1 0 y ] = [ 21 22 23 (21*x+22*y+23*z+r*1) ]
[ 31 32 33 s ][ 0 0 1 z ] [ 31 32 33 (31*x+32*y+33*z+s*1) ]
[ 0 0 0 1 ][ 0 0 0 1 ] [ 0 0 0 1 ]

where is your current translation (0,0,0) in your case.
And is the amount you want to translate by.

Your concept of translation is only correct if the initial matrix is the identity. The way this appear to occur when tranforming an object is that translation occurs in local space. so if you rotate something first, then translate, the object will appear to move along its local axes, not world axes.

If you are doing a lot of transformations in opengl anyway, ust that function and get the matrix straight from ogl. its not going to affect performance really and it might even help because you avoid performing the trig in rotations on the cpu.

Anyone know why I cant get the code tags to work?

 
Reedbeta

April 18, 2005, 03:07 PM

The cpp has to be in square brackets. (as it says above the reply box, if you look)

 
DonJuan

April 18, 2005, 04:50 PM


goddamn, i've never before seen this much bitching on a forum in my life. it's irritating that everyone has some sarcastic reply for every post. if you don't feel like answering someone, DON'T. even reedbeta's whining about questions he thinks are stupid. i guess i should't expect too much from computer science kids, but this place exists for asking and explaining. so let's try not to be cocks, k?

 
Reedbeta

April 18, 2005, 08:27 PM

The OP's question has already been answered. I don't think it's stupid.

 
cipherx

April 18, 2005, 11:52 PM

Thanks for your detailed explanation nih_co.

- Sid

 
tatsujin

April 19, 2005, 06:21 AM

If I may add... I always found it quite useful to take a peek at the source of Mesa when faced with these kinds of questions.

 
cipherx

April 19, 2005, 09:05 AM

Thanks for your suggestion tatsujin. I will definately do that the next time. Infact I did try and look for some source code (Python opengl) and that is how I managed the first matrix.

- Sid

 
This thread contains 8 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.