public static fp4 Normalize(fp4 v)
        {
            if (v == fp4.zero)
            {
                return(fp4.zero);
            }

            return(v / Magnitude(v));
        }
        public static fp DistanceSqr(fp4 p1, fp4 p2)
        {
            fp4 v;

            v.x.value = p1.x.value - p2.x.value;
            v.y.value = p1.y.value - p2.y.value;
            v.z.value = p1.z.value - p2.z.value;
            v.w.value = p1.w.value - p2.w.value;

            return(MagnitudeSqr(v));
        }
        public static fp4 Normalize(fp4 v, out fp magnitude)
        {
            if (v == fp4.zero)
            {
                magnitude = fp._0;
                return(fp4.zero);
            }

            magnitude = Magnitude(v);
            return(v / magnitude);
        }
        public static fp Magnitude(fp4 v)
        {
            fp r;

            r.value =
                ((v.x.value * v.x.value) >> fixlut.PRECISION) +
                ((v.y.value * v.y.value) >> fixlut.PRECISION) +
                ((v.z.value * v.z.value) >> fixlut.PRECISION) +
                ((v.w.value * v.w.value) >> fixlut.PRECISION);

            return(Sqrt(r));
        }
        public static fp4 MagnitudeClamp(fp4 v, fp length)
        {
            var sqrMagnitude = MagnitudeSqr(v);

            if (sqrMagnitude <= length * length)
            {
                return(v);
            }

            var magnitude  = Sqrt(sqrMagnitude);
            var normalized = v / magnitude;

            return(normalized * length);
        }
 public static fp Sum(fp4 v)
 {
     return(new fp(v.x.value + v.y.value + v.z.value + v.w.value));
 }
 public static fp Dot(fp4 a, fp4 b)
 {
     return(new fp(((a.x.value * b.x.value) >> fixlut.PRECISION) + ((a.y.value * b.y.value) >> fixlut.PRECISION) + ((a.z.value * b.z.value) >> fixlut.PRECISION) +
                   ((a.w.value * b.w.value) >> fixlut.PRECISION)));
 }
 public static fp4 Max(fp4 a, fp4 b)
 {
     return(new fp4(Max(a.x, b.x), Max(a.y, b.y), Max(a.z, b.z), Max(a.w, b.w)));
 }
 public static fp4 Abs(fp4 v)
 {
     return(new fp4(Abs(v.x), Abs(v.y), Abs(v.z), Abs(v.w)));
 }
Beispiel #10
0
 public static fp4 MagnitudeSet(fp4 v, fp length)
 {
     return(Normalize(v) * length);
 }
Beispiel #11
0
 public fp4 NextFp4(fp4 min, fp4 max)
 {
     return(NextFp4() * (max - min) + min);
 }
Beispiel #12
0
 public fp4 NextFp4(fp4 max)
 {
     return(NextFp4() * max);
 }