protected override void _InitializePhysicsWorld() { base._InitializePhysicsWorld(); if (collisionType == CollisionConfType.DefaultDynamicsWorldCollisionConf) { CollisionConf = new DefaultCollisionConfiguration(); } else if (collisionType == CollisionConfType.SoftBodyRigidBodyCollisionConf) { CollisionConf = new SoftBodyRigidBodyCollisionConfiguration(); } Dispatcher = new CollisionDispatcher(CollisionConf); if (broadphaseType == BroadphaseType.DynamicAABBBroadphase) { Broadphase = new DbvtBroadphase(); } else if (broadphaseType == BroadphaseType.Axis3SweepBroadphase) { Broadphase = new AxisSweep3(axis3SweepBroadphaseMin.ToBullet(), axis3SweepBroadphaseMax.ToBullet(), axis3SweepMaxProxies); } else if (broadphaseType == BroadphaseType.Axis3SweepBroadphase_32bit) { Broadphase = new AxisSweep3_32Bit(axis3SweepBroadphaseMin.ToBullet(), axis3SweepBroadphaseMax.ToBullet(), axis3SweepMaxProxies); } else { Broadphase = new SimpleBroadphase(); } World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, null, CollisionConf); World.Gravity = gravity.ToBullet(); if (_doDebugDraw) { DebugDrawUnity db = new DebugDrawUnity(); db.DebugMode = _debugDrawMode; World.DebugDrawer = db; } }
/* * Does not set any local variables. Is safe to use to create duplicate physics worlds for independant simulation. */ public bool CreatePhysicsWorld(out CollisionWorld world, out CollisionConfiguration collisionConfig, out CollisionDispatcher dispatcher, out BroadphaseInterface broadphase, out ConstraintSolver solver, out SoftBodyWorldInfo softBodyWorldInfo) { bool success = true; if (m_worldType == WorldType.SoftBodyAndRigidBody && m_collisionType == CollisionConfType.DefaultDynamicsWorldCollisionConf) { Debug.LogError("For World Type = SoftBodyAndRigidBody collisionType must be collisionType=SoftBodyRigidBodyCollisionConf. Switching"); m_collisionType = CollisionConfType.SoftBodyRigidBodyCollisionConf; success = false; } collisionConfig = null; if (m_collisionType == CollisionConfType.DefaultDynamicsWorldCollisionConf) { collisionConfig = new DefaultCollisionConfiguration(); } else if (m_collisionType == CollisionConfType.SoftBodyRigidBodyCollisionConf) { collisionConfig = new SoftBodyRigidBodyCollisionConfiguration(); } dispatcher = new CollisionDispatcher(collisionConfig); if (m_broadphaseType == BroadphaseType.DynamicAABBBroadphase) { broadphase = new DbvtBroadphase(); } else if (m_broadphaseType == BroadphaseType.Axis3SweepBroadphase) { broadphase = new AxisSweep3(m_axis3SweepBroadphaseMin.ToBullet(), m_axis3SweepBroadphaseMax.ToBullet(), axis3SweepMaxProxies); } else if (m_broadphaseType == BroadphaseType.Axis3SweepBroadphase_32bit) { broadphase = new AxisSweep3_32Bit(m_axis3SweepBroadphaseMin.ToBullet(), m_axis3SweepBroadphaseMax.ToBullet(), axis3SweepMaxProxies); } else { broadphase = null; } world = null; softBodyWorldInfo = null; solver = null; if (m_worldType == WorldType.CollisionOnly) { world = new CollisionWorld(dispatcher, broadphase, collisionConfig); } else if (m_worldType == WorldType.RigidBodyDynamics) { switch (solverType) { case SolverType.MLCP: DantzigSolver dtsolver = new DantzigSolver(); solver = new MlcpSolver(dtsolver); break; default: break; } world = new DiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfig); } else if (m_worldType == WorldType.MultiBodyWorld) { MultiBodyConstraintSolver mbConstraintSolver = null; switch (solverType) { /* case SolverType.MLCP: * DantzigSolver dtsolver = new DantzigSolver(); * mbConstraintSolver = new MultiBodyMLCPConstraintSolver(dtsolver); * break;*/ default: mbConstraintSolver = new MultiBodyConstraintSolver(); break; } world = new MultiBodyDynamicsWorld(dispatcher, broadphase, mbConstraintSolver, collisionConfig); } else if (m_worldType == WorldType.SoftBodyAndRigidBody) { SequentialImpulseConstraintSolver siConstraintSolver = new SequentialImpulseConstraintSolver(); constraintSolver = siConstraintSolver; siConstraintSolver.RandSeed = sequentialImpulseConstraintSolverRandomSeed; m_world = new SoftRigidDynamicsWorld(Dispatcher, Broadphase, siConstraintSolver, CollisionConf); _ddWorld = (DiscreteDynamicsWorld)m_world;; SoftRigidDynamicsWorld _sworld = (SoftRigidDynamicsWorld)m_world; m_world.DispatchInfo.EnableSpu = true; _sworld.WorldInfo.SparseSdf.Initialize(); _sworld.WorldInfo.SparseSdf.Reset(); _sworld.WorldInfo.AirDensity = 1.2f; _sworld.WorldInfo.WaterDensity = 0; _sworld.WorldInfo.WaterOffset = 0; _sworld.WorldInfo.WaterNormal = BulletSharp.Math.Vector3.Zero; _sworld.WorldInfo.Gravity = m_gravity.ToBullet(); } if (world is DiscreteDynamicsWorld) { ((DiscreteDynamicsWorld)world).Gravity = m_gravity.ToBullet(); } if (_doDebugDraw) { DebugDrawUnity db = new DebugDrawUnity(); db.DebugMode = _debugDrawMode; world.DebugDrawer = db; } return(success); }
/* * Does not set any local variables. Is safe to use to create duplicate physics worlds for independant simulation. */ public bool CreatePhysicsWorld(out CollisionWorld world, out CollisionConfiguration collisionConfig, out CollisionDispatcher dispatcher, out BroadphaseInterface broadphase, out SequentialImpulseConstraintSolver solver, out SoftBodyWorldInfo softBodyWorldInfo) { bool success = true; /* gRally * if (m_worldType == WorldType.SoftBodyAndRigidBody && m_collisionType == CollisionConfType.DefaultDynamicsWorldCollisionConf) * { * Debug.LogError( "For World Type = SoftBodyAndRigidBody collisionType must be collisionType=SoftBodyRigidBodyCollisionConf. Switching"); * m_collisionType = CollisionConfType.SoftBodyRigidBodyCollisionConf; * success = false; * } */ collisionConfig = null; broadphase = null; // gRally new AxisSweep3(m_axis3SweepBroadphaseMin.ToBullet(), m_axis3SweepBroadphaseMax.ToBullet(), axis3SweepMaxProxies); // gRally /* gRally * if (m_collisionType == CollisionConfType.DefaultDynamicsWorldCollisionConf) * { * collisionConfig = new DefaultCollisionConfiguration(); * } * else if (m_collisionType == CollisionConfType.SoftBodyRigidBodyCollisionConf) * { * collisionConfig = new SoftBodyRigidBodyCollisionConfiguration(); * } * * dispatcher = new CollisionDispatcher(collisionConfig); * * if (m_broadphaseType == BroadphaseType.DynamicAABBBroadphase) * { * broadphase = new DbvtBroadphase(); * } * else if (m_broadphaseType == BroadphaseType.Axis3SweepBroadphase) * { * broadphase = new AxisSweep3(m_axis3SweepBroadphaseMin.ToBullet(), m_axis3SweepBroadphaseMax.ToBullet(), axis3SweepMaxProxies); * } * else if (m_broadphaseType == BroadphaseType.Axis3SweepBroadphase_32bit) * { * broadphase = new AxisSweep3_32Bit(m_axis3SweepBroadphaseMin.ToBullet(), m_axis3SweepBroadphaseMax.ToBullet(), axis3SweepMaxProxies); * } * else * { * broadphase = null; * } */ world = null; softBodyWorldInfo = null; solver = null; /* gRally * if (m_worldType == WorldType.CollisionOnly) * { * world = new CollisionWorld(dispatcher, broadphase, collisionConfig); * } * else if (m_worldType == WorldType.RigidBodyDynamics) * { * world = new DiscreteDynamicsWorld(dispatcher, broadphase, null, collisionConfig); * } * else if (m_worldType == WorldType.MultiBodyWorld) * { * world = new MultiBodyDynamicsWorld(dispatcher, broadphase, null, collisionConfig); * } * else if (m_worldType == WorldType.SoftBodyAndRigidBody) * { * Solver = new SequentialImpulseConstraintSolver(); * Solver.RandSeed = sequentialImpulseConstraintSolverRandomSeed; * m_world = new SoftRigidDynamicsWorld(Dispatcher, Broadphase, Solver, CollisionConf); * _ddWorld = (DiscreteDynamicsWorld)m_world; * SoftRigidDynamicsWorld _sworld = (SoftRigidDynamicsWorld)m_world; * * m_world.DispatchInfo.EnableSpu = true; * _sworld.WorldInfo.SparseSdf.Initialize(); * _sworld.WorldInfo.SparseSdf.Reset(); * _sworld.WorldInfo.AirDensity = 1.2f; * _sworld.WorldInfo.WaterDensity = 0; * _sworld.WorldInfo.WaterOffset = 0; * _sworld.WorldInfo.WaterNormal = BulletSharp.Math.Vector3.Zero; * _sworld.WorldInfo.Gravity = m_gravity.ToBullet(); * } */ // gRally stuff! collisionConfig = new DefaultCollisionConfiguration(); dispatcher = new CollisionDispatcher(collisionConfig); // #gStageEditor broadphase = new AxisSweep3(GRSimData.PairCache); // #gStageEditor world = new DiscreteDynamicsWorld(GRSimData.BulletWorld, dispatcher, broadphase); // UP!_ddWorld = (DiscreteDynamicsWorld)m_world; if (world is DiscreteDynamicsWorld) { // gRally .. ((DiscreteDynamicsWorld)world).Gravity = m_gravity.ToBullet(); } if (_doDebugDraw) { DebugDrawUnity db = new DebugDrawUnity(); db.DebugMode = _debugDrawMode; world.DebugDrawer = db; } return(success); }
protected virtual void _InitializePhysicsWorld() { _isDisposed = false; if (m_worldType == WorldType.SoftBodyAndRigidBody && m_collisionType == CollisionConfType.DefaultDynamicsWorldCollisionConf) { BDebug.LogError(debugType, "For World Type = SoftBodyAndRigidBody collisionType must be collisionType=SoftBodyRigidBodyCollisionConf. Switching"); m_collisionType = CollisionConfType.SoftBodyRigidBodyCollisionConf; } if (m_collisionType == CollisionConfType.DefaultDynamicsWorldCollisionConf) { CollisionConf = new DefaultCollisionConfiguration(); } else if (m_collisionType == CollisionConfType.SoftBodyRigidBodyCollisionConf) { CollisionConf = new SoftBodyRigidBodyCollisionConfiguration(); } Dispatcher = new CollisionDispatcher(CollisionConf); if (m_broadphaseType == BroadphaseType.DynamicAABBBroadphase) { Broadphase = new DbvtBroadphase(); } else if (m_broadphaseType == BroadphaseType.Axis3SweepBroadphase) { Broadphase = new AxisSweep3(m_axis3SweepBroadphaseMin.ToBullet(), m_axis3SweepBroadphaseMax.ToBullet(), axis3SweepMaxProxies); } else if (m_broadphaseType == BroadphaseType.Axis3SweepBroadphase_32bit) { Broadphase = new AxisSweep3_32Bit(m_axis3SweepBroadphaseMin.ToBullet(), m_axis3SweepBroadphaseMax.ToBullet(), axis3SweepMaxProxies); } else { Broadphase = null; } if (m_worldType == WorldType.CollisionOnly) { m_world = new CollisionWorld(Dispatcher, Broadphase, CollisionConf); _ddWorld = null; } else if (m_worldType == WorldType.RigidBodyDynamics) { m_world = new DiscreteDynamicsWorld(Dispatcher, Broadphase, null, CollisionConf); _ddWorld = (DiscreteDynamicsWorld)m_world; } else if (m_worldType == WorldType.MultiBodyWorld) { m_world = new MultiBodyDynamicsWorld(Dispatcher, Broadphase, null, CollisionConf); _ddWorld = (DiscreteDynamicsWorld)m_world; } else if (m_worldType == WorldType.SoftBodyAndRigidBody) { Solver = new SequentialImpulseConstraintSolver(); Solver.RandSeed = sequentialImpulseConstraintSolverRandomSeed; softBodyWorldInfo = new SoftBodyWorldInfo { AirDensity = 1.2f, WaterDensity = 0, WaterOffset = 0, WaterNormal = BulletSharp.Math.Vector3.Zero, Gravity = UnityEngine.Physics.gravity.ToBullet(), Dispatcher = Dispatcher, Broadphase = Broadphase }; softBodyWorldInfo.SparseSdf.Initialize(); m_world = new SoftRigidDynamicsWorld(Dispatcher, Broadphase, Solver, CollisionConf); _ddWorld = (DiscreteDynamicsWorld)m_world; m_world.DispatchInfo.EnableSpu = true; softBodyWorldInfo.SparseSdf.Reset(); softBodyWorldInfo.AirDensity = 1.2f; softBodyWorldInfo.WaterDensity = 0; softBodyWorldInfo.WaterOffset = 0; softBodyWorldInfo.WaterNormal = BulletSharp.Math.Vector3.Zero; softBodyWorldInfo.Gravity = m_gravity.ToBullet(); } if (_ddWorld != null) { _ddWorld.Gravity = m_gravity.ToBullet(); } if (_doDebugDraw) { DebugDrawUnity db = new DebugDrawUnity(); db.DebugMode = _debugDrawMode; m_world.DebugDrawer = db; } }
/* Does not set any local variables. Is safe to use to create duplicate physics worlds for independant simulation. */ public bool CreatePhysicsWorld( out CollisionWorld world, out CollisionConfiguration collisionConfig, out CollisionDispatcher dispatcher, out BroadphaseInterface broadphase, out SequentialImpulseConstraintSolver solver, out SoftBodyWorldInfo softBodyWorldInfo) { bool success = true; if (m_worldType == WorldType.SoftBodyAndRigidBody && m_collisionType == CollisionConfType.DefaultDynamicsWorldCollisionConf) { BDebug.LogError(debugType, "For World Type = SoftBodyAndRigidBody collisionType must be collisionType=SoftBodyRigidBodyCollisionConf. Switching"); m_collisionType = CollisionConfType.SoftBodyRigidBodyCollisionConf; success = false; } collisionConfig = null; if (m_collisionType == CollisionConfType.DefaultDynamicsWorldCollisionConf) { collisionConfig = new DefaultCollisionConfiguration(); } else if (m_collisionType == CollisionConfType.SoftBodyRigidBodyCollisionConf) { collisionConfig = new SoftBodyRigidBodyCollisionConfiguration(); } dispatcher = new CollisionDispatcher(collisionConfig); if (m_broadphaseType == BroadphaseType.DynamicAABBBroadphase) { broadphase = new DbvtBroadphase(); } else if (m_broadphaseType == BroadphaseType.Axis3SweepBroadphase) { broadphase = new AxisSweep3(m_axis3SweepBroadphaseMin.ToBullet(), m_axis3SweepBroadphaseMax.ToBullet(), axis3SweepMaxProxies); } else if (m_broadphaseType == BroadphaseType.Axis3SweepBroadphase_32bit) { broadphase = new AxisSweep3_32Bit(m_axis3SweepBroadphaseMin.ToBullet(), m_axis3SweepBroadphaseMax.ToBullet(), axis3SweepMaxProxies); } else { broadphase = null; } world = null; softBodyWorldInfo = null; solver = null; if (m_worldType == WorldType.CollisionOnly) { world = new CollisionWorld(dispatcher, broadphase, collisionConfig); } else if (m_worldType == WorldType.RigidBodyDynamics) { world = new DiscreteDynamicsWorld(dispatcher, broadphase, null, collisionConfig); } else if (m_worldType == WorldType.MultiBodyWorld) { world = new MultiBodyDynamicsWorld(dispatcher, broadphase, null, collisionConfig); } else if (m_worldType == WorldType.SoftBodyAndRigidBody) { solver = new SequentialImpulseConstraintSolver(); solver.RandSeed = sequentialImpulseConstraintSolverRandomSeed; softBodyWorldInfo = new SoftBodyWorldInfo { AirDensity = 1.2f, WaterDensity = 0, WaterOffset = 0, WaterNormal = BulletSharp.Math.Vector3.Zero, Gravity = UnityEngine.Physics.gravity.ToBullet(), Dispatcher = dispatcher, Broadphase = broadphase }; softBodyWorldInfo.SparseSdf.Initialize(); world = new SoftRigidDynamicsWorld(dispatcher, broadphase, solver, collisionConfig); world.DispatchInfo.EnableSpu = true; softBodyWorldInfo.SparseSdf.Reset(); softBodyWorldInfo.AirDensity = 1.2f; softBodyWorldInfo.WaterDensity = 0; softBodyWorldInfo.WaterOffset = 0; softBodyWorldInfo.WaterNormal = BulletSharp.Math.Vector3.Zero; softBodyWorldInfo.Gravity = m_gravity.ToBullet(); } if (world is DiscreteDynamicsWorld) { ((DiscreteDynamicsWorld)world).Gravity = m_gravity.ToBullet(); } if (_doDebugDraw) { DebugDrawUnity db = new DebugDrawUnity(); db.DebugMode = _debugDrawMode; world.DebugDrawer = db; } return success; }