Exemplo n.º 1
0
        internal static object CreateMeshShapeF(object pWorld, int pIndicesCount, int[] indices, int pVerticesCount, float[] verticesAsFloats)
        {
            ObjectArray<int> indicesarr = new ObjectArray<int>(indices);
            ObjectArray<float> vertices = new ObjectArray<float>(verticesAsFloats);
            var world = pWorld as DiscreteDynamicsWorld;
            IndexedMesh mesh = new IndexedMesh();
            mesh.m_indexType = PHY_ScalarType.PHY_INTEGER;
            mesh.m_numTriangles = pIndicesCount / 3;
            mesh.m_numVertices = pVerticesCount;
            mesh.m_triangleIndexBase = indicesarr;
            mesh.m_vertexBase = vertices;
            mesh.m_vertexStride = 3;
            mesh.m_vertexType = PHY_ScalarType.PHY_FLOAT;
            mesh.m_triangleIndexStride = 3;

            TriangleIndexVertexArray tribuilder = new TriangleIndexVertexArray();
            tribuilder.AddIndexedMesh(mesh, PHY_ScalarType.PHY_INTEGER);
            BvhTriangleMeshShape meshShape = new BvhTriangleMeshShape(tribuilder, false, true);
            //TriangleMeshShape meshShape = new TriangleMeshShape(tribuilder);
            //meshShape.SetMargin(world.WorldSettings.Params.collisionMargin);
            float margin = 0.02f;
            meshShape.SetMargin(margin);
            return meshShape;
        }
        public override void InitializeDemo()
        {
            SetCameraDistance(50);
            int totalTriangles = 2 * (NUM_VERTS_X - 1) * (NUM_VERTS_Y - 1);

            int vertStride = 1;
            int indexStride = 3;

            BulletGlobals.gContactAddedCallback = new CustomMaterialCombinerCallback();


            gVertices = new ObjectArray<IndexedVector3>(totalVerts);
            gIndices = new ObjectArray<int>(totalTriangles * 3);

            SetVertexPositions(waveheight, 0.0f);
            
            gVertices.GetRawArray()[1].Y = 0.1f;


	int index=0;
    int i, j;
	for (i=0;i<NUM_VERTS_X-1;i++)
	{
		for (j=0;j<NUM_VERTS_Y-1;j++)
		{

#if SWAP_WINDING
#if SHIFT_INDICES
			gIndices[index++] = j*NUM_VERTS_X+i;
			gIndices[index++] = (j+1)*NUM_VERTS_X+i+1;
			gIndices[index++] = j*NUM_VERTS_X+i+1;
			
			gIndices[index++] = j*NUM_VERTS_X+i;
			gIndices[index++] = (j+1)*NUM_VERTS_X+i;
			gIndices[index++] = (j+1)*NUM_VERTS_X+i+1;
			
#else
			gIndices[index++] = (j+1)*NUM_VERTS_X+i+1;
			gIndices[index++] = j*NUM_VERTS_X+i+1;
			gIndices[index++] = j*NUM_VERTS_X+i;

			gIndices[index++] = (j+1)*NUM_VERTS_X+i;
			gIndices[index++] = (j+1)*NUM_VERTS_X+i+1;
			gIndices[index++] = j*NUM_VERTS_X+i;
#endif //SHIFT_INDICES
#else //SWAP_WINDING

#if SHIFT_INDICES
			gIndices[index++] = (j+1)*NUM_VERTS_X+i+1;
			gIndices[index++] = j*NUM_VERTS_X+i;
			gIndices[index++] = j*NUM_VERTS_X+i+1;

#if TEST_INCONSISTENT_WINDING
			gIndices[index++] = j*NUM_VERTS_X+i;
			gIndices[index++] = (j+1)*NUM_VERTS_X+i;
			gIndices[index++] = (j+1)*NUM_VERTS_X+i+1;

#else //TEST_INCONSISTENT_WINDING
			gIndices[index++] = (j+1)*NUM_VERTS_X+i;
			gIndices[index++] = j*NUM_VERTS_X+i;
			gIndices[index++] = (j+1)*NUM_VERTS_X+i+1;
#endif //TEST_INCONSISTENT_WINDING
			
			
			
#else //SHIFT_INDICES
			gIndices[index++] = j*NUM_VERTS_X+i;
			gIndices[index++] = j*NUM_VERTS_X+i+1;
			gIndices[index++] = (j+1)*NUM_VERTS_X+i+1;

			gIndices[index++] = j*NUM_VERTS_X+i;
			gIndices[index++] = (j+1)*NUM_VERTS_X+i+1;
			gIndices[index++] = (j+1)*NUM_VERTS_X+i;
#endif //SHIFT_INDICES

#endif //SWAP_WINDING
        }
    }

            m_indexVertexArrays = new TriangleIndexVertexArray(totalTriangles,
                gIndices,
                indexStride,
                totalVerts, gVertices, vertStride);

            bool useQuantizedAabbCompression = true;

             IndexedVector3  aabbMin = new IndexedVector3 (-1000,-1000,-1000);
             IndexedVector3 aabbMax = new IndexedVector3(1000, 1000, 1000);
	
            trimeshShape  = new BvhTriangleMeshShape(m_indexVertexArrays,useQuantizedAabbCompression,ref aabbMin,ref aabbMax,true);

            CollisionShape groundShape = trimeshShape;

            TriangleInfoMap triangleInfoMap = new TriangleInfoMap();

            InternalEdgeUtility.GenerateInternalEdgeInfo(trimeshShape, triangleInfoMap);


            m_collisionConfiguration = new DefaultCollisionConfiguration();


            m_dispatcher = new CollisionDispatcher(m_collisionConfiguration);



            m_broadphase = new DbvtBroadphase();
            m_constraintSolver = new SequentialImpulseConstraintSolver();
            m_dynamicsWorld = new DiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_constraintSolver, m_collisionConfiguration);
            m_dynamicsWorld.SetDebugDrawer(m_debugDraw);

            IndexedVector3 gravity = new IndexedVector3(0,-10,0);
	        m_dynamicsWorld.SetGravity(ref gravity);

	
	        float mass = 0.0f;
	        IndexedMatrix startTransform = IndexedMatrix.CreateTranslation(new IndexedVector3(0,-2,0));

            ConvexHullShape colShape = new ConvexHullShape(new List<IndexedVector3>(), 0);
	        for (int k=0;k<DemoMeshes.TaruVtxCount;k++)
	        {
                IndexedVector3 vtx = DemoMeshes.TaruVtx[k];
		        colShape.AddPoint(ref vtx);
	        }
	        //this will enable polyhedral contact clipping, better quality, slightly slower
            //colShape.InitializePolyhedralFeatures();

	        //the polyhedral contact clipping can use either GJK or SAT test to find the separating axis
	        m_dynamicsWorld.GetDispatchInfo().m_enableSatConvex=false;


            {
                //for (int i2 = 0; i2 < 1; i2++)
                //{
                //    startTransform._origin = new IndexedVector3(-10.0f + i2 * 3.0f, 2.2f + i2 * 0.1f, -1.3f);
                //    RigidBody body = LocalCreateRigidBody(10, startTransform, colShape);
                //    body.SetActivationState(ActivationState.DISABLE_DEACTIVATION);
                //    body.SetLinearVelocity(new IndexedVector3(0, 0, -1));
                //    //body->setContactProcessingThreshold(0.f);
                //}
            }
            {
                BoxShape colShape2 = new BoxShape(new IndexedVector3(1, 1, 1));
                //colShape.InitializePolyhedralFeatures();
                m_collisionShapes.Add(colShape2);
                startTransform._origin = new IndexedVector3(-16.0f + i * 3.0f, 1.0f + i * 0.1f, -1.3f);
                RigidBody body = LocalCreateRigidBody(10, startTransform, colShape2);
                body.SetActivationState(ActivationState.DISABLE_DEACTIVATION);
                body.SetLinearVelocity(new IndexedVector3(0, 0, -1));
            }

            startTransform = IndexedMatrix.Identity;

            staticBody = LocalCreateRigidBody(mass, startTransform,groundShape);
	        //staticBody->setContactProcessingThreshold(-0.031f);
	        staticBody.SetCollisionFlags(staticBody.GetCollisionFlags() | CollisionFlags.CF_KINEMATIC_OBJECT);//STATIC_OBJECT);

	        //enable custom material callback
	        staticBody.SetCollisionFlags(staticBody.GetCollisionFlags()  | CollisionFlags.CF_CUSTOM_MATERIAL_CALLBACK);
            m_debugDraw.SetDebugMode(DebugDrawModes.DBG_DrawText | DebugDrawModes.DBG_NoHelpText | DebugDrawModes.DBG_DrawWireframe | DebugDrawModes.DBG_DrawContactPoints);



            //base.InitializeDemo();
            //ClientResetScene();

        }
Exemplo n.º 3
0
    public static void DumpRaw(int[] indices, float[] vertices, int pIndicesCount, int pVerticesCount)
    {

        String fileName = "objTest6.raw";
        String completePath = System.IO.Path.Combine(Util.configDir(), fileName);
        StreamWriter sw = new StreamWriter(completePath);
        IndexedMesh mesh = new IndexedMesh();

        mesh.m_indexType = PHY_ScalarType.PHY_INTEGER;
        mesh.m_numTriangles = pIndicesCount / 3;
        mesh.m_numVertices = pVerticesCount;
        mesh.m_triangleIndexBase = indices;
        mesh.m_vertexBase = vertices;
        mesh.m_vertexStride = 3;
        mesh.m_vertexType = PHY_ScalarType.PHY_FLOAT;
        mesh.m_triangleIndexStride = 3;

        TriangleIndexVertexArray tribuilder = new TriangleIndexVertexArray();
        tribuilder.AddIndexedMesh(mesh, PHY_ScalarType.PHY_INTEGER);


        sw.WriteLine("Indices");
        sw.WriteLine(string.Format("int[] indices = new int[{0}];",pIndicesCount));
        for (int iter = 0; iter < indices.Length; iter++)
        {
            sw.WriteLine(string.Format("indices[{0}]={1};",iter,indices[iter]));
        }
        sw.WriteLine("VerticesFloats");
        sw.WriteLine(string.Format("float[] vertices = new float[{0}];", pVerticesCount));
        for (int iter = 0; iter < vertices.Length; iter++)
        {
            sw.WriteLine(string.Format("Vertices[{0}]={1};", iter, vertices[iter].ToString("0.0000")));
        }

            // for (int i = 0; i < pVerticesCount; i++)
            // {
            //
            //     string s = vertices[indices[i * 3]].ToString("0.0000");
            //     s += " " + vertices[indices[i * 3 + 1]].ToString("0.0000");
            //    s += " " + vertices[indices[i * 3 + 2]].ToString("0.0000");
            //
            //     sw.Write(s + "\n");
            //}

            sw.Close();
    }
