First Person Camera

Started by
14 comments, last by Drakon 22 years, 4 months ago
Ok, thanks
Yes, ... (*thinks... remembering which algebra I''m in*) Man... I dont even remember what algebra book I''m in, but I think its two... but we haven''t gotten to cos and sin yet...
Its far too late to read that stuff now, but I''ll look at it in the morning.
"Go for the eyes, Boo, go for the eyes!"
Advertisement
Another question... what is angle equal to?

Also: I don't understand whats going on in that tutorial stuff... I have a hard time learning math from tutorials.

Edited by - Drakon on November 27, 2001 9:33:22 AM
"Go for the eyes, Boo, go for the eyes!"
There are three ways to get measurments of a triangle: sine, cosine, and tangent. Each are methodical to SOHCAHTOA, meaning:

sine = opposite over hypotenuse
cosine= adjacent over hypotenuse
tangent = opposite over adjacent

You need to know these because when you turn left, for example, you would decrement a variable ''float angle''. Then, you need to figure out whether the sin, cos, or tangent is needed.

In the case of turning, the most commonly used are the negative cosine and the sine.

gluLookAt takes 9 arguments. The first three are the camera position (x,y,z), which are unaffected when you turn. The ones that are affected are the next three arguments, (lx, ly, lz) which are the look-x, look-y, and look-z. They determine the point where the camera is looking.

So when you move forward, you need to figure out what angle measurement between you and the z axis (and x axis) is so that you can move in the proper direction.

The mathematical (actually, it''s geometrical) way of calculating this properly is in the functions that I gave you.

Set up a system of BOOLs. Like this:

bool turnleft; bool turnright; bool forward; bool backward;

Then, (assuming that you are using GLUT), set up your keyboard up functions and keyboard down functions.


float turnangle;

void main(int argc, char **argv){
...
glutKeyboardUpFunc(KeysUp);
glutKeyboardFunc(KeysDown);
...
glutDisplayFunc(RenderScene);
...
glutMainLoop();
}

void KeysDown(unsigned char key, int x, int y){
switch(key){
case ''a'': turnleft=1; break;
case ''d'': turnright=1; break;
case ''w'': forward=1; break;
case ''s'': backward=1; break;
default: break;
}
}

void KeysUp(unsigned char key, int x, int y){
switch(key){
case ''a'': turnleft=0; break;
case ''d'': turnright=0; break;
case ''w'': forward=0; break;
case ''s'': backward=0; break;
default: break;
}
}

void RenderScene(void){
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
...
if(turnleft){
turnangle-=0.01;
moveLeftandRight(angle);
}
if(turnright){
turnangle+=0.01;
moveLeftanfRight(angle);
}
if(forward){
moveForwardandBackward(1);
}
if(backward){
moveForwardandBackward(-1);
}


Get it now? Geometry is the only way you can interpret the angles easily. Because the default setting for translating forward would be along the z axis, you not only need to compenstate your lx,ly,lz coords by translating along the z axis, but also the x axis.

This, my friend, is why geometry is critical.

~Jesse Lawson,
www.proggin.com/tutorials/opengl/index.htm

I just noticed that you aren''t using GLUT; I thought you would be. The functions are still cooperative, so try them before you deny them.
??? Huh ???

I have been searching for an answer on how to correctly move after turning, so I tried to use your code Zues_. However, just like all things, it screwed up. I can get it to turn very strangley, but, when I implemented the forward and backward movement code, it would stand still when I hit forward, when I hit back, it would rotate the screen, then when I hit forward again, it just screws up some more, and makes me frustrated. Does anyone have any other answers? Oh, and um, Zues_, you said that sin, and -cos are often used to determine this. Um, how is this? I''ve taken Algebra, but not Trigo yet. SOMEONE HELP ME! If you don''t, then I will have to calculate the additions to X and Z for all three hundred and sixty degrees of movement. Also, if I just add and subtract values from the camera''s X axis view, why does it stop when I reach 180 degrees and 360 degrees?

En taro Adun!
Doom to all who threaten the homeworld!
*Protoss Zealot - Starcraft*
----------------------------------------------------------You know, I might as well go ahead and say I can't fix the problem... because that's when I figure out how.
Do you know what sine, cosine, and tangent are? No?

Hmm... Look them up. To do what you want to do, the way you want to do it, you need to use SOHCAHTOA.

Do you know why?

Well, my examples involved incrementing an angle, right?

SOHCAHTOA was previously explained by me. Im serious, ask your math teacher about it, its hard to explain without visual contact. =)

This topic is closed to new replies.

Advertisement