Archived

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

ShawMishrak

Camera/Object Movement

Recommended Posts

I have a camera system setup that allows me to travel throughout the scene, but I am looking to have a fixed camera and allow the user to control a model in the scene. Using the MODELVIEW matrix mode, the translations/rotations move the camera instead of the model. I use glLoadIdentity() to reset the matrix and gluLookAt to position the camera. When it goes through the movement code, the camera goes to where the model is. If I use PROJECTION for the matrix mode, I just get a blank screen. Does anyone have any tutorials on this subject or know what might be going wrong? Basically, I am looking to have a fixed camera and quite a few fixed objects with one camera controlled object.

Share this post


Link to post
Share on other sites
The MODELVIEW matrix is both for the objects (MODEL) and the camera (VIEW). Moving an object 5 units to the right of the camera looks the same as moving the camera 5 units to the left.

You should accumulate the effects of moving the camera and models into the matrix so no call to glLoadIdenty() should be done after the camera movement.

glMatrixMode(MODELVIEW);
glLoadIdentity();
gluLookAt(...);

// Here do you probably have a glLoadIdentity() but that is wrong

drawObject();

Share this post


Link to post
Share on other sites
If the above isn''t true try this since I had the same prob
Hope it works!
  
glLoadIdentity();
move camera (aka) gluLookAt() and translate if wanted
glPushMatrix();
move models;
glPopMatrix();

Have fun! please tell me if it works if not try to help again!

Share this post


Link to post
Share on other sites
With a little work, the glPushMatrix() and glPopMatrix() worked, to an extent. I have the keyboard mapped to move forward/back/left/right using trig, and it works fine when I control the camera that way. When I try to control the model the same way, (passing the same X, Y, Z, Rotation Value that I passed when I was controling the camera) it won''t calculate the heading right. The rotation (left/right keys) work fine, but the up/down keys always move it in the same direction. The math works when the X, Y, Z, rotation values are applied to the camera (not using push/pop), but they don''t seem to work when they are applied to the model. Any ideas/suggestions?

Share this post


Link to post
Share on other sites