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\$
2
  • \$\begingroup\$ Are you asking how to rotate it's collision bounds? \$\endgroup\$
    – Lysol
    Feb 6, 2014 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\$ Feb 6, 2014 at 21:11

1 Answer 1

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\$
3
  • \$\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\$ Jan 7, 2014 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\$
    – House
    Jan 7, 2014 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\$
    – House
    Jan 13, 2014 at 18:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .