erincatto / box2d-lite

A small 2D physics engine
http://box2d.org/
MIT License
876 stars 118 forks source link

Question on order of bodies in arbiter code #8

Closed ericoporto closed 1 year ago

ericoporto commented 1 year ago

In the Arbiter code, there is a comparison of less than in the body pointers for body 1 and 2. Why is this there? Why is this necessary?

https://github.com/erincatto/box2d-lite/blob/227b71b6974ea57ab7e96d40f6374287bd6a0e77/src/Arbiter.cpp#L16-L27

I am porting this code to other language, and I am trying to figure some bugs that are appearing, and in this language, I can't do this type of comparisons on references, so I am just curious if I need to figure something to replicate this. Thanks!

erincatto commented 1 year ago

This if/else is not needed. I'm guessing this is leftover from an earlier version. You can just use

body1 = b1;
body2 = b2;
ericoporto commented 1 year ago

Thank you!

233888920-aa627fa1-2f91-43f5-8ddf-5f95b533d393

It's almost working but I guess I am doing something incorrectly with my contacts calculation