public override int Prepare(ref TSBBox box) { bool flag = box.min.x < this.boundings.min.x; if (flag) { this.minX = 0; } else { this.minX = (int)((long)FP.Floor((box.min.x - this.sphericalExpansion) / this.scaleX)); this.minX = (int)((long)TSMath.Max(this.minX, 0)); } bool flag2 = box.max.x > this.boundings.max.x; if (flag2) { this.maxX = this.heightsLength0 - 1; } else { this.maxX = (int)((long)FP.Ceiling((box.max.x + this.sphericalExpansion) / this.scaleX)); this.maxX = (int)((long)TSMath.Min(this.maxX, this.heightsLength0 - 1)); } bool flag3 = box.min.z < this.boundings.min.z; if (flag3) { this.minZ = 0; } else { this.minZ = (int)((long)FP.Floor((box.min.z - this.sphericalExpansion) / this.scaleZ)); this.minZ = (int)((long)TSMath.Max(this.minZ, 0)); } bool flag4 = box.max.z > this.boundings.max.z; if (flag4) { this.maxZ = this.heightsLength1 - 1; } else { this.maxZ = (int)((long)FP.Ceiling((box.max.z + this.sphericalExpansion) / this.scaleZ)); this.maxZ = (int)((long)TSMath.Min(this.maxZ, this.heightsLength1 - 1)); } this.numX = this.maxX - this.minX; this.numZ = this.maxZ - this.minZ; return(this.numX * this.numZ * 2); }
public override void Iterate() { bool flag = this.skipConstraint; if (!flag) { FP x = TSVector.Dot(ref this.body1.linearVelocity, ref this.jacobian[0]); x += TSVector.Dot(ref this.body2.linearVelocity, ref this.jacobian[1]); FP y = this.accumulatedImpulse * this.softnessOverDt; FP fP = -this.effectiveMass * (x + this.bias + y); bool flag2 = this.behavior == SoftBody.Spring.DistanceBehavior.LimitMinimumDistance; if (flag2) { FP y2 = this.accumulatedImpulse; this.accumulatedImpulse = TSMath.Max(this.accumulatedImpulse + fP, 0); fP = this.accumulatedImpulse - y2; } else { bool flag3 = this.behavior == SoftBody.Spring.DistanceBehavior.LimitMaximumDistance; if (flag3) { FP y3 = this.accumulatedImpulse; this.accumulatedImpulse = TSMath.Min(this.accumulatedImpulse + fP, 0); fP = this.accumulatedImpulse - y3; } else { this.accumulatedImpulse += fP; } } bool flag4 = !this.body1.isStatic; if (flag4) { TSVector tSVector; TSVector.Multiply(ref this.jacobian[0], fP * this.body1.inverseMass, out tSVector); TSVector.Add(ref tSVector, ref this.body1.linearVelocity, out this.body1.linearVelocity); } bool flag5 = !this.body2.isStatic; if (flag5) { TSVector tSVector; TSVector.Multiply(ref this.jacobian[1], fP * this.body2.inverseMass, out tSVector); TSVector.Add(ref tSVector, ref this.body2.linearVelocity, out this.body2.linearVelocity); } } }
public void Initialize(RigidBody body1, RigidBody body2, ref TSVector point1, ref TSVector point2, ref TSVector n, FP penetration, bool newContact, ContactSettings settings) { this.body1 = body1; this.body2 = body2; this.normal = n; this.normal.Normalize(); this.p1 = point1; this.p2 = point2; this.newContact = newContact; TSVector.Subtract(ref this.p1, ref body1.position, out this.relativePos1); TSVector.Subtract(ref this.p2, ref body2.position, out this.relativePos2); TSVector.Transform(ref this.relativePos1, ref body1.invOrientation, out this.realRelPos1); TSVector.Transform(ref this.relativePos2, ref body2.invOrientation, out this.realRelPos2); this.initialPen = penetration; this.penetration = penetration; this.body1IsMassPoint = body1.isParticle; this.body2IsMassPoint = body2.isParticle; if (newContact) { this.treatBody1AsStatic = body1.isStatic; this.treatBody2AsStatic = body2.isStatic; this.accumulatedNormalImpulse = FP.Zero; this.accumulatedTangentImpulse = FP.Zero; this.lostSpeculativeBounce = FP.Zero; switch (settings.MaterialCoefficientMixing) { case ContactSettings.MaterialCoefficientMixingType.TakeMaximum: this.staticFriction = TSMath.Max(body1.material.staticFriction, body2.material.staticFriction); this.dynamicFriction = TSMath.Max(body1.material.kineticFriction, body2.material.kineticFriction); this.restitution = TSMath.Max(body1.material.restitution, body2.material.restitution); break; case ContactSettings.MaterialCoefficientMixingType.TakeMinimum: this.staticFriction = TSMath.Min(body1.material.staticFriction, body2.material.staticFriction); this.dynamicFriction = TSMath.Min(body1.material.kineticFriction, body2.material.kineticFriction); this.restitution = TSMath.Min(body1.material.restitution, body2.material.restitution); break; case ContactSettings.MaterialCoefficientMixingType.UseAverage: this.staticFriction = (body1.material.staticFriction + body2.material.staticFriction) / (2 * FP.One); this.dynamicFriction = (body1.material.kineticFriction + body2.material.kineticFriction) / (2 * FP.One); this.restitution = (body1.material.restitution + body2.material.restitution) / (2 * FP.One); break; } } this.settings = settings; }
public override void Iterate() { bool flag = this.skipConstraint; if (!flag) { FP x = this.body1.linearVelocity * this.jacobian[0] + this.body1.angularVelocity * this.jacobian[1] + this.body2.linearVelocity * this.jacobian[2] + this.body2.angularVelocity * this.jacobian[3]; FP y = this.accumulatedImpulse * this.softnessOverDt; FP fP = -this.effectiveMass * (x + this.bias + y); bool flag2 = this.behavior == PointPointDistance.DistanceBehavior.LimitMinimumDistance; if (flag2) { FP y2 = this.accumulatedImpulse; this.accumulatedImpulse = TSMath.Max(this.accumulatedImpulse + fP, 0); fP = this.accumulatedImpulse - y2; } else { bool flag3 = this.behavior == PointPointDistance.DistanceBehavior.LimitMaximumDistance; if (flag3) { FP y3 = this.accumulatedImpulse; this.accumulatedImpulse = TSMath.Min(this.accumulatedImpulse + fP, 0); fP = this.accumulatedImpulse - y3; } else { this.accumulatedImpulse += fP; } } bool flag4 = !this.body1.isStatic; if (flag4) { this.body1.linearVelocity += this.body1.inverseMass * fP * this.jacobian[0]; this.body1.angularVelocity += TSVector.Transform(fP * this.jacobian[1], this.body1.invInertiaWorld); } bool flag5 = !this.body2.isStatic; if (flag5) { this.body2.linearVelocity += this.body2.inverseMass * fP * this.jacobian[2]; this.body2.angularVelocity += TSVector.Transform(fP * this.jacobian[3], this.body2.invInertiaWorld); } } }
public static void Min(ref TSVector2 value1, ref TSVector2 value2, out TSVector2 result) { result.x = TSMath.Min(value1.x, value2.x); result.y = TSMath.Min(value1.y, value2.y); }
public static TSVector2 Min(TSVector2 value1, TSVector2 value2) { return(new TSVector2( TSMath.Min(value1.x, value2.x), TSMath.Min(value1.y, value2.y))); }