简体   繁体   中英

Rotate a object around a point

how would I rotate an object around an object, such as rotating an object in circles around another object? Preferably using GL.Rotate and as little math as possible!

GL.Rotate defines a rotation matrix, that rotates a round 0.0. If you want to rotate around a pivot ( pivotX , pivotY ) you have to:

  1. Translate the object so that the pivot point is moved to (0, 0).
  2. Rotate the object.
  3. Move the object so that the pivot point moves in its original position.

eg:

GL.Translate(pivotX, pivotY, 0);    // 3. move back
GL.Roatate(angle, 0, 0, 1);         // 2. rotate
GL.Translate(-pivotX, -pivotY, 0);  // 1. move pivot to (0, 0) 

See also How to use Pivot Point in Transformations

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM