void OnCollision(object source, CollisionEvents.CollisionEventArgs args) { // Prepare contacts for processing PrepareContacts(args.Contacts, args.Rb); // Resolve interpenetration ResolveInterpenetration(args.Contacts, args.Rb); // Apply impulses ApplyImpulses(args.Contacts, args.Rb); }
/// <summary> /// Iterates throught the list of <c>HeightMap</c> and <c>CSACollider</c> /// to find the intersected points. /// </summary> /// <remarks> /// This function performs the Sphere-Triangle, Plane-Triangle, Curve-Triangle /// intersection tests. After found any contact points it sends toward the /// <c>PhysicsManager</c>. /// </remarks> void FixedUpdate() { debugSegments.Clear(); debugPoints.Clear(); debugVectors.Clear(); segmentColor.Clear(); foreach (HeightMapCollider hMapCollider in heightMapColliders) { if (!hMapCollider.enabled) { continue; } colors = new Color[hMapCollider.TriMesh.vertexCount]; Color origCol = new Color(200f / 255f, 200f / 255f, 200f / 255f); for (int i = 0; i < colors.Length; i++) { colors[i] = origCol; } foreach (DynamicCollider dynCollider in dynamicColliderList) { if (!dynCollider.enabled) { continue; } // creating a list of contacts for the physics manager List <Contact> contacts = new List <Contact>(); List <Segment> coarseContacts = new List <Segment>(); // position of bounding sphere in world coordinates Vector3 spherePos = dynCollider.BoundingSphere.CenterW; float radius = dynCollider.BoundingSphere.Radius; // filtering the triangle grid with the sphere projection hMapCollider.TriGrid.FilterBySphereProjection(spherePos, radius); if (dynCollider is CSACollider) { HandleCSAVsHeightMapCollision( dynCollider as CSACollider, hMapCollider, contacts, coarseContacts); } else if (dynCollider is BruteForceCollider) { HandleBruteForceVsHeightMapCollision( dynCollider as BruteForceCollider, hMapCollider, contacts, coarseContacts); } else if (dynCollider is VertexCollider) { HandleVertexVsHeightMapCollision( dynCollider as VertexCollider, hMapCollider, contacts, coarseContacts); } else if (dynCollider is SAGJKCollider) { HandleSAGJKVsHeightMapCollision( dynCollider as SAGJKCollider, hMapCollider, contacts, coarseContacts); } else if (dynCollider is GJKCollider) { HandleGJKVsHeightMapCollision( dynCollider as GJKCollider, hMapCollider, contacts, coarseContacts); } else if (dynCollider is XenoCollider) { HandleXenoVsHeighMapCollision( dynCollider as XenoCollider, hMapCollider, contacts, coarseContacts); } else if (dynCollider is ConvDecompCollider) { HandleConvDecompVsHeighMapCollision( dynCollider as ConvDecompCollider, hMapCollider, contacts, coarseContacts); } // reset the filtering of the triangle grid hMapCollider.TriGrid.Reset(); if (coarseContacts.Count > 0 && dynCollider.GetComponent <Rigidbody>() != null) { var args = new CollisionEvents.CoarseCollisionEventArgs( dynCollider.GetComponent <RigidBody>(), coarseContacts ); CollisionEvents.FireEvent(CollisionEvents.EventType.CoarseCollision, this, args); } // if any contacts got caught, we send them to the physics manager by the collision event if (contacts.Count > 0 && dynCollider.GetComponent <RigidBody>() != null) { var args = new CollisionEvents.CollisionEventArgs( dynCollider.GetComponent <RigidBody>(), contacts ); CollisionEvents.FireEvent(CollisionEvents.EventType.Collision, this, args); } } if (debugColors) { hMapCollider.TriMesh.colors = colors; } } }