Whats wrong with this bit of code?

void RenderCamera()
{
//glTranslatef(Mcamera.x,Mcamera.y,Mcamera.z);
int tx,ty,tz;
tx=ship[Mcamera.target].x;
ty=ship[Mcamera.target].y;
tz=ship[Mcamera.target].z;

glTranslatef(0,0,-Mcamera.zoom);  // bigger zoom is farther out you go

glTranslatef(tx,ty,tz);


glRotatef(Mcamera.xangle,1.0f,0,0);
glRotatef(Mcamera.yangle,0,1.0f,0);

}

I want the camera to rotate around the target ship. It’s pretty basic code. But something is wrong and it translates funny or rotates funny.
I’m just not sure if it’s a GL problem or my own error.

I think the problem might be in the zoom out… I didn’t really look at it too carefully.

I recommend using gluLookat()… with something like this:

gluLookat(MC.x,MC.y,MC.z,Ship.x,Ship.y,Ship.z,0.0,1.0,0.0)

Try this and let me know… for zooming you’re probably going to have to use some trig if the ship is moving!

[This message has been edited by ngill (edited 07-01-2000).]

You might want to swap the order of the translation and rotation (depending on what effect you’re trying to accomplish).

Also, is this code run before you render the scene (in the scene view matrix mode) or in the project matrix view mode?

Last, I would suggest changing the edge coordinates (or the near clipping plane location) rather than move the camera when zooming in/out. I think that looks better; it certainly emulates the real effect of a zoom lens much closer.