Edge Shapes A couple of questions

Link to Demo Here

Hi people, first off fantastic work on this project to everybody involved, they know who they are. Box2d is a god send to developers like me.

I have several issues with the above demo, my edge chains (many thanks shaktool for all your hard work on this) seem to have a problem with boxs but only at the point where the chain loop begins and ends, circles do not seem to have this problem, I am creating my chains by adding points recorded by the user mouse then creating the chain and calling body.CreateShape(chainDef);).

The second odd issue I have is the wheels quite often seem to stick to the floor lagging behind the truck somewhat (I understand this s most likely physic tweaks i.e. densities of my objects etc) but wondered if anyone had experienced what am seeing in my demo before.

Another problem and really this one isn't quite so box2d related, in the editor you draw ground objects by drawing rock shapes in a clockwise motion, if a user was to draw the shape anti clockwise the truck would be sucked into the shape with the hit detection on the inside of the shape. I understand that i could oppose the segment ends, but can anyone think of an elegant way to detect how or what the user has drawn 🙂

Many Thanks in Advance.

Tom
Assuming a polygon is not self intersecting, you can find out find out whether a polygon is clockwise or counter-clockwise by finding the sign of the area of the polygon:
http://valis.cs.uiuc.edu/~sariel/resear ... 00831.html
http://local.wasp.uwa.edu.au/~pbourke/g ... /polyarea/
Once you know the winding direction, you can decide whether to reverse the vertices before throwing them into an EdgeChain.

Your editor does allow self-intersecting polygons right now. Not sure what the best way to handle this is, though I should point out that there exist algorithms to detect intersecting line segments too. I've actually had luck hijacking Box2D's broadphase to quickly detect intersections between (non-box2D) line segments, but that's not necessarily the best solution, nor is it easy to explain.

Regarding the weirdness at the loop start/end point... do you have a redundant vertex in there? It is bad to have two adjacent vertices at the same location. The last vertex in the edge chain should not be at the same position as the first vertex. As long as you mark the chain as a loop, the start and end will be connected automatically.
Well a quick note to say you were bang on about the redundant vertex, only i was looking at the parser not how my mouse reads in the values! I was adding a duplicate right at the start. Note to self.. Read your traces!

I'm going to read over the links you sent, i'm still a little confused about actually coding somethng to determine the direction the chain should be.

Anyway over the moon about the other fix especially as it turned out to be something so simple.

Thanks
Wow! Creating a poly counter-clockwise is awesome! I DIDN'T KNOW! 😮

Original thread: https://box2d.org/forum/viewtopic.php?t=3077