Exemplo n.º 4
0
    public static void DumpRaw(ObjectArray<int>indices, ObjectArray<float> vertices, int pIndicesCount,int pVerticesCount )
    {

        String fileName = "objTest3.raw";
        String completePath = System.IO.Path.Combine(Util.configDir(), fileName);
        StreamWriter sw = new StreamWriter(completePath);
        IndexedMesh mesh = new IndexedMesh();

        mesh.m_indexType = PHY_ScalarType.PHY_INTEGER;
        mesh.m_numTriangles = pIndicesCount / 3;
        mesh.m_numVertices = pVerticesCount;
        mesh.m_triangleIndexBase = indices;
        mesh.m_vertexBase = vertices;
        mesh.m_vertexStride = 3;
        mesh.m_vertexType = PHY_ScalarType.PHY_FLOAT;
        mesh.m_triangleIndexStride = 3;

        TriangleIndexVertexArray tribuilder = new TriangleIndexVertexArray();
        tribuilder.AddIndexedMesh(mesh, PHY_ScalarType.PHY_INTEGER);



        for (int i = 0; i < pVerticesCount; i++)
        {

            string s = vertices[indices[i * 3]].ToString("0.0000");
            s += " " + vertices[indices[i * 3 + 1]].ToString("0.0000");
            s += " " + vertices[indices[i * 3 + 2]].ToString("0.0000");

            sw.Write(s + "\n");
        }

        sw.Close();
    }
Exemplo n.º 5
0
    public override BulletShape CreateMeshShape(BulletWorld pWorld, int pIndicesCount, int[] indices, int pVerticesCount, float[] verticesAsFloats)
    {
        //DumpRaw(indices,verticesAsFloats,pIndicesCount,pVerticesCount);

        for (int iter = 0; iter < pVerticesCount; iter++)
        {
            if (verticesAsFloats[iter] > 0 && verticesAsFloats[iter] < 0.0001) verticesAsFloats[iter] = 0;
            if (verticesAsFloats[iter] < 0 && verticesAsFloats[iter] > -0.0001) verticesAsFloats[iter] = 0;
        }

        ObjectArray<int> indicesarr = new ObjectArray<int>(indices);
        ObjectArray<float> vertices = new ObjectArray<float>(verticesAsFloats);
        DumpRaw(indicesarr,vertices,pIndicesCount,pVerticesCount);
        DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world;
        IndexedMesh mesh = new IndexedMesh();
        mesh.m_indexType = PHY_ScalarType.PHY_INTEGER;
        mesh.m_numTriangles = pIndicesCount/3;
        mesh.m_numVertices = pVerticesCount;
        mesh.m_triangleIndexBase = indicesarr;
        mesh.m_vertexBase = vertices;
        mesh.m_vertexStride = 3;
        mesh.m_vertexType = PHY_ScalarType.PHY_FLOAT;
        mesh.m_triangleIndexStride = 3;

        TriangleIndexVertexArray tribuilder = new TriangleIndexVertexArray();
        tribuilder.AddIndexedMesh(mesh, PHY_ScalarType.PHY_INTEGER);
        BvhTriangleMeshShape meshShape = new BvhTriangleMeshShape(tribuilder, true,true);
        meshShape.SetMargin(world.WorldSettings.Params.collisionMargin);
       // world.UpdateSingleAabb(meshShape);
        return new BulletShapeXNA(meshShape, BSPhysicsShapeType.SHAPE_MESH);

    }
Exemplo n.º 6
0
        public CollisionShape BuildCorner()
        {
            // slope.
            IndexedVector3[] vertices = new IndexedVector3[]{new IndexedVector3(0,0,0),new IndexedVector3(1,0,0),new IndexedVector3(0,0,1),new IndexedVector3(1,0,1),
                            new IndexedVector3(0,1,0),new IndexedVector3(1,1,0),new IndexedVector3(0,1,1),new IndexedVector3(1,1,1)};



            //int[] indices = new int[] { 0, 4, 5, 4, 6, 7, 7, 5, 4, 0, 4, 6, 6, 2, 0, 2, 6, 7, 4,5,0,2,2,7,5};
            //int[] indices = new int[] { 0, 4, 5, 4, 6, 7, 7, 5, 4,  6, 4,0,0,2,6, 7, 6, 2, 4, 5, 0, 2, 2, 7, 5 };
            int[] indices = new int[] { 1,4,5,
                1,5,7,
                7,3,1,
                3,7,6,
                7,5,4,
                4,6,7,
                4,1,3,
                3,6,4
            };

            int vertStride = 1;
            int indexStride = 3;

            ObjectArray<IndexedVector3> vertexArray = new ObjectArray<IndexedVector3>();
            for (int i = 0; i < vertices.Length; ++i)
            {
                vertexArray.Add(vertices[i]);
            }

            ObjectArray<int> intArray = new ObjectArray<int>();
            for (int i = 0; i < indices.Length; ++i)
            {
                intArray.Add(indices[i]);
            }
            TriangleIndexVertexArray indexVertexArray = new TriangleIndexVertexArray(indices.Length/3, intArray, indexStride, vertexArray.Count, vertexArray, vertStride);
            TriangleMeshShape triangleMesh = new TriangleMeshShape(indexVertexArray);
            //TriangleMeshShape triangleMesh = new BvhTriangleMeshShape(indexVertexArray,true,true);
            return triangleMesh;




        }
Exemplo n.º 7
0
        public override void InitializeDemo()
        {
            //string filename = @"E:\users\man\bullet\xna-concaveray-output-1.txt";
            //FileStream filestream = File.Open(filename, FileMode.Create, FileAccess.Write, FileShare.Read);
            //BulletGlobals.g_streamWriter = new StreamWriter(filestream);

			m_cameraDistance = 400f;
			m_farClip = 1500f;
            m_perspective = IndexedMatrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(40.0f), m_aspect, m_nearClip, m_farClip);


            m_animatedMesh = true;
			base.InitializeDemo();
			int totalTriangles = 2 * (NUM_VERTS_X - 1) * (NUM_VERTS_Y - 1);

			gVertices = new ObjectArray<IndexedVector3>(totalVerts);
			int indicesTotal = totalTriangles * 3;
            gIndices = new ObjectArray<int>(indicesTotal);

			BulletGlobals.gContactAddedCallback = null;

			SetVertexPositions(waveheight,0f);

			int vertStride = 1;
			int indexStride = 3;

			int index=0;
            //for (int i=0;i<NUM_VERTS_X-1;i++)
            //{
            //    for (int j=0;j<NUM_VERTS_Y-1;j++)
            //    {
            //        gIndices[index++] = j * NUM_VERTS_X + i;
            //        gIndices[index++] = (j + 1) * NUM_VERTS_X + i + 1;
            //        gIndices[index++] = j * NUM_VERTS_X + i + 1;

            //        gIndices[index++] = j * NUM_VERTS_X + i;
            //        gIndices[index++] = (j + 1) * NUM_VERTS_X + i;
            //        gIndices[index++] = (j + 1) * NUM_VERTS_X + i + 1;

            //    }
            //}

            for (int i = 0; i < NUM_VERTS_X - 1; i++)
            {
                for (int j = 0; j < NUM_VERTS_Y - 1; j++)
                {
                    gIndices[index++] = j * NUM_VERTS_X + i;
                    gIndices[index++] = j * NUM_VERTS_X + i + 1;
                    gIndices[index++] = (j + 1) * NUM_VERTS_X + i + 1;

                    gIndices[index++] = j * NUM_VERTS_X + i;
                    gIndices[index++] = (j + 1) * NUM_VERTS_X + i + 1;
                    gIndices[index++] = (j + 1) * NUM_VERTS_X + i;
                }
            }

			TriangleIndexVertexArray indexVertexArrays = new TriangleIndexVertexArray(totalTriangles,
				gIndices,indexStride,totalVerts,gVertices,vertStride);

			bool useQuantizedAabbCompression = true;

			float minX = NUM_VERTS_X * TRIANGLE_SIZE * 0.5f;
			float minZ = NUM_VERTS_Y * TRIANGLE_SIZE * 0.5f;

			//OptimizedBvh bvh = new OptimizedBvh();
	        IndexedVector3 aabbMin = new IndexedVector3(-minX,-5,-minZ);
	        IndexedVector3 aabbMax = new IndexedVector3(minX,5,minZ);




            m_trimeshShape = new BvhTriangleMeshShape(indexVertexArrays, useQuantizedAabbCompression, ref aabbMin, ref aabbMax, true);
            //m_trimeshShape = new BvhTriangleMeshShape(indexVertexArrays, useQuantizedAabbCompression,true);
	        IndexedVector3 scaling = IndexedVector3.One;
			CollisionShape groundShape = m_trimeshShape;
            //groundShape = new TriangleMeshShape(indexVertexArrays);
			//groundShape = new StaticPlaneShape(IndexedVector3.Up, 0f);
            IndexedVector3 up = new IndexedVector3(0.4f,1,0);
            up.Normalize();
			//groundShape = new StaticPlaneShape(up, 0f);
			//groundShape = new BoxShape(new IndexedVector3(1000, 10, 1000));
			m_collisionConfiguration = new DefaultCollisionConfiguration();
			m_dispatcher = new	CollisionDispatcher(m_collisionConfiguration);

			IndexedVector3 worldMin = aabbMin;
			IndexedVector3 worldMax = aabbMax;

			m_broadphase = new AxisSweep3Internal(ref worldMin, ref worldMax, 0xfffe, 0xffff, 16384, null, false);
			m_constraintSolver = new SequentialImpulseConstraintSolver();
			m_dynamicsWorld = new DiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_constraintSolver, m_collisionConfiguration);

			float mass = 0f;
			IndexedMatrix startTransform = IndexedMatrix.CreateTranslation(new IndexedVector3(2,-2,0));


			startTransform = IndexedMatrix.Identity;
			staticBody = LocalCreateRigidBody(mass, ref startTransform,groundShape);

			staticBody.SetCollisionFlags(staticBody.GetCollisionFlags() | CollisionFlags.CF_KINEMATIC_OBJECT);//STATIC_OBJECT);

			//enable custom material callback
			staticBody.SetCollisionFlags(staticBody.GetCollisionFlags() | CollisionFlags.CF_CUSTOM_MATERIAL_CALLBACK);

			//m_raycastBar = new btRaycastBar (m_debugDraw,4000.0f, 0.0f,-1000,30);
			m_raycastBar = new btRaycastBar(m_debugDraw, 300.0f, 0.0f, -1000, 200,worldMin.X,worldMax.X);
			m_raycastBar.min_x = -100;
			m_raycastBar.max_x = -100;

            ClientResetScene();

        }
