예제 #1
0
        internal static bool CirclesOverlap(ref fp2 aOrigin, ref fp aRadius, ref fp2 bOrigin,
                                            ref fp bRadius)
        {
            var radsum = aRadius.value + bRadius.value;

            return(DistanceSqr(ref aOrigin, ref bOrigin).value <= ((radsum * radsum) >> fixlut.PRECISION));
        }
예제 #2
0
        internal static fp Sqrt(fp num)
        {
            fp r;

            r.value = Sqrt_Raw(num.value);

            return(r);
        }
예제 #3
0
        public static fp2 Y(fp y)
        {
            fp2 r;

            r.x.value = 0;
            r.y.value = y.value;

            return(r);
        }
예제 #4
0
        internal static void ClampMagnitude(ref fp2 value, ref fp length)
        {
            if (SqrMagnitude(value).value <= ((length.value * length.value) >> fixlut.PRECISION))
            {
                return;
            }

            value = Normalize(value) * length;
        }
예제 #5
0
        internal static fp Max(fp a, fp b)
        {
            if (a.value > b.value)
            {
                return(a);
            }

            return(b);
        }
예제 #6
0
        internal static fp Min(fp a, fp b)
        {
            if (a.value < b.value)
            {
                return(a);
            }

            return(b);
        }
예제 #7
0
        internal static fp2 ClosestPointOnCicle(fp2 center, fp radius, fp2 point)
        {
            var v = fm.Normalize(point - center);

            v *= radius;
            v += center;

            return(v);
        }
예제 #8
0
//
//    internal static bool linecast_collider_fast(fix3 point0, fix3 point1, ref collider2 collider) {
//      fix3 intersection;
//
//      switch (collider.type) {
//        case collider2_types.circle: return linecast_circle_fast_nopoint(ref point0, ref point1, ref collider.circle.center, ref collider.circle.radius);
//        case collider2_types.aabb: return linecast_aabb(new line { point0 = point0, point1 = point1 }, collider.aabb, out intersection);
//        case collider2_types.oobb: return linecast_oobb(new line { point0 = point0, point1 = point1 }, collider.oobb, out intersection);
//      }
//
//      throw new NotImplementedException(collider.type.ToString());
//    }
//
        internal static bool linecast_circle_fast(ref fp2 point0, ref fp2 point1, ref fp2 circle_center,
                                                  ref fp circle_radius, out fp2 point)
        {
            fp2 v;
            fp2 z;
            fp2 z_normalized;
            fp  z_magnitude;

            v.x.value = point0.x.value - circle_center.x.value;
            v.y.value = point0.y.value - circle_center.y.value;

            z.x.value = point1.x.value - point0.x.value;
            z.y.value = point1.y.value - point0.y.value;

            z_normalized = z;
            z_magnitude  = default(fp);

            Normalize(ref z_normalized, ref z_magnitude);

            var b = Dot(ref v, ref z_normalized).value;
            var c = Dot(ref v, ref v).value - ((circle_radius.value * circle_radius.value) >> fixlut.PRECISION);

            if (c > fp.RAW_ZERO && b > fp.RAW_ZERO)
            {
                goto MISS;
            }

            var d = ((b * b) >> fixlut.PRECISION) - c;

            if (d < fp.RAW_ZERO)
            {
                goto MISS;
            }

            var distance = -b - Sqrt_Raw(d);

            if (distance <= z_magnitude.value)
            {
                if (distance < fp.RAW_ZERO)
                {
                    point = point0;
                }
                else
                {
                    point          = point0;
                    point.x.value += ((z_normalized.x.value * distance) >> fixlut.PRECISION);
                    point.y.value += ((z_normalized.y.value * distance) >> fixlut.PRECISION);
                }

                return(true);
            }

MISS:

            point = fp2.zero;
            return(false);
        }
예제 #9
0
        public static fp2 X(fp x)
        {
            fp2 r;

            r.x.value = x.value;
            r.y.value = 0;

            return(r);
        }
