private void AddPointsAndSprings(List <TriangleVertexIndices> indices, List <TSVector> vertices) { for (int i = 0; i < vertices.Count; i++) { SoftBody.MassPoint massPoint = new SoftBody.MassPoint(this.sphere, this, this.material); massPoint.Position = vertices[i]; massPoint.Mass = FP.EN1; this.points.Add(massPoint); } for (int j = 0; j < indices.Count; j++) { TriangleVertexIndices indices2 = indices[j]; SoftBody.Triangle triangle = new SoftBody.Triangle(this); triangle.indices = indices2; this.triangles.Add(triangle); triangle.boundingBox = TSBBox.SmallBox; triangle.boundingBox.AddPoint(this.points[triangle.indices.I0].position); triangle.boundingBox.AddPoint(this.points[triangle.indices.I1].position); triangle.boundingBox.AddPoint(this.points[triangle.indices.I2].position); triangle.dynamicTreeID = this.dynamicTree.AddProxy(ref triangle.boundingBox, triangle); } HashSet <SoftBody.Edge> edges = this.GetEdges(indices); int num = 0; foreach (SoftBody.Edge current in edges) { SoftBody.Spring spring = new SoftBody.Spring(this.points[current.Index1], this.points[current.Index2]); spring.Softness = FP.EN2; spring.BiasFactor = FP.EN1; spring.SpringType = SoftBody.SpringType.EdgeSpring; this.springs.Add(spring); num++; } }
private void DetectSoftSoft(SoftBody body1, SoftBody body2) { List <int> @new = this.potentialTriangleLists.GetNew(); List <int> new2 = this.potentialTriangleLists.GetNew(); body1.dynamicTree.Query(new2, @new, body2.dynamicTree); for (int i = 0; i < new2.Count; i++) { SoftBody.Triangle userData = body1.dynamicTree.GetUserData(@new[i]); SoftBody.Triangle userData2 = body2.dynamicTree.GetUserData(new2[i]); TSVector tSVector; TSVector tSVector2; FP penetration; bool flag = XenoCollide.Detect(userData, userData2, ref TSMatrix.InternalIdentity, ref TSMatrix.InternalIdentity, ref TSVector.InternalZero, ref TSVector.InternalZero, out tSVector, out tSVector2, out penetration); bool flag2 = flag; if (flag2) { int index = CollisionSystem.FindNearestTrianglePoint(body1, @new[i], ref tSVector); int index2 = CollisionSystem.FindNearestTrianglePoint(body2, new2[i], ref tSVector); this.RaiseCollisionDetected(body1.VertexBodies[index], body2.VertexBodies[index2], ref tSVector, ref tSVector, ref tSVector2, penetration); } } @new.Clear(); new2.Clear(); this.potentialTriangleLists.GiveBack(@new); this.potentialTriangleLists.GiveBack(new2); }
public virtual void DoSelfCollision(CollisionDetectedHandler collision) { bool flag = !this.selfCollision; if (!flag) { for (int i = 0; i < this.points.Count; i++) { this.queryList.Clear(); this.dynamicTree.Query(this.queryList, ref this.points[i].boundingBox); for (int j = 0; j < this.queryList.Count; j++) { SoftBody.Triangle userData = this.dynamicTree.GetUserData(this.queryList[j]); bool flag2 = userData.VertexBody1 != this.points[i] && userData.VertexBody2 != this.points[i] && userData.VertexBody3 != this.points[i]; if (flag2) { TSVector tSVector; TSVector normal; FP penetration; bool flag3 = XenoCollide.Detect(this.points[i].Shape, userData, ref this.points[i].orientation, ref TSMatrix.InternalIdentity, ref this.points[i].position, ref TSVector.InternalZero, out tSVector, out normal, out penetration); if (flag3) { int index = CollisionSystem.FindNearestTrianglePoint(this, this.queryList[j], ref tSVector); collision(this.points[i], this.points[index], tSVector, tSVector, normal, penetration); } } } } } }
private void DetectSoftRigid(RigidBody rigidBody, SoftBody softBody) { bool flag = rigidBody.Shape is Multishape; if (flag) { Multishape multishape = rigidBody.Shape as Multishape; multishape = multishape.RequestWorkingClone(); TSBBox boundingBox = softBody.BoundingBox; boundingBox.InverseTransform(ref rigidBody.position, ref rigidBody.orientation); int num = multishape.Prepare(ref boundingBox); List <int> @new = this.potentialTriangleLists.GetNew(); softBody.dynamicTree.Query(@new, ref rigidBody.boundingBox); foreach (int current in @new) { SoftBody.Triangle userData = softBody.dynamicTree.GetUserData(current); for (int i = 0; i < num; i++) { multishape.SetCurrentShape(i); TSVector tSVector; TSVector tSVector2; FP penetration; bool flag2 = XenoCollide.Detect(multishape, userData, ref rigidBody.orientation, ref TSMatrix.InternalIdentity, ref rigidBody.position, ref TSVector.InternalZero, out tSVector, out tSVector2, out penetration); bool flag3 = flag2; if (flag3) { int index = CollisionSystem.FindNearestTrianglePoint(softBody, current, ref tSVector); this.RaiseCollisionDetected(rigidBody, softBody.VertexBodies[index], ref tSVector, ref tSVector, ref tSVector2, penetration); } } } @new.Clear(); this.potentialTriangleLists.GiveBack(@new); multishape.ReturnWorkingClone(); } else { List <int> new2 = this.potentialTriangleLists.GetNew(); softBody.dynamicTree.Query(new2, ref rigidBody.boundingBox); foreach (int current2 in new2) { SoftBody.Triangle userData2 = softBody.dynamicTree.GetUserData(current2); TSVector tSVector3; TSVector tSVector4; FP penetration2; bool flag4 = XenoCollide.Detect(rigidBody.Shape, userData2, ref rigidBody.orientation, ref TSMatrix.InternalIdentity, ref rigidBody.position, ref TSVector.InternalZero, out tSVector3, out tSVector4, out penetration2); bool flag5 = flag4; if (flag5) { int index2 = CollisionSystem.FindNearestTrianglePoint(softBody, current2, ref tSVector3); this.RaiseCollisionDetected(rigidBody, softBody.VertexBodies[index2], ref tSVector3, ref tSVector3, ref tSVector4, penetration2); } } new2.Clear(); this.potentialTriangleLists.GiveBack(new2); } }
public static int FindNearestTrianglePoint(SoftBody sb, int id, ref TSVector point) { SoftBody.Triangle userData = sb.dynamicTree.GetUserData(id); TSVector position = sb.VertexBodies[userData.indices.I0].position; TSVector.Subtract(ref position, ref point, out position); FP sqrMagnitude = position.sqrMagnitude; position = sb.VertexBodies[userData.indices.I1].position; TSVector.Subtract(ref position, ref point, out position); FP sqrMagnitude2 = position.sqrMagnitude; position = sb.VertexBodies[userData.indices.I2].position; TSVector.Subtract(ref position, ref point, out position); FP sqrMagnitude3 = position.sqrMagnitude; bool flag = sqrMagnitude < sqrMagnitude2; int result; if (flag) { bool flag2 = sqrMagnitude < sqrMagnitude3; if (flag2) { result = userData.indices.I0; } else { result = userData.indices.I2; } } else { bool flag3 = sqrMagnitude2 < sqrMagnitude3; if (flag3) { result = userData.indices.I1; } else { result = userData.indices.I2; } } return(result); }