Newbie-Rotate Camera????

Started by
6 comments, last by Squizz 22 years, 8 months ago
How do I rotate the camera around several objects... please be simple and direct. I''m still a newbie. Thnkz in advance Squizz-Repaint the World
Squizz-Repaint the World
Advertisement
For a start you could try using glrotatef before you translate the scenario.......

glLoadidentity();
glRotatef (xx,xx,xx,xx);
glTranslatef (xx,xx,xx);

DRAW STUFF

if (key->left)
rotatef_left

if (key->right)
rotate_rigth


Hope this can help you out a little....

Take Care!

- -- ---[XaOs]--- -- -
- -- ---[XaOs]--- -- -[ Project fy ||| CyberTux ]
Unfortunatly it does not, I know those commands I what happens is they all rotate on thier OWN axis... is there a way to rotate them ALL... ie rotate the camera...

PLEASE HELP

Squizz-Repaint the World
Squizz-Repaint the World
You have to put glRotate before glTranslate to rotate the camera. If you put it after, then they rotate on their own axis.
Either that or, after drawing each item on the screen, load the Identity Matrix back up and call glRotate().

~ Dragonus
I such a DOOS
sorry for not reading your replay propley everything works now =) expect complex bricks... but thats not OpenGL thats game code... which I can sort out... Thnkz loadz as always you helpful guys in the gamedev forums always pull through.

Oh well thnkz again
*Squizz sets out to finish*

Squizz-Repaint the World
Squizz-Repaint the World
I think you can use glPushMatrix() and glPopMatrix() to rotate about one origin

glPushMatrix() pushes the current matrix onto the stack. All further drawing is then made around the origin at the top of the stack.

glPopMatrix() discards the matrix at the top of the stack and places the second matrix at the top of the stack. All other matrices in the stack are moved up by one.

// Reset modelview matrix to identity matrix
glLoadIdentity();

// Push the current matrix onto the stack
glPushMatrix();

// perform transformations i.e:

glTranslatef(xx,xx,xx);
glRotatef(xx,xx,xx);

// Draw object in centre of screen
glBegin(XX)
glVertex3f(xx,xx,xx);
glEnd();

// destroy top matrix on stack (One that had been effected by the translation and rotation) making the second matrix on the stack current. This effectively resets drawing back to the origin of the screen.
glPopMatrix();

// further drawing is made from the origin of the screen

Hope this helps using this you can draw many objects in relation to other objects origins. You need to do this to ensure that all objects have a local origin to rotate about rather than just rotating along there own axis.

If you want to do a lot of camera movement I suggest taking a look at the gluLookAt() function. This allows you to control a camera easily without having to worry about matrices and complex stuff. Maybe even build yourself a Camera class that uses lower level routines

If you need me to clarify anything or go into more depth about the gluLookAt() function don''t hesitate to reply.

Hope this helps!!

~Steve~
It''s a cruel world.....
I reply first, correct, and get missunderstood!!!!!!!
But Hey.....as long as things get good...everything is fine!! Rigth?


Take Care!




- -- ---[XaOs]--- -- -
- -- ---[XaOs]--- -- -[ Project fy ||| CyberTux ]

This topic is closed to new replies.

Advertisement