Advertisement

Space Ship Motion in 3D

Started by March 19, 2003 09:27 AM
3 comments, last by AntiVeggieBoy 21 years, 11 months ago
I need some help moving and rotating a ship in 3D space. I''m building a first person space fighter sim with a 3D virtual cockpit. I am basing the control system on Freelancer where the ship must pitch or yaw based on the distance the mouse cursor is from centre. The ship must always pitch up around it''s local X axis when the mouse is moved forward and yaw around it''s local Y axis when the mouse is moved sideways - all of this with no regard to it''s orientation in global space. I''m just stuck conceptualizing the data needed to represent all this and the order of the calculations. I also need to be able to resolve the orientation back to global space so I can send in a position, heading, pitch and roll back to the 3D model rendering functions. Any ideas?
Uhhh...
An object's local to world (or space in your case) matrix takes the form:
 /          \ | Rx Ry Rz 0 || Ux Uy Uz 0 || Ax Ay Az 0 || Px Py Pz 1 | \          /    

where (Rx,Ry,Rz) forms a vector that points to the object's right (i.e. the object's local x axis), (Ux, Uy, Uz) points up (i.e. object's local y axis),(Ax, Ay, Az) points forwards (the object's local z axis) and (Px, Py, Pz) is the object's position.

From this, you can get a new matrix:
M' = M.RotX
where RotX is a rotation about the matrix's right vector, i.e. pitch and
M' = M'.RotY
where RotY is a rotation about the matrix's up vector, i.e. yaw.

The order the rotations are applied will create different results, try both and see what 'feels' better. You won't then need to store any angles or do any conversions between angles and matricies. You will, however, need to know how to rotate a matrix about an axis by a given angle (and google would help here).

It helps if you structure your matrix type as:
struct/class Matrix{    Vector Right;    Vector Up;    Vector At;    Vector Position;};    


Skizz

[edited by - Skizz on March 19, 2003 11:13:02 AM]
Advertisement
So my spaceship starts with this matrix at identity
and if the player pitches or yaws, I would rotate the other two axis about the relevant axis and store this new orientation, then how would I get the pitch, heading, roll values? (possibly trig with components of these axis vectors?)
Uhhh...
As it''s a space sim, do you need to know what the current pitch and yaw is? I say this because they are relative values (i.e. relative the ground for pitch, to meridians for yaw) and in space there''s nothing to be relative to. You can do everything you need by just manipulating the matrix directly (or rather, multiplying it by the relavant rotation matrix). So the steps you''d do are:
1) Get the right vector from the object''s matrix
2) Build a rotation matrix from this vector and the pitch delta angle
3) Multiply object''s matrix and rotation matrix
4) Repeat using object''s up vector and yaw delta angle

If you really need to store the angles, then you''re best off using a quaternion as they don''t suffer from Gimbal Locks as they evaluate all rotation angles simultaneously. But if you''re having trouble conceptualising this using matricies, using quaternions is likely to make your head explode (it involes lots of imaginary numbers).

If I was doing this, I''d just have the object''s matrix and update it directly using the above method. This matrix can then be used as your camera matrix directly (unless you have an extrior view).

I believe the book ''Computer Graphics, Principles and Practice'' by Foley et al has a very good description of the use of matricies (and uses a flight sim as an example). It''s a bit pricey though but is an authoritive and useful must have book.

Skizz
Thanks all - I think I''ve got it - also found a great tut that explains step by step very nicely

http://www.sgi.com/software/performer/brew/aqua.html

Hopefully you''ll all be playing my demo soon
Uhhh...

This topic is closed to new replies.

Advertisement