Sign in to follow this  
ade-the-heat

camera+vector transformation problem

Recommended Posts

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

Share this post


Link to post
Share on other sites
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[i].doTransform();
objects[i].render();
glPopMatrix();
}
}

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
thanks.
I started the other one as I didn't quite understand your answer at first and wanted more people to help (selfish I know !)

so thanks again, again..

cheers

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this