# Thread: Problem on moving eye coordinate

1. ## Problem on moving eye coordinate

Hello,
I've spend some time on GLUT and trying to do a camera-moving stuff by myself. I hope I would learn something by doing it from scratch. So I'm sorry the code following may seems clumsy...

But here is my problem, when I try to move the cam forward. the cam DID move forward... But not in the direction of current eye coordinate, but along with the -Z arrow instead. However, I did rotate it before the tranlate it, and no other transformation between rotate & translate. If anyone got any clue about what's wrong, please point it out for me. If any background knowledge are needed, just a topic is fine. Thank you. =)

moveframe1.C

2. ## Re: Problem on moving eye coordinate

translate before rotating

3. ## Re: Problem on moving eye coordinate

Sorry, seems not working, either.
Thanks anyway.

4. ## Re: Problem on moving eye coordinate

Hi!! Another way for doing a camera from the scratch is using gluLookAt, with the advantages that it's more clean your code, but you have to performs cossine and sine functions to do the rotation... I'm just making better the operations I have of camera and soon I post here, right?

5. ## Re: Problem on moving eye coordinate

Hi!! These are:

mouse up {
angleY += K;
centerY = eyeY + sin(angleY);
}

mouse down {
angleY -= K;
centerY = eyeY + sin(angleY);
}

mouse left {
angleX += K;
centerX = eyeX + cos(angleX);
centerZ = eyeZ - sin(angleX);
}

mouse right {
angleX -= K;
centerX = eyeX + cos(angleX);
centerZ = eyeZ - sin(angleX);
}

hope it helps a little, if you need there are also the WSAD to implement a FPS Quake style camera, just contact by here or by email pedrodx@yahoo.com . Note that these I formulated so I'm not sure if these are optimized or work in all cases, but are fine.... See ya later!!!

6. ## Re: Problem on moving eye coordinate

could you post the WASD functions?

7. ## Re: Problem on moving eye coordinate

Hi! These are:

switch (key) {
case 87: //W
case 119: //w
eyeX += cos(angleX) * K;
eyeY += sin(angleY) * K;
eyeZ += -sin(angleX) * K;
centerX += cos(angleX) * K;
centerY += sin(angleY) * K;
centerZ += -sin(angleX) * K;
gluLookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, 0, 1, 0);
display4();
return;
case 83: //S
case 115: //s
eyeX -= cos(angleX) * K;
eyeY -= sin(angleY) * K;
eyeZ -= -sin(angleX) * K;
centerX -= cos(angleX) * K;
centerY -= sin(angleY) * K;
centerZ -= -sin(angleX) * K;
gluLookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, 0, 1, 0);
display4();
return;
case 65: //A
case 97: //a
eyeX += cos(angleX + pi/2) * K;
eyeZ += -sin(angleX + pi/2) * K;
centerX += cos(angleX + pi/2) * K;
centerZ += -sin(angleX + pi/2) * K;
gluLookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, 0, 1, 0);
display4();
return;
case 68: //D
case 100: //d
eyeX += cos(angleX - pi/2) * K;
eyeZ += -sin(angleX - pi/2) * K;
centerX += cos(angleX - pi/2) * K;
centerZ += -sin(angleX - pi/2) * K;
gluLookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, 0, 1, 0);
display4();
return;
}

and voilą!!! You have a Quake style FPS!!!
Although a good way to do that is when you press a key, you set a boolean to true, and when you release set to false. This increases real-time rendering. Although, I learn yesterday that you should NOT call display func directly, but call glutPostRedisplay();

Ahhhh! And remember doing the angle tests!! I didn't performed it in these operations. It means, in other words:

if (angleY > 90.0f) {
angleY = 90.0f;
}
if (angleY < -90.0f) {
angleY = -90.0f;
}

That restricts the player to look up and stop.

That's it! Hope it would be useful to the Opengl community, to me it was... Bye!!

8. ## Re: Problem on moving eye coordinate

thanks!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•