#### Archived

This topic is now archived and is closed to further replies.

# How do I do a flight sim style camera?

This topic is 6195 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Bascially I''m trying to figure out how to make a camera which has: a viewing direction, ie. Pitch, Yaw and Roll angles a position, ie. X, Y and Z co-ordinates Basically, I want to make it so that you can look in any direction, and then pressing forward will make you move in the direction in which you are looking. I''ve got it so that moving the mouse left and right will change the yaw, moving it up and down will change the pitch, pressing [ or ] will change the roll.... but I don''t know what to do with the X, y and z co-ordinates. Whenever I try and think about the trigonometry it makes my brain hurt I thought it might be possible to do it without trigonometry, just by rotating the Camera Position vector by the negative values of the viewing angles, then transforming it, and rotating it back, but I haven''t got that working. Does anyone know how to do this, or know of a tutorial on it?

##### Share on other sites
Hmm... Well, if your camera''s direction is represented by a single directional vector then you could just reduce it to length of 1 unit, multiply it by move speed, and add it to the camera''s positional vector. Just a though.

A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."

##### Share on other sites
Oh, and if you are not using a single vector (the more likely version) you could of course use matrix multiplication to translate all of your rotations and transformations into that single directional vector.

A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."

##### Share on other sites
True... but am I not then faced with a similar sort of problem trying to figure out how to rotate the camera's directional vector? (or vectors , I guess it'd be a forward vector and an up vector and I could use gluLookAt to make it very simple)

I mean I'd have three vectors, CamPos, CamDir, and CamUp.

- In order to rotate the camera left and right (relative to the viewer), I would rotate CamDir about CamUp,

- In order to roll it I rotate CamUp about CamDir

- In order to rotate it up and down I find the vector perpendicular to CamUp and CamDir and then rotate them both about that vector.

So I suppose that means the problem is reduced to finding a way to rotate an arbitrary vector about another arbitrary vector... is there an elegant way to do that?

Edited by - foolish_mortal on October 31, 2001 11:55:32 AM

##### Share on other sites
Rotation of a directional vector is not so hard. Just use gl commands and then get the matrix, and use it to get the resulting directional vector. But if the directional vector is only being used to figure out how to move in that direction, you could simple calculate the vector after each change in view angle, and not actually continue to work with that vector. You would only be using it for movement, not for the actual camera translations. But that would cause an interesting overhead, un-needed waste of computer power. So if your able to use the vector(s) for everything, it would be better.

A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."

##### Share on other sites
It''s probably simpler not to bother calculating the angles each time.

Could you elaborate on "Just use gl commands and then get the matrix, and use it to get the resulting directional vector."?

##### Share on other sites
I''m not good with matricies. But you can use the standard commands (ig: glRotatef, glTranslatef) and then you can use an opengl command to capture the current matrix (ig: put it into a variable). I can''t recall the command right now, prob. something simple like glGet.... But you then multiply certain parts of the matrix by your vertex to get the resulting vertex. Basically what opengl does behind the scenes.

##### Share on other sites
Hrm, guys all of us "know" matrix math, but we all stay out of it as long as possible. Even though matrix math is extremly powerful in 3D.

Anyway, since my studies now #include Advanced_Vector_Math im basiclly forced to keep all wierd matrix stuff in mind.

I would recommend, atleast considering using matrices instead of
the "demo-ish" rotate.x := -sin(v)*cos(v)...you know the rest.

(btw, once you understand you rotation & transformation works you''ll be spinning cameras all over the place.)

##### Share on other sites
I''m hung up on trying to program a matrix class for myself now, I think it''s quite a useful thing to have. In the back of the Red Book there''s an equation for rotating a matrix around a vector, which I hope will do the trick.

The thing about using glRotatef... etc is that although you can put a matrix into the system, using glLoadMatrix, I can''t find any way of outputting the values, and it seems that I need to know what the new values are in order to know what to rotate it around next time...

It''s funny there don''t seem to be any tutorials on this when there''s so many on the Quake-style movement.

1. 1
Rutin
29
2. 2
3. 3
4. 4
5. 5

• 13
• 13
• 11
• 10
• 13
• ### Forum Statistics

• Total Topics
632955
• Total Posts
3009450
• ### Who's Online (See full list)

There are no registered users currently online

×