public override void ProcessCollision(CollisionObject body0, CollisionObject body1, DispatcherInfo dispatchInfo, ManifoldResult resultOut) { if (m_manifoldPtr == null) { return; } resultOut.SetPersistentManifold(m_manifoldPtr); SphereShape sphere0 = body0.GetCollisionShape() as SphereShape; SphereShape sphere1 = body1.GetCollisionShape() as SphereShape; IndexedVector3 diff = body0.GetWorldTransform()._origin - body1.GetWorldTransform()._origin; float len = diff.Length(); float radius0 = sphere0.GetRadius(); float radius1 = sphere1.GetRadius(); #if CLEAR_MANIFOLD m_manifoldPtr.clearManifold(); //don't do this, it disables warmstarting #endif ///iff distance positive, don't generate a new contact if (len > (radius0 + radius1)) { #if !CLEAR_MANIFOLD resultOut.RefreshContactPoints(); #endif //CLEAR_MANIFOLD return; } ///distance (negative means penetration) float dist = len - (radius0 + radius1); IndexedVector3 normalOnSurfaceB = new IndexedVector3(1, 0, 0); if (len > MathUtil.SIMD_EPSILON) { normalOnSurfaceB = diff / len; } ///point on A (worldspace) ///btVector3 pos0 = col0.getWorldTransform().getOrigin() - radius0 * normalOnSurfaceB; ///point on B (worldspace) IndexedVector3 pos1 = body1.GetWorldTransform()._origin + radius1 * normalOnSurfaceB; /// report a contact. internally this will be kept persistent, and contact reduction is done resultOut.AddContactPoint(ref normalOnSurfaceB, ref pos1, dist); #if !CLEAR_MANIFOLD resultOut.RefreshContactPoints(); #endif //CLEAR_MANIFOLD }
public float GetMarginNonVirtual() { switch (m_shapeType) { case BroadphaseNativeTypes.SPHERE_SHAPE_PROXYTYPE: { SphereShape sphereShape = this as SphereShape; return(sphereShape.GetRadius()); } case BroadphaseNativeTypes.BOX_SHAPE_PROXYTYPE: { BoxShape convexShape = this as BoxShape; return(convexShape.GetMarginNV()); } case BroadphaseNativeTypes.TRIANGLE_SHAPE_PROXYTYPE: { TriangleShape triangleShape = this as TriangleShape; return(triangleShape.GetMarginNV()); } case BroadphaseNativeTypes.CYLINDER_SHAPE_PROXYTYPE: { CylinderShape cylShape = this as CylinderShape; return(cylShape.GetMarginNV()); } case BroadphaseNativeTypes.CAPSULE_SHAPE_PROXYTYPE: { CapsuleShape capsuleShape = this as CapsuleShape; return(capsuleShape.GetMarginNV()); } case BroadphaseNativeTypes.CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE: /* fall through */ case BroadphaseNativeTypes.CONVEX_HULL_SHAPE_PROXYTYPE: { PolyhedralConvexShape convexHullShape = this as PolyhedralConvexShape; return(convexHullShape.GetMarginNV()); } default: return(this.GetMargin()); } // should never reach here Debug.Assert(false); return(0.0f); }
public override void ProcessCollision(CollisionObject body0, CollisionObject body1, DispatcherInfo dispatchInfo, ManifoldResult resultOut) { //(void)dispatchInfo; //(void)resultOut; if (m_manifoldPtr == null) { return; } CollisionObject sphereObj = m_isSwapped ? body1 : body0; CollisionObject boxObj = m_isSwapped ? body0 : body1; IndexedVector3 pOnBox = new IndexedVector3();; IndexedVector3 normalOnSurfaceB = new IndexedVector3(); float penetrationDepth = 0f; IndexedVector3 sphereCenter = sphereObj.GetWorldTransform()._origin; SphereShape sphere0 = sphereObj.GetCollisionShape() as SphereShape; float radius = sphere0.GetRadius(); float maxContactDistance = m_manifoldPtr.GetContactBreakingThreshold(); resultOut.SetPersistentManifold(m_manifoldPtr); if (GetSphereDistance(boxObj, ref pOnBox, ref normalOnSurfaceB, ref penetrationDepth, sphereCenter, radius, maxContactDistance)) { /// report a contact. internally this will be kept persistent, and contact reduction is done resultOut.AddContactPoint(normalOnSurfaceB, pOnBox, penetrationDepth); } if (m_ownManifold) { if (m_manifoldPtr.GetNumContacts() > 0) { resultOut.RefreshContactPoints(); } } }