protected override void OnInitializePhysics() { // collision configuration contains default setup for memory, collision setup CollisionConf = new DefaultCollisionConfiguration(); Dispatcher = new CollisionDispatcher(CollisionConf); Broadphase = new DbvtBroadphase(); Solver = new SequentialImpulseConstraintSolver(); World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, Solver, CollisionConf); World.Gravity = Freelook.Up * -10.0f; BspLoader bspLoader = new BspLoader(); //string[] args = Environment.GetCommandLineArgs(); //if (args.Length == 1) //{ UnityEngine.TextAsset bytes = (UnityEngine.TextAsset)UnityEngine.Resources.Load("BspDemo"); System.IO.Stream byteStream = new System.IO.MemoryStream(bytes.bytes); bspLoader.LoadBspFile(byteStream); //} //else //{ // bspLoader.LoadBspFile(args[1]); //} BspConverter bsp2Bullet = new BspToBulletConverter(this); bsp2Bullet.ConvertBsp(bspLoader, 0.1f); }
public void SetUp() { conf = new DefaultCollisionConfiguration(); dispatcher = new CollisionDispatcher(conf); broadphase = new AxisSweep3(new Vector3(-1000, -1000, -1000), new Vector3(1000, 1000, 1000)); world = new DiscreteDynamicsWorld(dispatcher, broadphase, null, conf); // Initialize TriangleIndexVertexArray with float array indexVertexArray = new TriangleIndexVertexArray(TorusMesh.Indices, TorusMesh.Vertices); gImpactMeshShape = new GImpactMeshShape(indexVertexArray); gImpactMeshShape.CalculateLocalInertia(1.0f); gImpactMesh = CreateBody(1.0f, gImpactMeshShape, Vector3.Zero); // Initialize TriangleIndexVertexArray with Vector3 array Vector3[] torusVertices = new Vector3[TorusMesh.Vertices.Length / 3]; for (int i = 0; i < torusVertices.Length; i++) { torusVertices[i] = new Vector3( TorusMesh.Vertices[i * 3], TorusMesh.Vertices[i * 3 + 1], TorusMesh.Vertices[i * 3 + 2]); } indexVertexArray2 = new TriangleIndexVertexArray(TorusMesh.Indices, torusVertices); triangleMeshShape = new BvhTriangleMeshShape(indexVertexArray2, true); // CalculateLocalInertia must fail for static shapes (shapes based on TriangleMeshShape) //triangleMeshShape.CalculateLocalInertia(1.0f); triangleMesh = CreateBody(0.0f, triangleMeshShape, Vector3.Zero); }
protected override void OnInitializePhysics() { CollisionConf = new DefaultCollisionConfiguration(); Dispatcher = new CollisionDispatcher(CollisionConf); Broadphase = new DbvtBroadphase(); World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, null, CollisionConf); World.Gravity = new Vector3(0, -10, 0); // ground CollisionShape groundShape = new BoxShape(50, 1, 50); CollisionShapes.Add(groundShape); CollisionObject ground = LocalCreateRigidBody(0, Matrix.Identity, groundShape); ground.UserObject = "Ground"; // Objects //colShape = new BoxShape(1); Vector3[] points0 = { new Vector3(1, 0, 0), new Vector3(0, 1, 0), new Vector3(0, 0, 1) }; Vector3[] points1 = { new Vector3(1, 0, 0), new Vector3(0, 1, 0), new Vector3(0, 0, 1), new Vector3(0,0,-1), new Vector3(-1,-1,0) }; colShape0 = new ConvexHullShape(points0); colShape1 = new ConvexHullShape(points1); CollisionShapes.Add(colShape0); CollisionShapes.Add(colShape1); /*body2 =*/ LocalCreateRigidBody(0, body2Position, colShape1); rotBody = LocalCreateRigidBody(0, rotBodyPosition, colShape0); rotBody.CollisionFlags |= CollisionFlags.KinematicObject; rotBody.ActivationState = ActivationState.DisableDeactivation; }
protected override void OnInitializePhysics() { // collision configuration contains default setup for memory, collision setup CollisionConf = new DefaultCollisionConfiguration(); Dispatcher = new CollisionDispatcher(CollisionConf); Broadphase = new DbvtBroadphase(); Solver = new SequentialImpulseConstraintSolver(); World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, Solver, CollisionConf); World.Gravity = Freelook.Up * -10.0f; BspLoader bspLoader = new BspLoader(); string[] args = Environment.GetCommandLineArgs(); if (args.Length == 1) { bspLoader.LoadBspFile("data/BspDemo.bsp"); } else { bspLoader.LoadBspFile(args[1]); } BspConverter bsp2Bullet = new BspToBulletConverter(this); bsp2Bullet.ConvertBsp(bspLoader, 0.1f); }
protected override void OnInitializePhysics() { // collision configuration contains default setup for memory, collision setup CollisionConf = new DefaultCollisionConfiguration(); Dispatcher = new CollisionDispatcher(CollisionConf); Broadphase = new AxisSweep3(new Vector3(-10000, -10000, -10000), new Vector3(10000, 10000, 10000)); Solver = new SequentialImpulseConstraintSolver(); World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, Solver, CollisionConf); World.Gravity = new Vector3(0, -10, 0); //World.DispatchInfo.UseConvexConservativeDistanceUtil = true; //World.DispatchInfo.ConvexConservativeDistanceThreshold = 0.01f; // Setup a big ground box CollisionShape groundShape = new BoxShape(100, 10, 100); CollisionShapes.Add(groundShape); Matrix groundTransform = Matrix.Translation(0, -10, 0); RigidBody ground = LocalCreateRigidBody(0, groundTransform, groundShape); ground.UserObject = "Ground"; // Spawn one ragdoll SpawnRagdoll(new Vector3(1, 0.5f, 0)); SpawnRagdoll(new Vector3(-1, 0.5f, 0)); }
protected override void OnInitializePhysics() { // collision configuration contains default setup for memory, collision setup CollisionConf = new DefaultCollisionConfiguration(); Dispatcher = new CollisionDispatcher(CollisionConf); Broadphase = new DbvtBroadphase(); World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, null, CollisionConf); World.Gravity = new Vector3(0, -10, 0); // create the ground BoxShape groundShape = new BoxShape(50, 1, 50); //groundShape.InitializePolyhedralFeatures(); //CollisionShape groundShape = new StaticPlaneShape(new Vector3(0,1,0), 50); CollisionShapes.Add(groundShape); CollisionObject ground = LocalCreateRigidBody(0, Matrix.Identity, groundShape); ground.UserObject = "Ground"; // create a few dynamic rigidbodies const float mass = 1.0f; BoxShape colShape = new BoxShape(1); CollisionShapes.Add(colShape); Vector3 localInertia = colShape.CalculateLocalInertia(mass); const float start_x = StartPosX - ArraySizeX / 2; const float start_y = StartPosY; const float start_z = StartPosZ - ArraySizeZ / 2; int k, i, j; for (k = 0; k < ArraySizeY; k++) { for (i = 0; i < ArraySizeX; i++) { for (j = 0; j < ArraySizeZ; j++) { Matrix startTransform = Matrix.Translation( 2 * i + start_x, 2 * k + start_y, 2 * j + start_z ); // using motionstate is recommended, it provides interpolation capabilities // and only synchronizes 'active' objects DefaultMotionState myMotionState = new DefaultMotionState(startTransform); RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(mass, myMotionState, colShape, localInertia); RigidBody body = new RigidBody(rbInfo); rbInfo.Dispose(); // make it drop from a height body.Translate(new Vector3(0, 20, 0)); World.AddRigidBody(body); } } } }
protected override void OnInitializePhysics() { // collision configuration contains default setup for memory, collision setup CollisionConf = new DefaultCollisionConfiguration(); Dispatcher = new CollisionDispatcher(CollisionConf); Vector3 worldAabbMin = new Vector3(-10000, -10000, -10000); Vector3 worldAabbMax = new Vector3(10000, 10000, 10000); Broadphase = new AxisSweep3(worldAabbMin, worldAabbMax); Solver = new SequentialImpulseConstraintSolver(); World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, Solver, CollisionConf); World.Gravity = new Vector3(0, -10, 0); World.SetInternalTickCallback(MotorPreTickCallback, this, true); // create the ground CollisionShape groundShape = new BoxShape(200, 10, 200); CollisionShapes.Add(groundShape); CollisionObject ground = LocalCreateRigidBody(0, Matrix.Translation(0, -10, 0), groundShape); ground.UserObject = "Ground"; fCyclePeriod = 2000.0f; fMuscleStrength = 0.5f; m_Time = 0; SpawnTestRig(new Vector3(1, 0.5f, 0), false); SpawnTestRig(new Vector3(-2, 0.5f, 0), true); }
protected override void OnInitializePhysics() { BoxShape boxA = new BoxShape(new Vector3(1, 1, 1)); boxA.Margin = 0; BoxShape boxB = new BoxShape(new Vector3(0.5f, 0.5f, 0.5f)); boxB.Margin = 0; objects[0] = new CollisionObject(); objects[1] = new CollisionObject(); objects[0].CollisionShape = boxA; objects[1].CollisionShape = boxB; // collision configuration contains default setup for memory, collision setup CollisionConf = new DefaultCollisionConfiguration(); Dispatcher = new CollisionDispatcher(CollisionConf); Broadphase = new AxisSweep3(new Vector3(-1000, -1000, -1000), new Vector3(1000, 1000, 1000)); World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, null, CollisionConf); World.Gravity = new Vector3(0, -10, 0); IsDebugDrawEnabled = true; //World.AddCollisionObject(objects[0]); World.AddCollisionObject(objects[1]); Quaternion rotA = new Quaternion(0.739f, -0.204f, 0.587f, 0.257f); rotA.Normalize(); objects[0].WorldTransform = Matrix.RotationQuaternion(rotA) * Matrix.Translation(0, 3, 0); objects[1].WorldTransform = Matrix.Translation(0, 4.248f, 0); }
/* void MyContactCallback(object sender, ContactAddedEventArgs e) { if (e.CollisionObject0Wrapper.CollisionObject.CollisionShape.ShapeType == BroadphaseNativeType.CompoundShape) { CompoundShape compound = e.CollisionObject0Wrapper.CollisionObject.CollisionShape as CompoundShape; CollisionShape childShape = compound.GetChildShape(e.Index0); } if (e.CollisionObject1Wrapper.CollisionObject.CollisionShape.ShapeType == BroadphaseNativeType.CompoundShape) { CompoundShape compound = e.CollisionObject1Wrapper.CollisionObject.CollisionShape as CompoundShape; CollisionShape childShape = compound.GetChildShape(e.Index1); } e.IsContactModified = true; } */ public void SetupEmptyDynamicsWorld() { // collision configuration contains default setup for memory, collision setup CollisionConf = new DefaultCollisionConfiguration(); Dispatcher = new CollisionDispatcher(CollisionConf); CompoundCollisionAlgorithm.CompoundChildShapePairCallback = MyCompoundChildShapeCallback; convexDecompositionObjectOffset = new Vector3(10, 0, 0); Broadphase = new AxisSweep3(new Vector3(-10000, -10000, -10000), new Vector3(10000, 10000, 10000)); //Broadphase = new SimpleBroadphase(); Solver = new SequentialImpulseConstraintSolver(); World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, Solver, CollisionConf); // create the ground CollisionShape groundShape = new BoxShape(30, 2, 30); CollisionShapes.Add(groundShape); CollisionObject ground = LocalCreateRigidBody(0, Matrix.Translation(0, -4.5f, 0), groundShape); ground.UserObject = "Ground"; // create a few dynamic rigidbodies float mass = 1.0f; CollisionShape colShape = new BoxShape(1); CollisionShapes.Add(colShape); Vector3 localInertia = colShape.CalculateLocalInertia(mass); }
public void Setup(Vector3Df gravity) { bulletCollisionConfiguration = new DefaultCollisionConfiguration(); bulletCollisionDispatcher = new CollisionDispatcher(bulletCollisionConfiguration); bulletBroadphase = new DbvtBroadphase(); bulletWorld = new DiscreteDynamicsWorld(bulletCollisionDispatcher, bulletBroadphase, null, bulletCollisionConfiguration); bulletWorld.Gravity = new Vector3(gravity.X, gravity.Y, gravity.Z); }
public Physics() { CollisionConfiguration config = new DefaultCollisionConfiguration(); Dispatcher = new CollisionDispatcher(config); World = new DiscreteDynamicsWorld(Dispatcher, new DbvtBroadphase(), null, config); World.Gravity = new Vector3(0.0f, -9.81f, 0.0f); Props = new List<Prop>(); }
void SetupEmptyDynamicsWorld() { CollisionConf = new DefaultCollisionConfiguration(); Dispatcher = new CollisionDispatcher(CollisionConf); Broadphase = new DbvtBroadphase(); Solver = new SequentialImpulseConstraintSolver(); World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, Solver, CollisionConf); World.Gravity = new Vector3(0, -10, 0); }
/// <summary> /// コンストラクター /// </summary> public PhysicsSimulator() { var cc = new DefaultCollisionConfiguration (); this.dispatcher = new CollisionDispatcher (cc); this.broadphase = new DbvtBroadphase (); this.solver = new SequentialImpulseConstraintSolver (); this.wld = new DiscreteDynamicsWorld (dispatcher, broadphase, solver, cc); this.wld.Gravity = new BulletSharp.Vector3 (0, -9.8f, 0); // 重力は-Y方向 }
public override void Run() { var conf = new DefaultCollisionConfiguration(); var dispatcher = new CollisionDispatcher(conf); var broadphase = new AxisSweep3(new Vector3(-1000, -1000, -1000), new Vector3(1000, 1000, 1000)); world = new DiscreteDynamicsWorld(dispatcher, broadphase, null, conf); var indexVertexArray = new TriangleIndexVertexArray(TorusMesh.Indices, TorusMesh.Vertices); foreach (var indexedMesh in indexVertexArray.IndexedMeshArray) { indexedMesh.ToString(); } AddToDisposeQueue(indexVertexArray); var gImpactMesh = new GImpactMeshShape(indexVertexArray); Vector3 aabbMin, aabbMax; gImpactMesh.GetAabb(Matrix.Identity, out aabbMin, out aabbMax); CreateBody(1.0f, gImpactMesh, Vector3.Zero); AddToDisposeQueue(gImpactMesh); gImpactMesh = null; var triangleMesh = new BvhTriangleMeshShape(indexVertexArray, true); triangleMesh.CalculateLocalInertia(1.0f); triangleMesh.GetAabb(Matrix.Identity, out aabbMin, out aabbMax); CreateBody(1.0f, triangleMesh, Vector3.Zero); AddToDisposeQueue(triangleMesh); triangleMesh = null; indexVertexArray = null; AddToDisposeQueue(conf); AddToDisposeQueue(dispatcher); AddToDisposeQueue(broadphase); AddToDisposeQueue(world); //conf.Dispose(); conf = null; //dispatcher.Dispose(); dispatcher = null; //broadphase.Dispose(); broadphase = null; for (int i = 0; i < 600; i++) { world.StepSimulation(1.0f / 60.0f); } world.Dispose(); world = null; ForceGC(); TestWeakRefs(); ClearRefs(); }
/// <summary> /// コンストラクター /// </summary> public CollisionAnalyzer() { var cc = new DefaultCollisionConfiguration (); dispatcher = new CollisionDispatcher (cc); broadphase = new DbvtBroadphase (); broadphase.OverlappingPairCache.SetInternalGhostPairCallback (new GhostPairCallback ()); // solver = new SequentialImpulseConstraintSolver (); this.wld = new DiscreteDynamicsWorld (dispatcher, broadphase, null, cc); this.prevContacts = new List<OverlappingPair> (); this.currContacts = new List<OverlappingPair> (); }
public void SetUp() { conf = new DefaultCollisionConfiguration(); dispatcher = new CollisionDispatcher(conf); broadphase = new AxisSweep3(new Vector3(-1000, -1000, -1000), new Vector3(1000, 1000, 1000)); world = new DiscreteDynamicsWorld(dispatcher, broadphase, null, conf); action = new Action(); world.AddAction(action); world.AddAction(action); world.RemoveAction(action); world.RemoveAction(action); world.AddAction(action); }
/* void MyContactCallback(object sender, ContactAddedEventArgs e) { if (e.CollisionObject0Wrapper.CollisionObject.CollisionShape.ShapeType == BroadphaseNativeType.CompoundShape) { CompoundShape compound = e.CollisionObject0Wrapper.CollisionObject.CollisionShape as CompoundShape; CollisionShape childShape = compound.GetChildShape(e.Index0); } if (e.CollisionObject1Wrapper.CollisionObject.CollisionShape.ShapeType == BroadphaseNativeType.CompoundShape) { CompoundShape compound = e.CollisionObject1Wrapper.CollisionObject.CollisionShape as CompoundShape; CollisionShape childShape = compound.GetChildShape(e.Index1); } e.IsContactModified = true; } */ public void SetupEmptyDynamicsWorld() { // collision configuration contains default setup for memory, collision setup CollisionConf = new DefaultCollisionConfiguration(); Dispatcher = new CollisionDispatcher(CollisionConf); Broadphase = new AxisSweep3(new Vector3(-10000, -10000, -10000), new Vector3(10000, 10000, 10000)); Solver = new SequentialImpulseConstraintSolver(); World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, Solver, CollisionConf); // create the ground CollisionShape groundShape = new BoxShape(30, 2, 30); CollisionShapes.Add(groundShape); CollisionObject ground = LocalCreateRigidBody(0, Matrix.Translation(0, -4.5f, 0), groundShape); ground.UserObject = "Ground"; }
static void Main(string[] args) { var config = new BulletSharp.DefaultCollisionConfiguration(); var dispatcher = new BulletSharp.CollisionDispatcher(config); var pair = new BulletSharp.DbvtBroadphase(); var world = new BulletSharp.CollisionWorld(dispatcher, pair, config); var players = new Dictionary <Guid, RigidBody>(); var ci = new RigidBodyConstructionInfo(1, new DefaultMotionState(), new SphereShape(.513037f)); var rb = new RigidBody(ci); rb.Gravity = Vector3.Zero; rb.Translate(new Vector3(0f, 1.5f, 0f)); world.AddCollisionObject(rb); }
public override void Run() { var conf = new DefaultCollisionConfiguration(); // Test CollisionConfiguration methods var pool = conf.CollisionAlgorithmPool; AddToDisposeQueue(pool); pool = conf.PersistentManifoldPool; AddToDisposeQueue(pool); pool = null; var simplexSolver = conf.SimplexSolver; //var simplexResult = simplexSolver.CachedBC; //AddToDisposeQueue(simplexResult); //simplexResult = null; AddToDisposeQueue(simplexSolver); simplexSolver = null; var createFunc = conf.GetCollisionAlgorithmCreateFunc(BroadphaseNativeType.BoxShape, BroadphaseNativeType.BoxShape); AddToDisposeQueue(createFunc); createFunc = conf.GetCollisionAlgorithmCreateFunc(BroadphaseNativeType.SphereShape, BroadphaseNativeType.SphereShape); AddToDisposeQueue(createFunc); createFunc = conf.GetCollisionAlgorithmCreateFunc(BroadphaseNativeType.SphereShape, BroadphaseNativeType.TriangleShape); AddToDisposeQueue(createFunc); createFunc = conf.GetCollisionAlgorithmCreateFunc(BroadphaseNativeType.TriangleShape, BroadphaseNativeType.SphereShape); AddToDisposeQueue(createFunc); createFunc = conf.GetCollisionAlgorithmCreateFunc(BroadphaseNativeType.BoxShape, BroadphaseNativeType.StaticPlaneShape); AddToDisposeQueue(createFunc); createFunc = conf.GetCollisionAlgorithmCreateFunc(BroadphaseNativeType.StaticPlaneShape, BroadphaseNativeType.BoxShape); AddToDisposeQueue(createFunc); createFunc = conf.GetCollisionAlgorithmCreateFunc(BroadphaseNativeType.CylinderShape, BroadphaseNativeType.CylinderShape); AddToDisposeQueue(createFunc); createFunc = conf.GetCollisionAlgorithmCreateFunc(BroadphaseNativeType.CylinderShape, BroadphaseNativeType.TerrainShape); AddToDisposeQueue(createFunc); createFunc = conf.GetCollisionAlgorithmCreateFunc(BroadphaseNativeType.TerrainShape, BroadphaseNativeType.CylinderShape); AddToDisposeQueue(createFunc); createFunc = conf.GetCollisionAlgorithmCreateFunc(BroadphaseNativeType.CompoundShape, BroadphaseNativeType.CompoundShape); AddToDisposeQueue(createFunc); createFunc = conf.GetCollisionAlgorithmCreateFunc(BroadphaseNativeType.CompoundShape, BroadphaseNativeType.BoxShape); AddToDisposeQueue(createFunc); createFunc = conf.GetCollisionAlgorithmCreateFunc(BroadphaseNativeType.BoxShape, BroadphaseNativeType.CompoundShape); AddToDisposeQueue(createFunc); createFunc = null; conf = null; ForceGC(); TestWeakRefs(); ClearRefs(); }
public Physics() { CollisionConfiguration collisionConf = new DefaultCollisionConfiguration(); CollisionDispatcher dispatcher = new CollisionDispatcher(collisionConf); World = new DiscreteDynamicsWorld(dispatcher, new DbvtBroadphase(), null, collisionConf); World.Gravity = new Vector3(0, -10, 0); // create the ground CollisionShape groundShape = new BoxShape(50, 1, 50); CollisionObject ground = LocalCreateRigidBody(0, Matrix.Identity, groundShape); ground.UserObject = "Ground"; // create a box CollisionShape boxShape = new BoxShape(1); LocalCreateRigidBody(1.0f, Matrix.Translation(0, 20, 0), boxShape); }
public void SetUp() { conf = new DefaultCollisionConfiguration(); dispatcher = new CollisionDispatcher(conf); broadphase = new AxisSweep3(new Vector3(-1000, -1000, -1000), new Vector3(1000, 1000, 1000)); world = new DiscreteDynamicsWorld(dispatcher, broadphase, null, conf); indexVertexArray = new TriangleIndexVertexArray(TorusMesh.Indices, TorusMesh.Vertices); gImpactMeshShape = new GImpactMeshShape(indexVertexArray); triangleMeshShape = new BvhTriangleMeshShape(indexVertexArray, true); triangleMeshShape.CalculateLocalInertia(1.0f); gImpactMesh = CreateBody(1.0f, gImpactMeshShape, Vector3.Zero); triangleMesh = CreateBody(1.0f, triangleMeshShape, Vector3.Zero); }
public Physics() { // collision configuration contains default setup for memory, collision setup CollisionConf = new DefaultCollisionConfiguration(); Dispatcher = new CollisionDispatcher(CollisionConf); Broadphase = new DbvtBroadphase(); Solver = new SequentialImpulseConstraintSolver(); World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, Solver, CollisionConf); World.Gravity = new Vector3(0, 0, -10); BspLoader bspLoader = new BspLoader(); bspLoader.LoadBspFile("BspDemo.bsp"); BspConverter bsp2Bullet = new BspToBulletConverter(this); bsp2Bullet.ConvertBsp(bspLoader, 0.1f); }
protected override void OnInitializePhysics() { // collision configuration contains default setup for memory, collision setup CollisionConf = new DefaultCollisionConfiguration(); Dispatcher = new CollisionDispatcher(CollisionConf); Broadphase = new DbvtBroadphase(); Solver = new SequentialImpulseConstraintSolver(); World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, Solver, CollisionConf); World.Gravity = new Vector3(0, -10, 0); importer = new BulletXmlWorldImporter(World); if (!importer.LoadFile("data\\bullet_basic.xml")) { //throw new FileNotFoundException(); } }
static DefaultRigidBodyWorld() { // Broadphase algorithms are responsible for calculating bounding // boxes. We should probably use an AABB Tree (DbvtBroadphase) // because they are generally good for worlds with lots of motion. // Sweep and Prune Broadphases are best when most of the world is // static. Broadphase = new DbvtBroadphase(); CollisionConfiguration = new DefaultCollisionConfiguration(); Dispatcher = new CollisionDispatcher(CollisionConfiguration); Solver = new SequentialImpulseConstraintSolver(); DynamicsWorld = new DiscreteDynamicsWorld(Dispatcher, Broadphase, Solver, CollisionConfiguration); DynamicsWorld.Gravity = new Vector3(0F, 0F, -9.81F); Ground = PhysicsHelpers.MakePlane(new Vector3(0, 0, 1), 0); DynamicsWorld.AddRigidBody(Ground); }
public void SetUp() { conf = new DefaultCollisionConfiguration(); dispatcher = new CollisionDispatcher(conf); broadphase = new AxisSweep3(new Vector3(-1000, -1000, -1000), new Vector3(1000, 1000, 1000)); world = new DiscreteDynamicsWorld(dispatcher, broadphase, null, conf); broadphase.OverlappingPairUserCallback = new AxisSweepUserCallback(); boxShape = new BoxShape(1); body1 = CreateBody(10.0f, new SphereShape(1.0f), new Vector3(2, 2, 0)); body2 = CreateBody(1.0f, new SphereShape(1.0f), new Vector3(0, 2, 0)); ghostObject = new PairCachingGhostObject(); ghostObject.WorldTransform = Matrix.Translation(-1, 2, 0); ghostObject.CollisionShape = boxShape; broadphase.OverlappingPairCache.SetInternalGhostPairCallback(new GhostPairCallback()); }
void Awake () { if (BtWorld.main == null || gameObject.tag.Equals ("main")) BtWorld.main = this; // TODO: expose in editor? broadphase = new BulletSharp.DbvtBroadphase (); collisionConfiguration = new BulletSharp.DefaultCollisionConfiguration (); dispatcher = new BulletSharp.CollisionDispatcher (collisionConfiguration); solver = new BulletSharp.SequentialImpulseConstraintSolver (); world = new BulletSharp.DiscreteDynamicsWorld (dispatcher, broadphase, solver, collisionConfiguration); world.Gravity = new BulletSharp.Vector3 (gravity.x, gravity.y, gravity.z); world.DebugDrawer = new UnityDebugDrawer (); world.DebugDrawer.DebugMode = BulletSharp.DebugDrawModes.None; foreach (BulletSharp.DebugDrawModes drawMode in debugDrawModes) { world.DebugDrawer.DebugMode |= drawMode; } }
protected override void OnInitializePhysics() { // collision configuration contains default setup for memory, collision setup CollisionConf = new DefaultCollisionConfiguration(); Dispatcher = new CollisionDispatcher(CollisionConf); Broadphase = new AxisSweep3(new Vector3(-1000, -1000, -1000), new Vector3(1000, 1000, 1000)); Solver = new SequentialImpulseConstraintSolver(); World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, Solver, CollisionConf); World.DispatchInfo.AllowedCcdPenetration = 0.0001f; //World.Gravity = Freelook.Up * -10.0f; Matrix startTransform = Matrix.Translation(10.210098f, -1.6433364f, 16.453260f); ghostObject = new PairCachingGhostObject(); ghostObject.WorldTransform = startTransform; Broadphase.OverlappingPairCache.SetInternalGhostPairCallback(new GhostPairCallback()); const float characterHeight = 1.75f; const float characterWidth = 1.75f; ConvexShape capsule = new CapsuleShape(characterWidth, characterHeight); ghostObject.CollisionShape = capsule; ghostObject.CollisionFlags = CollisionFlags.CharacterObject; const float stepHeight = 0.35f; character = new KinematicCharacterController(ghostObject, capsule, stepHeight); BspLoader bspLoader = new BspLoader(); bspLoader.LoadBspFile("data/BspDemo.bsp"); BspConverter bsp2Bullet = new BspToBulletConverter(this); bsp2Bullet.ConvertBsp(bspLoader, 0.1f); World.AddCollisionObject(ghostObject, CollisionFilterGroups.CharacterFilter, CollisionFilterGroups.StaticFilter | CollisionFilterGroups.DefaultFilter); World.AddAction(character); convexResultCallback = new ClosestConvexResultCallback(); convexResultCallback.CollisionFilterMask = (short)CollisionFilterGroups.StaticFilter; cameraSphere = new SphereShape(0.2f); }
public static void TestGCCollection() { var conf = new DefaultCollisionConfiguration(); var dispatcher = new CollisionDispatcher(conf); var broadphase = new DbvtBroadphase(); var world = new DiscreteDynamicsWorld(dispatcher, broadphase, null, conf); world.Gravity = new Vector3(0, -10, 0); var conf_wr = new WeakReference(conf); var dispatcher_wr = new WeakReference(dispatcher); var broadphase_wr = new WeakReference(broadphase); var world_wr = new WeakReference(broadphase); //conf.Dispose(); conf = null; dispatcher.OnDisposing += onDisposing; dispatcher.OnDisposed += onDisposed; //dispatcher.Dispose(); dispatcher = null; broadphase.OnDisposing += onDisposing; broadphase.OnDisposed += onDisposed; //broadphase.Dispose(); broadphase = null; world.OnDisposing += onDisposing; world.OnDisposed += onDisposed; world.SetInternalTickCallback(WorldPreTickCallback); world.StepSimulation(1.0f/60.0f); //world.SetInternalTickCallback(null); //world.Dispose(); world = null; GC.Collect(); GC.WaitForPendingFinalizers(); TestWeakRef("CollisionConfiguration", conf_wr); TestWeakRef("CollisionDispatcher", dispatcher_wr); TestWeakRef("DbvtBroadphase", broadphase_wr); TestWeakRef("DiscreteDynamicsWorld", world_wr); }
static void TestAxisSweepOverlapCallback() { var conf = new DefaultCollisionConfiguration(); var dispatcher = new CollisionDispatcher(conf); var broadphase = new AxisSweep3(new Vector3(-1000, -1000, -1000), new Vector3(1000, 1000, 1000)); world = new DiscreteDynamicsWorld(dispatcher, broadphase, null, conf); //broadphase.OverlappingPairUserCallback = new AxisSweepUserCallback(); //AddToDisposeQueue(broadphase.OverlappingPairUserCallback); CreateBody(10.0f, new SphereShape(1.0f), new Vector3(2, 2, 0)); CreateBody(1.0f, new SphereShape(1.0f), new Vector3(0, 2, 0)); CustomBroadphaseAabbCallback aabbCallback = new CustomBroadphaseAabbCallback(); broadphase.AabbTest(new Vector3(-1000, -1000, -1000), new Vector3(1000, 1000, 1000), aabbCallback); AddToDisposeQueue(aabbCallback); aabbCallback = null; // FIXME: RayTest crashes for DbvtBroadphase CustomBroadphaseRayTestCallback rayCallback = new CustomBroadphaseRayTestCallback(); //broadphase.RayTest(new Vector3(0, 2, 0), new Vector3(2, 2, 0), rayCallback); AddToDisposeQueue(rayCallback); rayCallback = null; broadphase = null; world.StepSimulation(1.0f / 60.0f); world.Dispose(); world = null; GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); GC.WaitForPendingFinalizers(); TestWeakRefs(); disposeQueue.Clear(); }
protected override void OnInitializePhysics() { int i; shootBoxInitialSpeed = 4000; // collision configuration contains default setup for memory, collision setup CollisionConf = new DefaultCollisionConfiguration(); Dispatcher = new CollisionDispatcher(CollisionConf); //Dispatcher.RegisterCollisionCreateFunc(BroadphaseNativeType.BoxShape, BroadphaseNativeType.BoxShape, // CollisionConf.GetCollisionAlgorithmCreateFunc(BroadphaseNativeType.ConvexShape, BroadphaseNativeType.ConvexShape)); Broadphase = new DbvtBroadphase(); // the default constraint solver. Solver = new SequentialImpulseConstraintSolver(); World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, Solver, CollisionConf); World.SolverInfo.SolverMode |= SolverModes.Use2FrictionDirections | SolverModes.RandomizeOrder; //World.SolverInfo.SplitImpulse = 0; World.SolverInfo.NumIterations = 20; World.DispatchInfo.UseContinuous = ccdMode; World.Gravity = new Vector3(0, -10, 0); BoxShape ground = new BoxShape(200, 1, 200); ground.InitializePolyhedralFeatures(); CollisionShapes.Add(ground); RigidBody body = LocalCreateRigidBody(0, Matrix.Identity, ground); body.Friction = 0.5f; //body.RollingFriction = 0.3f; body.UserObject = "Ground"; //CollisionShape shape = new CylinderShape(CubeHalfExtents, CubeHalfExtents, CubeHalfExtents); CollisionShape shape = new BoxShape(CubeHalfExtents, CubeHalfExtents, CubeHalfExtents); CollisionShapes.Add(shape); const int numObjects = 120; for (i = 0; i < numObjects; i++) { //stack them const int colsize = 10; int row = (int)((i * CubeHalfExtents * 2) / (colsize * 2 * CubeHalfExtents)); int row2 = row; int col = (i) % (colsize) - colsize / 2; if (col > 3) { col = 11; row2 |= 1; } Matrix trans = Matrix.Translation(col * 2 * CubeHalfExtents + (row2 % 2) * CubeHalfExtents, row * 2 * CubeHalfExtents + CubeHalfExtents + ExtraHeight, 0); body = LocalCreateRigidBody(1, trans, shape); body.SetAnisotropicFriction(shape.AnisotropicRollingFrictionDirection, AnisotropicFrictionFlags.AnisotropicRollingFriction); body.Friction = 0.5f; //body.RollingFriction = 0.3f; if (ccdMode) { body.CcdMotionThreshold = 1e-7f; body.CcdSweptSphereRadius = 0.9f * CubeHalfExtents; } } }
protected override void OnInitializePhysics() { // collision configuration contains default setup for memory, collision setup CollisionConf = new DefaultCollisionConfiguration(); Dispatcher = new CollisionDispatcher(CollisionConf); Vector3 worldMin = new Vector3(-1000, -1000, -1000); Vector3 worldMax = new Vector3(1000, 1000, 1000); Broadphase = new AxisSweep3(worldMin, worldMax); Solver = new SequentialImpulseConstraintSolver(); World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, Solver, CollisionConf); World.SolverInfo.SplitImpulse = 1; World.Gravity = new Vector3(0, -10, 0); IsDebugDrawEnabled = true; CollisionShape colShape = new BoxShape(1); CollisionShapes.Add(colShape); for (int j = 0; j < NumDynamicBoxesX; j++) { for (int i = 0; i < NumDynamicBoxesY; i++) { //CollisionShape colShape = new CapsuleShape(0.5f,2.0f);//boxShape = new SphereShape(1.0f); Matrix startTransform = Matrix.Translation(5 * (i - NumDynamicBoxesX / 2), 10, 5 * (j - NumDynamicBoxesY / 2)); LocalCreateRigidBody(1.0f, startTransform, colShape); } } SetVertexPositions(WaveHeight, 0.0f); const bool useQuantizedAabbCompression = true; groundShape = new BvhTriangleMeshShape(indexVertexArrays, useQuantizedAabbCompression); CollisionShapes.Add(groundShape); staticBody = LocalCreateRigidBody(0.0f, Matrix.Identity, groundShape); staticBody.CollisionFlags |= CollisionFlags.StaticObject; staticBody.UserObject = "Ground"; }