PDA

View Full Version : Rotate around a certain point!!!!

angeldarkholme
10-13-2005, 08:49 PM
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=10*cos(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.

10-13-2005, 10:19 PM
Hi...

You can try this:

void DrawGLScene(void)
{

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

// R = radius
ex = R*cos(theta*DTOR); // DTOR = pi/180
ez = R*sin(theta*DTOR);
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....

Overmind
10-14-2005, 05:28 AM
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.

angeldarkholme
10-14-2005, 05:41 AM
Hi!!

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

Any suggestions?

angeldarkholme
10-14-2005, 05:50 AM
Thanks guys!

That's right.....The gluLookAt should not be in:

glMatrixMode(GL_PROJECTION);

Nobody told me that before!!

thanks a lot.

angeldarkholme
10-14-2005, 04:51 PM
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!!!