Exemplo n.º 8
0
        public static CollisionShape BuildCorner(IndexedVector3[] vertices, int[] indices)
        {
            int vertStride = 1;
            int indexStride = 3;

            ObjectArray<IndexedVector3> vertexArray = new ObjectArray<IndexedVector3>();
            for (int i = 0; i < vertices.Length; ++i)
            {
                vertexArray.Add(vertices[i]);
            }

            ObjectArray<int> intArray = new ObjectArray<int>();
            for (int i = 0; i < indices.Length; ++i)
            {
                intArray.Add(indices[i]);
            }
            TriangleIndexVertexArray indexVertexArray = new TriangleIndexVertexArray(indices.Length / 3, intArray, indexStride, vertexArray.Count, vertexArray, vertStride);
            TriangleMeshShape triangleMesh = new TriangleMeshShape(indexVertexArray);
            return triangleMesh;
        }
Exemplo n.º 9
0
        public void InitGImpactCollision()
        {

            /// Create Torus Shape
            {
                m_indexVertexArrays = new TriangleIndexVertexArray(DemoMeshes.TORUS_NUM_TRIANGLES, DemoMeshes.gTorusIndices, 3, DemoMeshes.TORUS_NUM_VERTICES, DemoMeshes.gTorusVertices, 3);

#if BULLET_GIMPACT_CONVEX_DECOMPOSITION
			btGImpactConvexDecompositionShape * trimesh  = new
			btGImpactConvexDecompositionShape(
			m_indexVertexArrays, IndexedVector3(1.f,1.f,1.f),btScalar(0.01));
			trimesh->setMargin(0.07);
			trimesh->updateBound();


#else
                //GImpactMeshShape trimesh = new GImpactMeshShape(m_indexVertexArrays);
                //IndexedVector3 scaling = IndexedVector3.One;
                //trimesh.SetLocalScaling(ref scaling);
                //trimesh.SetMargin(0.07f); ///?????
                //trimesh.UpdateBound();
#endif

                //m_trimeshShape = trimesh;

            }

            /// Create Bunny Shape
            {
                m_indexVertexArrays2 = new TriangleIndexVertexArray(DemoMeshes.BUNNY_NUM_TRIANGLES, DemoMeshes.gBunnyIndices, 3, DemoMeshes.BUNNY_NUM_VERTICES, DemoMeshes.gBunnyVertices, 3);
#if BULLET_GIMPACT_CONVEX_DECOMPOSITION
			btGImpactConvexDecompositionShape * trimesh2  = new
			btGImpactConvexDecompositionShape(
			m_indexVertexArrays2, IndexedVector3(4.f,4.f,4.f),btScalar(0.01));
			trimesh2->setMargin(0.07);
			trimesh2->updateBound();
#else
                GImpactMeshShape trimesh2 = new GImpactMeshShape(m_indexVertexArrays2);
                IndexedVector3 scaling = new IndexedVector3(4.0f, 4.0f, 4.0f);
                trimesh2.SetLocalScaling(ref scaling);
                //trimesh2.SetMargin(0.07f); ///?????
                trimesh2.UpdateBound();
#endif
                m_trimeshShape2 = trimesh2;

            }


            ///register GIMPACT algorithm
            CollisionDispatcher dispatcher = m_dynamicsWorld.GetDispatcher() as CollisionDispatcher;

            GImpactCollisionAlgorithm.RegisterAlgorithm(dispatcher);
        }
