Esempio n. 1
0
        public bool Intersect(NuGenRay3F ray, ref float t, ref float u, ref float v, ref NuGenVec3F normal)
        {
            NuGenVec3F e1 = p1 - p0;
            NuGenVec3F e2 = p2 - p0;
            NuGenVec3F p  = NuGenVec3F.Cross(ray.Direction, e2);

            float a = NuGenVec3F.Dot(e1, p);

            if (a > -NuGenVector.TINY_FLOAT && a < NuGenVector.TINY_FLOAT)
            {
                return(false);
            }
            float      f = 1.0f / a;
            NuGenVec3F s = ray.Point - p0;

            u = f * NuGenVec3F.Dot(s, p);

            if (u < 0.0f || u > 1.0f)
            {
                return(false);
            }
            NuGenVec3F q = NuGenVec3F.Cross(s, e1);

            v = f * NuGenVec3F.Dot(ray.Direction, q);

            if (v < 0.0f || (u + v) > 1.0f)
            {
                return(false);
            }
            t      = f * NuGenVec3F.Dot(e2, q);
            normal = NuGenVec3F.Cross(e1, e2); normal.Normalize();
            return(true);
        }
Esempio n. 2
0
 public static bool ApproxEquals(NuGenVec3F a, NuGenVec3F b)
 {
     return
         (Math.Abs(a._x[0] - b._x[0]) < NuGenVector.TINY_FLOAT &&
          Math.Abs(a._x[1] - b._x[1]) < NuGenVector.TINY_FLOAT &&
          Math.Abs(a._x[2] - b._x[2]) < NuGenVector.TINY_FLOAT);
 }
Esempio n. 3
0
        public bool Intersect(NuGenRay3F ray, ref float t, ref NuGenVec3F normal)
        {
            NuGenVec3F l  = center - ray.Point;
            float      s  = NuGenVec3F.Dot(l, ray.Direction);
            float      l2 = l.SquaredLength;
            float      rr = radius * radius;

            if (s < 0.0f && l2 > rr)
            {
                return(false);
            }
            float m2 = l2 - s * s;

            if (m2 > rr)
            {
                return(false);
            }
            float q = (float)Math.Sqrt(rr - m2);

            if (l2 > rr)
            {
                t = s - q;
            }

            else
            {
                t = s + q;
            }
            normal = (ray.Point + ray.Direction * t) - center;
            normal.Normalize();
            return(true);
        }
Esempio n. 4
0
        public NuGenRot3F(NuGenVec3F from, NuGenVec3F to)
        {
            from.Normalize();
            to.Normalize();

            float cost =
                NuGenVec3F.Dot(from, to) /
                (float)Math.Sqrt(NuGenVec3F.Dot(from, to) * NuGenVec3F.Dot(to, to));

            if (cost > 0.99999)
            {
                r = 1;
                v = new NuGenVec3F(0, 0, 0);
            }

            else if (cost < -0.99999)
            {
                NuGenVec3F frm = from.Normalized;
                v = NuGenVec3F.Cross(frm, NuGenVec3F.UnitX);

                if (v.Length < 0.00001)
                {
                    v = NuGenVec3F.Cross(frm, NuGenVec3F.UnitY);
                }
                r = 0;
                v.Normalize();
            }

            else
            {
                r  = (float)Math.Sqrt(0.5 * (1.0 + cost));
                v  = NuGenVec3F.Cross(from, to);
                v *= (float)Math.Sqrt((0.5 * (1.0 - cost)) / NuGenVec3F.Dot(v, v));
            }
        }
Esempio n. 5
0
        public NuGenRot3F(NuGenVec3F from, NuGenVec3F to)
        {
            from.Normalize();
            to.Normalize();

            float cost =
                NuGenVec3F.Dot(from, to) /
                (float)Math.Sqrt(NuGenVec3F.Dot(from, to) * NuGenVec3F.Dot(to, to));

            if (cost > 0.99999)
            {
                r = 1;
                v = new NuGenVec3F(0, 0, 0);
            }

            else if (cost < -0.99999)
            {
                NuGenVec3F frm = from.Normalized;
                v = NuGenVec3F.Cross(frm, NuGenVec3F.UnitX);

                if (v.Length < 0.00001) v = NuGenVec3F.Cross(frm, NuGenVec3F.UnitY);
                r = 0;
                v.Normalize();
            }

            else
            {
                r = (float)Math.Sqrt(0.5 * (1.0 + cost));
                v = NuGenVec3F.Cross(from, to);
                v *= (float)Math.Sqrt((0.5 * (1.0 - cost)) / NuGenVec3F.Dot(v, v));
            }
        }
Esempio n. 6
0
 public static NuGenVec3F Cross(NuGenVec3F a, NuGenVec3F b)
 {
     return(new NuGenVec3F(
                a.y * b.z - a.z * b.y,
                a.z * b.x - a.x * b.z,
                a.x * b.y - a.y * b.x
                ));
 }
Esempio n. 7
0
 public static NuGenVec3F Max(NuGenVec3F a, NuGenVec3F b)
 {
     return(new NuGenVec3F(
                Math.Max(a._x[0], b._x[0]),
                Math.Max(a._x[1], b._x[1]),
                Math.Max(a._x[2], b._x[2])
                ));
 }
