///<summary> /// Constructs a new convex-convex manifold. ///</summary> public GeneralConvexContactManifold() { contacts = new RawList <Contact>(4); unusedContacts = new UnsafeResourcePool <Contact>(4); contactIndicesToRemove = new RawList <int>(4); pairTester = new GeneralConvexPairTester(); }
public override void UpdateTimeOfImpact(Collidable requester, double dt) { //Notice that we don't test for convex entity null explicitly. The convex.IsActive property does that for us. if (convex.IsActive && convex.Entity.PositionUpdateMode == PositionUpdateMode.Continuous) { //Only perform the test if the minimum radii are small enough relative to the size of the velocity. Vector3 velocity = convex.Entity.LinearVelocity * dt; double velocitySquared = velocity.LengthSquared(); double minimumRadius = convex.Shape.MinimumRadius * MotionSettings.CoreShapeScaling; timeOfImpact = 1; if (minimumRadius * minimumRadius < velocitySquared) { for (int i = 0; i < contactManifold.ActivePairs.Count; i++) { GeneralConvexPairTester pair = contactManifold.ActivePairs.Values[i]; ReusableGenericCollidable <ConvexShape> boxCollidable = (ReusableGenericCollidable <ConvexShape>)pair.CollidableB; RayHit rayHit; RigidTransform worldTransform = boxCollidable.WorldTransform; if (GJKToolbox.CCDSphereCast(new Ray(convex.WorldTransform.Position, velocity), minimumRadius, boxCollidable.Shape, ref worldTransform, timeOfImpact, out rayHit) && rayHit.T > Toolbox.BigEpsilon) { timeOfImpact = rayHit.T; } } } } }
private GeneralConvexPairTester GetPair(ref Vector3i position) { // TODO: Efficiency! GeneralConvexPairTester pair = testerPool.Take(); ReusableGenericCollidable <ConvexShape> boxCollidable = new ReusableGenericCollidable <ConvexShape>(mesh.ChunkShape.ShapeAt(position.X, position.Y, position.Z, out Vector3 offs)); pair.Initialize(convex, boxCollidable); boxCollidable.WorldTransform = new RigidTransform(new Vector3( mesh.Position.X + position.X + offs.X, mesh.Position.Y + position.Y + offs.Y, mesh.Position.Z + position.Z + offs.Z)); return(pair); }
private void ReturnPair(GeneralConvexPairTester pair) { pair.CleanUp(); testerPool.GiveBack(pair); }
private void ReturnPair(GeneralConvexPairTester pair) { boxCollidablePool.GiveBack((ReusableBoxCollidable)pair.CollidableB); pair.CleanUp(); testerPool.GiveBack(pair); }