0

I'm looking to construct an object from lots of smaller boxes and joins in specific places. Some of the boxes are rotated, and I want the joints to go at the corners/vertices, like how a rag-doll elbow & knee joints make up the arms & legs.

Is there a correct way to go about this? I am assuming I may have to translate the local shape vertices to world positions and offset the body centre points each time, but it's quite complicated and wondered if this has been covered elsewhere.

I've seen a few posts about adding multiple fixtures to one body eg Box2d multiple fixtures and positioning But that's not what I want to do.

Thanks

Community
  • 1
  • 1
MachineElf
  • 1,231
  • 2
  • 15
  • 28
  • have you checked out the source code of the testbeds that come with the box2d source? there is a ragdoll example that you could check out and see how he did it. I imagine it would be a fairly efficient way of doing it. – Shannon Jun 15 '11 at 00:11
  • Thanks Shannon, I did look at the test bed but seem to remember it wasn't quite what I wanted (I'm not doing an actual ragdoll character). Cute little fellas though! – MachineElf Jun 15 '11 at 09:37

1 Answers1

2

For design/layout, you can have the body position for all the boxes in the same place eg. (0,0) and add fixtures where ever it suits you in 'world coordinates' to make it easier to construct the figure. Then you can also add joints in world coordinates to join them up.

Everything should work fine like that but it's important to remember that if you later use body->GetPosition() on the boxes, you will get whatever point (0,0) has moved to relative to the current box position, which is most likely quite useless. What you really want is body->GetWorldCenter(), which will return the current center of mass for each box.

iforce2d
  • 8,194
  • 3
  • 29
  • 40
  • Hi iforce, that's an interesting solution and certainly easier! I guess you could even do something like offset/update all the body's fixtures by GetWorldCenter() so that GetPosition() is now correct? – MachineElf Jun 15 '11 at 09:34
  • I guess so, but I can't think of why you would want to know where the original (0,0) position is. The only reason you even cared about the body position in the first place is because you had to specify one to create the body. – iforce2d Jun 15 '11 at 13:12