Jump to content
  • Advertisement


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.

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

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 this post

Link to post
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 this post

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

D3DXMATRIX* D3DXMatrixRotationX(

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.

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

Share this post

Link to post
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.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!