Esempio n. 1
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. 2
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. 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 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;
        }