PDA

View Full Version : Camera



johnnyp05
08-08-2005, 10:22 AM
Hi, can anyone PLEASE explain how you can use glTranslate() and glRotate() to manipulate the camera? I thought those two functions are for tranforming objects? thanks!

johnnyp05
08-08-2005, 10:25 AM
p.s. just an example that allows me to rotate my view on the spot full 360 rotation, i can kinda do that with gluLookAt() function, but i hear it's better to use tranformation functions. Thanks again!

mikael_aronsson
08-08-2005, 10:51 AM
glRotate( 0.0, 1.0, 0.0, angle); should do just fine.

johnnyp05
08-08-2005, 11:38 AM
hmmmm sorry that doesn't help me...

I have this code here...


glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear screen and depth buffer
glLoadIdentity();

gluLookAt(0.0, 0.0, 10, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glRotatef(30, 0.0, 0.1, 0.0);

DrawCube();

from what i can see from my book here, that should rotate the camera view :confused: but obviously any code that follows after the glRotate() will be transformed, therefore my 3D cube being rotated and not the camera? Could you explain please?

Aeluned
08-08-2005, 01:22 PM
Don't try to rotate the camera...that's impossible.
Instead, try and realize the truth: there is no camera.

By rotating, say, 45 degrees before rendering anything, you've effectively rotated the camera 45 degrees.

any subsequent rotations after that will be in addition to your initial rotation.

You can use push()/pop() to save and restore the modelview matrix derived by doing your initial rotation before and after you render any objects.

a little something like this:

//rotate camera
glMatrixMode(GL_MODELVIEW);
glRotatef(45,0,1,0);

glPushMatrix();
glRotate(10,1,0,0);
glTranslate(1,0,0);
DrawCube();
glPopMatrix();

etc...

johnnyp05
08-08-2005, 02:09 PM
Aaah right got ya thanks :) I thought ppl talked about a camera, as in creating a camera object or something, didn't realise it was virtual talk :) tanks for help man