3D transformations

Started by
5 comments, last by Wayfarer 23 years, 7 months ago
This should be an easy question for a 3D guru: How do you rotate your camera around an object in world space at a given distance from it, instead of the camera rotating around its own point? I haven''t any luck getting my matrices to work properly. Btw, this is for D3D.
Advertisement
Although I'm not a 3D guru, you could try this:
- Start with identity matrix
- Multiply with the object matrix
- Take only the rotation part of the camera matrix, and multiply this.
- Take only the position part of the camera matrix, and translate.

Now you should be at the position you wanted.
If you do a normal matrix multiplication, translation goes before rotation.



Edited by - baskuenen on August 29, 2000 7:32:22 PM
I don''t quite understand the order of your matrices or what you''re applying
them to. This is what I''m trying to do in this order:

Set up the camera so it is relative to my object in world space:
This needs to be changed somehow:

D3DMATRIX V;

// these are all inverse matrices using the camera''s position and orientation
// translates camera back to origin and aligns orientation with all 3 axes
V = T * Y * X * Z;

lpdevice->SetTransform ( D3DTRANSFORMSTATE_VIEW, &V );


Get the world matrix of my object and draw it in world space:

D3DMATRIX W;

// these are all matrices using the object''s position and orientation
// rotates locally around origin first and then translates to world space
W = Z * X * Y * T;

lpdevice->SetTransform( D3DTRANSFORMSTATE_WORLD, &W );

// render my object here
lpdevice->DrawIndexedPrimitive(...)


Using the above transformations, I want to be able to rotate my camera
around the y-axis on the xz plane, using the object''s position as its
rotation point. The camera will always face the object as it rotates.
And the camera should still be able to rotate around the object even
if the camera rolls or changes pitch.

I''ve tried several different things, but still no luck. The camera
always seems to rotate about its own point or do other crazy things.
Still doesn''t work. Tried modifying my view projection matrix like:

// inverse matrices to bring camera back to origin
V = T * Y * X * Z;

V = V * T2;

where T2 is a matrix that translates the camera from the origin
just a small distance away, but I honestly don''t know what I''m doing.
Need some serious help.

YES! I finally got it working. Here''s what I got:

To rotate an object around a point in world space:

W = (Y2) * Z * X * (T2 * Y) * T;

Z,X,Y,T are the object''s orientation and position.
T2 is the distance to rotate from the point.
Y2 is an optional rotation matrix. You can set it up as
180 degrees if you want the object''s front side to face
the point.


And if you want to rotate the camera around a point in
world space, it''s just the opposite:

// Z,X,Y,T are the camera''s inverse matrices for orientation and position.
V = T * ( Y * T2) * X * Z * (Y2);

T2 is the distance to rotate from the point.
Y2 is a 180 degree rotation matrix if you want to get
the camera to face the rotation point.


Enough matrices for now. There''s never a guru around when
you need ''em.
quote:Original post by Wayfarer

Enough matrices for now. There''s never a guru around when
you need ''em.


I think you learned more this way, don''t you think so too?



- WitchLord

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Ok, here''s one for you if you want to take the matrix challenge:

How about a triple rotation system (well, I call it triple from
a nested point of view) like a planetary system?

Have the camera (always facing the rotation point) rotate around
object1 in world space, while this system (object1,camera) rotates
around object2, while this entire system (object1,camera, object2)
rotates around the origin.

This topic is closed to new replies.

Advertisement