# camera rotation around rotating obj...

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.

You can do your camera without gluLookAt just using glRotate and glTranslate commands.

Originally posted by trying newbie:
[b]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. [/b]

You can check out: http://glfw.sourceforge.net/tutorials/tutorials.html

The Camera section has a lesson on using gluLookAt to rotate around an object (lesson 8).

I have some stuff on different camera systems done without lookat…

temp site: http://141.217.130.254/miguel