public override void InitializeDemo() { base.InitializeDemo(); SetCameraDistance(50); heightFields.Clear(); //collisionShapes = new ObjectArray<CollisionShape>(); m_collisionConfiguration = new DefaultCollisionConfiguration(); ///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded) m_dispatcher = new CollisionDispatcher(m_collisionConfiguration); m_broadphase = new DbvtBroadphase(); m_broadphase.GetOverlappingPairCache().SetInternalGhostPairCallback(new GhostPairCallback()); // Needed once to enable ghost objects inside Bullet //broadphase = new AxisSweep3(new Vector3(-1000, -1000, -1000), new Vector3(1000, 1000, 1000)); //new DbvtBroadphase(); SequentialImpulseConstraintSolver sol = new SequentialImpulseConstraintSolver(); m_constraintSolver = sol; m_dynamicsWorld = new DiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_constraintSolver, m_collisionConfiguration); m_dynamicsWorld.GetDispatchInfo().SetAllowedCcdPenetration(0.0001f); //world.DispatchInfo.AllowedCcdPenetration = 0.0001f; //world.Gravity = new Vector3(0, gravity, 0); mobControllers = new Dictionary <SceneNode, BulletMobState>(); LoadPlayerController(new Entity(), new SceneNode(), null, Vector3.Zero); //IndexedVector3 walkDir = new IndexedVector3(0, 0, -1); //playerController.SetWalkDirection(ref walkDir); //float[,] heights = new float[128, 128]; //LoadHeightField(heights, 10, 129, 129, Vector3.Zero, 1); float[,] heights = new float[32, 32]; LoadHeightField(heights, 10, 33, 33, Vector3.Zero, 1); ClientResetScene(); }
public override void InitializeDemo() { base.InitializeDemo(); SetCameraDistance(50); heightFields.Clear(); //collisionShapes = new ObjectArray<CollisionShape>(); m_collisionConfiguration = new DefaultCollisionConfiguration(); ///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded) m_dispatcher = new CollisionDispatcher(m_collisionConfiguration); m_broadphase = new DbvtBroadphase(); m_broadphase.GetOverlappingPairCache().SetInternalGhostPairCallback(new GhostPairCallback()); // Needed once to enable ghost objects inside Bullet //broadphase = new AxisSweep3(new Vector3(-1000, -1000, -1000), new Vector3(1000, 1000, 1000)); //new DbvtBroadphase(); SequentialImpulseConstraintSolver sol = new SequentialImpulseConstraintSolver(); m_constraintSolver = sol; m_dynamicsWorld = new DiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_constraintSolver, m_collisionConfiguration); m_dynamicsWorld.GetDispatchInfo().SetAllowedCcdPenetration(0.0001f); //world.DispatchInfo.AllowedCcdPenetration = 0.0001f; //world.Gravity = new Vector3(0, gravity, 0); mobControllers = new Dictionary<SceneNode, BulletMobState>(); LoadPlayerController(new Entity(), new SceneNode(), null, Vector3.Zero); //IndexedVector3 walkDir = new IndexedVector3(0, 0, -1); //playerController.SetWalkDirection(ref walkDir); //float[,] heights = new float[128, 128]; //LoadHeightField(heights, 10, 129, 129, Vector3.Zero, 1); float[,] heights = new float[32, 32]; LoadHeightField(heights, 10, 33, 33, Vector3.Zero, 1); ClientResetScene(); }
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(); }
public override void InitializeDemo() { base.InitializeDemo(); SetCameraDistance(50f); //string filename = @"E:\users\man\bullet\xna-basic-output-1.txt"; //FileStream filestream = File.Open(filename, FileMode.Create, FileAccess.Write, FileShare.Read); //BulletGlobals.g_streamWriter = new StreamWriter(filestream); ///collision configuration contains default setup for memory, collision setup m_collisionConfiguration = new DefaultCollisionConfiguration(); ///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded) m_dispatcher = new CollisionDispatcher(m_collisionConfiguration); IndexedVector3 worldMin = new IndexedVector3(-1000, -1000, -1000); IndexedVector3 worldMax = -worldMin; m_broadphase = new AxisSweep3Internal(ref worldMin, ref worldMax, 0xfffe, 0xffff, 16384, null, false); //pairCache = new SortedOverlappingPairCache(); //m_broadphase = new SimpleBroadphase(1000, pairCache); ///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded) SequentialImpulseConstraintSolver sol = new SequentialImpulseConstraintSolver(); m_constraintSolver = sol; m_dynamicsWorld = new DiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_constraintSolver, m_collisionConfiguration); m_dynamicsWorld.GetDispatchInfo().SetAllowedCcdPenetration(0.0001f); IndexedVector3 gravity = new IndexedVector3(0, -10, 0); m_dynamicsWorld.SetGravity(ref gravity); ///create a few basic rigid bodies IndexedVector3 halfExtents = new IndexedVector3(50, 50, 50); //IndexedVector3 halfExtents = new IndexedVector3(10, 10, 10); CollisionShape groundShape = new BoxShape(ref halfExtents); //CollisionShape groundShape = new StaticPlaneShape(new IndexedVector3(0,1,0), 50); m_collisionShapes.Add(groundShape); IndexedMatrix groundTransform = IndexedMatrix.CreateTranslation(new IndexedVector3(0, -50, 0)); //IndexedMatrix groundTransform = IndexedMatrix.CreateTranslation(new IndexedVector3(0,-10,0)); float mass = 0f; LocalCreateRigidBody(mass, ref groundTransform, groundShape); #region CharacterController IndexedMatrix startTransform = IndexedMatrix.Identity; //startTransform.setOrigin (btVector3(0.0, 4.0, 0.0)); startTransform._origin = new IndexedVector3(10.210098f, -1.6433364f, 16.453260f); m_ghostObject = new PairCachingGhostObject(); m_ghostObject.SetWorldTransform(startTransform); m_broadphase.GetOverlappingPairCache().SetInternalGhostPairCallback(new GhostPairCallback()); float characterHeight = 1.75f; float characterWidth = 1.75f; ConvexShape capsule = new CapsuleShape(characterWidth, characterHeight); m_ghostObject.SetCollisionShape(capsule); m_ghostObject.SetCollisionFlags(CollisionFlags.CF_CHARACTER_OBJECT); float stepHeight = 0.35f; int upAxis = 1; m_character = new KinematicCharacterController(m_ghostObject, capsule, stepHeight, upAxis); m_dynamicsWorld.AddCollisionObject(m_ghostObject, CollisionFilterGroups.CharacterFilter, CollisionFilterGroups.StaticFilter | CollisionFilterGroups.DefaultFilter); m_dynamicsWorld.AddAction(m_character); #endregion }
public override void InitializeDemo() { base.InitializeDemo(); SetCameraDistance(50f); //string filename = @"E:\users\man\bullet\xna-basic-output-1.txt"; //FileStream filestream = File.Open(filename, FileMode.Create, FileAccess.Write, FileShare.Read); //BulletGlobals.g_streamWriter = new StreamWriter(filestream); ///collision configuration contains default setup for memory, collision setup m_collisionConfiguration = new DefaultCollisionConfiguration(); ///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded) m_dispatcher = new CollisionDispatcher(m_collisionConfiguration); IndexedVector3 worldMin = new IndexedVector3 (-1000,-1000,-1000); IndexedVector3 worldMax = -worldMin; m_broadphase = new AxisSweep3Internal(ref worldMin, ref worldMax, 0xfffe, 0xffff, 16384, null, false); //pairCache = new SortedOverlappingPairCache(); //m_broadphase = new SimpleBroadphase(1000, pairCache); ///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded) SequentialImpulseConstraintSolver sol = new SequentialImpulseConstraintSolver(); m_constraintSolver = sol; m_dynamicsWorld = new DiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_constraintSolver, m_collisionConfiguration); m_dynamicsWorld.GetDispatchInfo().SetAllowedCcdPenetration(0.0001f); IndexedVector3 gravity = new IndexedVector3(0, -10, 0); m_dynamicsWorld.SetGravity(ref gravity); ///create a few basic rigid bodies IndexedVector3 halfExtents = new IndexedVector3(50, 50, 50); //IndexedVector3 halfExtents = new IndexedVector3(10, 10, 10); CollisionShape groundShape = new BoxShape(ref halfExtents); //CollisionShape groundShape = new StaticPlaneShape(new IndexedVector3(0,1,0), 50); m_collisionShapes.Add(groundShape); IndexedMatrix groundTransform = IndexedMatrix.CreateTranslation(new IndexedVector3(0, -50, 0)); //IndexedMatrix groundTransform = IndexedMatrix.CreateTranslation(new IndexedVector3(0,-10,0)); float mass = 0f; LocalCreateRigidBody(mass, ref groundTransform, groundShape); #region CharacterController IndexedMatrix startTransform = IndexedMatrix.Identity; //startTransform.setOrigin (btVector3(0.0, 4.0, 0.0)); startTransform._origin = new IndexedVector3(10.210098f,-1.6433364f,16.453260f); m_ghostObject = new PairCachingGhostObject(); m_ghostObject.SetWorldTransform(startTransform); m_broadphase.GetOverlappingPairCache().SetInternalGhostPairCallback(new GhostPairCallback()); float characterHeight=1.75f; float characterWidth =1.75f; ConvexShape capsule = new CapsuleShape(characterWidth,characterHeight); m_ghostObject.SetCollisionShape (capsule); m_ghostObject.SetCollisionFlags (CollisionFlags.CF_CHARACTER_OBJECT); float stepHeight = 0.35f; int upAxis = 1; m_character = new KinematicCharacterController (m_ghostObject,capsule,stepHeight,upAxis); m_dynamicsWorld.AddCollisionObject(m_ghostObject, CollisionFilterGroups.CharacterFilter, CollisionFilterGroups.StaticFilter | CollisionFilterGroups.DefaultFilter); m_dynamicsWorld.AddAction(m_character); #endregion }
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(); }