Archived

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

IVI4j

Viewpoint problem

Recommended Posts

I''m trying to add a movable camera to my demo, which already has a movable MD2 in the middle of the screen. The other objects are a textured quad (for the ground) and some spheres to show where the worlds axis are. The problem is that when I push the keys to move the camera, the MD2 rotates too, and when you try to rotate the MD2 the camera moves also. Heres the code for the demo. void fi3Rotatef(float Xr, float Yr, float Zr) { glRotatef(Zr, 0.0f, 0.0f, 1.0f); glRotatef(Yr, 0.0f, 1.0f, 0.0f); glRotatef(Xr, 1.0f, 0.0f, 0.0f); } void fi3Unrotatef(float Xr, float Yr, float Zr) { glRotatef(Xr, 1.0f, 0.0f, 0.0f); glRotatef(Yr, 0.0f, 1.0f, 0.0f); glRotatef(Zr, 0.0f, 0.0f, 1.0f); } void Render() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatef(0.0f, 0.0f, -40.0f); //Zoom out fi3Rotatef(CamX, CamY, 0.0f); //Rotate viewpoint glEnable(GL_TEXTURE_2D); DrawGround(50); //Draws the textured ground glDisable(GL_TEXTURE_2D); DrawSpheres(7.0f); fi3Unrotatef(-CamX, -CamY, -CamZ); //Undo the rotations //Rotate for the MD2 fi3Rotatef((Ships[1].Xrot), (Ships[1].Yrot), (Ships[1].Zrot)); DisplayMD2(Raptor,1); //Draw MD2 //Clearscreen glFlush(); SwapBuffers(g_HDC); } It seems to me that the ship and camera should be completely independant of eachother. The DrawGround and DrawSpheres functions both return to the origin and undo any rotations they used using the fi3Unrotatef function. Thanks in advance.

Share this post


Link to post
Share on other sites

Try to Seperate your render function into two functions: RenderCamera, and Render Scene.

Instead of undoing the rotation try to call loadIdentity() instead.... i don't know (undoing the rotation should do the same thing that loadIdentity() does) but try this anyway

[edited by - snisarenko on October 16, 2002 6:22:54 PM]

Share this post


Link to post
Share on other sites
Thanks for the suggestions. I tried them but came to wondering why I was unrotating the cameras angle in the first place, since everything in the scene is effected by it. So I removed the line : fi3Unrotatef(-CamX, -CamY, -CamZ);. This fixed the problem on the X and Y axis (both camera and MD2), the only problem left is with the MD2''s Z axis. When the user pushes the key to rotate the MD2 on it''s Z axis, The MD2 rotates on the camera''s Z axis. Any ideas?

Share this post


Link to post
Share on other sites