Saturday, October 28, 2017

2d - How do I rotate a bounding box together with a sprite?


I have a game object with a sprite that can rotate. It's a rectangle. I need its bounding box to rotate with it. How do I make sure that they can both rotate, but they're always both at the same angle?



Answer



Each corner should be rotated around the center of the box.


Typically this would be done by translating the box back to the origin, rotating, then translating back to the starting position.


Imagine the points that make up the corners rotating around a circle:


enter image description here


For rotating each point, see this answer.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...