rotating the camera around a object
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
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.
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.
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.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement