camera+vector transformation problem
I use the function gluLookAt for the camera.
However, after I've called it the model matrix is now in the place where the camera is.
So, I put the Push and Pop matrix around it.
Now everything is all over the place - nothing is where it should be and nothing seems to move.
what's wrong with that ? It seems such an ordinary thing to do and what's the solution.
cheers
Ade
i have no idea what you're describing, but your rendering code should be something like this:
void render(){glClear( ... );glMatrixMode( GL_MODELVIEW );glLoadIdentity();gluLookAt( x,y,z, ex,ey,ez, 0,1,0 ); for(int i=0; i<numObjects; i++) { glPushMatrix(); objects.doTransform(); objects.render(); glPopMatrix(); }}
ok, that isn't what I've got but it's close enough-
so after the PushMatrix you transform the object-shouldn't you glLoadIdentity before transforming the object ?
If I do the glLoadIdentity before the transform then the object I'm drawing is someplace else - I can't see it although it must be there someplace.
cheers
so after the PushMatrix you transform the object-shouldn't you glLoadIdentity before transforming the object ?
If I do the glLoadIdentity before the transform then the object I'm drawing is someplace else - I can't see it although it must be there someplace.
cheers
Quote:shouldn't you glLoadIdentity before transforming the object ?
No, you want to concatenate the model's transformation with the camera's transformation.
Try it silvermace's way and see if it works (if you haven't already).
Well, suppose the camera is at position
(100,100,-100) and is looking in the -ve z direction
and the object is at
(100,100,-200)
If you don't load the identity then the object will appear to be at 200 units in front of the camera instead of 100.
or is my understanding wrong?
(100,100,-100) and is looking in the -ve z direction
and the object is at
(100,100,-200)
If you don't load the identity then the object will appear to be at 200 units in front of the camera instead of 100.
or is my understanding wrong?
Why did you start two threads about this? I replied with the correct way in your other thread.
However, for an explanation of why:
Your understanding is wrong. To render object in relation to a camera, they need to be transformed into camera space first, otherwise it'll be like the camera is perpetually stationed at the origin, looking along the -ve or +ve z axis. In OpenGL, you need to load the camera matrix into the modelview matrix, before you perform and local object transformations, that way, those objects are also transformed into camera space, before being rendered. gluLookAt essentially loads a camera matrix ( inverted "frame" matrix ) into the currently active matrix.
However, for an explanation of why:
Your understanding is wrong. To render object in relation to a camera, they need to be transformed into camera space first, otherwise it'll be like the camera is perpetually stationed at the origin, looking along the -ve or +ve z axis. In OpenGL, you need to load the camera matrix into the modelview matrix, before you perform and local object transformations, that way, those objects are also transformed into camera space, before being rendered. gluLookAt essentially loads a camera matrix ( inverted "frame" matrix ) into the currently active matrix.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement