Physics Simulation Forum

 

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Mon Mar 05, 2012 11:54 pm 
Offline
User avatar

Joined: Mon Mar 05, 2012 11:39 pm
Posts: 18
Location: Lancaster, UK
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
viewtopic.php?f=9&t=6853&hilit=heightfield


Top
 Profile  
 
PostPosted: Mon Mar 12, 2012 8:38 pm 
Offline
User avatar

Joined: Mon Mar 05, 2012 11:39 pm
Posts: 18
Location: Lancaster, UK
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:
        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);
            }
        }


Top
 Profile  
 
PostPosted: Tue Mar 13, 2012 7:40 pm 
Offline
User avatar

Joined: Mon Mar 05, 2012 11:39 pm
Posts: 18
Location: Lancaster, UK
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group