Archived

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

rotating the camera around a object

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

Recommended Posts

Hello, In D3DIm how would you rotate the camera around a object? In other words, the object stays completely still while the camera makes a complete circle around the object. Thanks, Brian Draeger briandra2@aol.com

Share on other sites
Within the context of using a standard "LookAt" camera where you specify a camera position and a ''target'' point you can setup what you want rather easily.

Firstly you need to define range, or radius. This variable will be the distance of your camera from it''s target. You then use some simple trig and an incrementing angle variable to calculate the position of the camera around the target.

// for a camera rotating around the Y axis of an object.
camera.x = target.x + cos(angle) * radius;
camera.z = target.z + sin(angle) * radius;
camera.y = target.y + someOffset;

SetViewMatrix(viewMatrix, camera, target, upVector);

Your object can be moving around in your world all you want since the camera''s view matrix will be calculated directly depending on the target''s position. It could produce some real nifty effects.

This is a very simplistic implementation, but it should get you started. If you want something more complicated, you can get into Quaternions, which if not mistaken will allow you to position the camera at any point along the surface of an imaginary sphere that surrounds the object rather neatly. I will be researching how to do this myself for my own project.

Share on other sites
instead of using those sin and cosine functions you can use D3DXMatrixRotationX.

D3DXMATRIX* D3DXMatrixRotationX(
D3DXMATRIX* pOut,
FLOAT Angle
);

Just take that function and give it an empty matrix and the amount you want to rotate add the object vertex. Then apply it to the world. Correct me if I am wrong anyone.
~Wave

You can change the x at the end of the func to y or z. Depending on your need.

Share on other sites
Yes... you are correct... you can build a matrix which is first translated, and then rotated by whatever you want... usually we like to rotate first and translate next. To make this camera, you want to translate by a vector whose length is the radius I spoke of earlier... And then rotate by your angle.

1. 1
2. 2
Rutin
22
3. 3
4. 4
JoeJ
16
5. 5

• 14
• 29
• 9
• 11
• 11
• Forum Statistics

• Total Topics
631775
• Total Posts
3002278
×