public static void processCollision(CollisionObject col0, CollisionObject col1, DispatcherInfo dispatchInfo, PersistentManifold resultOut) { SphereShape sphere0 = (SphereShape)col0.getCollisionShape(); SphereShape sphere1 = (SphereShape)col1.getCollisionShape(); VInt3 diff = col0.getWorldTransform().position - col1.getWorldTransform().position; VFixedPoint len = diff.magnitude; VFixedPoint radius0 = sphere0.getRadius(); VFixedPoint radius1 = sphere1.getRadius(); // if distance positive, don't generate a new contact if (len > (radius0 + radius1)) { return; } // distance (negative means penetration) VFixedPoint dist = len - (radius0 + radius1); VInt3 normalOnSurfaceB = VInt3.zero; if (dist < Globals.EPS) { normalOnSurfaceB = diff / len; } // report a contact. internally this will be kept persistent, and contact reduction is done ManifoldPoint contactPoint = new ManifoldPoint(col0.getWorldTransform().position - normalOnSurfaceB * radius0, col1.getWorldTransform().position + normalOnSurfaceB * radius1, normalOnSurfaceB, dist); resultOut.addManifoldPoint(contactPoint); }
public static void processCollision(CollisionObject body0, CollisionObject body1, DispatcherInfo dispatchInfo, PersistentManifold resultOut) { }
public void init(DispatcherInfo dispatchInfo, CollisionDispatcher dispatcher) { this.dispatchInfo = dispatchInfo; this.dispatcher = dispatcher; }
public static void processCollision(CollisionObject body0, CollisionObject body1, DispatcherInfo dispatchInfo, PersistentManifold resultOut) { bool needSwap = body0.getCollisionShape() is CapsuleShape; CollisionObject sphereObject = needSwap ? body1 : body0; CollisionObject capsuleObject = needSwap ? body0 : body1; SphereShape sphere = (SphereShape)sphereObject.getCollisionShape(); CapsuleShape capsule = (CapsuleShape)capsuleObject.getCollisionShape(); VInt3 spherePos = sphereObject.getWorldTransform().position; VIntTransform capsuleTransform = capsuleObject.getWorldTransform(); VInt3 p0 = capsuleTransform.TransformPoint(capsule.getUpAxis() * capsule.getHalfHeight()); VInt3 p1 = capsuleTransform.TransformPoint(capsule.getUpAxis() * -capsule.getHalfHeight()); VFixedPoint param = VFixedPoint.Zero; VFixedPoint dist2 = Distance.distancePointSegmentSquared(p0, p1, spherePos, ref param); VFixedPoint dist = FMath.Sqrt(dist2); VFixedPoint penetration = dist - (sphere.getRadius() + capsule.getRadius()); if (penetration > Globals.getContactBreakingThreshold()) { return; } VInt3 lineWorldPos = p0 * (VFixedPoint.One - param) + p1 * param; VInt3 diff = (spherePos - lineWorldPos) / dist; VInt3 sphereWorldPos = spherePos - diff * sphere.getRadius(); VInt3 capsuleWorldPos = lineWorldPos + diff * capsule.getRadius(); ManifoldPoint contractPoint = new ManifoldPoint(needSwap ? capsuleWorldPos : sphereWorldPos, needSwap ? sphereWorldPos: capsuleWorldPos, diff * (needSwap ? -1 : 1), penetration); resultOut.addManifoldPoint(contractPoint); }
public static void processCollision(CollisionObject body0, CollisionObject body1, DispatcherInfo dispatchInfo, PersistentManifold resultOut) { bool isSwapped = body1.getCollisionShape() is SphereShape; CollisionObject sphereObj = isSwapped ? body1 : body0; CollisionObject boxObj = isSwapped ? body0 : body1; VInt3 normalOnSurfaceB; VFixedPoint penetrationDepth; VInt3 sphereCenter = sphereObj.getWorldTransform().position; SphereShape sphere0 = (SphereShape)sphereObj.getCollisionShape(); VFixedPoint radius = sphere0.getRadius(); if (getSphereDistance((BoxShape)boxObj.getCollisionShape(), boxObj.getWorldTransform(), sphereCenter, radius, out normalOnSurfaceB, out penetrationDepth)) { VInt3 worldPosOnSphere = sphereCenter - normalOnSurfaceB * radius; VInt3 worldPosOnBox = worldPosOnSphere - normalOnSurfaceB * penetrationDepth; ManifoldPoint contactPoint = new ManifoldPoint(isSwapped ? worldPosOnBox : worldPosOnSphere, isSwapped ? worldPosOnSphere : worldPosOnBox, normalOnSurfaceB * (isSwapped ? -1 : 1), penetrationDepth); resultOut.addManifoldPoint(contactPoint); } }
public static void processCollision(CollisionObject body0, CollisionObject body1, DispatcherInfo dispatchInfo, PersistentManifold resultOut) { bool needSwap = body0.getCollisionShape() is CapsuleShape; CollisionObject boxObject = needSwap ? body1 : body0; CollisionObject capsuleObject = needSwap ? body0 : body1; BoxShape boxShape = (BoxShape)boxObject.getCollisionShape(); CapsuleShape capsuleShape = (CapsuleShape)capsuleObject.getCollisionShape(); VIntTransform boxTransform = boxObject.getWorldTransform(); VIntTransform capsuleTransform = capsuleObject.getWorldTransform(); VInt3 p0 = capsuleTransform.TransformPoint(capsuleShape.getUpAxis() * capsuleShape.getHalfHeight()), p1 = capsuleTransform.TransformPoint(capsuleShape.getUpAxis() * -capsuleShape.getHalfHeight()); VFixedPoint lParam = VFixedPoint.Zero; VInt3 closestPointBoxLS = VInt3.zero; VFixedPoint distSq = SegmentBoxDistance.distanceSegmentBoxSquared(p0, p1, boxShape.getHalfExtent(), boxTransform, ref lParam, ref closestPointBoxLS); VInt3 closestPointBoxWS = boxTransform.TransformPoint(closestPointBoxLS); VInt3 closestPointLineWS = p0 * (VFixedPoint.One - lParam) + p1 * lParam; VFixedPoint dist = FMath.Sqrt(distSq) - capsuleShape.getRadius(); if (dist > VFixedPoint.Zero) { return; } if ((closestPointBoxWS - closestPointLineWS).sqrMagnitude > Globals.EPS2) { VInt3 normalOnBoxWS = (closestPointLineWS - closestPointBoxWS).Normalize(); ManifoldPoint contactPoint = new ManifoldPoint(needSwap ? closestPointLineWS - normalOnBoxWS * capsuleShape.getRadius() : closestPointBoxWS, !needSwap ? closestPointLineWS - normalOnBoxWS * capsuleShape.getRadius() : closestPointBoxWS, normalOnBoxWS * (needSwap ? 1 : -1), dist); resultOut.addManifoldPoint(contactPoint); } else //box and line are intersected { //EPA LineShape coreShape = new LineShape(capsuleShape); VInt3 pa = VInt3.zero, pb = VInt3.zero, normal = VInt3.zero; VFixedPoint depth = VFixedPoint.Zero; PxGJKStatus result = EpaSolver.calcPenDepth(coreShape, boxShape, capsuleTransform, boxTransform, ref pa, ref pb, ref normal, ref depth); if (result == PxGJKStatus.EPA_CONTACT) { ManifoldPoint contactPoint = new ManifoldPoint(needSwap ? pa - normal * capsuleShape.getRadius() : pb, !needSwap ? pa - normal * capsuleShape.getRadius() : pb, needSwap ? normal : -normal, depth - capsuleShape.getRadius()); resultOut.addManifoldPoint(contactPoint); } } }
public static void processCollision(CollisionObject body0, CollisionObject body1, DispatcherInfo dispatchInfo, PersistentManifold resultOut) { BoxShape box0 = (BoxShape)body0.getCollisionShape(); BoxShape box1 = (BoxShape)body1.getCollisionShape(); VIntTransform transform0 = body0.getWorldTransform(); VIntTransform transform1 = body1.getWorldTransform(); VInt3 box0Extent = box0.getHalfExtent(); VInt3 box1Extent = box1.getHalfExtent(); doBoxBoxGenerateContacts(box0Extent, box1Extent, transform0, transform1, resultOut); if (resultOut.getContactPointsNum() == 0) { VInt3 pa = VInt3.zero, pb = VInt3.zero, normal = VInt3.zero; VFixedPoint depth = VFixedPoint.Zero; PxGJKStatus result = EpaSolver.calcPenDepth(box0, box1, transform0, transform1, ref pa, ref pb, ref normal, ref depth); if (result == PxGJKStatus.EPA_CONTACT) { ManifoldPoint contactPoint = new ManifoldPoint(pa, pb, normal, depth); resultOut.addManifoldPoint(contactPoint); } } }
public static void processCollision(CollisionObject body0, CollisionObject body1, DispatcherInfo dispatchInfo, PersistentManifold resultOut) { CapsuleShape capsule0 = (CapsuleShape)body0.getCollisionShape(); CapsuleShape capsule1 = (CapsuleShape)body1.getCollisionShape(); VIntTransform transform0 = body0.getWorldTransform(); VIntTransform transform1 = body1.getWorldTransform(); VInt3 p00 = transform0.TransformPoint(capsule0.getUpAxis() * capsule0.getHalfHeight()); VInt3 p01 = transform0.TransformPoint(capsule0.getUpAxis() * -capsule0.getHalfHeight()); VInt3 p10 = transform1.TransformPoint(capsule1.getUpAxis() * capsule1.getHalfHeight()); VInt3 p11 = transform1.TransformPoint(capsule1.getUpAxis() * -capsule1.getHalfHeight()); VInt3 x, y; VFixedPoint dist2 = Distance.SegmentSegmentDist2(p00, p01 - p00, p10, p11 - p10, out x, out y); VFixedPoint dist = FMath.Sqrt(dist2); VFixedPoint penetration = dist - (capsule0.getRadius() + capsule1.getRadius()); if (penetration > Globals.getContactBreakingThreshold()) { return; } VInt3 diff = (x - y) / dist; VInt3 posWorldOnA = x - diff * capsule0.getRadius(); VInt3 posWorldOnB = y + diff * capsule1.getRadius(); ManifoldPoint contractPoint = new ManifoldPoint(posWorldOnA, posWorldOnB, diff, penetration); resultOut.addManifoldPoint(contractPoint); }