when I use getPosition() I get the center point of the body. The fixture's position in the body is relative to the body. However if the body is inclined and has an angle do I need to calculate the starting point of the body? I need this point to draw a sprite on it. Is there an easy way to do this?

  • 1
    \$\begingroup\$ What is "the starting point" of a body? Coordinates that are closest to the origin of the world? Coordinates furthest from it? Something else? \$\endgroup\$ – Tyyppi_77 Apr 6 '17 at 12:15
  • \$\begingroup\$ @Tyyppi_77 You know when I draw something on the canvas I need to know where to put this sprite. Say if I have a rectangle I need the top left point of the rectangle. If it is a line it is the left end of the line. \$\endgroup\$ – newguy Apr 6 '17 at 12:17
  • \$\begingroup\$ You would need to rotate your sprite to be in sync with your box2d body/fixture. \$\endgroup\$ – jgallant Apr 6 '17 at 16:11
  • \$\begingroup\$ @jgallant Thanks I figure out I need to anchor my sprite to its center and then rotate it to get the result. \$\endgroup\$ – newguy Apr 6 '17 at 16:38

Say that you want the vertex at L = (-w/2, -h/2), where w is the width of the rectangle and h is the height. Say that your box is at point P, rotated of an angle theta with respect to the axis orthogonal to the 2D plane.

First, get L' = R(theta) L, using the rotation matrix R(theta). This is the vector pointing at the desired corner, rotated according to the orientation of the box. Second, translate it with P, so that your desired point is X = P + L'.


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.