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

Started by
10 comments, last by Scouting Ninja 11 years, 1 month ago

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!

Advertisement

Good work!

I see,you multiply the offset after calculating the rotation point and then subtract it from the position.

This will definitely be a useful piece of code thanks!

This topic is closed to new replies.

Advertisement