Esempio n. 8
0
        public override bool Equals(object obj)
        {
            NuGenVec3F x = (NuGenVec3F)obj;

            return(
                _x[0] == x._x[0] &&
                _x[1] == x._x[1] &&
                _x[2] == x._x[2]
                );
        }
Esempio n. 9
0
        public bool Intersect(NuGenRay3F ray, ref float t, ref NuGenVec3F normal)
        {
            NuGenVec3F l = center - ray.Point;
            float s = NuGenVec3F.Dot(l, ray.Direction);
            float l2 = l.SquaredLength;
            float rr = radius * radius;

            if (s < 0.0f && l2 > rr) return false;
            float m2 = l2 - s * s;

            if (m2 > rr) return false;
            float q = (float)Math.Sqrt(rr - m2);

            if (l2 > rr) t = s - q;

            else t = s + q;
            normal = (ray.Point + ray.Direction * t) - center;
            normal.Normalize();
            return true;
        }
Esempio n. 10
0
        public bool Intersect(NuGenRay3F ray, ref float t, ref float u, ref float v, ref NuGenVec3F normal)
        {
            NuGenVec3F e1 = p1 - p0;
            NuGenVec3F e2 = p2 - p0;
            NuGenVec3F p = NuGenVec3F.Cross(ray.Direction, e2);

            float a = NuGenVec3F.Dot(e1, p);

            if (a > -NuGenVector.TINY_FLOAT && a < NuGenVector.TINY_FLOAT) return false;
            float f = 1.0f / a;
            NuGenVec3F s = ray.Point - p0;
            u = f * NuGenVec3F.Dot(s, p);

            if (u < 0.0f || u > 1.0f) return false;
            NuGenVec3F q = NuGenVec3F.Cross(s, e1);
            v = f * NuGenVec3F.Dot(ray.Direction, q);

            if (v < 0.0f || (u + v) > 1.0f) return false;
            t = f * NuGenVec3F.Dot(e2, q);
            normal = NuGenVec3F.Cross(e1, e2); normal.Normalize();
            return true;
        }
Esempio n. 11
0
 public NuGenShift3F(NuGenVec3F shift)
 {
     v = shift;
 }
Esempio n. 12
0
 public NuGenShift3F(float x, float y, float z)
 {
     v = new NuGenVec3F(x, y, z);
 }
Esempio n. 13
0
 public NuGenScale3F(float x, float y, float z)
 {
     v = new NuGenVec3F(x, y, z);
 }
Esempio n. 14
0
 public NuGenRot3F(float radians, NuGenVec3F axis)
 {
     axis.Normalize();
     r = (float)Math.Cos(radians / 2.0);
     v = axis.Normalized * (float)Math.Sin(radians / 2.0);
 }
Esempio n. 15
0
 public static NuGenVec3F Max(NuGenVec3F a, NuGenVec3F b)
 {
     return new NuGenVec3F(
         Math.Max(a._x[0], b._x[0]),
         Math.Max(a._x[1], b._x[1]),
         Math.Max(a._x[2], b._x[2])
         );
 }
Esempio n. 16
0
 public static NuGenVec3F Cross(NuGenVec3F a, NuGenVec3F b)
 {
     return new NuGenVec3F(
         a.y * b.z - a.z * b.y,
         a.z * b.x - a.x * b.z,
         a.x * b.y - a.y * b.x
         );
 }
Esempio n. 17
0
 public static float Dot(NuGenVec3F u, NuGenVec3F v)
 {
     return u[0] * v[0] + u[1] * v[1] + u[2] * v[2];
 }
Esempio n. 18
0
 public NuGenShift3F(NuGenVec3F shift)
 {
     v = shift;
 }
Esempio n. 19
0
 public NuGenScale3F(NuGenVec3F shift)
 {
     v = shift;
 }
Esempio n. 20
0
 public NuGenRay3F(NuGenPnt3F p, NuGenVec3F v)
 {
     this.p = p;
     this.v = v;
 }
Esempio n. 21
0
 public NuGenScale3F(float x, float y, float z)
 {
     v = new NuGenVec3F(x, y, z);
 }
Esempio n. 22
0
 public NuGenScale3F(NuGenVec3F shift)
 {
     v = shift;
 }
Esempio n. 23
0
 public static float Dot(NuGenVec3F u, NuGenVec3F v)
 {
     return(u[0] * v[0] + u[1] * v[1] + u[2] * v[2]);
 }
Esempio n. 24
0
 public NuGenRot3F(float radians, NuGenVec3F axis)
 {
     axis.Normalize();
     r = (float)Math.Cos(radians / 2.0);
     v = axis.Normalized * (float)Math.Sin(radians / 2.0);
 }
Esempio n. 25
0
 public NuGenRay3F(NuGenPnt3F p, NuGenVec3F v)
 {
     this.p = p;
     this.v = v;
 }
Esempio n. 26
0
 public NuGenShift3F(float x, float y, float z)
 {
     v = new NuGenVec3F(x, y, z);
 }