Exemple #1
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);
        }
Exemple #2
0
        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));
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        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);
        }
Exemple #5
0
 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)
                ));
 }
Exemple #6
0
 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)
                ));
 }
Exemple #7
0
        public void PositionalCorrection()
        {
            TFPhysics settings   = TFPhysics.instance;
            FixVec2   correction = (FixMath.Max(penetration - settings.penetrationAllowance, Fix.zero)) / (A.invMass + B.invMass)
                                   * normal * settings.penetrationCorrection;

            A.Position -= correction * A.invMass;
            B.Position += correction * B.invMass;
        }
Exemple #8
0
        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));
        }
Exemple #9
0
        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;
        }
Exemple #10
0
        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();
        }
Exemple #11
0
 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)));
 }
Exemple #12
0
 /// 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)));
 }
Exemple #13
0
 public static void Max(ref FixVector2 value1, ref FixVector2 value2, out FixVector2 result)
 {
     result.x = FixMath.Max(value1.x, value2.x);
     result.y = FixMath.Max(value1.y, value2.y);
 }
Exemple #14
0
 public static FixVector2 Max(FixVector2 value1, FixVector2 value2)
 {
     return(new FixVector2(
                FixMath.Max(value1.x, value2.x),
                FixMath.Max(value1.y, value2.y)));
 }