Exemplo n.º 10
0
		//-----------------------------------------------------------------------------------------------

		public override void InitializeDemo()
		{
			//string filename = @"C:\users\man\bullett\xna-concave-output.txt";
			//FileStream filestream = File.Open(filename, FileMode.Create, FileAccess.Write, FileShare.Read);
			//BulletGlobals.g_streamWriter = new StreamWriter(filestream);

            
            m_animatedMesh = true;
			base.InitializeDemo();
			int totalTriangles = 2 * (NUM_VERTS_X - 1) * (NUM_VERTS_Y - 1);

            gVertices = new ObjectArray<IndexedVector3>(totalVerts);
			int indicesTotal = totalTriangles * 3;
            gIndices = new ObjectArray<int>(indicesTotal);

            //BulletGlobals.gContactAddedCallback = new CustomMaterialCombinerCallback();

			SetVertexPositions(waveheight,0f);

			int vertStride = 1;
			int indexStride = 3;

			int index=0;
			for (int i=0;i<NUM_VERTS_X-1;i++)
			{
				for (int j=0;j<NUM_VERTS_Y-1;j++)
				{
                    gIndices[index++] = j * NUM_VERTS_X + i;
                    gIndices[index++] = j * NUM_VERTS_X + i + 1;
                    gIndices[index++] = (j + 1) * NUM_VERTS_X + i + 1;

                    gIndices[index++] = j * NUM_VERTS_X + i;
                    gIndices[index++] = (j + 1) * NUM_VERTS_X + i + 1;
                    gIndices[index++] = (j + 1) * NUM_VERTS_X + i;
				}
			}

            if (BulletGlobals.g_streamWriter != null)
            {
                index = 0;
                BulletGlobals.g_streamWriter.WriteLine("setIndexPositions");
                for (int i = 0; i < gIndices.Count; i++)
                {
                    BulletGlobals.g_streamWriter.WriteLine(String.Format("{0} {1}", i, gIndices[i]));
                }
            }


			TriangleIndexVertexArray indexVertexArrays = new TriangleIndexVertexArray(totalTriangles,
				gIndices,indexStride,totalVerts,gVertices,vertStride);

			bool useQuantizedAabbCompression = true;


            OptimizedBvh bvh = new OptimizedBvh();
	        IndexedVector3 aabbMin = new IndexedVector3(-1000,-1000,-1000);
	        IndexedVector3 aabbMax = new IndexedVector3(1000,1000,1000);

            m_trimeshShape = new BvhTriangleMeshShape(indexVertexArrays, useQuantizedAabbCompression, ref aabbMin, ref aabbMax, true);
            //CollisionShape trimeshShape = new TriangleMeshShape(indexVertexArrays);

            IndexedVector3 scaling = IndexedVector3.One;
            //m_trimeshShape.SetOptimizedBvh(bvh, ref scaling);
            
			//BulletWorldImporter import = new BulletWorldImporter(0);//don't store info into the world
			//if (import.loadFile("myShape.bullet"))
			//{
			//    int numBvh = import.getNumBvhs();
			//    if (numBvh != 0)
			//    {
			//        OptimizedBvh bvh = import.getBvhByIndex(0);
			//        IndexedVector3 aabbMin = new IndexedVector3(-1000,-1000,-1000);
			//        IndexedVector3 aabbMax = new IndexedVector3(1000,1000,1000);
			
			//        trimeshShape = new indexVertexArrays,useQuantizedAabbCompression,ref aabbMin,ref aabbMax,false);
			//        IndexedVector3 scaling = IndexedVector3.One;
			//        trimeshShape.setOptimizedBvh(bvh, ref scaling);
			//        //trimeshShape  = new btBvhTriangleMeshShape(m_indexVertexArrays,useQuantizedAabbCompression,aabbMin,aabbMax);
			//        //trimeshShape.setOptimizedBvh(bvh);
			
			//    }
			//    int numShape = import.getNumCollisionShapes();
			//    if (numShape != 0)
			//    {
			//        trimeshShape = (BvhTriangleMeshShape)import.getCollisionShapeByIndex(0);
					
			//        //if you know the name, you can also try to get the shape by name:
			//        String meshName = import.getNameForPointer(trimeshShape);
			//        if (meshName != null)
			//        {
			//            trimeshShape = (BvhTriangleMeshShape)import.getCollisionShapeByName(meshName);
			//        }
					
			//    }
			//}


            //CollisionShape groundShape = trimeshShape;//m_trimeshShape;
            CollisionShape groundShape = m_trimeshShape;//m_trimeshShape;

            //groundShape = new TriangleShape(new IndexedVector3(0,` 0, 100), new IndexedVector3(100, 0, 0),new IndexedVector3(-100, 0, -100));
            //groundShape = new StaticPlaneShape(IndexedVector3.Up, 0f);
            //groundShape = new BoxShape(new IndexedVector3(100f, 0.1f, 100f));
            IndexedVector3 up = new IndexedVector3(0.4f,1,0);
            up.Normalize();
            //groundShape = new StaticPlaneShape(up, 0f);
            //groundShape = new TriangleMeshShape(indexVertexArrays);
            
			m_collisionConfiguration = new DefaultCollisionConfiguration();
			m_dispatcher = new	CollisionDispatcher(m_collisionConfiguration);

			IndexedVector3 worldMin = new IndexedVector3(-1000,-1000,-1000);
			IndexedVector3 worldMax = new IndexedVector3(1000,1000,1000);
            //m_broadphase = new AxisSweep3Internal(ref worldMin, ref worldMax, 0xfffe, 0xffff, 16384, null, false);
            m_broadphase = new DbvtBroadphase();
			m_constraintSolver = new SequentialImpulseConstraintSolver();
			m_dynamicsWorld = new DiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_constraintSolver, m_collisionConfiguration);

			float mass = 0f;
			IndexedMatrix startTransform = IndexedMatrix.CreateTranslation(new IndexedVector3(2,-2,0));

            //CompoundShape colShape = new CompoundShape();
            //IndexedVector3 halfExtents = new IndexedVector3(4, 1, 1);
            //CollisionShape cylinderShape = new CylinderShapeX(ref halfExtents);
            //CollisionShape boxShape = new BoxShape(new IndexedVector3(4, 1, 1));
            //IndexedMatrix localTransform = IndexedMatrix.Identity;
            //colShape.addChildShape(ref localTransform, boxShape);
            //Quaternion orn = Quaternion.CreateFromYawPitchRoll(MathUtil.SIMD_HALF_PI, 0f, 0f);
            //localTransform = IndexedMatrix.CreateFromQuaternion(orn);
            //colShape.addChildShape(ref localTransform, cylinderShape);

            ////BoxShape colShape = new BoxShape(new IndexedVector3(1, 1, 1));


            //int numCollideObjects = 1;
            //m_collisionShapes.Add(colShape);
            //{
            //    for (int i = 0; i < numCollideObjects; i++)
            //    {
            //        startTransform._origin = new IndexedVector3(4,10+i*2,1);
            //        localCreateRigidBody(1, ref startTransform,colShape);
            //    }
            //}

			CollisionShape boxShape = new BoxShape(new IndexedVector3(1, 1, 1));
			//CollisionShape boxShape = new SphereShape(1);
            //CollisionShape boxShape = new SphereShape(1);
            //CollisionShape boxShape = new CapsuleShapeZ(0.5f, 1);
            m_collisionShapes.Add(boxShape);
            for (int i = 0; i < 1; i++)
            {
                startTransform._origin = new IndexedVector3(2f * i, 5, 1);
                LocalCreateRigidBody(1, ref startTransform, boxShape);
            }


			startTransform = IndexedMatrix.Identity;
			staticBody = LocalCreateRigidBody(mass, ref startTransform,groundShape);

			staticBody.SetCollisionFlags(staticBody.GetCollisionFlags() | CollisionFlags.CF_KINEMATIC_OBJECT);//STATIC_OBJECT);

			//enable custom material callback
			staticBody.SetCollisionFlags(staticBody.GetCollisionFlags() | CollisionFlags.CF_CUSTOM_MATERIAL_CALLBACK);

            //clientResetScene();
		}
