Rotate around a certain point!!!!

Hi everybody!
Here’s my problem:
I want to follow a circle around the origin and look always at the origin, using gluLookAt…
My code is this:

glMatrixMode(GL_PROJECTION);
theta+=10;
float xp=10cos(theta);
float yp=0;
float zp=10
sin(theta);
float xd=-cos(theta);
float yd=0;
float zd=-sin(theta);
float xu=0;
float yu=1;
float zu=0;
gluLookAt(xp,yp,zp,xd,yd,zd,xu,yu,zu);

Now…

What can I do to keep my object in the center of the screen instead of moving it around???

I don’t now why I move all the scene around instead of moving only the point of view!!

Any help will be very appreciated.

Hi…

You can try this:

void DrawGLScene(void)
{

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

// R = radius
ex = Rcos(thetaDTOR); // DTOR = pi/180
ez = Rsin(thetaDTOR);
ey = 0.0f; // ?

gluLookAt(ex,ey,ez, // eye coords
cx,cy,cz, // centre coords
0,1,0 ); // up


DrawObjectAt(cx,cy,cz);


theta+=theta_step;
if(theta>=360.0f)
theta=0.0f;

} // end of Draw()


Make sure you put gluLookAt(…) first.
Then draw your object(s), and update your variables at the end of Draw() loop.

Hope that helps…

gluLookAt should NOT be put on the GL_PROJECTION matrix. It should be the first thing to be put on the GL_MODELVIEW matrix…

Also you are missing a glLoadIdentity. gluLookAt multiplies with the current matrix.

Hi!!

Thanks for your help !!!
I have done it but my object still going around the scene!

Any suggestions?

Thanks guys!

That’s right…The gluLookAt should not be in:

glMatrixMode(GL_PROJECTION);

Nobody told me that before!!

thanks a lot.

Im back with another problem…now…

My gluLookAt is working very well if I have 1 object in my screen…but…

What should I do if I have more than 1 object??

It looks like im doing the translate wrong because my objects rotate all together in one point!!!