Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 27 Jul 2012
Offline Last Active Mar 25 2013 03:16 AM

#5040418 Rotation of a Bounding Box around a point that is not the objects centre

Posted by on 07 March 2013 - 09:23 AM

Ive figured it out really was quite simple to be honest.


involved adding the radius of the circle to be rotated around to the objects position, then when the object had been rotated working out the objects current orientation

and multiplying that by the radius offset and taking it from the position before adding it the rotated corners.


Here's the code that is being used:

D3DXVECTOR2 X(cosf(Rot), sinf(Rot));
	D3DXVECTOR2 Y(-sinf(Rot), cosf(Rot));

	X *= halfWidth/2;
	Y *= halfHeight/2;

	Corner[0] = Centre - X - Y;
	Corner[1] = Centre + X - Y;
	Corner[2] = Centre + X + Y;
	Corner[3] = Centre - X + Y;

	float offsetX = orientation.x * Offset;
	float offsetY = orientation.y * Offset;

	D3DXVECTOR2 offset(offsetX, offsetY);

	pos -= offset;

	Corner[0] += pos;
	Corner[1] += pos;
	Corner[2] += pos;
	Corner[3] += pos;

	Centre += pos;

Thanks for all the help! Wouldn't have made it without the pointers in the write direction!