Camera Rotation

Started by
27 comments, last by glProgram 22 years, 6 months ago
Are you doing...

glLoadIdentity()
glLookAt(...)
push
glRotate() or glTranslate etc...
pop

make sure that the values to glLookAt are not huge numbers...
Advertisement
um.... where exactly were you planning to use gluLookAt if not on the modelview matrix? That is exactly where it should be used, regardless of your projection.

Follow Ansi2000''s structure (rendering objects between the matrix push and pop), making sure that all these operations are done on the modelview matrix.
a near value of 0.0 is not allowed try something larger
OK! I added gluPerspective to the rotation and movement
functions, and it seems to work!!!
Though the camera still doesn''t want to move in the
direction it is facing
(And I DO use camDIR.x/y/z+x/y/z in gluLookAt center params)

ANSI2000, no I don''t and no I don''t use large numbers.
Sorry didn''t see that there was 2 pages...
Bad Monkey, what are you talking about?
You CAN''T use gluLookAt in the MODEL_VIEW matrix!
And what difference would push or pop make?
the usage of push/pop is in case you are rendering other objects apart from that one. This prevents the other objects transformations/rotations from changing the current objects.
Quoted from the GLU specification:

"gluLookAt creates a commonly-used viewing matrix..."

Since when did you apply a viewing matrix to anything besides the OpenGL modelview matrix?

Camera transformations (with the exception of zooming) should not be done in the projection matrix... that is what the modelview matrix is all about... a viewing matrix is essentially the same as a modelling matrix (ie, you are positioning the "camera" as a virtual object in the scene before positioning any other objects).

In effect, what I am saying is you MUST use gluLookAt on the MODEL_VIEW matrix... it is designed to replace glRotate and glTranslate calls when setting your initial ("camera") transformation on a scene.

Using it on the projection matrix is probably what is screwing up your clipping planes.
What you have to do...

Try this...

Start a brand new empty project...

Do all you init code...

In your draw scene code....

Do the following...


glLookAt(some values)
push
draw cube
rotate cube
pop
Here''s my code for a camera. Not all of it''s here, but I just want to show how to put all this theory into practice.

// Moves the camera to the position specified by the use
void Camera::Move(int dir, float dist)
{
switch (dir)
{
case (C_MOVE_FORWARD):
{
x_pos += dist * sinf(y_angle * DEGTORAD);
z_pos -= dist * cosf(y_angle * DEGTORAD);
} break;
case (C_MOVE_BACKWARD):
{
x_pos += -dist * sinf(y_angle * DEGTORAD);
z_pos -= -dist * cosf(y_angle * DEGTORAD);
} break;
case (C_STRAFE_LEFT):
{
x_pos += -dist * cosf(y_angle * DEGTORAD);
z_pos += -dist * sinf(y_angle * DEGTORAD);
} break;
case (C_STRAFE_RIGHT):
{
x_pos += dist * cosf(y_angle * DEGTORAD);
z_pos += dist * sinf(y_angle * DEGTORAD);
} break;
}
}

// Positions camera after adjusting properties
void FPCamera:ositionCamera()
{
gluLookAt(x_pos, y_pos, z_pos,
x_pos + sinf(y_angle * DEGTORAD) * sinf((x_angle + 90)* DEGTORAD),
y_pos + cosf((x_angle + 90) * DEGTORAD),
z_pos + cosf(y_angle * DEGTORAD) * -sinf((x_angle + 90) * DEGTORAD),
0, 1, 0);
}

Never mind that they''re parts of two different classes and assume DEGTORAD is defined as 180/pi. Hope this helps

This topic is closed to new replies.

Advertisement