User Tools

Site Tools


en:examples:maths:rotate_a_point_around_a_center

Rotate a point around a center

Code

  // Point to rotate
  orxVECTOR point = orxVECTOR_0;
  orxVector_Set(&point,100,-100,0);
 
  // Center of rotation
  orxVECTOR center = orxVECTOR_0;
  orxVector_Set(&center,50,-50,0);
 
  // New location of point after rotation
  orxVECTOR result = orxVECTOR_0;
 
  // Angle of rotation
  float angle = 30;
 
   // Translate the point back to origin
  orxVector_Sub(&result, &point, &center);
 
  // Rotate the point
  orxVector_2DRotate(&result, &result, angle * orxMATH_KF_DEG_TO_RAD);
 
  // Translate back by adding the center
  orxVector_Add(&result, &result, &center);
en/examples/maths/rotate_a_point_around_a_center.txt · Last modified: 2018/02/14 00:47 (7 years ago) by 127.0.0.1