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();

        }
        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();
        }