turbulenz / turbulenz_engine

Turbulenz is a modular 3D and 2D game framework for making HTML5 powered games for browsers, desktops and mobile devices.
http://turbulenz.com
MIT License
4.57k stars 513 forks source link

physicsDevice.createConvexHullShape creates incorrect hull shape #38

Open davidfooks opened 10 years ago

davidfooks commented 10 years ago

Create a convex hull with the following points

        var myPoints = [
            -1, -1, -2,
             1, -1, -2,
            -1,  1, -2,
             1,  1, -2,
            -1, -1,  1,
             1, -1,  1,
            -1,  1,  1,
             1,  1,  1,
             0,  0,  2
        ];

        shape = physicsDevice.createConvexHullShape({
                points    : myPoints,
                margin    : 0.005
            });

Note that the resulting convex hull consists of only one triangle (in the simulation and rendering).

You can test this by replacing these points in the physics_collisionmesh sample: https://github.com/turbulenz/turbulenz_engine/blob/master/samples/tsscripts/templates/physics_collisionmesh.ts#L661

However, if I move the points by some small random number

        var i;
        for (i = 0; i < myPoints.length; i += 1)
        {
            myPoints[i] += Math.random() * 0.01;
        }

The convex hull renders and behaves as expected.

If there are some expected properties of the points array can you please document them here: http://docs.turbulenz.com/jslibrary_api/physicsdevice_api.html#createconvexhullshape

ianballantyne commented 10 years ago

Thank you for identifying this issue, we will look into and get back to you.