Advice about Kinect and Dynamic Heightfield

Post Reply
User avatar
JohnHardy
Posts: 18
Joined: Mon Mar 05, 2012 11:39 pm
Location: Lancaster, UK
Contact:

Advice about Kinect and Dynamic Heightfield

Post by JohnHardy » Mon Mar 05, 2012 11:54 pm

Hi folks,

I am attempting to convert a real-time-ish point cloud from a Kinect into a collision object and was wondering what advice you have about the best way to go about such a thing.

I was considering using the heightfield shape, mapping the point cloud into a grid and then simply updating the z-values of each vertex in the collision data, but I don't know if this is desirable or even possible? My other thought was to use a cloth soft body, but this might have quite a bit of overhead?

Any help / advice you have to offer would be greatly appreciated! :)

John

p.s. This is very similar to what I want to do:
http://www.youtube.com/watch?v=SaT7UCP09Ww
http://bulletphysics.org/Bullet/phpBB3/ ... eightfield

User avatar
JohnHardy
Posts: 18
Joined: Mon Mar 05, 2012 11:39 pm
Location: Lancaster, UK
Contact:

Re: Advice about Kinect and Dynamic Heightfield

Post by JohnHardy » Mon Mar 12, 2012 8:38 pm

Just wanted to say I managed to get this working by updating the BvhTriangleMeshShape. :-) I'll post up the source to the project soon if anyone is interested.

Here are some pics of the work so far: http://goo.gl/fIixl

Cheers,

John

Code: Select all

        private void RebuildTerrainPhysicsMesh()
        {
            // If our ground has not been created yet, or destroyed.
            if (GroundBody == null)
            {
                // Ensure our groundMesh and groundShape are destroyed and properly disposed of.
                if (GroundMesh != null)
                {
                    GroundMesh = null;
                }
                if (GroundShape != null)
                {
                    Physics.CollisionShapes.Remove(GroundShape);
                    GroundShape.Dispose();
                    GroundShape = null;
                }

                // Create the mesh container.
                GroundMesh = new IndexedMesh();
                int iTotalTriangles = 2 * (iTerrainWidth - 1) * (iTerrainHeight - 1);
                GroundMesh.Allocate(this.tTerrainVB.Length, sizeof(float) * 3, iTotalTriangles, sizeof(uint) * 3);

                // Write the verts.
                BulletSharp.DataStream pData = GroundMesh.LockVerts();
                for (int i = 0, n = tTerrainVB.Length; i < n; ++i)
                {
                    pData.Write(tTerrainVB[i].Position.x);
                    pData.Write(tTerrainVB[i].Position.y + 1.0f);
                    pData.Write(tTerrainVB[i].Position.z);
                }
                pData.Close();

                // And write the indicies.
                IntArray tIndexData = GroundMesh.TriangleIndices;
                for (int i = 0, n = tTerrainIB.Length; i < n; ++i)
                    tIndexData[i] = (int)tTerrainIB[i];

                // Setup the shape.
                TriangleIndexVertexArray vertexArray = new TriangleIndexVertexArray();
                vertexArray.AddIndexedMesh(GroundMesh);
                GroundShape = new BvhTriangleMeshShape(vertexArray, true);

                // And the rigid body in the world.
                Physics.CollisionShapes.Add(GroundShape);
                GroundBody = Physics.LocalCreateRigidBody(0, Matrix4.IDENTITY, GroundShape);
                GroundBody.UserObject = "Ground";
            }

            // Otherwise we have a valid shape already, just push the updates and refit it.
            else
            {
                BulletSharp.DataStream pData = GroundMesh.LockVerts();
                for (int i = 0, n = tTerrainVB.Length; i < n; ++i)
                {
                    pData.Write(tTerrainVB[i].Position.x);
                    pData.Write(tTerrainVB[i].Position.y + 1.0f);
                    pData.Write(tTerrainVB[i].Position.z);
                }
                pData.Close();

                GroundShape.RecalcLocalAabb();
                GroundShape.RefitTree(GroundShape.LocalAabbMin, GroundShape.LocalAabbMax);
            }
        }

User avatar
JohnHardy
Posts: 18
Joined: Mon Mar 05, 2012 11:39 pm
Location: Lancaster, UK
Contact:

Re: Advice about Kinect and Dynamic Heightfield

Post by JohnHardy » Tue Mar 13, 2012 7:40 pm

Just wanted to say a big thanks to everyone involved in making Bullet (and Ogre). :mrgreen:

Follow this link for some pics of the finished (ish) game: http://goo.gl/GBgkS

Cheers,

John

Image
Image

Post Reply