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

Topics I've Started

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

22 February 2013 - 08:03 AM



Ive been trying to work out how to rotate a bounding box about a position that is not the objects centre and perform collisions based on SAT Collision Dectection. I have the collisions working but i cannot figure out how to rotate the bounding box into the right location as all I seem to be able to manage is to rotate the bounding box around the objects centre position.


This is what i have so far:


        float Rot = Entity.getRotation();
	D3DXVECTOR2 pos = D3DXVECTOR2(Entity.getPosition().x,Entity.getPosition().y);
	Centre = Entity.getCentre() + pos;	

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

	X *= Entity.getWidth()/2;
	Y *= Entity.getHeight()/2;

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

This code rotates about the objects centre position but i cant mange to rotate about a position say 15 pixels in the positive X direction from its own centre.


Any Ideas on how I would accomplish this?