private static void RecordCollision(BSAPIXNA world, CollisionObject objA, CollisionObject objB, IndexedVector3 contact, IndexedVector3 norm, float penetration) { IndexedVector3 contactNormal = norm; if ((objA.GetCollisionFlags() & BulletXNA.BulletCollision.CollisionFlags.BS_WANTS_COLLISIONS) == 0 && (objB.GetCollisionFlags() & BulletXNA.BulletCollision.CollisionFlags.BS_WANTS_COLLISIONS) == 0) { return; } uint idA = (uint)objA.GetUserPointer(); uint idB = (uint)objB.GetUserPointer(); if (idA > idB) { uint temp = idA; idA = idB; idB = temp; contactNormal = -contactNormal; } //ulong collisionID = ((ulong) idA << 32) | idB; CollisionDesc cDesc = new CollisionDesc() { aID = idA, bID = idB, point = new Vector3(contact.X,contact.Y,contact.Z), normal = new Vector3(contactNormal.X,contactNormal.Y,contactNormal.Z), penetration = penetration }; if (world.LastCollisionDesc < world.UpdatedCollisions.Length) world.UpdatedCollisions[world.LastCollisionDesc++] = (cDesc); m_collisionsThisFrame++; }
private int PhysicsStepint(BulletWorld pWorld,float timeStep, int m_maxSubSteps, float m_fixedTimeStep, out int updatedEntityCount, out EntityProperties[] updatedEntities, out int collidersCount, out CollisionDesc[] colliders, int maxCollisions, int maxUpdates) { int numSimSteps = 0; Array.Clear(UpdatedObjects, 0, UpdatedObjects.Length); Array.Clear(UpdatedCollisions, 0, UpdatedCollisions.Length); LastEntityProperty=0; LastCollisionDesc=0; updatedEntityCount = 0; collidersCount = 0; if (pWorld is BulletWorldXNA) { DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; world.LastCollisionDesc = 0; world.LastEntityProperty = 0; numSimSteps = world.StepSimulation(timeStep, m_maxSubSteps, m_fixedTimeStep); PersistentManifold contactManifold; CollisionObject objA; CollisionObject objB; ManifoldPoint manifoldPoint; PairCachingGhostObject pairCachingGhostObject; m_collisionsThisFrame = 0; int numManifolds = world.GetDispatcher().GetNumManifolds(); for (int j = 0; j < numManifolds; j++) { contactManifold = world.GetDispatcher().GetManifoldByIndexInternal(j); int numContacts = contactManifold.GetNumContacts(); if (numContacts == 0) continue; objA = contactManifold.GetBody0() as CollisionObject; objB = contactManifold.GetBody1() as CollisionObject; manifoldPoint = contactManifold.GetContactPoint(0); //IndexedVector3 contactPoint = manifoldPoint.GetPositionWorldOnB(); // IndexedVector3 contactNormal = -manifoldPoint.m_normalWorldOnB; // make relative to A RecordCollision(this, objA, objB, manifoldPoint.GetPositionWorldOnB(), -manifoldPoint.m_normalWorldOnB, manifoldPoint.GetDistance()); m_collisionsThisFrame ++; if (m_collisionsThisFrame >= 9999999) break; } foreach (GhostObject ghostObject in specialCollisionObjects.Values) { pairCachingGhostObject = ghostObject as PairCachingGhostObject; if (pairCachingGhostObject != null) { RecordGhostCollisions(pairCachingGhostObject); } } updatedEntityCount = LastEntityProperty; updatedEntities = UpdatedObjects; collidersCount = LastCollisionDesc; colliders = UpdatedCollisions; } else { //if (updatedEntities is null) //updatedEntities = new List<BulletXNA.EntityProperties>(); //updatedEntityCount = 0; //collidersCount = 0; updatedEntities = new EntityProperties[0]; colliders = new CollisionDesc[0]; } return numSimSteps; }
private int PhysicsStep2(BulletWorld pWorld, float timeStep, int m_maxSubSteps, float m_fixedTimeStep, out int updatedEntityCount, out EntityProperties[] updatedEntities, out int collidersCount, out CollisionDesc[] colliders) { int epic = PhysicsStepint(pWorld, timeStep, m_maxSubSteps, m_fixedTimeStep, out updatedEntityCount, out updatedEntities, out collidersCount, out colliders, m_maxCollisions, m_maxUpdatesPerFrame); return epic; }
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 BulletWorld Initialize(Vector3 maxPosition, ConfigurationParameters parms, int maxCollisions, ref CollisionDesc[] collisionArray, int maxUpdates, ref EntityProperties[] updateArray ) { UpdatedObjects = updateArray; UpdatedCollisions = collisionArray; /* TODO */ ConfigurationParameters[] configparms = new ConfigurationParameters[1]; configparms[0] = parms; Vector3 worldExtent = maxPosition; m_maxCollisions = maxCollisions; m_maxUpdatesPerFrame = maxUpdates; specialCollisionObjects = new Dictionary<uint, GhostObject>(); return new BulletWorldXNA(1, PhysicsScene, BSAPIXNA.Initialize2(worldExtent, configparms, maxCollisions, ref collisionArray, maxUpdates, ref updateArray, null)); }
public override BulletWorld Initialize(Vector3 maxPosition, ConfigurationParameters parms, int maxCollisions, ref CollisionDesc[] collisionArray, int maxUpdates, ref EntityProperties[] updateArray ) { /* TODO */ return new BulletWorldXNA(1, null, null); }