public void initialize() { // Calculate average bounciness/restitution e = FixMath.Min(A.Bounciness, B.Bounciness); // Calculate static & dynamic friction sf = FixMath.Sqrt(A.StaticFriction * A.StaticFriction + B.StaticFriction * B.StaticFriction); df = FixMath.Sqrt(A.DynamicFriction * A.DynamicFriction + B.DynamicFriction * B.DynamicFriction); for (int i = 0; i < contactCount; i++) { //Calculate radii from COM to contact FixVec2 ra = contacts[i] -= A.info.position; FixVec2 rb = contacts[i] -= B.info.position; //? FixVec2 rv = B.info.velocity + FixVec2.Cross(B.info.angularVelocity, rb) - A.info.velocity - FixVec2.Cross(A.info.angularVelocity, ra); // Determine if we should perform a resting collision or not // The idea is if the only thing moving this object is gravity, // then the collision should be performed without any restitution if (rv.GetMagnitudeSquared() < TFPhysics.instance.resting) { e = 0; } } }
/// Returns the fraction along the segment query the cpBB is hit. Returns INFINITY if it doesn't hit. public static Fix SegmentQuery(ref AABB aabb, ref FixVec2 a, ref FixVec2 b) { var idx = 1.0f / (b.X - a.X); var tx1 = (aabb.L == a.X ? Fix.MinValue : (aabb.L - a.X) * idx); var tx2 = (aabb.R == a.X ? Fix.MaxValue : (aabb.R - a.X) * idx); var txmin = FixMath.Min(tx1, tx2); var txmax = FixMath.Max(tx1, tx2); var idy = 1.0f / (b.Y - a.Y); var ty1 = (aabb.B == a.Y ? Fix.MinValue : (aabb.B - a.Y) * idy); var ty2 = (aabb.T == a.Y ? Fix.MaxValue : (aabb.T - a.Y) * idy); var tymin = FixMath.Min(ty1, ty2); var tymax = FixMath.Max(ty1, ty2); if (tymin <= txmax && txmin <= tymax) { var min = FixMath.Max(txmin, tymin); var max = FixMath.Min(txmax, tymax); if (0 <= max && min <= 1) { return(FixMath.Max(min, 0)); } } return(Fix.MaxValue); }
public static FixVec2 NormalizedToPoint(FixRect rectangle, FixVec2 normalizedRectCoordinates) { Fix x = FixMath.Min(FixMath.Max(Fix.Zero, normalizedRectCoordinates.X), Fix.One); Fix y = FixMath.Min(FixMath.Max(Fix.Zero, normalizedRectCoordinates.Y), Fix.One); return(new FixVec2(rectangle.xMin + (rectangle.xMax - rectangle.xMin) * x, rectangle.yMin + (rectangle.yMax - rectangle.yMin) * y)); }
public static AABB Union(AABB a, AABB b) { AABB C; C.min = new FixVec2(FixMath.Min(a.min.x, b.min.x), FixMath.Min(a.min.y, b.min.y)); C.max = new FixVec2(FixMath.Max(a.max.x, b.max.x), FixMath.Max(a.max.y, b.max.y)); return(C); }
public static AABB Union(AABB a, AABB b) { AABB C; C.min = new FixVec2(FixMath.Min(a.min.X, b.min.X), FixMath.Min(a.min.Y, b.min.Y)); C.max = new FixVec2(FixMath.Max(a.max.X, b.max.X), FixMath.Max(a.max.Y, b.max.Y)); return(C); }
public static AABB Expand(AABB aabb, FixVec2 v) { return(new AABB( FixMath.Min(aabb.L, v.X), FixMath.Min(aabb.B, v.Y), FixMath.Max(aabb.R, v.X), FixMath.Max(aabb.T, v.Y) )); }
public static AABB Merge(AABB a, AABB b) { return(new AABB( FixMath.Min(a.L, b.L), FixMath.Min(a.B, b.B), FixMath.Max(a.R, b.R), FixMath.Max(a.T, b.T) )); }
public FixVec3 ClosestPoint(FixVec3 point) { // Clamp point to bounds Fix x = FixMath.Min(FixMath.Max(_min.X, point.X), _max.X); Fix y = FixMath.Min(FixMath.Max(_min.Y, point.Y), _max.Y); Fix z = FixMath.Min(FixMath.Max(_min.Z, point.Z), _max.Z); // Return clamped point return(new FixVec3(x, y, z)); }
public void Encapsulate(Fix x, Fix y) { _min = new FixVec2(FixMath.Min(x, _min.X), FixMath.Min(y, _min.Y)); _max = new FixVec2(FixMath.Max(x, _max.X), FixMath.Max(y, _max.Y)); _size = _max - _min; _center = _min + _size / 2; }
public void Encapsulate(FixBounds other) { Fix x; Fix y; Fix z; // Expand min x = FixMath.Min(_min.X, other._min.X); y = FixMath.Min(_min.Y, other._min.Y); z = FixMath.Min(_min.Z, other._min.Z); _min = new FixVec3(x, y, z); // Expand max x = FixMath.Max(_max.X, other._max.X); y = FixMath.Max(_max.Y, other._max.Y); z = FixMath.Max(_max.Z, other._max.Z); _max = new FixVec3(x, y, z); // Update other values UpdateFromMinMax(); }
public static FixVec2 PointToNormalized(FixRect rectangle, FixVec2 point) { return(new FixVec2(FixMath.Min(FixMath.Max(Fix.Zero, (point.X - rectangle.xMin) / (rectangle.xMax - rectangle.xMin)), Fix.One), FixMath.Min(FixMath.Max(Fix.Zero, (point.Y - rectangle.yMin) / (rectangle.yMax - rectangle.yMin)), Fix.One))); }
/// Merges @c a and @c b and returns the area of the merged bounding box. public static Fix MergedArea(AABB a, AABB b) { return((FixMath.Max(a.R, b.R) - FixMath.Min(a.L, b.L)) * (FixMath.Max(a.T, b.T) - FixMath.Min(a.B, b.B))); }
public static void Min(ref FixVector2 value1, ref FixVector2 value2, out FixVector2 result) { result.x = FixMath.Min(value1.x, value2.x); result.y = FixMath.Min(value1.y, value2.y); }
public static FixVector2 Min(FixVector2 value1, FixVector2 value2) { return(new FixVector2( FixMath.Min(value1.x, value2.x), FixMath.Min(value1.y, value2.y))); }