protected override void UpdateContainedPairs() { RigidTransform rtMesh = mesh.WorldTransform; RigidTransform rtMobile = mobile.WorldTransform; QuickList <Vector3i> overlaps = new QuickList <Vector3i>(BufferPools <Vector3i> .Thread); mesh.ChunkShape.GetOverlaps(ref rtMesh, mobile.BoundingBox, ref overlaps); for (int i = 0; i < overlaps.Count; i++) { Vector3i pos = overlaps.Elements[i]; Vector3 offs; ReusableGenericCollidable <ConvexShape> colBox = new ReusableGenericCollidable <ConvexShape>(mesh.ChunkShape.ShapeAt(pos.X, pos.Y, pos.Z, out offs)); Vector3 input = new Vector3(pos.X + offs.X, pos.Y + offs.Y, pos.Z + offs.Z); Vector3 transfd = Quaternion.Transform(input, rtMesh.Orientation); RigidTransform outp = new RigidTransform(transfd + rtMesh.Position, rtMesh.Orientation); colBox.WorldTransform = outp; colBox.UpdateBoundingBoxForTransform(ref outp); QuickList <Vector3i> overlaps2 = new QuickList <Vector3i>(BufferPools <Vector3i> .Thread); mobile.ChunkShape.GetOverlaps(ref rtMobile, colBox.BoundingBox, ref overlaps2); for (int x = 0; x < overlaps2.Count; x++) { Vector3i pos2 = overlaps2.Elements[x]; Vector3 offs2; ReusableGenericCollidable <ConvexShape> colBox2 = new ReusableGenericCollidable <ConvexShape>(mobile.ChunkShape.ShapeAt(pos2.X, pos2.Y, pos2.Z, out offs2)); colBox2.SetEntity(mobile.Entity); Vector3 input2 = new Vector3(pos2.X + offs2.X, pos2.Y + offs2.Y, pos2.Z + offs2.Z); Vector3 transfd2 = Quaternion.Transform(input2, rtMobile.Orientation); RigidTransform outp2 = new RigidTransform(transfd2 + rtMobile.Position, rtMobile.Orientation); colBox2.WorldTransform = outp2; TryToAdd(colBox, colBox2, mesh.Entity != null ? mesh.Entity.Material : null, mobile.Entity != null ? mobile.Entity.Material : null); } overlaps2.Dispose(); } overlaps.Dispose(); }
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(); Vector3 offs; ReusableGenericCollidable <ConvexShape> boxCollidable = new ReusableGenericCollidable <ConvexShape>((ConvexShape)mesh.ChunkShape.ShapeAt(position.X, position.Y, position.Z, out 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); }
protected override void UpdateContainedPairs() { RigidTransform rt = mesh.WorldTransform; QuickList <Vector3i> overlaps = new QuickList <Vector3i>(BufferPools <Vector3i> .Thread); mesh.ChunkShape.GetOverlaps(ref rt, convex.BoundingBox, ref overlaps); for (int i = 0; i < overlaps.Count; i++) { Vector3i pos = overlaps.Elements[i]; Vector3 offs; ReusableGenericCollidable <ConvexShape> colBox = new ReusableGenericCollidable <ConvexShape>(mesh.ChunkShape.ShapeAt(pos.X, pos.Y, pos.Z, out offs)); colBox.SetEntity(mesh.Entity); Vector3 input = new Vector3(pos.X + offs.X, pos.Y + offs.Y, pos.Z + offs.Z); Vector3 transfd = Quaternion.Transform(input, rt.Orientation); RigidTransform outp = new RigidTransform(transfd + rt.Position, rt.Orientation); colBox.WorldTransform = outp; TryToAdd(colBox, convex, mesh.Entity != null ? mesh.Entity.Material : null, convex.Entity != null ? convex.Entity.Material : null); } overlaps.Dispose(); }