Advertisement

another camera question(please help me!!!)

Started by May 08, 2003 05:12 PM
0 comments, last by Trying newbie 21 years, 9 months ago
ok so i have a cube that is rotating on all 3 axis. what i want to do now is have the camera rotate around the rotating cube i guess rotating around the y axis. i do have gluLookAt() set up right now but i dont know if i need it...ill post the code. void Render() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear screen and depth buffer glLoadIdentity(); // reset modelview matrix gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); angle = angle + 0.1f; // increase our rotation angle counter if (angle >= 360.0f) angle = 0.0f; glTranslatef(0.0f, 0.0f, -10.0f); // perform transformations glRotatef(angle, 1.0f, 0.0f, 0.0f); // place cube at (0,-3) and rotate it glRotatef(angle, 0.0f, 1.0f, 0.0f); glRotatef(angle, 0.0f, 0.0f, 1.0f); DrawCube(0.0f, 0.0f, 0.0f); // draw the transformed cube glFlush(); SwapBuffers(g_HDC); // bring backbuffer to foreground } my first approach was to name a variable eyex...for the first number of the look at function and do something like: eyex = eyex + .1; if (eyex >= 0.0); eyex = 0.0; all that did was sent my object off into the distance...so how can i make my camera starting at say (0,0,10) rotate around smoothly too (10,0,0) then to (0,0,-10) then to (-10,0,0) and back and continue the circle? thanks in advance for your help. [edited by - trying newbie on May 8, 2003 7:47:00 PM]
i always think i have it figured out only to realize that i dont know where to begin.
To rotate a point you have to use the sin and cos functions...
If you want to rotate a point on the y axys, for example you should use

newx=cos(yangle)*radius;
newz=sin(yangle)*radius;

the use gluLookAt with newx and newz in the head pos.
Remember to look always at the object, (the lookat set of params of gluLookAt should always be the same...

Enjoy!

P.S. I''m not pretty sure of the formulas!!!! but the technique is that...

---------------------------------------
There are 10 type of people:
those who knows binary code
and those who doesn''t
---------------------------------------
---------------------------------------There are 10 type of people:those who knows binary codeand those who doesn't---------------------------------------

This topic is closed to new replies.

Advertisement