public static VoltAABB CreateMerged(VoltAABB aabb1, VoltAABB aabb2) { return(new VoltAABB( TSMath.Max(aabb1.top, aabb2.top), TSMath.Min(aabb1.bottom, aabb2.bottom), TSMath.Min(aabb1.left, aabb2.left), TSMath.Max(aabb1.right, aabb2.right))); }
/// <summary> /// Builds the AABB by combining all the shape AABBs. /// </summary> private void UpdateAABB() { FP top = FP.NegativeInfinity; FP right = FP.NegativeInfinity; FP bottom = FP.PositiveInfinity; FP left = FP.PositiveInfinity; for (int i = 0; i < this.shapeCount; i++) { VoltAABB aabb = this.shapes[i].AABB; top = TSMath.Max(top, aabb.Top); right = TSMath.Max(right, aabb.Right); bottom = TSMath.Min(bottom, aabb.Bottom); left = TSMath.Min(left, aabb.Left); } this.AABB = new VoltAABB(top, bottom, left, right); }
internal void Solve(Manifold manifold) { VoltBody bodyA = manifold.ShapeA.Body; VoltBody bodyB = manifold.ShapeB.Body; FP elasticity = bodyA.World.Elasticity; // Calculate relative bias velocity TSVector2 vb1 = bodyA.BiasVelocity + (bodyA.BiasRotation * this.toALeft); TSVector2 vb2 = bodyB.BiasVelocity + (bodyB.BiasRotation * this.toBLeft); FP vbn = TSVector2.Dot((vb1 - vb2), this.normal); // Calculate and clamp the bias impulse FP jbn = this.nMass * (vbn - this.bias); jbn = TSMath.Max(-this.jBias, jbn); this.jBias += jbn; // Apply the bias impulse this.ApplyNormalBiasImpulse(bodyA, bodyB, jbn); // Calculate relative velocity TSVector2 vr = this.RelativeVelocity(bodyA, bodyB); FP vrn = TSVector2.Dot(vr, this.normal); // Calculate and clamp the normal impulse FP jn = nMass * (vrn + (this.restitution * elasticity)); jn = TSMath.Max(-this.cachedNormalImpulse, jn); this.cachedNormalImpulse += jn; // Calculate the relative tangent velocity FP vrt = TSVector2.Dot(vr, this.normal.Left()); // Calculate and clamp the friction impulse FP jtMax = manifold.Friction * this.cachedNormalImpulse; FP jt = vrt * tMass; FP result = TSMath.Clamp(this.cachedTangentImpulse + jt, -jtMax, jtMax); jt = result - this.cachedTangentImpulse; this.cachedTangentImpulse = result; // Apply the normal and tangent impulse this.ApplyContactImpulse(bodyA, bodyB, jn, jt); }
private static VoltAABB ComputeBounds( TSVector2[] vertices, int count) { FP top = vertices[0].y; FP bottom = vertices[0].y; FP left = vertices[0].x; FP right = vertices[0].x; for (int i = 1; i < count; i++) { top = TSMath.Max(top, vertices[i].y); bottom = TSMath.Min(bottom, vertices[i].y); left = TSMath.Min(left, vertices[i].x); right = TSMath.Max(right, vertices[i].x); } return(new VoltAABB(top, bottom, left, right)); }
public static void Max(ref TSVector2 value1, ref TSVector2 value2, out TSVector2 result) { result.x = TSMath.Max(value1.x, value2.x); result.y = TSMath.Max(value1.y, value2.y); }
public static TSVector2 Max(TSVector2 value1, TSVector2 value2) { return(new TSVector2( TSMath.Max(value1.x, value2.x), TSMath.Max(value1.y, value2.y))); }