0
votes

I am using gluLookAt() to set the "camera" position and orientation

GLU.gluLookAt(xPosition, yPosition, zPosition,
              xPosition + lx, yPosition, zPosition + lz
              0, 1, 0);

my lz and lx variables represent my forward vector

lz = Math.cos(angle);
lx = -Math.sin(angle);

When turn around in the 3D world, it appears that I am rotating around an axis that is always infront of me

I know this because my xPosition and yPosition variables stay the same, but I appear to spin around an object when im close to it and I turn.

Axis Diagram

I know there is not a problem with the maths that I have used here, because I have tried using code from past projects that have worked properly but the problem still remains.

This is what I am doing in the rendering loop

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//draw scene from user perspective
glLoadIdentity();
GLU.gluLookAt(camera.getxPos(), camera.getyPos(), camera.getzPos(), 
      camera.getxPos()+camera.getLx(), camera.getyPos(),     camera.getzPos()+p1.getLz(),
      0, 1, 0);


glBegin(GL_QUADS);
glVertex3f(-dim, dim, 0);
glVertex3f(dim, dim, 0);
glVertex3f(dim, 0, 0);
glVertex3f(-dim, 0, 0);
glEnd();

pollInput();
camera.update();

I have tried rendering a box where the player coordinates are and I got this result. The camera appears to be looking from behind the player coordinates. To use an analogy right now its like a 3rd Person game and It should look like a first person game

The small box here is rendered in the camera coordinates, to give some perspective the bigger box is infront.

Third PersonThird Person 2

1
note that you use xPosition + lz. Probably should be xPosition + lxTal Darom
Thats just a typo on the question, sorrylilroo
Are you trying to rotate the camera around the object? Is the location of the object is xPosition, yPosition, zPosition? if so you should give xPosition + lx, yPosition, zPosition + lz as the first three params (eye location) and xPosition, yPosition, zPosition as the nest params (object location)Tal Darom
The "camera" yaw is controlled by pressing the 'A' and 'D' keys, 'A' yaws left and 'D' yaws right. My problem is that the yaw axis appears to be infront of the camera. The object location is separate, I can choose to look at it or not. the lx and lz variables are calculated using the angle of the yaw, its just that when i am close to an object and i try to turn the camera the problem is particularly obvious because the location of the yaw axis goes inside the objectlilroo
The code you are using is terribly outdated anyway; I'd recommend switching to newer version; you will need to create all the matrices by yourself, but the problem will most likely disappear.Bartek Banachewicz

1 Answers

0
votes

Solved!

The problem was that I was initially calling gluLookAt() while the matrix mode was set to GL_PROJECTION.

I removed that line and moved it to just after I had set the matrix mode to GL_MODELVIEW and that solved the problem.