static Collisions() { collisionConfig = new DefaultCollisionConfiguration(); collisionDispatcher = new CollisionDispatcher(collisionConfig); broadphase = new DbvtBroadphase(); colWorld = new DiscreteDynamicsWorld(collisionDispatcher, broadphase, null, collisionConfig); colWorld.Gravity = new BulletSharp.Math.Vector3(0, 0, 0); HardCollisionAction = null; SoftCollisionAction = null; //Prepare simulation parameters, try 25 steps to see the ball mid air // var simulationIterations = 125; // var simulationTimestep = 1f / 60f; // //Step through the desired amount of simulation ticks // for (var i = 0; i < simulationIterations; i++) // { // Update(simulationTimestep); // } balls = new List <BallInfo>(); boxes = new List <BoxInfo>(); }
protected virtual void _InitializePhysicsWorld() { _isDisposed = false; CreatePhysicsWorld(out m_world, out CollisionConf, out Dispatcher, out Broadphase, out constraintSolver, out softBodyWorldInfo); if (m_world is DiscreteDynamicsWorld) { _ddWorld = (DiscreteDynamicsWorld)m_world; } //Add a BPhysicsWorldLateHelper component to call FixedUpdate PhysicsWorldHelper = GetComponent <BasePhysicsWorldHelper>(); if (PhysicsWorldHelper == null) { if (helperType == HelperType.LateUpdate) { PhysicsWorldHelper = gameObject.AddComponent <BPhysicsWorldLateHelper>(); } if (helperType == HelperType.Thread) { PhysicsWorldHelper = gameObject.AddComponent <BThreadedWorldHelper>(); } } PhysicsWorldHelper.m_world = world; PhysicsWorldHelper.m_ddWorld = _ddWorld; PhysicsWorldHelper.PhysicsWorld = this; PhysicsWorldHelper.m__frameCount = 0; }
public void Initialize() { if (World != null) // check if we are already initialized { return; } enabled = true; CollisionConf = new DefaultCollisionConfiguration(); Dispatcher = new CollisionDispatcher(CollisionConf); // Select Brodphase Broadphase = new DbvtBroadphase(); //Broadphase = new AxisSweep3(new Vector3(-1000.0f, -1000.0f, -30.0f), new Vector3(2000.0f, 3000.0f, 1000.0f), 32766); DantzigSolver dtsolver = new DantzigSolver(); Solver = new MlcpSolver(dtsolver); //Create a collision world of your choice, for now pass null as the constraint solver World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, Solver, CollisionConf); var si = World.SolverInfo; si.NumIterations = 2; si.TimeStep = 0.001f; World.SetGravity(ref _gravityVec); ghostPairCallback = new GhostPairCallback(); World.PairCache.SetInternalGhostPairCallback(ghostPairCallback); }
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); }
public void Init(string MediaDir) { //Creamos el mundo fisico por defecto. collisionConfiguration = new DefaultCollisionConfiguration(); dispatcher = new CollisionDispatcher(collisionConfiguration); GImpactCollisionAlgorithm.RegisterAlgorithm(dispatcher); constraintSolver = new SequentialImpulseConstraintSolver(); overlappingPairCache = new DbvtBroadphase(); //AxisSweep3(new BsVector3(-5000f, -5000f, -5000f), new BsVector3(5000f, 5000f, 5000f), 8192); dynamicsWorld = new DiscreteDynamicsWorld(dispatcher, overlappingPairCache, constraintSolver, collisionConfiguration); dynamicsWorld.Gravity = new TGCVector3(0, -100f, 0).ToBulletVector3(); //Creamos el terreno var meshRigidBody = BulletRigidBodyFactory.Instance.CreateSurfaceFromHeighMap(triangleDataVB); dynamicsWorld.AddRigidBody(meshRigidBody); //Creamos la esfera del dragon dragonBall = BulletRigidBodyFactory.Instance.CreateBall(30f, 0.75f, new TGCVector3(100f, 500f, 100f)); dragonBall.SetDamping(0.1f, 0.5f); dragonBall.Restitution = 1f; dragonBall.Friction = 1; dynamicsWorld.AddRigidBody(dragonBall); var textureDragonBall = TgcTexture.createTexture(D3DDevice.Instance.Device, MediaDir + @"Texturas\dragonball.jpg"); sphereMesh = new TGCSphere(1, textureDragonBall, TGCVector3.Empty); sphereMesh.updateValues(); director = new TGCVector3(1, 0, 0); }
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); CreateGround(); Vector3[] rotatingPoints = { new Vector3(1, 0, 0), new Vector3(0, 1, 0), new Vector3(0, 0, 1) }; _rotatingShape = new ConvexHullShape(rotatingPoints); _rotatingBody = LocalCreateRigidBody(0, _rotBodyPosition, _rotatingShape); _rotatingBody.CollisionFlags |= CollisionFlags.KinematicObject; _rotatingBody.ActivationState = ActivationState.DisableDeactivation; Vector3[] staticPoints = { 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) }; _staticShape = new ConvexHullShape(staticPoints); _staticBody = LocalCreateRigidBody(0, _staticBodyPosition, _staticShape); }
public ConstraintDemoSimulation() { CollisionConfiguration = new DefaultCollisionConfiguration(); Dispatcher = new CollisionDispatcher(CollisionConfiguration); Broadphase = new DbvtBroadphase(); World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, null, CollisionConfiguration); CreateGround(); _cubeShape = new BoxShape(CubeHalfExtent); CreateGears(); CreateHingedBoxes(); CreateMotorHinge(); CreateMotorHinge2(); CreateSlider(); CreateD6Slider(); CreateDoor(); CreateGeneric6DofConstraint(); CreateConeTwist(); CreateUniversalConstraint(); CreateGeneric6DofSpringConstraint(); CreateHinge(); CreateHinge2(); }
public void Init(TgcSimpleTerrain terrain) { collisionConfiguration = new DefaultCollisionConfiguration(); dispatcher = new CollisionDispatcher(collisionConfiguration); GImpactCollisionAlgorithm.RegisterAlgorithm(dispatcher); constraintSolver = new SequentialImpulseConstraintSolver(); broadphaseInterface = new DbvtBroadphase(); dynamicsWorld = new DiscreteDynamicsWorld(dispatcher, broadphaseInterface, constraintSolver, collisionConfiguration); dynamicsWorld.Gravity = gravity; var ballShape = new SphereShape(50); var ballTransform = TGCMatrix.Identity; ballTransform.Origin = initialPosition; var ballMotionState = new DefaultMotionState(ballTransform.ToBsMatrix); var ballInertia = ballShape.CalculateLocalInertia(1f); var ballInfo = new RigidBodyConstructionInfo(1, ballMotionState, ballShape, ballInertia); RigidCamera = new RigidBody(ballInfo); RigidCamera.SetDamping(0.9f, 0.9f); //esto es para que no le afecte la gravedad al inicio de la partida //RigidCamera.ActivationState = ActivationState.IslandSleeping; dynamicsWorld.AddRigidBody(RigidCamera); var heighmapRigid = BulletRigidBodyFactory.Instance.CreateSurfaceFromHeighMap(terrain.getData()); dynamicsWorld.AddRigidBody(heighmapRigid); }
public PhysicsEngine() { //CreateSchedulers(); //NextTaskScheduler(); using (var collisionConfigurationInfo = new DefaultCollisionConstructionInfo { DefaultMaxPersistentManifoldPoolSize = 800, DefaultMaxCollisionAlgorithmPoolSize = 800 }) { collisionConf = new DefaultCollisionConfiguration(collisionConfigurationInfo); }; dispatcher = new CollisionDispatcher(collisionConf); broadphase = new DbvtBroadphase(); var solver = new SequentialImpulseConstraintSolver(); //var Solver = new NncgConstraintSolver(); //DiscreteDynamicsWorldMultiThreaded(dispatcher, broadphase, Solver, collisionConf); World = new DiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConf); //dispatcher = new CollisionDispatcherMultiThreaded(collisionConf); //Solver = new ConstraintSolverPoolMultiThreaded(MaxThreadCount); //World = new DiscreteDynamicsWorldMultiThreaded(dispatcher, broadphase, Solver, null, collisionConf); //World.SolverInfo.SolverMode = SolverModes.Simd | SolverModes.UseWarmStarting; //World = new DiscreteDynamicsWorldMultiThreaded(dispatcher, broadphase, cspm, csM, collisionConf); //World.Gravity = new Vector3(0, 0f, 0); // CreateFloor(); //World.LatencyMotionStateInterpolation = false; //for character controllers broadphase.OverlappingPairCache.SetInternalGhostPairCallback(new GhostPairCallback()); World.DebugDrawer = new PhysicsDebugDraw(World); }
protected override void OnInitializePhysics() { // collision configuration contains default setup for memory, collision setup CollisionConf = new DefaultCollisionConfiguration(); // Use the default collision dispatcher. For parallel processing you can use a diffent dispatcher. Dispatcher = new CollisionDispatcher(CollisionConf); var simplex = new VoronoiSimplexSolver(); var pdSolver = new MinkowskiPenetrationDepthSolver(); var convexAlgo2D = new Convex2DConvex2DAlgorithm.CreateFunc(simplex, pdSolver); Dispatcher.RegisterCollisionCreateFunc(BroadphaseNativeType.Convex2DShape, BroadphaseNativeType.Convex2DShape, convexAlgo2D); Dispatcher.RegisterCollisionCreateFunc(BroadphaseNativeType.Box2DShape, BroadphaseNativeType.Convex2DShape, convexAlgo2D); Dispatcher.RegisterCollisionCreateFunc(BroadphaseNativeType.Convex2DShape, BroadphaseNativeType.Box2DShape, convexAlgo2D); Dispatcher.RegisterCollisionCreateFunc(BroadphaseNativeType.Box2DShape, BroadphaseNativeType.Box2DShape, new Box2DBox2DCollisionAlgorithm.CreateFunc()); Broadphase = new DbvtBroadphase(); // the default constraint solver. Solver = new SequentialImpulseConstraintSolver(); World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, Solver, CollisionConf); World.Gravity = new Vector3(0, -10, 0); CreateGround(); Create2dBodies(); }
/* * 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); }
static void Main(string[] args) { { var world = new DiscreteDynamicsWorld(); world.Gravity = new Vector3(0.0f, -10.0f, 0.0f); var info0 = new RigidBodyConstructionInfo(); info0.Mass = 1.0f; info0.CollisionShape = new BulletDotNet.Shapes.BoxShape(Vector3.One); info0.CenterOfMass = Vector3.Zero; var rb0 = new RigidBody(info0, OnGetTransform0, OnSetTransform0); var info1 = new RigidBodyConstructionInfo(); info1.Mass = 0.0f; info1.CollisionShape = new BulletDotNet.Shapes.BoxShape(Vector3.One); info1.CenterOfMass = Vector3.Zero; var rb1 = new RigidBody(info1, OnGetTransform1, OnSetTransform1); world.AddRigidBody(rb0); world.AddRigidBody(rb1); for (int i = 0; i < 100; i++) { rb0.Activate(); world.StepSimulation(1.0f / 60.0f); } world.RemoveRigidBody(rb0); world.RemoveRigidBody(rb1); } GC.Collect(); GC.WaitForPendingFinalizers(); }
//---------------------------------------------------------------------------------------------- public void InitialiseWorld(ref DiscreteDynamicsWorld world) { IndexedVector3 worldMin = new IndexedVector3(-1000, -1000, -1000); IndexedVector3 worldMax = -worldMin; IBroadphaseInterface bp = new AxisSweep3Internal(ref worldMin, ref worldMax, 0xfffe, 0xffff, 16384, null, false); //m_broadphase = new DbvtBroadphase(); IOverlappingPairCache pairCache = null; //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(); DefaultCollisionConfiguration collisionConfig = new DefaultCollisionConfiguration(); ///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded) CollisionDispatcher dispatcher = new CollisionDispatcher(collisionConfig); world = new DiscreteDynamicsWorld(dispatcher, bp, sol, collisionConfig); IndexedVector3 gravity = new IndexedVector3(0, -10, 0); world.SetGravity(ref gravity); world.SetDebugDrawer(BulletGlobals.gDebugDraw); }
public void Initialize() { dispatcher = new CollisionDispatcher(defaultCollisionConfiguration); world = new DiscreteDynamicsWorld(dispatcher, broadphase, sequentialImpulseConstraintSolver, defaultCollisionConfiguration); BulletSharp.Math.Vector3 gravity = new BulletSharp.Math.Vector3(0, -9.81f, 0); world.SetGravity(ref gravity); }
public override void InitializeDemo() { base.InitializeDemo(); SetCameraDistance(SCALING * 50f); //string filename = @"C:\users\man\bullett\xna-largemesh-output.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); m_broadphase = new DbvtBroadphase(); IOverlappingPairCache pairCache = null; //pairCache = new SortedOverlappingPairCache(); //m_broadphase = new SimpleBroadphase(10000, 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); IndexedVector3 gravity = new IndexedVector3(0, -10, 0); m_dynamicsWorld.SetGravity(ref gravity); m_profileManager = new BasicProfileManager(); BulletGlobals.g_profileManager = m_profileManager; m_profileIterator = m_profileManager.getIterator(); ///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), 0); LocalCreateRigidBody(0f, IndexedMatrix.Identity, groundShape); //CollisionShape groundShape = BuildLargeMesh(); m_collisionShapes.Add(groundShape); CollisionShape sphereShape = new SphereShape(0.2f); int size = 16;// 5; // 16 for (int i = 0; i < size; ++i) { for (int j = 0; j < size; ++j) { IndexedMatrix m = IndexedMatrix.CreateTranslation(new IndexedVector3(i, 1, j)); RigidBody rb = LocalCreateRigidBody(1f, m, sphereShape); rb.SetActivationState(ActivationState.ISLAND_SLEEPING); } } ClientResetScene(); }
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); 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)); }
public override void InitializeDemo() { m_maxIterations = 10; 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); m_broadphase = new DbvtBroadphase(); IOverlappingPairCache pairCache = null; //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); IndexedVector3 gravity = new IndexedVector3(0, -10, 0); m_dynamicsWorld.SetGravity(ref gravity); m_dynamicsWorld.SetForceUpdateAllAabbs(false); BuildLevelMap(); }
protected override void OnInitializePhysics() { 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); CreateGround(); CreateBoxStack(); }
public void Init() { #region MUNDO //Creamos el mundo fisico por defecto. collisionConfiguration = new DefaultCollisionConfiguration(); dispatcher = new CollisionDispatcher(collisionConfiguration); GImpactCollisionAlgorithm.RegisterAlgorithm(dispatcher); constraintSolver = new SequentialImpulseConstraintSolver(); overlappingPairCache = new DbvtBroadphase(); dynamicsWorld = new DiscreteDynamicsWorld(dispatcher, overlappingPairCache, constraintSolver, collisionConfiguration) { Gravity = new TGCVector3(0, -20f, 0).ToBsVector }; #endregion #region PISO var d3dDevice = D3DDevice.Instance.Device; //El piso es un plano estatico se dice que si tiene masa 0 es estatico. var floorShape = new StaticPlaneShape(TGCVector3.Up.ToBsVector, 0); var floorMotionState = new DefaultMotionState();// Matrix.Translation(0f, 200f, -700f));//esto puede ir sin parametro y funciona var floorInfo = new RigidBodyConstructionInfo(0, floorMotionState, floorShape); floorBody = new RigidBody(floorInfo); dynamicsWorld.AddRigidBody(floorBody); //Cargamos objetos de render del framework. //var floorTexture = TgcTexture.createTexture(d3dDevice, GameModel.mediaDir + "texturas\\terrain\\TerrainTexture1.jpg"); //floorMesh = new TgcPlane(new TGCVector3(0, 0, 0), new TGCVector3(400, 0f, 400), TgcPlane.Orientations.XZplane, floorTexture); #endregion }
private void PickRigidBody(RigidBody body, ref Vector3 pickPosition) { if (body.IsStaticObject || body.IsKinematicObject) { return; } _pickedBody = body; _pickedBody.ActivationState = ActivationState.DisableDeactivation; DiscreteDynamicsWorld world = _demo.Simulation.World; Vector3 localPivot = Vector3.TransformCoordinate(pickPosition, Matrix.Invert(body.CenterOfMassTransform)); if (_demo.Input.KeysDown.Contains(Keys.ShiftKey)) { var dof6 = new Generic6DofConstraint(body, Matrix.Translation(localPivot), false) { LinearLowerLimit = Vector3.Zero, LinearUpperLimit = Vector3.Zero, AngularLowerLimit = Vector3.Zero, AngularUpperLimit = Vector3.Zero }; world.AddConstraint(dof6); _rigidBodyPickConstraint = dof6; dof6.SetParam(ConstraintParam.StopCfm, 0.8f, 0); dof6.SetParam(ConstraintParam.StopCfm, 0.8f, 1); dof6.SetParam(ConstraintParam.StopCfm, 0.8f, 2); dof6.SetParam(ConstraintParam.StopCfm, 0.8f, 3); dof6.SetParam(ConstraintParam.StopCfm, 0.8f, 4); dof6.SetParam(ConstraintParam.StopCfm, 0.8f, 5); dof6.SetParam(ConstraintParam.StopErp, 0.1f, 0); dof6.SetParam(ConstraintParam.StopErp, 0.1f, 1); dof6.SetParam(ConstraintParam.StopErp, 0.1f, 2); dof6.SetParam(ConstraintParam.StopErp, 0.1f, 3); dof6.SetParam(ConstraintParam.StopErp, 0.1f, 4); dof6.SetParam(ConstraintParam.StopErp, 0.1f, 5); } else { var p2p = new Point2PointConstraint(body, localPivot); world.AddConstraint(p2p); _rigidBodyPickConstraint = p2p; p2p.Setting.ImpulseClamp = 30; //very weak constraint for picking p2p.Setting.Tau = 0.001f; /* * p2p.SetParam(ConstraintParams.Cfm, 0.8f, 0); * p2p.SetParam(ConstraintParams.Cfm, 0.8f, 1); * p2p.SetParam(ConstraintParams.Cfm, 0.8f, 2); * p2p.SetParam(ConstraintParams.Erp, 0.1f, 0); * p2p.SetParam(ConstraintParams.Erp, 0.1f, 1); * p2p.SetParam(ConstraintParams.Erp, 0.1f, 2); */ } }
private void PickBody() { Vector3 rayFrom = _demo.FreeLook.Eye; Vector3 rayTo = _demo.GetCameraRayTo(); DiscreteDynamicsWorld world = _demo.Simulation.World; using (var rayCallback = new ClosestRayResultCallback(ref rayFrom, ref rayTo)) { world.RayTestRef(ref rayFrom, ref rayTo, rayCallback); if (rayCallback.HasHit) { Vector3 pickPosition = rayCallback.HitPointWorld; var body = rayCallback.CollisionObject as RigidBody; if (body != null) { PickRigidBody(body, ref pickPosition); } else { var collider = rayCallback.CollisionObject as MultiBodyLinkCollider; if (collider != null) { PickMultiBody(collider, ref pickPosition); } } _oldPickingDist = (pickPosition - rayFrom).Length; } } }
protected override void OnInitializePhysics() { // collision configuration contains default setup for memory, collision setup using (var cci = new DefaultCollisionConstructionInfo() { DefaultMaxPersistentManifoldPoolSize = 32768 }) { CollisionConf = new DefaultCollisionConfiguration(cci); } Dispatcher = new CollisionDispatcher(CollisionConf); Dispatcher.DispatcherFlags = DispatcherFlags.DisableContactPoolDynamicAllocation; // the maximum size of the collision world. Make sure objects stay within these boundaries // Don't make the world AABB size too large, it will harm simulation quality and performance Vector3 worldAabbMin = new Vector3(-1000, -1000, -1000); Vector3 worldAabbMax = new Vector3(1000, 1000, 1000); Broadphase = new AxisSweep3(worldAabbMin, worldAabbMax, 3500); //Broadphase = new DbvtBroadphase(); Solver = new SequentialImpulseConstraintSolver(); World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, Solver, CollisionConf); World.Gravity = new Vector3(0, -10, 0); World.SolverInfo.SolverMode |= SolverModes.EnableFrictionDirectionCaching; World.SolverInfo.NumIterations = 5; _scenes[SceneIndex](); }
public BenchmarkDemoSimulation() { using (var cci = new DefaultCollisionConstructionInfo() { DefaultMaxPersistentManifoldPoolSize = 32768 }) { CollisionConfiguration = new DefaultCollisionConfiguration(cci); } Dispatcher = new CollisionDispatcher(CollisionConfiguration); Dispatcher.DispatcherFlags = DispatcherFlags.DisableContactPoolDynamicAllocation; // The maximum size of the collision world. Make sure objects stay within these boundaries // Don't make the world AABB size too large, it will harm simulation quality and performance var worldAabbMin = new Vector3(-1000, -1000, -1000); var worldAabbMax = new Vector3(1000, 1000, 1000); Broadphase = new AxisSweep3(worldAabbMin, worldAabbMax, 3500); //Broadphase = new DbvtBroadphase(); World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, null, CollisionConfiguration); World.SolverInfo.SolverMode |= SolverModes.EnableFrictionDirectionCaching; World.SolverInfo.NumIterations = 5; _scenes = new Action[] { Create3KBoxes, CreateStructures, CreateTaruStack, CreateShapesGravity, CreateTaruGravity }; _scenes[_scene](); }
public override void InitializeDemo() { // std::cerr << "initializing...\n"; m_nearClip = 1f; m_farClip = 1000f; m_aspect = m_glutScreenWidth / m_glutScreenHeight; m_perspective = IndexedMatrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(40.0f), m_aspect, m_nearClip, m_farClip); // set up basic state m_upAxis = 1; // start with Y-axis as "up" m_type = PHY_ScalarType.PHY_FLOAT; m_model = eTerrainModel.eRadial;//eFractal; m_isDynamic = true; // set up the physics world 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); 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); // initialize axis- or type-dependent physics from here ClientResetScene(); }
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); groundShape = new BoxShape(30, 1, 30); ground = CreateBody(0, Matrix.Translation(0, -5, 0), groundShape); ground.CollisionFlags |= CollisionFlags.CustomMaterialCallback; compoundShape = new CompoundShape(); boxShape = new BoxShape(1, 1, 1); compoundShape.AddChildShape(Matrix.Identity, boxShape); boxShape2 = new BoxShape(1, 1, 1); compoundShape.AddChildShape(Matrix.Translation(0, -1, 0), boxShape2); boxShape3 = new BoxShape(1, 1, 1); compoundShape.AddChildShape(Matrix.Translation(0, -2, 0), boxShape3); compoundShape2 = new CompoundShape(); compoundShape2.AddChildShape(Matrix.Identity, compoundShape); compound = CreateBody(1, Matrix.Translation(0, 0, 0), compoundShape2); ManifoldPoint.ContactAdded += ContactAdded; }
/// Bulletの世界を作る /// </summary> /// <param name="gravity">重力</param> /// <returns>Bulletの世界</returns> public DiscreteDynamicsWorld CreateDynamicsWorld(SlimDX.Vector3 gravity) { var dynamicsWorld = new DiscreteDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration); dynamicsWorld.Gravity = gravity; return(dynamicsWorld); }
public DistanceDemoSimulation() { CollisionConfiguration = new DefaultCollisionConfiguration(); Dispatcher = new CollisionDispatcher(CollisionConfiguration); Broadphase = new DbvtBroadphase(); World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, null, CollisionConfiguration); CreateGround(); Vector3[] rotatingPoints = { new Vector3(1, 0, 0), new Vector3(0, 1, 0), new Vector3(0, 0, 1) }; _rotatingShape = new ConvexHullShape(rotatingPoints); _rotatingBody = PhysicsHelper.CreateStaticBody(_rotBodyPosition, _rotatingShape, World); _rotatingBody.CollisionFlags |= CollisionFlags.KinematicObject; _rotatingBody.ActivationState = ActivationState.DisableDeactivation; Vector3[] staticPoints = { 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) }; _staticShape = new ConvexHullShape(staticPoints); Matrix staticBodyPosition = Matrix.Translation(0, 5, 0); _staticBody = PhysicsHelper.CreateStaticBody(staticBodyPosition, _staticShape, World); }
public ConvexDecompositionDemoSimulation(bool enableSat) { _enableSat = enableSat; CollisionConfiguration = new DefaultCollisionConfiguration(); Dispatcher = new CollisionDispatcher(CollisionConfiguration); Broadphase = new AxisSweep3(new Vector3(-10000, -10000, -10000), new Vector3(10000, 10000, 10000)); World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, null, CollisionConfiguration); CreateGround(); ManifoldPoint.ContactAdded += MyContactCallback; //CompoundCollisionAlgorithm.CompoundChildShapePairCallback = MyCompoundChildShapeCallback; string path = Path.Combine("data", "file.obj"); var wavefrontModel = WavefrontObj.Load(path); if (wavefrontModel.Indices.Count == 0) { return; } var localScaling = new Vector3(6, 6, 6); _triangleMesh = CreateTriangleMesh(wavefrontModel.Indices, wavefrontModel.Vertices, localScaling); // Convex hull approximation ConvexHullShape convexShape = CreateHullApproximation(_triangleMesh); float mass = 1.0f; PhysicsHelper.CreateBody(mass, Matrix.Translation(0, 2, 14), convexShape, World); // Non-moving body var objectOffset = new Vector3(10, 0, 0); const bool useQuantization = true; var concaveShape = new BvhTriangleMeshShape(_triangleMesh, useQuantization); PhysicsHelper.CreateStaticBody(Matrix.Translation(objectOffset), concaveShape, World); Hacd hacd = ComputeHacd(wavefrontModel); hacd.Save("output.wrl", false); var compoundShape = CreateCompoundShape(hacd, localScaling); mass = 10.0f; objectOffset = new Vector3(-10, 0, -6); var body2 = PhysicsHelper.CreateBody(mass, Matrix.Translation(objectOffset), compoundShape, World); body2.CollisionFlags |= CollisionFlags.CustomMaterialCallback; objectOffset.Z += 6; body2 = PhysicsHelper.CreateBody(mass, Matrix.Translation(objectOffset), compoundShape, World); body2.CollisionFlags |= CollisionFlags.CustomMaterialCallback; objectOffset.Z += 6; body2 = PhysicsHelper.CreateBody(mass, Matrix.Translation(objectOffset), compoundShape, World); body2.CollisionFlags |= CollisionFlags.CustomMaterialCallback; }
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; var bspLoader = new BspLoader(); string[] args = Environment.GetCommandLineArgs(); if (args.Length == 1) { bspLoader.LoadBspFile(Path.Combine("data", "BspDemo.bsp")); } 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); }
internal DynamicWorldImp() { //Debug.WriteLine("DynamicWorldImp"); //Default // collision configuration contains default setup for memory, collision setup BtCollisionConf = new DefaultCollisionConfiguration(); BtDispatcher = new CollisionDispatcher(BtCollisionConf); BtBroadphase = new DbvtBroadphase(); BtSolver = new SequentialImpulseConstraintSolver(); // BtCollisionShapes = new AlignedCollisionShapeArray(); BtWorld = new DiscreteDynamicsWorld(BtDispatcher, BtBroadphase, BtSolver, BtCollisionConf) { Gravity = new Vector3(0, -9.81f, 0) }; BtWorld.SolverInfo.NumIterations = 5; BtWorld.PerformDiscreteCollisionDetection(); //GImpactCollisionAlgorithm.RegisterAlgorithm(BtDispatcher); // BtWorld.SetInternalTickCallback(MyTickCallBack); //BtWorld.SetInternalTickCallback(TickTack); //ManifoldPoint.ContactAdded += OnContactAdded; //PersistentManifold.ContactDestroyed += OnContactDestroyed; //PersistentManifold.ContactProcessed += OnContactProcessed; }
public FisicaMundo() { //Implementación Iniciales collisionConfiguration = new DefaultCollisionConfiguration(); dispatcher = new CollisionDispatcher(collisionConfiguration); GImpactCollisionAlgorithm.RegisterAlgorithm(dispatcher); constraintSolver = new SequentialImpulseConstraintSolver(); overlappingPairCache = new DbvtBroadphase(); dynamicsWorld = new DiscreteDynamicsWorld(dispatcher, overlappingPairCache, constraintSolver, collisionConfiguration) { Gravity = new TGCVector3(0, -10f, 0).ToBulletVector3() }; var cuerpoPiso = new StaticPlaneShape(TGCVector3.Up.ToBulletVector3(), 0) { LocalScaling = new TGCVector3().ToBulletVector3() }; MotionState movimientoPiso = new DefaultMotionState(); piso = new RigidBody(new RigidBodyConstructionInfo(0, movimientoPiso, cuerpoPiso)) { RollingFriction = 0.3f, Restitution = 0.4f, UserObject = "floorBody" }; dynamicsWorld.AddRigidBody(piso); }
public override void InitializeDemo() { base.InitializeDemo(); SetCameraDistance(SCALING * 50f); //string filename = @"C:\users\man\bullett\xna-largemesh-output.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); m_broadphase = new DbvtBroadphase(); IOverlappingPairCache pairCache = null; //pairCache = new SortedOverlappingPairCache(); //m_broadphase = new SimpleBroadphase(10000, 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); IndexedVector3 gravity = new IndexedVector3(0, -10, 0); m_dynamicsWorld.SetGravity(ref gravity); m_profileManager = new BasicProfileManager(); BulletGlobals.g_profileManager = m_profileManager; m_profileIterator = m_profileManager.getIterator(); ///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), 0); LocalCreateRigidBody(0f, IndexedMatrix.Identity, groundShape); //CollisionShape groundShape = BuildLargeMesh(); m_collisionShapes.Add(groundShape); CollisionShape sphereShape = new SphereShape(0.2f); int size = 16;// 5; // 16 for (int i = 0; i < size; ++i) { for (int j = 0; j < size; ++j) { IndexedMatrix m = IndexedMatrix.CreateTranslation(new IndexedVector3(i, 1, j)); RigidBody rb = LocalCreateRigidBody(1f, m, sphereShape); rb.SetActivationState(ActivationState.ISLAND_SLEEPING); } } ClientResetScene(); }
public override void InitializeDemo() { m_maxIterations = 500; SetCameraDistance(SCALING * 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); m_broadphase = new DbvtBroadphase(); IOverlappingPairCache pairCache = null; //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); 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, -52, 0)); //IndexedMatrix groundTransform = IndexedMatrix.CreateTranslation(new IndexedVector3(0,-10,0)); float mass = 0f; LocalCreateRigidBody(mass, ref groundTransform, groundShape); CreateScene5(20); ClientResetScene(); }
public override void InitializeDemo() { SetCameraDistance(50f); 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); //m_broadphase = new DbvtBroadphase(); IOverlappingPairCache pairCache = null; //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); 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); CollisionShape shape = SetupShape(); IndexedMatrix objTransform = IndexedMatrix.CreateTranslation(new IndexedVector3(0,2,0)); LocalCreateRigidBody(mass, ref objTransform, shape); //ClientResetScene(); }
public override void InitializeDemo() { //maxiterations = 10; SetCameraDistance(100f); m_cameraTargetPosition = new IndexedVector3(); m_cameraPosition = new IndexedVector3(0, 0, -m_cameraDistance); //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); //m_broadphase = new DbvtBroadphase(); IOverlappingPairCache pairCache = null; //pairCache = new SortedOverlappingPairCache(); //m_broadphase = new SimpleBroadphase(1000, pairCache); m_broadphase = new DbvtBroadphase(); IndexedVector3 worldAabbMin = new IndexedVector3(-200, -200, -200); IndexedVector3 worldAabbMax = -worldAabbMin; //m_broadphase = new AxisSweep3Internal(ref worldAabbMin, ref worldAabbMax, 0xfffe, 0xffff, 16384, null, true); ///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); IndexedVector3 gravity = new IndexedVector3(0, -10, 0); m_dynamicsWorld.SetGravity(ref gravity); m_profileManager = new BasicProfileManager(); BulletGlobals.g_profileManager = m_profileManager; m_profileIterator = m_profileManager.getIterator(); BuildBoard(); }
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 BulletWorldXNA(uint id, BSScene physScene, DiscreteDynamicsWorld xx) : base(id, physScene) { world = xx; }
private static DiscreteDynamicsWorld Initialize2(Vector3 worldExtent, ConfigurationParameters[] o, int mMaxCollisionsPerFrame, ref CollisionDesc[] collisionArray, int mMaxUpdatesPerFrame, ref EntityProperties[] updateArray, object mDebugLogCallbackHandle) { CollisionWorld.WorldData.ParamData p = new CollisionWorld.WorldData.ParamData(); p.angularDamping = BSParam.AngularDamping; p.defaultFriction = o[0].defaultFriction; p.defaultFriction = o[0].defaultFriction; p.defaultDensity = o[0].defaultDensity; p.defaultRestitution = o[0].defaultRestitution; p.collisionMargin = o[0].collisionMargin; p.gravity = o[0].gravity; p.linearDamping = BSParam.LinearDamping; p.angularDamping = BSParam.AngularDamping; p.deactivationTime = BSParam.DeactivationTime; p.linearSleepingThreshold = BSParam.LinearSleepingThreshold; p.angularSleepingThreshold = BSParam.AngularSleepingThreshold; p.ccdMotionThreshold = BSParam.CcdMotionThreshold; p.ccdSweptSphereRadius = BSParam.CcdSweptSphereRadius; p.contactProcessingThreshold = BSParam.ContactProcessingThreshold; p.terrainImplementation = BSParam.TerrainImplementation; p.terrainFriction = BSParam.TerrainFriction; p.terrainHitFraction = BSParam.TerrainHitFraction; p.terrainRestitution = BSParam.TerrainRestitution; p.terrainCollisionMargin = BSParam.TerrainCollisionMargin; p.avatarFriction = BSParam.AvatarFriction; p.avatarStandingFriction = BSParam.AvatarStandingFriction; p.avatarDensity = BSParam.AvatarDensity; p.avatarRestitution = BSParam.AvatarRestitution; p.avatarCapsuleWidth = BSParam.AvatarCapsuleWidth; p.avatarCapsuleDepth = BSParam.AvatarCapsuleDepth; p.avatarCapsuleHeight = BSParam.AvatarCapsuleHeight; p.avatarContactProcessingThreshold = BSParam.AvatarContactProcessingThreshold; p.vehicleAngularDamping = BSParam.VehicleAngularDamping; p.maxPersistantManifoldPoolSize = o[0].maxPersistantManifoldPoolSize; p.maxCollisionAlgorithmPoolSize = o[0].maxCollisionAlgorithmPoolSize; p.shouldDisableContactPoolDynamicAllocation = o[0].shouldDisableContactPoolDynamicAllocation; p.shouldForceUpdateAllAabbs = o[0].shouldForceUpdateAllAabbs; p.shouldRandomizeSolverOrder = o[0].shouldRandomizeSolverOrder; p.shouldSplitSimulationIslands = o[0].shouldSplitSimulationIslands; p.shouldEnableFrictionCaching = o[0].shouldEnableFrictionCaching; p.numberOfSolverIterations = o[0].numberOfSolverIterations; p.linksetImplementation = BSParam.LinksetImplementation; p.linkConstraintUseFrameOffset = BSParam.NumericBool(BSParam.LinkConstraintUseFrameOffset); p.linkConstraintEnableTransMotor = BSParam.NumericBool(BSParam.LinkConstraintEnableTransMotor); p.linkConstraintTransMotorMaxVel = BSParam.LinkConstraintTransMotorMaxVel; p.linkConstraintTransMotorMaxForce = BSParam.LinkConstraintTransMotorMaxForce; p.linkConstraintERP = BSParam.LinkConstraintERP; p.linkConstraintCFM = BSParam.LinkConstraintCFM; p.linkConstraintSolverIterations = BSParam.LinkConstraintSolverIterations; p.physicsLoggingFrames = o[0].physicsLoggingFrames; DefaultCollisionConstructionInfo ccci = new DefaultCollisionConstructionInfo(); DefaultCollisionConfiguration cci = new DefaultCollisionConfiguration(); CollisionDispatcher m_dispatcher = new CollisionDispatcher(cci); if (p.maxPersistantManifoldPoolSize > 0) cci.m_persistentManifoldPoolSize = (int)p.maxPersistantManifoldPoolSize; if (p.shouldDisableContactPoolDynamicAllocation !=0) m_dispatcher.SetDispatcherFlags(DispatcherFlags.CD_DISABLE_CONTACTPOOL_DYNAMIC_ALLOCATION); //if (p.maxCollisionAlgorithmPoolSize >0 ) DbvtBroadphase m_broadphase = new DbvtBroadphase(); //IndexedVector3 aabbMin = new IndexedVector3(0, 0, 0); //IndexedVector3 aabbMax = new IndexedVector3(256, 256, 256); //AxisSweep3Internal m_broadphase2 = new AxisSweep3Internal(ref aabbMin, ref aabbMax, Convert.ToInt32(0xfffe), 0xffff, ushort.MaxValue/2, null, true); m_broadphase.GetOverlappingPairCache().SetInternalGhostPairCallback(new GhostPairCallback()); SequentialImpulseConstraintSolver m_solver = new SequentialImpulseConstraintSolver(); DiscreteDynamicsWorld world = new DiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_solver, cci); world.LastCollisionDesc = 0; world.LastEntityProperty = 0; world.WorldSettings.Params = p; world.SetForceUpdateAllAabbs(p.shouldForceUpdateAllAabbs != 0); world.GetSolverInfo().m_solverMode = SolverMode.SOLVER_USE_WARMSTARTING | SolverMode.SOLVER_SIMD; if (p.shouldRandomizeSolverOrder != 0) world.GetSolverInfo().m_solverMode |= SolverMode.SOLVER_RANDMIZE_ORDER; world.GetSimulationIslandManager().SetSplitIslands(p.shouldSplitSimulationIslands != 0); //world.GetDispatchInfo().m_enableSatConvex Not implemented in C# port if (p.shouldEnableFrictionCaching != 0) world.GetSolverInfo().m_solverMode |= SolverMode.SOLVER_ENABLE_FRICTION_DIRECTION_CACHING; if (p.numberOfSolverIterations > 0) world.GetSolverInfo().m_numIterations = (int) p.numberOfSolverIterations; world.GetSolverInfo().m_damping = world.WorldSettings.Params.linearDamping; world.GetSolverInfo().m_restitution = world.WorldSettings.Params.defaultRestitution; world.GetSolverInfo().m_globalCfm = 0.0f; world.GetSolverInfo().m_tau = 0.6f; world.GetSolverInfo().m_friction = 0.3f; world.GetSolverInfo().m_maxErrorReduction = 20f; world.GetSolverInfo().m_numIterations = 10; world.GetSolverInfo().m_erp = 0.2f; world.GetSolverInfo().m_erp2 = 0.1f; world.GetSolverInfo().m_sor = 1.0f; world.GetSolverInfo().m_splitImpulse = false; world.GetSolverInfo().m_splitImpulsePenetrationThreshold = -0.02f; world.GetSolverInfo().m_linearSlop = 0.0f; world.GetSolverInfo().m_warmstartingFactor = 0.85f; world.GetSolverInfo().m_restingContactRestitutionThreshold = 2; world.SetForceUpdateAllAabbs(true); //BSParam.TerrainImplementation = 0; world.SetGravity(new IndexedVector3(0,0,p.gravity)); // Turn off Pooling since globals and pooling are bad for threading. BulletGlobals.VoronoiSimplexSolverPool.SetPoolingEnabled(false); BulletGlobals.SubSimplexConvexCastPool.SetPoolingEnabled(false); BulletGlobals.ManifoldPointPool.SetPoolingEnabled(false); BulletGlobals.CastResultPool.SetPoolingEnabled(false); BulletGlobals.SphereShapePool.SetPoolingEnabled(false); BulletGlobals.DbvtNodePool.SetPoolingEnabled(false); BulletGlobals.SingleRayCallbackPool.SetPoolingEnabled(false); BulletGlobals.SubSimplexClosestResultPool.SetPoolingEnabled(false); BulletGlobals.GjkPairDetectorPool.SetPoolingEnabled(false); BulletGlobals.DbvtTreeColliderPool.SetPoolingEnabled(false); BulletGlobals.SingleSweepCallbackPool.SetPoolingEnabled(false); BulletGlobals.BroadphaseRayTesterPool.SetPoolingEnabled(false); BulletGlobals.ClosestNotMeConvexResultCallbackPool.SetPoolingEnabled(false); BulletGlobals.GjkEpaPenetrationDepthSolverPool.SetPoolingEnabled(false); BulletGlobals.ContinuousConvexCollisionPool.SetPoolingEnabled(false); BulletGlobals.DbvtStackDataBlockPool.SetPoolingEnabled(false); BulletGlobals.BoxBoxCollisionAlgorithmPool.SetPoolingEnabled(false); BulletGlobals.CompoundCollisionAlgorithmPool.SetPoolingEnabled(false); BulletGlobals.ConvexConcaveCollisionAlgorithmPool.SetPoolingEnabled(false); BulletGlobals.ConvexConvexAlgorithmPool.SetPoolingEnabled(false); BulletGlobals.ConvexPlaneAlgorithmPool.SetPoolingEnabled(false); BulletGlobals.SphereBoxCollisionAlgorithmPool.SetPoolingEnabled(false); BulletGlobals.SphereSphereCollisionAlgorithmPool.SetPoolingEnabled(false); BulletGlobals.SphereTriangleCollisionAlgorithmPool.SetPoolingEnabled(false); BulletGlobals.GImpactCollisionAlgorithmPool.SetPoolingEnabled(false); BulletGlobals.GjkEpaSolver2MinkowskiDiffPool.SetPoolingEnabled(false); BulletGlobals.PersistentManifoldPool.SetPoolingEnabled(false); BulletGlobals.ManifoldResultPool.SetPoolingEnabled(false); BulletGlobals.GJKPool.SetPoolingEnabled(false); BulletGlobals.GIM_ShapeRetrieverPool.SetPoolingEnabled(false); BulletGlobals.TriangleShapePool.SetPoolingEnabled(false); BulletGlobals.SphereTriangleDetectorPool.SetPoolingEnabled(false); BulletGlobals.CompoundLeafCallbackPool.SetPoolingEnabled(false); BulletGlobals.GjkConvexCastPool.SetPoolingEnabled(false); BulletGlobals.LocalTriangleSphereCastCallbackPool.SetPoolingEnabled(false); BulletGlobals.BridgeTriangleRaycastCallbackPool.SetPoolingEnabled(false); BulletGlobals.BridgeTriangleConcaveRaycastCallbackPool.SetPoolingEnabled(false); BulletGlobals.BridgeTriangleConvexcastCallbackPool.SetPoolingEnabled(false); BulletGlobals.MyNodeOverlapCallbackPool.SetPoolingEnabled(false); BulletGlobals.ClosestRayResultCallbackPool.SetPoolingEnabled(false); BulletGlobals.DebugDrawcallbackPool.SetPoolingEnabled(false); return world; }
public override void InitializeDemo() { // Setup the basic world SetTexturing(true); SetShadows(true); SetCameraDistance(5.0f); m_collisionConfiguration = new DefaultCollisionConfiguration(); m_dispatcher = new CollisionDispatcher(m_collisionConfiguration); IndexedVector3 worldAabbMin = new IndexedVector3(-10000,-10000,-10000); IndexedVector3 worldAabbMax = new IndexedVector3(10000,10000,10000); //m_broadphase = new AxisSweep3Internal(ref worldAabbMin, ref worldAabbMax, 0xfffe, 0xffff, 16384, null, true); m_broadphase = new SimpleBroadphase(1000, null); m_constraintSolver = new SequentialImpulseConstraintSolver(); m_dynamicsWorld = new DiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_constraintSolver, m_collisionConfiguration); //m_dynamicsWorld.getDispatchInfo().m_useConvexConservativeDistanceUtil = true; //m_dynamicsWorld.getDispatchInfo().m_convexConservativeDistanceThreshold = 0.01f; // Setup a big ground box { CollisionShape groundShape = new BoxShape(new IndexedVector3(200.0f,10.0f,200.0f)); m_collisionShapes.Add(groundShape); IndexedMatrix groundTransform = IndexedMatrix.CreateTranslation(0,-10,0); CollisionObject fixedGround = new CollisionObject(); fixedGround.SetCollisionShape(groundShape); fixedGround.SetWorldTransform(ref groundTransform); fixedGround.SetUserPointer("Ground"); m_dynamicsWorld.AddCollisionObject(fixedGround); } // Spawn one ragdoll IndexedVector3 startOffset = new IndexedVector3(1,0.5f,0); //string filename = @"c:\users\man\bullet\xna-ragdoll-constraints-output.txt"; //FileStream filestream = File.Open(filename, FileMode.Create, FileAccess.Write, FileShare.Read); //BulletGlobals.g_streamWriter = new StreamWriter(filestream); SpawnRagdoll(ref startOffset, BulletGlobals.g_streamWriter); //startOffset = new IndexedVector3(-1,0.5f,0); //spawnRagdoll(ref startOffset); ClientResetScene(); }
//---------------------------------------------------------------------------------------------- protected virtual void RenderScenePassMultiWorld(int pass, GameTime gameTime,DiscreteDynamicsWorld world) { IndexedMatrix m = IndexedMatrix.Identity; IndexedBasisMatrix rot = IndexedBasisMatrix.Identity; int numObjects = world.GetNumCollisionObjects(); IndexedVector3 wireColor = new IndexedVector3(1, 0, 0); for (int i = 0; i < numObjects; i++) { CollisionObject colObj = world.GetCollisionObjectArray()[i]; RigidBody body = RigidBody.Upcast(colObj); if (body != null && body.GetMotionState() != null) { DefaultMotionState myMotionState = (DefaultMotionState)body.GetMotionState(); //myMotionState.m_graphicsWorldTrans.getOpenGLMatrix(m); m = myMotionState.m_graphicsWorldTrans; rot = myMotionState.m_graphicsWorldTrans._basis; } else { //colObj.getWorldTransform().getOpenGLMatrix(m); m = colObj.GetWorldTransform(); rot = colObj.GetWorldTransform()._basis; } wireColor = new IndexedVector3(1.0f, 1.0f, 0.5f); //wants deactivation if ((i & 1) != 0) wireColor = new IndexedVector3(0f, 0f, 1f); ///color differently for active, sleeping, wantsdeactivation states if (colObj.GetActivationState() == ActivationState.ACTIVE_TAG) //active { if ((i & 1) != 0) { wireColor += new IndexedVector3(1f, 0f, 0f); } else { wireColor += new IndexedVector3(.5f, 0f, 0f); } } if (colObj.GetActivationState() == ActivationState.ISLAND_SLEEPING) //ISLAND_SLEEPING { if ((i & 1) != 0) { wireColor += new IndexedVector3(0f, 1f, 0f); } else { wireColor += new IndexedVector3(0f, 05f, 0f); } } IndexedVector3 min, max; world.GetBroadphase().GetBroadphaseAabb(out min, out max); min -= MathUtil.MAX_VECTOR; max += MathUtil.MAX_VECTOR; // printf("aabbMin=(%f,%f,%f)\n",aabbMin.getX(),aabbMin.getY(),aabbMin.getZ()); // printf("aabbMax=(%f,%f,%f)\n",aabbMax.getX(),aabbMax.getY(),aabbMax.getZ()); // m_dynamicsWorld.getDebugDrawer().drawAabb(aabbMin,aabbMax,btVector3(1,1,1)); switch (pass) { case 0: { m_shapeDrawer.DrawXNA(ref m, colObj.GetCollisionShape(), ref wireColor, m_debugDraw.GetDebugMode(), ref min, ref max, ref m_lookAt, ref m_perspective); break; } case 1: { IndexedVector3 shadow = rot * m_lightDirection; m_shapeDrawer.DrawShadow(ref m, ref shadow, colObj.GetCollisionShape(), ref min, ref max); break; } case 2: { IndexedVector3 adjustedWireColor = wireColor * 0.3f; m_shapeDrawer.DrawXNA(ref m, colObj.GetCollisionShape(), ref adjustedWireColor, 0, ref min, ref max, ref m_lookAt, ref m_perspective); break; } } } }
private static object Initialize2(Vector3 worldExtent, ConfigurationParameters[] o, int mMaxCollisionsPerFrame, ref List<BulletXNA.CollisionDesc> collisionArray, int mMaxUpdatesPerFrame, ref List<BulletXNA.EntityProperties> updateArray, object mDebugLogCallbackHandle) { CollisionWorld.WorldData.ParamData p = new CollisionWorld.WorldData.ParamData(); p.angularDamping = o[0].XangularDamping; p.defaultFriction = o[0].defaultFriction; p.defaultFriction = o[0].defaultFriction; p.defaultDensity = o[0].defaultDensity; p.defaultRestitution = o[0].defaultRestitution; p.collisionMargin = o[0].collisionMargin; p.gravity = o[0].gravity; p.linearDamping = o[0].XlinearDamping; p.angularDamping = o[0].XangularDamping; p.deactivationTime = o[0].XdeactivationTime; p.linearSleepingThreshold = o[0].XlinearSleepingThreshold; p.angularSleepingThreshold = o[0].XangularSleepingThreshold; p.ccdMotionThreshold = o[0].XccdMotionThreshold; p.ccdSweptSphereRadius = o[0].XccdSweptSphereRadius; p.contactProcessingThreshold = o[0].XcontactProcessingThreshold; p.terrainImplementation = o[0].XterrainImplementation; p.terrainFriction = o[0].XterrainFriction; p.terrainHitFraction = o[0].XterrainHitFraction; p.terrainRestitution = o[0].XterrainRestitution; p.terrainCollisionMargin = o[0].XterrainCollisionMargin; p.avatarFriction = o[0].XavatarFriction; p.avatarStandingFriction = o[0].XavatarStandingFriction; p.avatarDensity = o[0].XavatarDensity; p.avatarRestitution = o[0].XavatarRestitution; p.avatarCapsuleWidth = o[0].XavatarCapsuleWidth; p.avatarCapsuleDepth = o[0].XavatarCapsuleDepth; p.avatarCapsuleHeight = o[0].XavatarCapsuleHeight; p.avatarContactProcessingThreshold = o[0].XavatarContactProcessingThreshold; p.vehicleAngularDamping = o[0].XvehicleAngularDamping; p.maxPersistantManifoldPoolSize = o[0].maxPersistantManifoldPoolSize; p.maxCollisionAlgorithmPoolSize = o[0].maxCollisionAlgorithmPoolSize; p.shouldDisableContactPoolDynamicAllocation = o[0].shouldDisableContactPoolDynamicAllocation; p.shouldForceUpdateAllAabbs = o[0].shouldForceUpdateAllAabbs; p.shouldRandomizeSolverOrder = o[0].shouldRandomizeSolverOrder; p.shouldSplitSimulationIslands = o[0].shouldSplitSimulationIslands; p.shouldEnableFrictionCaching = o[0].shouldEnableFrictionCaching; p.numberOfSolverIterations = o[0].numberOfSolverIterations; p.linksetImplementation = o[0].XlinksetImplementation; p.linkConstraintUseFrameOffset = o[0].XlinkConstraintUseFrameOffset; p.linkConstraintEnableTransMotor = o[0].XlinkConstraintEnableTransMotor; p.linkConstraintTransMotorMaxVel = o[0].XlinkConstraintTransMotorMaxVel; p.linkConstraintTransMotorMaxForce = o[0].XlinkConstraintTransMotorMaxForce; p.linkConstraintERP = o[0].XlinkConstraintERP; p.linkConstraintCFM = o[0].XlinkConstraintCFM; p.linkConstraintSolverIterations = o[0].XlinkConstraintSolverIterations; p.physicsLoggingFrames = o[0].XphysicsLoggingFrames; DefaultCollisionConstructionInfo ccci = new DefaultCollisionConstructionInfo(); DefaultCollisionConfiguration cci = new DefaultCollisionConfiguration(); CollisionDispatcher m_dispatcher = new CollisionDispatcher(cci); if (p.maxPersistantManifoldPoolSize > 0) cci.m_persistentManifoldPoolSize = (int)p.maxPersistantManifoldPoolSize; if (p.shouldDisableContactPoolDynamicAllocation !=0) m_dispatcher.SetDispatcherFlags(DispatcherFlags.CD_DISABLE_CONTACTPOOL_DYNAMIC_ALLOCATION); //if (p.maxCollisionAlgorithmPoolSize >0 ) DbvtBroadphase m_broadphase = new DbvtBroadphase(); //IndexedVector3 aabbMin = new IndexedVector3(0, 0, 0); //IndexedVector3 aabbMax = new IndexedVector3(256, 256, 256); //AxisSweep3Internal m_broadphase2 = new AxisSweep3Internal(ref aabbMin, ref aabbMax, Convert.ToInt32(0xfffe), 0xffff, ushort.MaxValue/2, null, true); m_broadphase.GetOverlappingPairCache().SetInternalGhostPairCallback(new GhostPairCallback()); SequentialImpulseConstraintSolver m_solver = new SequentialImpulseConstraintSolver(); DiscreteDynamicsWorld world = new DiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_solver, cci); world.UpdatedObjects = updateArray; world.UpdatedCollisions = collisionArray; world.WorldSettings.Params = p; world.SetForceUpdateAllAabbs(p.shouldForceUpdateAllAabbs != 0); world.GetSolverInfo().m_solverMode = SolverMode.SOLVER_USE_WARMSTARTING | SolverMode.SOLVER_SIMD; if (p.shouldRandomizeSolverOrder != 0) world.GetSolverInfo().m_solverMode |= SolverMode.SOLVER_RANDMIZE_ORDER; world.GetSimulationIslandManager().SetSplitIslands(p.shouldSplitSimulationIslands != 0); //world.GetDispatchInfo().m_enableSatConvex Not implemented in C# port if (p.shouldEnableFrictionCaching != 0) world.GetSolverInfo().m_solverMode |= SolverMode.SOLVER_ENABLE_FRICTION_DIRECTION_CACHING; if (p.numberOfSolverIterations > 0) world.GetSolverInfo().m_numIterations = (int) p.numberOfSolverIterations; world.GetSolverInfo().m_damping = world.WorldSettings.Params.linearDamping; world.GetSolverInfo().m_restitution = world.WorldSettings.Params.defaultRestitution; world.GetSolverInfo().m_globalCfm = 0.0f; world.GetSolverInfo().m_tau = 0.6f; world.GetSolverInfo().m_friction = 0.3f; world.GetSolverInfo().m_maxErrorReduction = 20f; world.GetSolverInfo().m_numIterations = 10; world.GetSolverInfo().m_erp = 0.2f; world.GetSolverInfo().m_erp2 = 0.1f; world.GetSolverInfo().m_sor = 1.0f; world.GetSolverInfo().m_splitImpulse = false; world.GetSolverInfo().m_splitImpulsePenetrationThreshold = -0.02f; world.GetSolverInfo().m_linearSlop = 0.0f; world.GetSolverInfo().m_warmstartingFactor = 0.85f; world.GetSolverInfo().m_restingContactRestitutionThreshold = 2; world.SetForceUpdateAllAabbs(true); world.SetGravity(new IndexedVector3(0,0,p.gravity)); return world; }
public override void InitializeDemo() { base.InitializeDemo(); SetCameraDistance(SCALING * 50f); //string filename = @"e:\users\man\bullet\xna-largemesh-output.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); m_broadphase = new DbvtBroadphase(); IOverlappingPairCache pairCache = null; //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); 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(IndexedVector3.Up, 50); CollisionShape groundShape = BuildLargeMesh(); m_collisionShapes.Add(groundShape); IndexedMatrix groundTransform = IndexedMatrix.CreateTranslation(new IndexedVector3(0, 0, 0)); //IndexedMatrix groundTransform = IndexedMatrix.CreateTranslation(new IndexedVector3(0,-10,0)); //IndexedMatrix rotateMatrix = IndexedMatrix.CreateFromYawPitchRoll(0, MathUtil.SIMD_PI / 2.0f, 0); //IndexedMatrix rotateMatrix = IndexedMatrix.Identity; IndexedMatrix rotateMatrix = IndexedMatrix.Identity; rotateMatrix._basis.SetEulerZYX(0, 0, MathUtil.SIMD_PI * 0.7f); rotateMatrix._origin = IndexedVector3.Zero; float mass = 0f; LocalCreateRigidBody(mass, ref rotateMatrix, groundShape); CollisionShape boxShape = new BoxShape(new IndexedVector3(0.2f, 0.2f, 0.2f)); //CollisionShape boxShape = new SphereShape(0.2f); //CollisionShape boxShape = new CylinderShapeX(new IndexedVector3(0.2f, 0.4f, 0.2f)); //CollisionShape boxShape = new CapsuleShape(0.2f, 0.4f); IndexedMatrix boxTransform = IndexedMatrix.Identity; boxTransform._basis.SetEulerZYX(MathUtil.SIMD_PI * 0.2f, MathUtil.SIMD_PI * 0.4f, MathUtil.SIMD_PI * 0.7f); boxTransform._origin = new IndexedVector3(0.0f, 5.0f, 0.0f); LocalCreateRigidBody(1.25f, boxTransform, boxShape); ClientResetScene(); }
//---------------------------------------------------------------------------------------------------------------- public override void InitializeDemo() { CollisionShape groundShape = new BoxShape(new IndexedVector3(50, 3, 50)); //CollisionShape groundShape = new StaticPlaneShape(IndexedVector3.Up, 0f); m_collisionShapes.Add(groundShape); 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 SimpleBroadphase(100, null); m_constraintSolver = new SequentialImpulseConstraintSolver(); m_dynamicsWorld = new DiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_constraintSolver, m_collisionConfiguration); //m_dynamicsWorld.setGravity(new IndexedVector3(0,0,0)); IndexedMatrix tr = IndexedMatrix.CreateTranslation(0, -10, 0); //either use heightfield or triangle mesh //create ground object LocalCreateRigidBody(0f, ref tr, groundShape); CollisionShape chassisShape = new BoxShape(new IndexedVector3(1.0f, 0.5f, 2.0f)); m_collisionShapes.Add(chassisShape); CompoundShape compound = new CompoundShape(); m_collisionShapes.Add(compound); //localTrans effectively shifts the center of mass with respect to the chassis IndexedMatrix localTrans = IndexedMatrix.CreateTranslation(0, 1, 0); compound.AddChildShape(ref localTrans, chassisShape); { CollisionShape suppShape = new BoxShape(new IndexedVector3(0.5f, 0.1f, 0.5f)); //localTrans effectively shifts the center of mass with respect to the chassis IndexedMatrix suppLocalTrans = IndexedMatrix.CreateTranslation(0f, 1.0f, 2.5f); compound.AddChildShape(ref suppLocalTrans, suppShape); } tr._origin = IndexedVector3.Zero; m_carChassis = LocalCreateRigidBody(800f, ref tr, compound);//chassisShape); //m_carChassis = LocalCreateRigidBody(800f, ref tr, chassisShape);//chassisShape); //CollisionShape liftShape = new BoxShape(new IndexedVector3(0.5f, 2.0f, 0.05f)); //m_collisionShapes.Add(liftShape); //m_liftStartPos = new IndexedVector3(0.0f, 2.5f, 3.05f); //IndexedMatrix liftTrans = IndexedMatrix.CreateTranslation(m_liftStartPos); //m_liftBody = LocalCreateRigidBody(10f, ref liftTrans, liftShape); //IndexedMatrix localA = MathUtil.SetEulerZYX(0f, MathUtil.SIMD_HALF_PI, 0f); //localA._origin = new IndexedVector3(0f, 1.0f, 3.05f); //IndexedMatrix localB = MathUtil.SetEulerZYX(0f, MathUtil.SIMD_HALF_PI, 0f); //localB._origin = new IndexedVector3(0f, -1.5f, -0.05f); //m_liftHinge = new HingeConstraint(m_carChassis, m_liftBody, ref localA, ref localB); //// m_liftHinge.setLimit(-LIFT_EPS, LIFT_EPS); //m_liftHinge.SetLimit(0.0f, 0.0f); //m_dynamicsWorld.AddConstraint(m_liftHinge, true); //CompoundShape forkCompound = new CompoundShape(); //m_collisionShapes.Add(forkCompound); //IndexedMatrix forkLocalTrans = IndexedMatrix.Identity; //CollisionShape forkShapeA = new BoxShape(new IndexedVector3(1.0f, 0.1f, 0.1f)); //m_collisionShapes.Add(forkShapeA); //forkCompound.AddChildShape(ref forkLocalTrans, forkShapeA); //CollisionShape forkShapeB = new BoxShape(new IndexedVector3(0.1f, 0.02f, 0.6f)); //m_collisionShapes.Add(forkShapeB); //forkLocalTrans = IndexedMatrix.CreateTranslation(-0.9f, -0.08f, 0.7f); //forkCompound.AddChildShape(ref forkLocalTrans, forkShapeB); //CollisionShape forkShapeC = new BoxShape(new IndexedVector3(0.1f, 0.02f, 0.6f)); //m_collisionShapes.Add(forkShapeC); //forkLocalTrans = IndexedMatrix.CreateTranslation(0.9f, -0.08f, 0.7f); //forkCompound.AddChildShape(ref forkLocalTrans, forkShapeC); //m_forkStartPos = new IndexedVector3(0.0f, 0.6f, 3.2f); //IndexedMatrix forkTrans = IndexedMatrix.CreateTranslation(m_forkStartPos); //m_forkBody = LocalCreateRigidBody(5f, ref forkTrans, forkCompound); //localA = MathUtil.SetEulerZYX(0f, 0f, MathUtil.SIMD_HALF_PI); //localA._origin = new IndexedVector3(0.0f, -1.9f, 0.05f); //IndexedVector3 col0 = MathUtil.matrixColumn(ref localA, 0); //IndexedVector3 col1 = MathUtil.matrixColumn(ref localA, 1); //IndexedVector3 col2 = MathUtil.matrixColumn(ref localA, 2); ////localB = MathUtil.setEulerZYX(0f, 0f, MathUtil.SIMD_HALF_PI); //localB = MathUtil.SetEulerZYX(0f, 0f, MathUtil.SIMD_HALF_PI); //localB._origin = new IndexedVector3(0.0f, 0.0f, -0.1f); //m_forkSlider = new SliderConstraint(m_liftBody, m_forkBody, ref localA, ref localB, true); //m_forkSlider.SetLowerLinLimit(0.1f); //m_forkSlider.SetUpperLinLimit(0.1f); //// m_forkSlider.setLowerAngLimit(-LIFT_EPS); //// m_forkSlider.setUpperAngLimit(LIFT_EPS); //m_forkSlider.SetLowerAngLimit(0.0f); //m_forkSlider.SetUpperAngLimit(0.0f); //IndexedMatrix localAVec = IndexedMatrix.Identity; //IndexedMatrix localBVec = IndexedMatrix.Identity; //m_forkSlider2 = new HingeConstraint(m_liftBody, m_forkBody, ref localAVec, ref localBVec); //m_dynamicsWorld.AddConstraint(m_forkSlider, true); //m_dynamicsWorld.addConstraint(m_forkSlider2, true); CompoundShape loadCompound = new CompoundShape(true); m_collisionShapes.Add(loadCompound); CollisionShape loadShapeA = new BoxShape(new IndexedVector3(2.0f, 0.5f, 0.5f)); m_collisionShapes.Add(loadShapeA); IndexedMatrix loadTrans = IndexedMatrix.Identity; loadCompound.AddChildShape(ref loadTrans, loadShapeA); CollisionShape loadShapeB = new BoxShape(new IndexedVector3(0.1f, 1.0f, 1.0f)); m_collisionShapes.Add(loadShapeB); loadTrans = IndexedMatrix.CreateTranslation(2.1f, 0.0f, 0.0f); loadCompound.AddChildShape(ref loadTrans, loadShapeB); CollisionShape loadShapeC = new BoxShape(new IndexedVector3(0.1f, 1.0f, 1.0f)); m_collisionShapes.Add(loadShapeC); loadTrans = IndexedMatrix.CreateTranslation(-2.1f, 0.0f, 0.0f); loadCompound.AddChildShape(ref loadTrans, loadShapeC); m_loadStartPos = new IndexedVector3(0.0f, -3.5f, 7.0f); loadTrans = IndexedMatrix.CreateTranslation(m_loadStartPos); m_loadBody = LocalCreateRigidBody(4f, ref loadTrans, loadCompound); #if false { CollisionShape liftShape = new BoxShape(new IndexedVector3(0.5f, 2.0f, 0.05f)); m_collisionShapes.Add(liftShape); IndexedMatrix liftTrans = IndexedMatrix.CreateTranslation(m_liftStartPos); m_liftBody = localCreateRigidBody(10f, ref liftTrans, liftShape); IndexedMatrix localA = MathUtil.setEulerZYX(0f, MathUtil.SIMD_HALF_PI, 0f); localA._origin = new IndexedVector3(0f, 1.0f, 3.05f); IndexedMatrix localB = MathUtil.setEulerZYX(0f, MathUtil.SIMD_HALF_PI, 0f); localB._origin = new IndexedVector3(0f, -1.5f, -0.05f); m_liftHinge = new HingeConstraint(m_carChassis, m_liftBody, ref localA, ref localB); // m_liftHinge.setLimit(-LIFT_EPS, LIFT_EPS); m_liftHinge.setLimit(0.0f, 0.0f); m_dynamicsWorld.addConstraint(m_liftHinge, true); CollisionShape forkShapeA = new BoxShape(new IndexedVector3(1.0f, 0.1f, 0.1f)); m_collisionShapes.Add(forkShapeA); CompoundShape forkCompound = new CompoundShape(); m_collisionShapes.Add(forkCompound); IndexedMatrix forkLocalTrans = IndexedMatrix.Identity; forkCompound.addChildShape(ref forkLocalTrans, forkShapeA); CollisionShape forkShapeB = new BoxShape(new IndexedVector3(0.1f, 0.02f, 0.6f)); m_collisionShapes.Add(forkShapeB); forkLocalTrans = IndexedMatrix.CreateTranslation(-0.9f, -0.08f, 0.7f); forkCompound.addChildShape(ref forkLocalTrans, forkShapeB); CollisionShape forkShapeC = new BoxShape(new IndexedVector3(0.1f, 0.02f, 0.6f)); m_collisionShapes.Add(forkShapeC); forkLocalTrans = IndexedMatrix.CreateTranslation(0.9f, -0.08f, 0.7f); forkCompound.addChildShape(ref forkLocalTrans, forkShapeC); m_forkStartPos = new IndexedVector3(0.0f, 0.6f, 3.2f); IndexedMatrix forkTrans = IndexedMatrix.CreateTranslation(m_forkStartPos); m_forkBody = localCreateRigidBody(5f, ref forkTrans, forkCompound); localA = MathUtil.setEulerZYX(0f, 0f, MathUtil.SIMD_HALF_PI); localA._origin = new IndexedVector3(0.0f, -1.9f, 0.05f); localB = MathUtil.setEulerZYX(0f, 0f, MathUtil.SIMD_HALF_PI); localB._origin = new IndexedVector3(0.0f, 0.0f, -0.1f); m_forkSlider = new SliderConstraint(m_liftBody, m_forkBody, ref localA, ref localB, true); m_forkSlider.setLowerLinLimit(0.1f); m_forkSlider.setUpperLinLimit(0.1f); // m_forkSlider.setLowerAngLimit(-LIFT_EPS); // m_forkSlider.setUpperAngLimit(LIFT_EPS); m_forkSlider.setLowerAngLimit(0.0f); m_forkSlider.setUpperAngLimit(0.0f); m_dynamicsWorld.addConstraint(m_forkSlider, true); CompoundShape loadCompound = new CompoundShape(); m_collisionShapes.Add(loadCompound); CollisionShape loadShapeA = new BoxShape(new IndexedVector3(2.0f, 0.5f, 0.5f)); m_collisionShapes.Add(loadShapeA); IndexedMatrix loadTrans = IndexedMatrix.Identity; loadCompound.addChildShape(ref loadTrans, loadShapeA); CollisionShape loadShapeB = new BoxShape(new IndexedVector3(0.1f, 1.0f, 1.0f)); m_collisionShapes.Add(loadShapeB); loadTrans = IndexedMatrix.CreateTranslation(2.1f, 0.0f, 0.0f); loadCompound.addChildShape(ref loadTrans, loadShapeB); CollisionShape loadShapeC = new BoxShape(new IndexedVector3(0.1f, 1.0f, 1.0f)); m_collisionShapes.Add(loadShapeC); loadTrans = IndexedMatrix.CreateTranslation(-2.1f, 0.0f, 0.0f); loadCompound.addChildShape(ref loadTrans, loadShapeC); m_loadStartPos = new IndexedVector3(0.0f, -3.5f, 7.0f); loadTrans = IndexedMatrix.CreateTranslation(m_loadStartPos); m_loadBody = localCreateRigidBody(4f, ref loadTrans, loadCompound); } #endif //m_carChassis.setDamping(0.2f, 0.2f); ClientResetScene(); /// create vehicle SetCameraDistance(26.0f); SetTexturing(true); SetShadows(true); }
protected override void Initialize() { base.Initialize(); SetCameraDistance(50.0f); ///collision configuration contains default setup for memory, collision setup m_collisionConfiguration = new DefaultCollisionConfiguration(); //m_collisionConfiguration.setConvexConvexMultipointIterations(); ///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(); ///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded) m_constraintSolver = new SequentialImpulseConstraintSolver(); m_dynamicsWorld = new DiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_constraintSolver, m_collisionConfiguration); IndexedVector3 gravity = new IndexedVector3(0, -10, 0); m_dynamicsWorld.SetGravity(ref gravity); // NEW => btGhostPairCallback ================================= m_ghostPairCallback = new GhostPairCallback(); m_dynamicsWorld.GetBroadphase().GetOverlappingPairCache().SetInternalGhostPairCallback(m_ghostPairCallback); // Needed once to enable ghost objects inside Bullet // NEW => btGhostObject ======================================= m_ghostObject = new GhostObject(); CollisionShape shape = new BoxShape(new IndexedVector3(5f)); // As far as I know only the world aabb of the shape will be used (i.e. a box always parallel to the x,y,z axis of variable size) m_collisionShapes.Add(shape); m_ghostObject.SetCollisionShape(shape); m_ghostObject.SetCollisionFlags(CollisionFlags.CF_NO_CONTACT_RESPONSE); // We can choose to make it "solid" if we want... m_dynamicsWorld.AddCollisionObject(m_ghostObject, CollisionFilterGroups.SensorTrigger, CollisionFilterGroups.AllFilter & ~CollisionFilterGroups.SensorTrigger); //m_ghostObject.setWorldTransform(btTransform(btQuaternion::getIdentity(),btVector3(0,5,-15))); IndexedMatrix im = IndexedMatrix.CreateFromQuaternion(quatDeg45Y); im._origin = new IndexedVector3(0, 5, -15); m_ghostObject.SetWorldTransform(im); // NEW => btPairCachingGhostObject ============================ m_pairCachingGhostObject = new PairCachingGhostObject(); shape = new ConeShape(7.0f, 14.0f); m_collisionShapes.Add(shape); m_pairCachingGhostObject.SetCollisionShape(shape); m_pairCachingGhostObject.SetCollisionFlags(CollisionFlags.CF_NO_CONTACT_RESPONSE); // We can choose to make it "solid" if we want... m_dynamicsWorld.AddCollisionObject(m_pairCachingGhostObject, CollisionFilterGroups.SensorTrigger, CollisionFilterGroups.AllFilter & ~CollisionFilterGroups.SensorTrigger); //m_pairCachingGhostObject.setWorldTransform(btTransform(btQuaternion::getIdentity(),btVector3(0,5,15))); im._origin = new IndexedVector3(0, 7, 15); m_pairCachingGhostObject.SetWorldTransform(im); //============================================================= ///create a few basic rigid bodies CollisionShape groundShape = new BoxShape(new IndexedVector3(50)); m_collisionShapes.Add(groundShape); IndexedMatrix groundTransform = IndexedMatrix.Identity; groundTransform._origin = new IndexedVector3(0, -50, 0); float mass = 0.0f; LocalCreateRigidBody(mass, groundTransform, groundShape); // spawn some cubes (code pasted from appBasicDemo...) if(true) { //create a few dynamic rigidbodies CollisionShape colShape = new BoxShape(new IndexedVector3(SCALING, SCALING, SCALING)); //btCollisionShape* colShape = new btSphereShape(btScalar(1.)); //CollisionShape colShape = new CylinderShape(new IndexedVector3(1f, 1, 1f)); m_collisionShapes.Add(colShape); /// Create Dynamic Objects IndexedMatrix startTransform = IndexedMatrix.Identity; mass = 1f; //rigidbody is dynamic if and only if mass is non zero, otherwise static bool isDynamic = mass != 0f; IndexedVector3 localInertia = IndexedVector3.Zero; if (isDynamic) { colShape.CalculateLocalInertia(mass, out localInertia); } float start_x = START_POS_X - ARRAY_SIZE_X / 2; float start_y = START_POS_Y; float start_z = START_POS_Z - ARRAY_SIZE_Z / 2; for (int k = 0; k < ARRAY_SIZE_Y; k++) { for (int i = 0; i < ARRAY_SIZE_X; i++) { for (int j = 0; j < ARRAY_SIZE_Z; j++) { startTransform._origin = (new IndexedVector3(2.0f * i + start_x, 20 + 2.0f * k + start_y, 2.0f * j + start_z) * SCALING); //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects DefaultMotionState myMotionState = new DefaultMotionState(startTransform, IndexedMatrix.Identity); RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(mass, myMotionState, colShape, localInertia); RigidBody body = new RigidBody(rbInfo); //body.setContactProcessingThreshold(colShape.getContactBreakingThreshold()); body.SetActivationState(ActivationState.ISLAND_SLEEPING); m_dynamicsWorld.AddRigidBody(body); body.SetActivationState(ActivationState.ISLAND_SLEEPING); body.SetUserPointer(String.Format("Box X{0} Y{1} Z{2}", k, i, j)); } } } } ClientResetScene(); }
public override void InitializeDemo() { //maxiterations = 10; SetCameraDistance(SCALING * 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); IOverlappingPairCache pairCache = null; //pairCache = new SortedOverlappingPairCache(); pairCache = new HashedOverlappingPairCache(); m_broadphase = new DbvtBroadphase(pairCache); //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); 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)); float mass = 0f; float topY = 2.5f; float bottomY = 0.5f; float diff = 10f; float left = -(diff / 2f); float right = -left; LocalCreateRigidBody(mass, ref groundTransform, groundShape); { /// Create Dynamic Objects IndexedMatrix startTransform = IndexedMatrix.Identity; mass = 0f; //rigidbody is dynamic if and only if mass is non zero, otherwise static bool isDynamic = mass != 0f; RigidBody rb = null; //startTransform._origin = new IndexedVector3(left, topY, 0); //collisionTopLeftCorner = BuildCorner(vertices, topLeft); //rb = LocalCreateRigidBody(0f, startTransform, collisionTopLeftCorner); //rb.SetUserPointer("TopLeftCorner"); //startTransform._origin = new IndexedVector3(right, topY, 0); //collisionTopRightCorner = BuildCorner(vertices, topRight); //rb = LocalCreateRigidBody(0f, startTransform, collisionTopRightCorner); //rb.SetUserPointer("TopRightCorner"); startTransform._origin = new IndexedVector3(left, bottomY, 0); collisionBottomLeftCorner = BuildCorner(vertices, bottomLeft); rb = LocalCreateRigidBody(0f, startTransform, collisionBottomLeftCorner); rb.SetUserPointer("BottomLeftCorner"); startTransform._origin = new IndexedVector3(right, bottomY, 0); collisionBottomRightCorner = BuildCorner(vertices, bottomRight); rb = LocalCreateRigidBody(0f, startTransform, collisionBottomRightCorner); rb.SetUserPointer("BottomRightCorner"); startTransform._origin = IndexedVector3.Zero; m_playerSphere = LocalCreateRigidBody(1f, startTransform, new SphereShape(0.25f)); m_playerSphere.SetActivationState(ActivationState.DISABLE_DEACTIVATION); } BulletGlobals.gDebugDraw.SetDebugMode(BulletXNA.LinearMath.DebugDrawModes.DBG_DrawAabb | BulletXNA.LinearMath.DebugDrawModes.DBG_DrawNormals | BulletXNA.LinearMath.DebugDrawModes.DBG_DrawContactPoints); m_dynamicsWorld.SetDebugDrawer(BulletGlobals.gDebugDraw); //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(); }
public override void InitializeDemo() { SetCameraDistance(30f); //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); m_broadphase = new DbvtBroadphase(); IOverlappingPairCache pairCache = null; //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); 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); { int numBlocksTall = 10;//18; //How many 'stories' tall. float blockWidth = 6f; //Total width/length of the tower. float blockHeight = 2f; //create a few dynamic rigidbodies IndexedVector3 extents = new IndexedVector3(blockWidth/3, blockHeight, blockWidth); IndexedVector3 boxHalfExtents = extents * 0.5f; CollisionShape colShape = new BoxShape(boxHalfExtents); //btCollisionShape* colShape = new btSphereShape(btScalar(1.)); //CollisionShape colShape = new CylinderShape(new IndexedVector3(1f, 1, 1f)); //m_collisionShapes.Add(colShape); /// Create Dynamic Objects IndexedMatrix startTransform = IndexedMatrix.Identity; mass = 1f; //rigidbody is dynamic if and only if mass is non zero, otherwise static bool isDynamic = mass != 0f; IndexedVector3 localInertia = IndexedVector3.Zero; if (isDynamic) { colShape.CalculateLocalInertia(mass, out localInertia); } //The default number of iterations is 10, which works fine, but this demo //is all about stability (it's jenga!). Increase the iterations a bit. //Even though it's using twice as many iterations, it will early-out //before reaching the limit MOST of the time. //It's still pretty playable at around 7-8 max iterations, though. IndexedMatrix transform = IndexedMatrix.Identity; for (int i = 0; i < numBlocksTall; i++) { if (i % 2 == 0) { for (int j = 0; j < 3; j++) { transform = IndexedMatrix.Identity; IndexedVector3 position = new IndexedVector3(j * (blockWidth/3) - blockWidth/3, blockHeight / 2 + i * (blockHeight), 0); //position += boxHalfExtents; transform._origin = position; RigidBody rb = LocalCreateRigidBody(mass, transform, colShape); rb.SetActivationState(ActivationState.ISLAND_SLEEPING); } } else { transform = IndexedMatrix.CreateRotationY(MathUtil.SIMD_HALF_PI); for (int j = 0; j < 3; j++) { IndexedVector3 position = new IndexedVector3(0, blockHeight / 2 + (i) * (blockHeight), j * (blockWidth / 3) - blockWidth / 3f); transform._origin = position; //position += boxHalfExtents; transform._origin = position; RigidBody rb = LocalCreateRigidBody(mass, transform, colShape); rb.SetActivationState(ActivationState.ISLAND_SLEEPING); } } } //game.Camera.Position = new Vector3(0, 5, 15); } ClientResetScene(); }
public override void InitializeDemo() { //string filename = @"C:\users\man\bullet\xna-motor-output.txt"; //FileStream filestream = File.Open(filename, FileMode.Create, FileAccess.Write, FileShare.Read); //BulletGlobals.g_streamWriter = new StreamWriter(filestream); m_Time = 0; m_fCyclePeriod = 2000.0f; // in milliseconds // new SIMD solver for joints clips accumulated impulse, so the new limits for the motor // should be (numberOfsolverIterations * oldLimits) // currently solver uses 10 iterations, so: m_fMuscleStrength = 0.5f; SetCameraDistance(5.0f); m_collisionConfiguration = new DefaultCollisionConfiguration(); m_dispatcher = new CollisionDispatcher(m_collisionConfiguration); m_broadphase = new DbvtBroadphase(); IOverlappingPairCache pairCache = null; m_broadphase = new SimpleBroadphase(1000, pairCache); SequentialImpulseConstraintSolver sol = new SequentialImpulseConstraintSolver(); m_constraintSolver = sol; m_dynamicsWorld = new DiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_constraintSolver, m_collisionConfiguration); IndexedVector3 gravity = new IndexedVector3(0, -10, 0); m_dynamicsWorld.SetGravity(ref gravity); m_dynamicsWorld.SetInternalTickCallback(new MotorPreTickCallback(),this,true); // Setup a big ground box { CollisionShape groundShape = new BoxShape(new IndexedVector3(200.0f,10.0f,200.0f)); m_collisionShapes.Add(groundShape); IndexedMatrix groundTransform = IndexedMatrix.CreateTranslation(0,-10,0); LocalCreateRigidBody(0f,ref groundTransform,groundShape); } // Spawn one ragdoll IndexedVector3 startOffset = new IndexedVector3(1,0.5f,0); SpawnTestRig(ref startOffset, false); startOffset = new IndexedVector3(-2, 0.5f, 0); SpawnTestRig(ref startOffset, true); ClientResetScene(); }
public override void InitializeDemo() { //string filename = @"E:\users\man\bullet\xna-constraint-output.txt"; //FileStream filestream = File.Open(filename, FileMode.Create, FileAccess.Write, FileShare.Read); //BulletGlobals.g_streamWriter = new StreamWriter(filestream); //maxiterations = 100; 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_constraintSolver = new SequentialImpulseConstraintSolver(); m_dynamicsWorld = new DiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_constraintSolver,m_collisionConfiguration); m_dynamicsWorld.SetDebugDrawer(m_debugDraw); SetCameraDistance(26f); //CollisionShape groundShape = new BoxShape(new IndexedVector3(50f, 40f, 50f)); CollisionShape groundShape = new StaticPlaneShape(new IndexedVector3(0, 1, 0), 40); m_collisionShapes.Add(groundShape); IndexedMatrix groundTransform = IndexedMatrix.Identity; groundTransform._origin = new IndexedVector3(0, -56, 0); RigidBody groundBody = LocalCreateRigidBody(0, ref groundTransform, groundShape); CollisionShape shape = new BoxShape(new IndexedVector3(CUBE_HALF_EXTENTS, CUBE_HALF_EXTENTS, CUBE_HALF_EXTENTS)); m_collisionShapes.Add(shape); IndexedMatrix trans = IndexedMatrix.Identity; trans._origin = new IndexedVector3(0, 20, 0); float mass = 1f; #if true //point to point constraint with a breaking threshold { trans = IndexedMatrix.Identity; trans._origin = new IndexedVector3(1,30,-5); LocalCreateRigidBody( mass,trans,shape); trans._origin = new IndexedVector3(0,0,-5); RigidBody body0 = LocalCreateRigidBody( mass,trans,shape); trans._origin = new IndexedVector3(2*CUBE_HALF_EXTENTS,20,0); mass = 1.0f; RigidBody body1 = null;//localCreateRigidBody( mass,trans,shape); IndexedVector3 pivotInA = new IndexedVector3(CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS,0); TypedConstraint p2p = new Point2PointConstraint(body0,ref pivotInA); m_dynamicsWorld.AddConstraint(p2p); p2p.SetBreakingImpulseThreshold(10.2f); p2p.SetDbgDrawSize(5.0f); } #endif #if true //point to point constraint (ball socket) //SEEMS OK { //trans = IndexedMatrix.Identity; RigidBody body0 = LocalCreateRigidBody( mass,ref trans,shape); trans._origin = new IndexedVector3(2*CUBE_HALF_EXTENTS,20,0); mass = 1f; RigidBody body1 = null;//localCreateRigidBody( mass,trans,shape); IndexedVector3 pivotInA = new IndexedVector3(CUBE_HALF_EXTENTS,-CUBE_HALF_EXTENTS,-CUBE_HALF_EXTENTS); IndexedVector3 axisInA = new IndexedVector3(0,0,1); IndexedVector3 pivotInB = body1 != null ? body1.GetCenterOfMassTransform().Inverse() * (body0.GetCenterOfMassTransform() * (pivotInA)) : pivotInA; IndexedVector3 axisInB = body1 != null ? (body1.GetCenterOfMassTransform()._basis.Inverse() * (body1.GetCenterOfMassTransform()._basis * axisInA)) : body0.GetCenterOfMassTransform()._basis * axisInA; #if P2P TypedConstraint p2p = new Point2PointConstraint(body0,ref pivotInA); //btTypedConstraint* p2p = new btPoint2PointConstraint(*body0,*body1,pivotInA,pivotInB); //btTypedConstraint* hinge = new btHingeConstraint(*body0,*body1,pivotInA,pivotInB,axisInA,axisInB); m_dynamicsWorld.AddConstraint(p2p); p2p.SetDbgDrawSize(5.0f); #else HingeConstraint hinge = new HingeConstraint(body0,ref pivotInA,ref axisInA,false); float targetVelocity = 1f; float maxMotorImpulse = 1.0f; hinge.EnableAngularMotor(true,targetVelocity,maxMotorImpulse); m_dynamicsWorld.AddConstraint(hinge);//p2p); hinge.SetDbgDrawSize(5f); #endif } #endif #if true //create a slider, using the generic D6 constraint // SEEMS OK { mass = 1f; IndexedVector3 sliderWorldPos = new IndexedVector3(0,10,0); IndexedVector3 sliderAxis = new IndexedVector3(1,0,0); float angle=0f;//SIMD_RADS_PER_DEG * 10.f; IndexedBasisMatrix sliderOrientation = new IndexedBasisMatrix(new IndexedQuaternion(sliderAxis,angle)); trans = IndexedMatrix.Identity; trans._origin = sliderWorldPos; //trans.setBasis(sliderOrientation); sliderTransform = trans; d6body0 = LocalCreateRigidBody( mass,ref trans,shape); d6body0.SetActivationState(ActivationState.DISABLE_DEACTIVATION); RigidBody fixedBody1 = LocalCreateRigidBody(0,ref trans,null); m_dynamicsWorld.AddRigidBody(fixedBody1); IndexedMatrix frameInA, frameInB; frameInA = IndexedMatrix.Identity; frameInB = IndexedMatrix.Identity; frameInA._origin = new IndexedVector3(0, 5, 0); frameInB._origin = new IndexedVector3(0, 5, 0); // bool useLinearReferenceFrameA = false;//use fixed frame B for linear llimits bool useLinearReferenceFrameA = true;//use fixed frame A for linear llimits spSlider6Dof = new Generic6DofConstraint(fixedBody1, d6body0,ref frameInA,ref frameInB,useLinearReferenceFrameA); spSlider6Dof.SetLinearLowerLimit(ref lowerSliderLimit); spSlider6Dof.SetLinearUpperLimit(ref hiSliderLimit); //range should be small, otherwise singularities will 'explode' the constraint IndexedVector3 angularLower = new IndexedVector3(-1.5f,0,0); IndexedVector3 angularUpper = -angularLower; spSlider6Dof.SetAngularLowerLimit(ref angularLower); spSlider6Dof.SetAngularUpperLimit(ref angularUpper); // slider.setAngularLowerLimit(IndexedVector3(0,0,0)); // slider.setAngularUpperLimit(IndexedVector3(0,0,0)); spSlider6Dof.SetAngularLowerLimit(new IndexedVector3(-MathUtil.SIMD_PI, 0, 0)); spSlider6Dof.SetAngularUpperLimit(new IndexedVector3(1.5f, 0, 0)); spSlider6Dof.GetTranslationalLimitMotor().m_enableMotor[0] = true; spSlider6Dof.GetTranslationalLimitMotor().m_targetVelocity.X = -5.0f; spSlider6Dof.GetTranslationalLimitMotor().m_maxMotorForce.X = 0.1f; m_dynamicsWorld.AddConstraint(spSlider6Dof); spSlider6Dof.SetDbgDrawSize(5f); } #endif #if true { // create a door using hinge constraint attached to the world CollisionShape pDoorShape = new BoxShape(new IndexedVector3(2.0f, 5.0f, 0.2f)); m_collisionShapes.Add(pDoorShape); IndexedMatrix doorTrans = IndexedMatrix.Identity; doorTrans._origin = new IndexedVector3(-5.0f, -2.0f, 0.0f); RigidBody pDoorBody = LocalCreateRigidBody( 1.0f, ref doorTrans, pDoorShape); pDoorBody.SetActivationState(ActivationState.DISABLE_DEACTIVATION); IndexedVector3 btPivotA = new IndexedVector3( 10f+2.1f, -2.0f, 0.0f ); // right next to the door slightly outside IndexedVector3 btAxisA = new IndexedVector3( 0.0f, 1.0f, 0.0f ); // pointing upwards, aka Y-axis spDoorHinge = new HingeConstraint( pDoorBody, ref btPivotA, ref btAxisA,false ); spDoorHinge.SetLimit(-MathUtil.SIMD_PI * 0.25f, MathUtil.SIMD_PI * 0.25f); m_dynamicsWorld.AddConstraint(spDoorHinge); spDoorHinge.SetDbgDrawSize(5.0f); } #endif #if true { // create a generic 6DOF constraint // SEEMS OK - But debug draw a bit wrong? IndexedMatrix tr = IndexedMatrix.Identity; tr._origin = new IndexedVector3(10f, 6f, 0f); //tr.getBasis().setEulerZYX(0,0,0); // RigidBody pBodyA = localCreateRigidBody( mass, tr, shape); RigidBody pBodyA = LocalCreateRigidBody( 0.0f, ref tr, shape); // RigidBody pBodyA = localCreateRigidBody( 0.0, tr, 0); pBodyA.SetActivationState(ActivationState.DISABLE_DEACTIVATION); tr = IndexedMatrix.Identity; tr._origin = new IndexedVector3(0f, 6f, 0f); //tr.getBasis().setEulerZYX(0,0,0); RigidBody pBodyB = LocalCreateRigidBody(mass, ref tr, shape); pBodyB.SetActivationState(ActivationState.DISABLE_DEACTIVATION); IndexedMatrix frameInA, frameInB; frameInA = IndexedMatrix.CreateTranslation(-5,0,0); frameInB = IndexedMatrix.CreateTranslation(5,0,0); Generic6DofConstraint pGen6DOF = new Generic6DofConstraint(pBodyA, pBodyB, ref frameInA, ref frameInB, true); // btGeneric6DofConstraint* pGen6DOF = new btGeneric6DofConstraint(*pBodyA, *pBodyB, frameInA, frameInB, false); IndexedVector3 linearLower = new IndexedVector3(-10, -2, -1); pGen6DOF.SetLinearLowerLimit(ref linearLower); IndexedVector3 linearUpper = new IndexedVector3(10,2,1); pGen6DOF.SetLinearUpperLimit(ref linearUpper); // ? why again? //linearLower = new IndexedVector3(-10,0,0); //pGen6DOF.setLinearLowerLimit(ref linearLower); // pGen6DOF.setLinearUpperLimit(IndexedVector3(10., 0., 0.)); // pGen6DOF.setLinearLowerLimit(IndexedVector3(0., 0., 0.)); // pGen6DOF.setLinearUpperLimit(IndexedVector3(0., 0., 0.)); // pGen6DOF.getTranslationalLimitMotor().m_enableMotor[0] = true; // pGen6DOF.getTranslationalLimitMotor().m_targetVelocity[0] = 5.0f; // pGen6DOF.getTranslationalLimitMotor().m_maxMotorForce[0] = 0.1f; // pGen6DOF.setAngularLowerLimit(IndexedVector3(0., SIMD_HALF_PI*0.9, 0.)); // pGen6DOF.setAngularUpperLimit(IndexedVector3(0., -SIMD_HALF_PI*0.9, 0.)); // pGen6DOF.setAngularLowerLimit(IndexedVector3(0., 0., -SIMD_HALF_PI)); // pGen6DOF.setAngularUpperLimit(IndexedVector3(0., 0., SIMD_HALF_PI)); IndexedVector3 angularLower = new IndexedVector3(-MathUtil.SIMD_HALF_PI * 0.5f, -0.75f, -MathUtil.SIMD_HALF_PI * 0.8f); IndexedVector3 angularUpper = -angularLower; pGen6DOF.SetAngularLowerLimit(ref angularLower); pGen6DOF.SetAngularUpperLimit(ref angularUpper); // pGen6DOF.setAngularLowerLimit(IndexedVector3(0.f, -0.75, SIMD_HALF_PI * 0.8f)); // pGen6DOF.setAngularUpperLimit(IndexedVector3(0.f, 0.75, -SIMD_HALF_PI * 0.8f)); // pGen6DOF.setAngularLowerLimit(IndexedVector3(0.f, -SIMD_HALF_PI * 0.8f, SIMD_HALF_PI * 1.98f)); // pGen6DOF.setAngularUpperLimit(IndexedVector3(0.f, SIMD_HALF_PI * 0.8f, -SIMD_HALF_PI * 1.98f)); // pGen6DOF.setAngularLowerLimit(IndexedVector3(-0.75,-0.5, -0.5)); // pGen6DOF.setAngularUpperLimit(IndexedVector3(0.75,0.5, 0.5)); // pGen6DOF.setAngularLowerLimit(IndexedVector3(-0.75,0., 0.)); // pGen6DOF.setAngularUpperLimit(IndexedVector3(0.75,0., 0.)); m_dynamicsWorld.AddConstraint(pGen6DOF, true); pGen6DOF.SetDbgDrawSize(5.0f); } #endif #if true { // create a ConeTwist constraint IndexedMatrix tr = IndexedMatrix.CreateTranslation(-10,5,0); RigidBody pBodyA = LocalCreateRigidBody( 1.0f, ref tr, shape); pBodyA.SetActivationState(ActivationState.DISABLE_DEACTIVATION); tr = IndexedMatrix.CreateTranslation(-10,-5,0); RigidBody pBodyB = LocalCreateRigidBody(0.0f, ref tr, shape); IndexedMatrix frameInA, frameInB; frameInA = MathUtil.SetEulerZYX(0, 0, MathUtil.SIMD_HALF_PI); frameInA._origin = new IndexedVector3(0, -5, 0); frameInB = MathUtil.SetEulerZYX(0, 0, MathUtil.SIMD_HALF_PI); frameInB._origin = new IndexedVector3(0, 5, 0); ConeTwistConstraint pCT = new ConeTwistConstraint(pBodyA, pBodyB, ref frameInA, ref frameInB); pCT.SetLimit(MathUtil.SIMD_QUARTER_PI * 0.6f, MathUtil.SIMD_QUARTER_PI, MathUtil.SIMD_PI * 0.8f, 0.5f); // soft limit == hard limit m_dynamicsWorld.AddConstraint(pCT, true); pCT.SetDbgDrawSize(5.0f); } #endif #if true { // Hinge connected to the world, with motor (to hinge motor with new and old constraint solver) // WORKS OK IndexedMatrix tr = IndexedMatrix.Identity; RigidBody pBody = LocalCreateRigidBody( 1.0f, ref tr, shape); pBody.SetActivationState(ActivationState.DISABLE_DEACTIVATION); IndexedVector3 btPivotA = new IndexedVector3( 10.0f, 0.0f, 0.0f ); IndexedVector3 btAxisA = new IndexedVector3( 0.0f, 0.0f, 1.0f ); HingeConstraint pHinge = new HingeConstraint(pBody, ref btPivotA, ref btAxisA,false); // pHinge.enableAngularMotor(true, -1.0, 0.165); // use for the old solver pHinge.EnableAngularMotor(true, -1.0f, 1.65f); // use for the new SIMD solver m_dynamicsWorld.AddConstraint(pHinge); pHinge.SetDbgDrawSize(5.0f); } #endif #if true { // WORKS OK // create a universal joint using generic 6DOF constraint // create two rigid bodies // static bodyA (parent) on top: IndexedMatrix tr = IndexedMatrix.CreateTranslation(20,4,0); RigidBody pBodyA = LocalCreateRigidBody( 0.0f, ref tr, shape); pBodyA.SetActivationState(ActivationState.DISABLE_DEACTIVATION); // dynamic bodyB (child) below it : tr = IndexedMatrix.CreateTranslation(20,0,0); RigidBody pBodyB = LocalCreateRigidBody(1.0f, ref tr, shape); pBodyB.SetActivationState(ActivationState.DISABLE_DEACTIVATION); // add some (arbitrary) data to build constraint frames IndexedVector3 parentAxis = new IndexedVector3(1.0f, 0.0f, 0.0f); IndexedVector3 childAxis = new IndexedVector3(0.0f, 0.0f, 1.0f); IndexedVector3 anchor = new IndexedVector3(20.0f, 2.0f, 0.0f); UniversalConstraint pUniv = new UniversalConstraint(pBodyA, pBodyB, ref anchor, ref parentAxis, ref childAxis); pUniv.SetLowerLimit(-MathUtil.SIMD_HALF_PI * 0.5f, -MathUtil.SIMD_HALF_PI * 0.5f); pUniv.SetUpperLimit(MathUtil.SIMD_HALF_PI * 0.5f, MathUtil.SIMD_HALF_PI * 0.5f); // add constraint to world m_dynamicsWorld.AddConstraint(pUniv, true); // draw constraint frames and limits for debugging pUniv.SetDbgDrawSize(5.0f); } #endif #if true // WORKS OK { // create a generic 6DOF constraint with springs IndexedMatrix tr = IndexedMatrix.CreateTranslation(-20f,16f,0f); //tr.setIdentity(); //tr.setOrigin(btVector3(btScalar(-20.), btScalar(16.), btScalar(0.))); //tr.getBasis().setEulerZYX(0,0,0); RigidBody pBodyA = LocalCreateRigidBody( 0.0f, ref tr, shape); pBodyA.SetActivationState(ActivationState.DISABLE_DEACTIVATION); //tr.setIdentity(); //tr.setOrigin(btVector3(btScalar(-10.), btScalar(16.), btScalar(0.))); //tr.getBasis().setEulerZYX(0,0,0); tr = IndexedMatrix.CreateTranslation(-10,16,0); RigidBody pBodyB = LocalCreateRigidBody(1.0f, ref tr, shape); pBodyB.SetActivationState(ActivationState.DISABLE_DEACTIVATION); IndexedMatrix frameInA = IndexedMatrix.CreateTranslation(10f,0f,0f); IndexedMatrix frameInB = IndexedMatrix.CreateTranslation(0f,0f,0f); Generic6DofSpringConstraint pGen6DOFSpring = new Generic6DofSpringConstraint(pBodyA, pBodyB, ref frameInA, ref frameInB, true); pGen6DOFSpring.SetLinearUpperLimit(new IndexedVector3(5f, 0f, 0f)); pGen6DOFSpring.SetLinearLowerLimit(new IndexedVector3(-5f, 0f, 0f)); pGen6DOFSpring.SetAngularLowerLimit(new IndexedVector3(0f, 0f, -1.5f)); pGen6DOFSpring.SetAngularUpperLimit(new IndexedVector3(0f, 0f, 1.5f)); m_dynamicsWorld.AddConstraint(pGen6DOFSpring, true); pGen6DOFSpring.SetDbgDrawSize(5.0f); pGen6DOFSpring.EnableSpring(0, true); pGen6DOFSpring.SetStiffness(0, 39.478f); pGen6DOFSpring.SetDamping(0, 0.5f); pGen6DOFSpring.EnableSpring(5, true); pGen6DOFSpring.SetStiffness(5, 39.478f); pGen6DOFSpring.SetDamping(0, 0.3f); pGen6DOFSpring.SetEquilibriumPoint(); } #endif #if true { // WORKS OK // create a Hinge2 joint // create two rigid bodies // static bodyA (parent) on top: IndexedMatrix tr = IndexedMatrix.CreateTranslation(-20f,4f,0f); RigidBody pBodyA = LocalCreateRigidBody( 0.0f, ref tr, shape); pBodyA.SetActivationState(ActivationState.DISABLE_DEACTIVATION); // dynamic bodyB (child) below it : tr = IndexedMatrix.CreateTranslation(-20f,0f,0f); RigidBody pBodyB = LocalCreateRigidBody(1.0f, ref tr, shape); pBodyB.SetActivationState(ActivationState.DISABLE_DEACTIVATION); // add some data to build constraint frames IndexedVector3 parentAxis = new IndexedVector3(0.0f, 1.0f, 0.0f); IndexedVector3 childAxis = new IndexedVector3(1.0f, 0.0f, 0.0f); IndexedVector3 anchor = new IndexedVector3(-20.0f, 0.0f, 0.0f); Hinge2Constraint pHinge2 = new Hinge2Constraint(pBodyA, pBodyB, ref anchor, ref parentAxis, ref childAxis); pHinge2.SetLowerLimit(-MathUtil.SIMD_HALF_PI * 0.5f); pHinge2.SetUpperLimit(MathUtil.SIMD_HALF_PI * 0.5f); // add constraint to world m_dynamicsWorld.AddConstraint(pHinge2, true); // draw constraint frames and limits for debugging pHinge2.SetDbgDrawSize(5.0f); } #endif #if true { // WORKS OK // create a Hinge joint between two dynamic bodies // create two rigid bodies // static bodyA (parent) on top: IndexedMatrix tr = IndexedMatrix.CreateTranslation(-20f,-2f,0f); RigidBody pBodyA = LocalCreateRigidBody( 1.0f, ref tr, shape); pBodyA.SetActivationState(ActivationState.DISABLE_DEACTIVATION); // dynamic bodyB: tr = IndexedMatrix.CreateTranslation(-30f,-2f,0f); RigidBody pBodyB = LocalCreateRigidBody(10.0f, ref tr, shape); pBodyB.SetActivationState(ActivationState.DISABLE_DEACTIVATION); // add some data to build constraint frames IndexedVector3 axisA = new IndexedVector3(0.0f, 1.0f, 0.0f); IndexedVector3 axisB = new IndexedVector3(0.0f, 1.0f, 0.0f); IndexedVector3 pivotA = new IndexedVector3(-5.0f, 0.0f, 0.0f); IndexedVector3 pivotB = new IndexedVector3(5.0f, 0.0f, 0.0f); spHingeDynAB = new HingeConstraint(pBodyA, pBodyB, ref pivotA, ref pivotB, ref axisA, ref axisB); spHingeDynAB.SetLimit(-MathUtil.SIMD_HALF_PI * 0.5f, MathUtil.SIMD_HALF_PI * 0.5f); // add constraint to world m_dynamicsWorld.AddConstraint(spHingeDynAB, true); // draw constraint frames and limits for debugging spHingeDynAB.SetDbgDrawSize(5.0f); } #endif #if true { // 6DOF connected to the world, with motor IndexedMatrix tr = IndexedMatrix.CreateTranslation(10,-15,0); RigidBody pBody = LocalCreateRigidBody( 1.0f, ref tr, shape); pBody.SetActivationState(ActivationState.DISABLE_DEACTIVATION); IndexedMatrix frameB = IndexedMatrix.Identity; Generic6DofConstraint pGen6Dof = new Generic6DofConstraint(pBody, ref frameB, false ); m_dynamicsWorld.AddConstraint(pGen6Dof); pGen6Dof.SetDbgDrawSize(5.0f); pGen6Dof.SetAngularLowerLimit(new IndexedVector3(0,0,0)); pGen6Dof.SetAngularUpperLimit(new IndexedVector3(0,0,0)); pGen6Dof.SetLinearLowerLimit(new IndexedVector3(-10.0f, 0, 0)); pGen6Dof.SetLinearUpperLimit(new IndexedVector3(10.0f, 0, 0)); pGen6Dof.GetTranslationalLimitMotor().m_enableMotor[0] = true; pGen6Dof.GetTranslationalLimitMotor().m_targetVelocity[0] = 5.0f; pGen6Dof.GetTranslationalLimitMotor().m_maxMotorForce[0] = 0.1f; } #endif }
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(); }
// Portable static method: prerequisite call: m_dynamicsWorld.getBroadphase().getOverlappingPairCache().setInternalGhostPairCallback(new btGhostPairCallback()); public static void GetCollidingObjectsInsidePairCachingGhostObject(DiscreteDynamicsWorld m_dynamicsWorld, PairCachingGhostObject m_pairCachingGhostObject, ObjectArray<CollisionObject> collisionArrayOut) { bool addOnlyObjectsWithNegativeDistance = true; // With "false" things don't change much, and the code is a bit faster and cleaner... collisionArrayOut.Resize(0); if (m_pairCachingGhostObject == null || m_dynamicsWorld == null) return; //#define USE_PLAIN_COLLISION_WORLD // We dispatch all collision pairs of the ghost object every step (slow) #if USE_PLAIN_COLLISION_WORLD //====================================================================================================== // I thought this line was no longer needed, but it seems to be necessary (and I believe it's an expensive call): m_dynamicsWorld.getDispatcher().dispatchAllCollisionPairs(m_pairCachingGhostObject.getOverlappingPairCache(), m_dynamicsWorld.getDispatchInfo(), m_dynamicsWorld.getDispatcher()); // Maybe the call can be automatically triggered by some other Bullet call (I'm almost sure I could comment it out in another demo I made long ago...) // So by now the general rule is: in real projects, simply comment it out and see if it works! //====================================================================================================== // UPDATE: in dynamic worlds, the line above can be commented out and the broadphase pair can be retrieved through the call to findPair(...) below. // In collision worlds probably the above line is needed only if collision detection for all the bodies hasn't been made... This is something // I'm still not sure of... the general rule is to try to comment out the line above and try to use findPair(...) and see if it works whenever possible.... //====================================================================================================== #endif //USE_PLAIN_COLLISION_WORLD ObjectArray<BroadphasePair> collisionPairs = m_pairCachingGhostObject.GetOverlappingPairCache().GetOverlappingPairArray(); int numObjects = collisionPairs.Count; PersistentManifoldArray m_manifoldArray = new PersistentManifoldArray(); bool added; for (int i = 0; i < numObjects; i++) { m_manifoldArray.Resize(0); #if USE_PLAIN_COLLISION_WORLD const btBroadphasePair& collisionPair = collisionPairs[i]; if (collisionPair.m_algorithm) collisionPair.m_algorithm.getAllContactManifolds(m_manifoldArray); else { // THIS SHOULD NEVER HAPPEN, AND IF IT DOES, PLEASE RE-ENABLE the "call" a few lines above... printf("No collisionPair.m_algorithm - probably m_dynamicsWorld.getDispatcher().dispatchAllCollisionPairs(...) must be missing.\n"); } #else // USE_PLAIN_COLLISION_WORLD BroadphasePair cPair = collisionPairs[i]; //unless we manually perform collision detection on this pair, the contacts are in the dynamics world paircache: BroadphasePair collisionPair = m_dynamicsWorld.GetPairCache().FindPair(cPair.m_pProxy0, cPair.m_pProxy1); if (collisionPair == null) { continue; } if (collisionPair.m_algorithm != null) { collisionPair.m_algorithm.GetAllContactManifolds(m_manifoldArray); } else { // THIS SHOULD NEVER HAPPEN, AND IF IT DOES, PLEASE RE-ENABLE the "call" a few lines above... //printf("No collisionPair.m_algorithm - probably m_dynamicsWorld.getDispatcher().dispatchAllCollisionPairs(...) must be missing.\n"); } #endif //USE_PLAIN_COLLISION_WORLD added = false; for (int j = 0; j < m_manifoldArray.Count; j++) { PersistentManifold manifold = m_manifoldArray[j]; // Here we are in the narrowphase, but can happen that manifold.getNumContacts()==0: if (addOnlyObjectsWithNegativeDistance) { for (int p = 0, numContacts = manifold.GetNumContacts(); p < numContacts; p++) { ManifoldPoint pt = manifold.GetContactPoint(p); if (pt.GetDistance() < 0.0) { // How can I be sure that the colObjs are all distinct ? I use the "added" flag. collisionArrayOut.Add((CollisionObject)(manifold.GetBody0() == m_pairCachingGhostObject ? manifold.GetBody1() : manifold.GetBody0())); added = true; break; } } if (added) { break; } } else if (manifold.GetNumContacts() > 0) { collisionArrayOut.Add((CollisionObject)(manifold.GetBody0() == m_pairCachingGhostObject ? manifold.GetBody1() : manifold.GetBody0())); break; } } } }
public override void InitializeDemo() { m_cameraDistance = 10.0f; //string filename = @"e:\users\man\bullet\gimpact-demo-xna.txt"; //FileStream filestream = File.Open(filename, FileMode.Create, FileAccess.Write, FileShare.Read); //BulletGlobals.g_streamWriter = new StreamWriter(filestream); /// Init Bullet m_collisionConfiguration = new DefaultCollisionConfiguration(); m_dispatcher = new CollisionDispatcher(m_collisionConfiguration); //btOverlappingPairCache* broadphase = new btSimpleBroadphase(); //m_broadphase = new btSimpleBroadphase(); int maxProxies = 1024; IndexedVector3 worldAabbMin = new IndexedVector3(-10000, -10000, -10000); IndexedVector3 worldAabbMax = new IndexedVector3(10000, 10000, 10000); m_broadphase = new AxisSweep3Internal(ref worldAabbMin, ref worldAabbMax, 0xfffe, 0xffff, 16384, null, false); //m_broadphase = new SimpleBroadphase(16384,null); m_constraintSolver = new SequentialImpulseConstraintSolver(); m_dynamicsWorld = new DiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_constraintSolver, m_collisionConfiguration); //create trimesh model and shape InitGImpactCollision(); /// Create Scene float mass = 0.0f; IndexedMatrix startTransform = IndexedMatrix.Identity; CollisionShape staticboxShape1 = new BoxShape(new IndexedVector3(200, 1, 200));//floor staticboxShape1.SetUserPointer("Floor"); CollisionShape staticboxShape2 = new BoxShape(new IndexedVector3(1, 50, 200));//left wall staticboxShape1.SetUserPointer("LeftWall"); CollisionShape staticboxShape3 = new BoxShape(new IndexedVector3(1, 50, 200));//right wall staticboxShape1.SetUserPointer("RightWall"); CollisionShape staticboxShape4 = new BoxShape(new IndexedVector3(200, 50, 1));//front wall staticboxShape1.SetUserPointer("FrontWall"); CollisionShape staticboxShape5 = new BoxShape(new IndexedVector3(200, 50, 1));//back wall staticboxShape1.SetUserPointer("BackWall"); CompoundShape staticScenario = new CompoundShape();//static scenario startTransform._origin = new IndexedVector3(0, 0, 0); staticScenario.AddChildShape(ref startTransform, staticboxShape1); startTransform._origin = new IndexedVector3(-200, 25, 0); staticScenario.AddChildShape(ref startTransform, staticboxShape2); startTransform._origin = new IndexedVector3(200, 25, 0); staticScenario.AddChildShape(ref startTransform, staticboxShape3); startTransform._origin = new IndexedVector3(0, 25, 200); staticScenario.AddChildShape(ref startTransform, staticboxShape4); startTransform._origin = new IndexedVector3(0, 25, -200); staticScenario.AddChildShape(ref startTransform, staticboxShape5); startTransform._origin = new IndexedVector3(0, 0, 0); //RigidBody staticBody = LocalCreateRigidBody(mass, startTransform, staticScenario); RigidBody staticBody = LocalCreateRigidBody(mass, startTransform, staticboxShape1); staticBody.SetCollisionFlags(staticBody.GetCollisionFlags()|CollisionFlags.CF_STATIC_OBJECT); //enable custom material callback staticBody.SetCollisionFlags(staticBody.GetCollisionFlags()|CollisionFlags.CF_CUSTOM_MATERIAL_CALLBACK); //static plane IndexedVector3 normal = new IndexedVector3(0.4f,1.5f,-0.4f); normal.Normalize(); CollisionShape staticplaneShape6 = new StaticPlaneShape(ref normal,0.0f);// A plane startTransform._origin = IndexedVector3.Zero; RigidBody staticBody2 = LocalCreateRigidBody(mass, startTransform, staticplaneShape6); staticBody2.SetCollisionFlags(staticBody2.GetCollisionFlags()|CollisionFlags.CF_STATIC_OBJECT); startTransform = IndexedMatrix.Identity; /// Create Dynamic Boxes { int numBoxes = 1; for (int i = 0; i < numBoxes; i++) { CollisionShape boxShape = new BoxShape(new IndexedVector3(1, 1, 1)); //CollisionShape mesh = new BvhTriangleMeshShape(m_indexVertexArrays2,true,true); startTransform._origin = new IndexedVector3(2 * i - (numBoxes-1), 2, -3); //startTransform._origin = new IndexedVector3(2 * i - 5, 10, -3); //LocalCreateRigidBody(1, startTransform, m_trimeshShape2); LocalCreateRigidBody(1, startTransform, boxShape); } } }
//----------------------------------------------------------------------------------------------- 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(); }
//---------------------------------------------------------------------------------------------- public RigidBody LocalCreateRigidBodyMultiWorld(float mass, ref IndexedMatrix startTransform, CollisionShape shape, DiscreteDynamicsWorld world) { Debug.Assert((shape == null || shape.GetShapeType() != BroadphaseNativeTypes.INVALID_SHAPE_PROXYTYPE)); //rigidbody is dynamic if and only if mass is non zero, otherwise static bool isDynamic = !MathUtil.CompareFloat(mass, 0f); IndexedVector3 localInertia = IndexedVector3.Zero; if (isDynamic) { shape.CalculateLocalInertia(mass, out localInertia); } //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects //#define USE_MOTIONSTATE 1 //#ifdef USE_MOTIONSTATE DefaultMotionState myMotionState = new DefaultMotionState(startTransform, IndexedMatrix.Identity); RigidBodyConstructionInfo cInfo = new RigidBodyConstructionInfo(mass, myMotionState, shape, localInertia); RigidBody body = new RigidBody(cInfo); if (BulletGlobals.g_streamWriter != null && true) { BulletGlobals.g_streamWriter.WriteLine("localCreateRigidBody [{0}] startTransform", body.m_debugBodyId); MathUtil.PrintMatrix(BulletGlobals.g_streamWriter, startTransform); BulletGlobals.g_streamWriter.WriteLine(""); } world.AddRigidBody(body); return body; }
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() { //maxiterations = 10; SetCameraDistance(SCALING * 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); //m_broadphase = new DbvtBroadphase(); IOverlappingPairCache pairCache = null; //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); 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); { //create a few dynamic rigidbodies CollisionShape colShape = new BoxShape(new IndexedVector3(SCALING, SCALING, SCALING)); //CollisionShape colShape = BuildCorner(); //btCollisionShape* colShape = new btSphereShape(btScalar(1.)); //CollisionShape colShape = new CylinderShape(new IndexedVector3(1f, 1, 1f)); m_collisionShapes.Add(colShape); /// Create Dynamic Objects IndexedMatrix startTransform = IndexedMatrix.Identity; mass = 1f; //rigidbody is dynamic if and only if mass is non zero, otherwise static bool isDynamic = mass != 0f; IndexedVector3 localInertia = IndexedVector3.Zero; if (isDynamic) { colShape.CalculateLocalInertia(mass, out localInertia); } float start_x = START_POS_X - ARRAY_SIZE_X/2; float start_y = START_POS_Y; float start_z = START_POS_Z - ARRAY_SIZE_Z/2; for (int k=0;k<ARRAY_SIZE_Y;k++) { for (int i=0;i<ARRAY_SIZE_X;i++) { for(int j = 0;j<ARRAY_SIZE_Z;j++) { startTransform._origin = (new IndexedVector3(2.0f * i + start_x, 20 + 2.0f * k + start_y, 2.0f * j + start_z) * SCALING); //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects DefaultMotionState myMotionState = new DefaultMotionState(startTransform, IndexedMatrix.Identity); RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(mass, myMotionState, colShape, localInertia); RigidBody body = new RigidBody(rbInfo); //body->setContactProcessingThreshold(colShape->getContactBreakingThreshold()); //body.SetActivationState(ActivationState.ISLAND_SLEEPING); m_dynamicsWorld.AddRigidBody(body); //body.SetActivationState(ActivationState.ISLAND_SLEEPING); body.SetUserPointer(String.Format("Box X{0} Y{1} Z{2}", k, i, j)); } } } } //ClientResetScene(); }