CollisionShape BuildLargeMesh()
{
	//int vertStride = sizeof(IndexedVector3);
	//int indexStride = 3*sizeof(int);

	int vertStride = 1;
	int indexStride = 3;

	ObjectArray<IndexedVector3> vertexArray = new ObjectArray<IndexedVector3>();
	for (int i = 0; i < vertices.Length; ++i)
	{
		vertexArray.Add(vertices[i]);
	}

	ObjectArray<int> intArray = new ObjectArray<int>();
	for (int i = 0; i < indices.Length; ++i)
	{
		intArray.Add(indices[i]);
	}
    //TriangleIndexVertexArray indexVertexArray = new TriangleIndexVertexArray(DemoMeshes.BUNNY_NUM_TRIANGLES, DemoMeshes.gBunnyIndices, 3, DemoMeshes.BUNNY_NUM_VERTICES, DemoMeshes.gBunnyVertices, 3);

    TriangleIndexVertexArray indexVertexArray = new TriangleIndexVertexArray(numTriangles, intArray, indexStride, vertexArray.Count, vertexArray, vertStride);
    TriangleMeshShape triangleMesh = new TriangleMeshShape(indexVertexArray);
    //TriangleMeshShape triangleMesh = new BvhTriangleMeshShape(indexVertexArray,true,true);
	return triangleMesh;

}