Archived

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

Vector of viewing camera

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

what''s a quick way of getting the vector for the viewing camera. The vector that would point out into world space from the middle of my viewing screen... Currently I calculated it using cos''s and sin''s using the x,y,z position and rotation of the camera which seems real innefficient... Thanks.

Share this post


Link to post
Share on other sites
Just out of curiousity is there a link to these kind of definitions.... my next query would be how to find the pan vectors (left and right side), other than using A.B=ABcos(th) and setting th to 90deg. Can I grab side vectors from a matrix?

Would be nice to see exactly what each element in each transformation matrix equates too (i.e. _13 of View matrix = x vector of view camera...)

Share this post


Link to post
Share on other sites
This is actually plain old vector maths - learning about vectors and matrices, and their geometric properties in particular gives you lots of nice mathematical optimisations for this sort of thing.


Back to your question:

In a matrix which consists only of rotations, the top left 3x3 rows (or columns) of it consist of 3 unit length vectors known as "basis vectors" (collectively known as an "orthonormal basis").

Each of those vectors is at exactly 90 degrees to the other vectors so the first vector (in the D3D coordinate system) points to the "right", the second vector points "up" and the third vector points "forward" (or in the direction).

So using the same layout as before:
right.x = view._11;
right.y = view._21;
right.z = view._31;
up.x = view._12;
up.y = view._22;
up.z = view._32;
direction.x = view._13;
direction.y = view._23;
direction.z = view._33;

The Left, Down and Backwards directions are simply the negated vectors of the above.

Visualised, the basis can be rendered as 3 lines all coming out of a single origin. This origin is the position or translation part of the matrix. This looks exactly like the commonly used "axis tripod" you find in things like 3DS Max.

Knowing the above, take another look at an identity matrix - the right vector is 1,0,0, the up vector is 0,1,0, the forward vector is 0,0,1 - think of other matrix operations and forms in this geometric sense and other things should become more intuitive.

Any pure rotation still preserves the perpendicular (90 degrees) nature of the vectors.

A uniform scale in your matrix changes the length of each of the basis vectors to the same magnitude.

A non-uniform scale sets the lengths of the vectors to different amounts.

Once a scale is applied, the vectors are no longer unit length so the basis changes from being an orthonormal basis [all vectors 90 degrees from each other AND unit length] to being a plain orthogonal [all vectors 90 degrees from each other] basis (orthonormal is a subset of orthogonal anyway).

A translation simply moves the origin of the basis - it''s separate from the actual basis really - it doesn''t have much to do with rotation (unless you multiply the matrix with another matrix in which case getting the order [pre or post] right is important).

Skews in matrices cause the orthogonality (all vectors perpendicular/90 degrees) property to be lost.

If the rotation part of your matrix is orthogonal a nice (mostly unrelated) optimisation is you can substitute any inversions for transposes. Camera and most world matrices usually are so you can do that with them.


There are plenty of other nice properties etc which should be covered in any decent matrix and vector tutorial/book - once you understand them to some extent, a lot of other things should slot into place nicely. Personaly I cringe when I see overuse of trigonometry in places where specific angles aren''t required (including professional game code!).




--
Simon O''Connor
3D Game Programmer &
Microsoft DirectX MVP

Share this post


Link to post
Share on other sites