ivansafrin/Polycode — Issue #68: addPhysicsChild w/ENTITY_MESH breaks on counterclockwise polygons
Author: mcclure
Created: 2011-12-15 03:37:33+00:00
State: open

Running this exact version of my test program https://bitbucket.org/runhello/polyconsole/changeset/1ab28626c267

I create a 2D physics space. I make sort of a trough lined at the bottom with a series of circles (just to have something to interact with). In the start state, the scene looks like this:

http://i.imgur.com/LuG12.png

Notice the six visible polygons. To make these polygons (if you want to see the code, look under svgloader.cpp in the above-linked repository, the part starting with "if (points.size()>2) {"), I create a ScreenMesh. Then I get the Mesh affiliated with that ScreenMesh. Then I create a Polygon, add the points of the polygon I desire one by one to the Polygon, add the Polygon to the Mesh, then add the original ScreenMesh to the physics space as an ENTITY_MESH. The triangles are ScreenMeshes created of type Mesh::TRI_MESH; the other polygons are ScreenMeshes created of type Mesh::TRIFAN_MESH.

Here is the important distinction to make: the three polygons on the left, the points were added to the polygon in clockwise order. The three polygons on the right, the points were added to the polygon in counter-clockwise order.

If I allow the physics to run for a couple seconds, at the end the scene looks like this:

http://i.imgur.com/LuG12.png

Notice: The three polygons on the left, the clockwise polygons, behave correctly. The three polygons on the right, the counterclockwise polygons, do NOT behave correctly. (Also notice all Polygons *draw* correctly.) The counterclockwise polygons have the following incorrect behaviors:

- They do not engage in collisions of any kind with the other non-static polygons. (They do engage in collisions with static polygons.)
- Their interactions with the static polygons are incorrect. It's not obvious from this screenshot (you can kind of tell if you look at the fourth object from the left, the second triangle) but all polygons of "counterclockwise type" I've created act as if they have infinite friction and fixed rotation (neither of these things are true). All these meshes seem to do is fall until they hit a

None of this behavior is hinted at in the documentation.