2
\$\begingroup\$

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?

\$\endgroup\$
  • \$\begingroup\$ Are you asking how to rotate it's collision bounds? \$\endgroup\$ – Lysol Feb 6 '14 at 21:03
  • \$\begingroup\$ Yes, but I got an answer on that a long time ago. No idea how it arrived at the 'active' section again :) Thanks anyway \$\endgroup\$ – user3150201 Feb 6 '14 at 21:11
2
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ Thanks for your answer. Thing is, I'm familiar with the way you're describing, but for some reason, when I use it in my program, in addition to the rotation, the box also distortes and skews. I made a question about this, could you please look at it? Thanks gamedev.stackexchange.com/questions/68504/… \$\endgroup\$ – user3150201 Jan 7 '14 at 20:56
  • \$\begingroup\$ Have you ensured it's the rotation code that's bugged? Perhaps it's the drawing code? Attach the debugger and try zero rotation to start. Then try 360 degrees, 180, 90. Step through and ensure the values turn out to what they should be. I closed your other question as a duplicate because it was essentially the same question as this, except it was more of a "What's wrong with my code" type question, which aren't a good fit for this site. Good luck! \$\endgroup\$ – MichaelHouse Jan 7 '14 at 22:08
  • \$\begingroup\$ @user3150201 Lars has a solution for you as to your bug with the implementation. I believe my answer above answers this question. \$\endgroup\$ – MichaelHouse Jan 13 '14 at 18:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.