Archived

This topic is now archived and is closed to further replies.

Caesar

Camera aka Matrix vs Matrix

Recommended Posts

Hi!, beyond that movie-like headline, there''s a rookie problem. I just discovered the basics of matrices (okay, I''ve read all the stuff twice I guess) and I have the following questions 1) which matrix shoull I apply camera transformations to? Normally, there should be an World Space matrix. In other words, is it correct to create a rotating triangle that moves forward and back like: while(1){ glPushMatrix(); glMatrixMode(GL_MODELVIEW); glRotatef(10,1,0,0); glPopMatrix(); glPushMatrix(); glMatrixMode(GL_PROJECTION); glTranslatef(0,0,values depending on cycle odd/even); glPopMatrix(); } what matrix is the right one to do camera stuff.... is it projection matrix or the one at the very beggining (I always push and pop and don''t know what it is, btw. what is it?) 2)assuming projection matrix is the right one, when I translate the object on the z axis, I always get incorrect results. When translating on x,y, it works the way I wanted it to, but this way, I always get my triangle (one triangle, z for all vertices is 0) disappear (but from left to right, or vice versa when translating the in opposite direction). I can pick it for moving the camera so that the triangle is behind it, but when it should be in front of it? And why does it disappear so long and not in just a single cycle? Thanks

Share this post


Link to post
Share on other sites
Generally, the only thing in the projection matrix should be the projection; that is, orthographic or perspective. Use Model-View for everything else; as its name implies, it stores both the Model transformation and the View transformation.

Share this post


Link to post
Share on other sites
ummm, that''s tricky... I shoul be able to manipulate the object separately from manipulating the world. Imagine I spin the camera around my object and spin the object in the oposite diretion the same time... ?? Is this really correct??

Share this post


Link to post
Share on other sites
I thought that in modelview matrix, only object are affected... I''ll play with it and see the results.

When I have two objects each rotated 10 degrees in different direction, do I have to redo those things each time I change the camera position

Share this post


Link to post
Share on other sites
The redbook uses an actual, real-life camera as an analogue of the OpenGL rendering process. It''s a good way to think of it, I believe (I think theres'' a link to it somewhere here at GameDev.Net).

It also explains why there''s a modelview matrix instead of two separate ones. For example, moving the camera closer to an object (manipulating the view matrix) gives the same effect as moving the object closer to the camera (manipulating the world model matrix).

If you spin the camera in one direction and spin the object in the same direction with the same speed, you would see no no change. But if, as you suggested, you spin the camera and the object in opposite directions, you would see the object spinning twice as fast (I think).

Share this post


Link to post
Share on other sites