Mirrored Bodies do not behave the same as theyr originals

General Box2D issues or C++ specific issues
d.baechtold
Posts: 5
Joined: Mon Jul 18, 2011 10:40 am

Mirrored Bodies do not behave the same as theyr originals

Postby d.baechtold » Mon Jul 18, 2011 10:59 am

Hi

I have a simple World which is symetric, meaning that all Bodies on the left side of the middle Axis are mirrored (Copies) to the right side, too (this is done by multiplying the x value of the position Vector by -1). The Simulation however is not the same, which I would expect:
Box2d mirrored objects.png
Box2d mirrored objects.png (4.72 KiB) Viewed 2138 times


When not mirroring the Bodies, but just placing a 1:1 Copy on the right side (this is done by adding a given value to the x value of the position Vector), both Body Groups behave the same, as expected:
Box2d copied objects.png
Box2d copied objects.png (4.42 KiB) Viewed 2138 times


Does this maybe depend on the order in which the Bodies are added to the world, or are there other (good?) reasons for this? It would be great if Somebody could provide a Solution how to have both Simulations (original and mirrored one) behaving the same way.

Thanks a lot
Dan

irresistible force
Posts: 1991
Joined: Tue Jun 24, 2008 8:25 pm
Location: Tokyo
Contact:

Re: Mirrored Bodies do not behave the same as theyr original

Postby irresistible force » Mon Jul 18, 2011 8:22 pm

It's pretty hard to figure out the problem without knowing what you mean by 'behave'.

d.baechtold
Posts: 5
Joined: Mon Jul 18, 2011 10:40 am

Re: Mirrored Bodies do not behave the same as theyr original

Postby d.baechtold » Mon Jul 18, 2011 11:23 pm

Ok, new Picture:
Box2D mirror.png
Box2D mirror.png (17.46 KiB) Viewed 2131 times

irresistible force
Posts: 1991
Joined: Tue Jun 24, 2008 8:25 pm
Location: Tokyo
Contact:

Re: Mirrored Bodies do not behave the same as theyr original

Postby irresistible force » Tue Jul 19, 2011 1:51 am

wow you certainly are good with the pictures!
I would first check whether adding the bodies in the same order for each group will help, but I still have my doubts whether you would ever get a perfectly mirrored result. Is is possible to just use physics on one side only and just draw the mirrored version on the other side?

d.baechtold
Posts: 5
Joined: Mon Jul 18, 2011 10:40 am

Re: Mirrored Bodies do not behave the same as theyr original

Postby d.baechtold » Tue Jul 19, 2011 2:05 am

Thanks ;)

I'll try some tweaks with the order. As of now, i've added the first original Body, then it's Copy, then it's mirrored Copy, and then proceeded with the next original Body, but this didn't do the trick.

The Mirror-Thing may seem unreasonable, but the Reason is simple: The Simulation is made on two Client Devices, each one displaying the Picture from "his" Side of View.. so both Clients shoud have the same Simulation Result, even while the second one works on a mirrored World.

irresistible force
Posts: 1991
Joined: Tue Jun 24, 2008 8:25 pm
Location: Tokyo
Contact:

Re: Mirrored Bodies do not behave the same as theyr original

Postby irresistible force » Tue Jul 19, 2011 7:44 am

You could still have the second device running the same simulation, just render it mirrored though couldn't you? And mirror any input if necessary... I guess it depends on what kind of interaction from the user is necessary as to how far you could take that idea.

d.baechtold
Posts: 5
Joined: Mon Jul 18, 2011 10:40 am

Re: Mirrored Bodies do not behave the same as theyr original

Postby d.baechtold » Wed Jul 20, 2011 4:13 pm

Yes indeed! I still don't see why these Differences occur, but your Idea is just great - it already works :D

Thank you very much for your Help!

Erin Catto
Site Admin
Posts: 2948
Joined: Thu Sep 06, 2007 12:34 am

Re: Mirrored Bodies do not behave the same as theyr original

Postby Erin Catto » Wed Jul 20, 2011 4:33 pm

Box2D uses an iterative solver that is order dependent. As such, mirroring likely won't work.

Consider a vertical stack of identical square boxes. Such a stack is a mirror of itself. Experience with Box2D shows that tall stacks of boxes eventually fall when the number of boxes passes some threshold. But there is no way for a vertical stack to fall symmetrically. Therefore, a vertical stack fails to be a mirror of itself. Thus mirroring does not work in general.

d.baechtold
Posts: 5
Joined: Mon Jul 18, 2011 10:40 am

Re: Mirrored Bodies do not behave the same as theyr original

Postby d.baechtold » Thu Jul 21, 2011 9:07 am

I understand now.. thanks Erin for your Explanation :)


Return to “Bugs, Requests, and Feedback”



Who is online

Users browsing this forum: No registered users and 1 guest