Camera/Object Movement

Started by
3 comments, last by ShawMishrak 22 years, 8 months ago
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.
Advertisement
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();
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 wantedglPushMatrix();move models;glPopMatrix();  

Have fun! please tell me if it works if not try to help again!
one thing forgot after moving the camera and before pushing the matrix draw the world then push the matrix
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?

This topic is closed to new replies.

Advertisement