Not logged in, Join Here! or Log In Below:  
News Articles Search    

 Home / 3D Theory & Graphics / rotating around a fixed point Account Manager
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.

March 31, 2005, 09:50 AM


How can you rotate around a fixed 3d point?


March 31, 2005, 10:31 AM

you cannot.. you always rotate around an axis!


March 31, 2005, 10:42 AM

I want to rotate a point A around a point C.

Can i not build an axis out of these two points?


March 31, 2005, 11:01 AM

No, you cannot.


March 31, 2005, 11:29 AM

You need to transform point A so that it's origin is C. Then rotate it. Then transform it back.



March 31, 2005, 04:55 PM

In response to: "code I make an axis out of those points". Absolutely. However, would it be the axis you want? Try this, while in your chair look around for a door knob. Now face the doorknob and point to it with your right arm. Your head is the location of the camera (A). The doorknob is what you want to rotate around (C). Your arm is the axis between A and C. Rotating around your arm what do you get? Is it what you wanted?

D3D and OpenGL have view matrix helper functions that take:

- Where the Eye is (A).
- A point the Eye should Lookat (C).
- What direction Up is to the Eye.
- Other stuff that is not central to this dicussion.

You should use this helper function (D3DXMatrixLookAtLH is D3D) to rotate the camera around the point. What you want to do is place the Eye in different locations, while keeping the Lookat constant. The appropriate way to move the Eye is on a sphere. Keep track of the Eye with two angles, one is how far around the sphere to go(azimuth), the other is how far up and down the sphere to go (altitude). To convert this to 3D coordinates use:

  2.     float z = r * cos(g_azi) * cos(g_alt);
  3.     float x = r * sin(g_azi) * cos(g_alt);
  4.     float y = r * sin(g_alt);
  6.     D3DXVECTOR3 vEyePt( x, y, z );
  7.     D3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 0.0f );
  8.     D3DXMATRIXA16 matView;
  9.     D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec );

I've ommitted the proper vUpVec, you should figure that out on your own.


This thread contains 6 messages.
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.