예제 #10
0
        internal static int RoundToInt(fp num)
        {
            var fraction = Fractions(num);

            if (fraction.value >= fp.half.value)
            {
                return(num.as_int_int + 1);
            }

            return(num.as_int_int);
        }
예제 #11
0
        internal static fp Ceil(fp num)
        {
            var fractions = Fractions(num);

            if (fractions.value == 0)
            {
                return(num);
            }

            return(num + fp.one);
        }
예제 #12
0
        public static fp Cos(fp num)
        {
            var sign = fp.one;

            if (num > fp.pi || num < -fp.pi)
            {
                sign = fp.minus_one;
            }

            return(fm.Cos(num) * sign);
        }
예제 #13
0
        internal static fp2 Reflect(fp2 vector, fp2 normal)
        {
            fp dot = (vector.x * normal.x) + (vector.y * normal.y);

            fp2 result;

            result.x = vector.x - ((fp.two * dot) * normal.x);
            result.y = vector.y - ((fp.two * dot) * normal.y);

            return(result);
        }
예제 #14
0
        public static fp SqrtAprox(fp num)
        {
            var sign = fp.one;

            if (num < fp.zero)
            {
                sign = fp.minus_one;
                num *= fp.minus_one;
            }

            return(fm.SqrtAprox(num) * sign);
        }
예제 #15
0
        internal static fp2 Rotate(fp2 vector, fp rotation)
        {
            var cs = fixmath.Cos(rotation);
            var sn = fixmath.Sin(rotation);

            var px = (vector.x * cs) - (vector.y * sn);
            var pz = (vector.x * sn) + (vector.y * cs);

            vector.x = px;
            vector.y = pz;

            return(vector);
        }
예제 #16
0
        internal static void Normalize(ref fp2 v, ref fp m)
        {
            m = Magnitude(v);

            if (m.value <= fp.epsilon.value)
            {
                v = default(fp2);
                return;
            }

            v.x.value = ((v.x.value << fixlut.PRECISION) / m.value);
            v.y.value = ((v.y.value << fixlut.PRECISION) / m.value);
        }
예제 #17
0
        internal static fp Clamp(fp num, fp min, fp max)
        {
            if (num.value < min.value)
            {
                return(min);
            }

            if (num.value > max.value)
            {
                return(max);
            }

            return(num);
        }
예제 #18
0
 public static fp Asin(fp num)
 {
     return(fm.Asin(num));
 }
예제 #19
0
 internal static fp Clamp01(fp num)
 {
     return(Clamp(num, fp.zero, fp.one));
 }
예제 #20
0
 internal static fp2 Lerp(fp2 from, fp2 to, fp t)
 {
     t = Clamp01(t);
     return(new fp2(from.x + (to.x - from.x) * t, from.y + (to.y - from.y) * t));
 }
예제 #21
0
        internal static void Normalize(ref fp2 v)
        {
            fp m = default(fp);

            Normalize(ref v, ref m);
        }
예제 #22
0
 internal static fp Abs(fp num)
 {
     return(new fp(Math.Abs(num.value)));
 }
예제 #23
0
 internal static fp Lerp(fp from, fp to, fp t)
 {
     return(from + ((to - from) * Clamp01(t)));
 }
예제 #24
0
 public static fp Ceil(fp num)
 {
     return(fm.Ceil(num));
 }
예제 #25
0
 public static fp Sqrt(fp num)
 {
     return(fm.Sqrt(num));
 }
예제 #26
0
 internal static fp Sign(fp num)
 {
     return((num.value < fp.RAW_ZERO) ? fp.minus_one : fp.one);
 }
예제 #27
0
 public static fp Floor(fp num)
 {
     return(fm.Floor(num));
 }
예제 #28
0
 public static fp Atan(fp num)
 {
     return(fm.Atan(num));
 }
예제 #29
0
 public static fp Fractions(fp num)
 {
     return(fm.Fractions(num));
 }
예제 #30
0
 internal static fp2 ClampMagnitude(fp2 value, fp length)
 {
     ClampMagnitude(ref value, ref length);
     return(value);
 }