View Full Version : 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 (http://mail.cs.nchu.edu.tw/~s9256033/moveframe1.C)

zukko

03-10-2005, 06:46 PM

translate before rotating

Sorry, seems not working, either.

Thanks anyway.

pedrodx

03-11-2005, 08:30 AM

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?

pedrodx

03-14-2005, 02:08 AM

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!!!

zukko

03-14-2005, 10:39 AM

could you post the WASD functions?

pedrodx

03-17-2005, 02:18 AM

Hi! These are:

switch (key) {

case 87: //W

case 119: //w

glLoadIdentity();

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

glLoadIdentity();

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

glLoadIdentity();

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

glLoadIdentity();

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!!

zukko

03-17-2005, 08:59 AM

thanks!

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.