コード例 #1
0
 /// <summary>
 /// Tests for intersection between a <see cref="Ray"/> and a <see cref="Sphere"/>.
 /// </summary>
 /// <param name="ray">A <see cref="Ray"/> instance.</param>
 /// <param name="sphere">A <see cref="Sphere"/> instance.</param>
 /// <returns>An <see cref="IntersectionPair"/> instance containing the intersection information.</returns>
 public static IntersectionPair Intersects(Ray ray, Sphere sphere)
 {
     // TODO: Implement this.
     throw new NotImplementedException();
 }
コード例 #2
0
        /// <summary>
        /// Tests for intersection between a <see cref="Ray"/> and a <see cref="Triangle"/>.
        /// </summary>
        /// <param name="ray">A <see cref="Ray"/> instance.</param>
        /// <param name="triangle">A <see cref="Triangle"/> instance.</param>
        /// <returns>An <see cref="IntersectionPair"/> instance containing the intersection information.</returns>
        /// <remarks>
        /// For information about the algorithm visit http://www.acm.org/jgt/papers/MollerTrumbore97/ 
        /// </remarks>
        public static IntersectionPair Intersects(Ray ray, Triangle triangle)
        {
            // Find the vectors for the 2 edges sharing trangle.Point0
            Vector3F edge1 = triangle.Point1 - triangle.Point0;
            Vector3F edge2 = triangle.Point2 - triangle.Point0;

            // Begin calculating determinant - also used to calc the U parameter.
            Vector3F pvec = Vector3F.CrossProduct(ray.Direction, edge2);

            float det = Vector3F.Dot(edge1, pvec);

            // If determinant is zero the ray lies in plane of the triangle
            if (MathFunctions.ApproxEquals(det, 0.0f))
            {
                return new IntersectionPair(false, Vector3F.Zero);
            }

            float invDet = 1.0f / det;

            // Calculate the distance from triangle.Point0 to the ray origin
            Vector3F tvec = ray.Origin - triangle.Point0;

            // Calculate U parameter and test bounds
            float u = Vector3F.Dot(tvec, pvec) * invDet;
            if ((u < 0.0f) || u > 1.0f)
                return new IntersectionPair(false, Vector3F.Zero);

            // Prepare to test the V parameter
            Vector3F qvec  = Vector3F.CrossProduct(tvec, edge1);

            // Calculate V parameter and test bounds
            float v = Vector3F.Dot(ray.Direction, qvec) * invDet;
            if ((v < 0.0f) || v > 1.0f)
                return new IntersectionPair(false, Vector3F.Zero);

            // The ray intersects the triangle
            // Calculate the distance from  the ray origin to the intersection point.
            //t = Vector3F.Dot(edge2, qvec) * invDet;

            return new IntersectionPair(true, triangle.FromBarycentric(u,v));
        }
コード例 #3
0
 /// <summary>
 /// Tests for intersection between a <see cref="Ray"/> and an <see cref="AxisAlignedBox">axis aligned box</see>.
 /// </summary>
 /// <param name="ray">A <see cref="Ray"/> instance.</param>
 /// <param name="aabb">A <see cref="AxisAlignedBox"/> instance.</param>
 /// <returns>An <see cref="IntersectionPair"/> instance containing the intersection information.</returns>
 public static IntersectionPair Intersects(Ray ray, AxisAlignedBox aabb)
 {
     // TODO: Implement this.
     throw new NotImplementedException();
 }
コード例 #4
0
 /// <summary>
 /// Tests for intersection between a <see cref="Ray"/> and an <see cref="OrientedBox">oriented box</see>.
 /// </summary>
 /// <param name="ray">A <see cref="Ray"/> instance.</param>
 /// <param name="obb">A <see cref="OrientedBox"/> instance.</param>
 /// <returns>An <see cref="IntersectionPair"/> instance containing the intersection information.</returns>
 public static IntersectionPair Intersects(Ray ray, OrientedBox obb)
 {
     // TODO: Implement this.
     throw new NotImplementedException();
 }
コード例 #5
0
        /// <summary>
        /// Tests for intersection between a <see cref="Ray"/> and a <see cref="Plane"/>.
        /// </summary>
        /// <param name="ray">A <see cref="Ray"/> instance.</param>
        /// <param name="plane">A <see cref="Plane"/> instance.</param>
        /// <returns>An <see cref="IntersectionPair"/> instance containing the intersection information.</returns>
        public static IntersectionPair Intersects(Ray ray, Plane plane)
        {
            bool intersect = false;
            Vector3F hitPoint = Vector3F.Zero;
            float denominator = Vector3F.Dot(plane.Normal, ray.Direction);

            // Check if the ray is parrallel to the plane
            if (MathFunctions.ApproxEquals(denominator, 0.0f))
            {
                // If the line is parallel to the plane it only intersects the plane if it is on the plane.
                intersect = (plane.GetSign(ray.Origin) == MathFunctions.Sign.Zero);
                if (intersect)
                    hitPoint = ray.Origin;
            }
            else
            {
                float t = (plane.Constant - Vector3F.Dot(plane.Normal, ray.Origin)) / denominator;
                hitPoint = ray.Origin + ray.Direction * t;
                intersect = true;
            }

            return new IntersectionPair(intersect, hitPoint);
        }
コード例 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Ray"/> class using given ray.
 /// </summary>
 /// <param name="ray">A <see cref="Ray"/> instance to assign values from.</param>
 public Ray(Ray ray)
 {
     _origin		= ray.Origin;
     _direction	= ray.Direction;
 }
コード例 #7
0
 /// <summary>
 /// Tests for intersection between a <see cref="Ray"/> and a <see cref="Sphere"/>.
 /// </summary>
 /// <param name="ray">A <see cref="Ray"/> instance.</param>
 /// <param name="sphere">A <see cref="Sphere"/> instance.</param>
 /// <returns>An <see cref="IntersectionPair"/> instance containing the intersection information.</returns>
 public static IntersectionPair Intersects(Ray ray, Sphere sphere)
 {
     // TODO: Implement this.
     throw new NotImplementedException();
 }
コード例 #8
0
 /// <summary>
 /// Tests for intersection between a <see cref="Ray"/> and an <see cref="OrientedBox">oriented box</see>.
 /// </summary>
 /// <param name="ray">A <see cref="Ray"/> instance.</param>
 /// <param name="obb">A <see cref="OrientedBox"/> instance.</param>
 /// <returns>An <see cref="IntersectionPair"/> instance containing the intersection information.</returns>
 public static IntersectionPair Intersects(Ray ray, OrientedBox obb)
 {
     // TODO: Implement this.
     throw new NotImplementedException();
 }
コード例 #9
0
 /// <summary>
 /// Tests for intersection between a <see cref="Ray"/> and an <see cref="AxisAlignedBox">axis aligned box</see>.
 /// </summary>
 /// <param name="ray">A <see cref="Ray"/> instance.</param>
 /// <param name="aabb">A <see cref="AxisAlignedBox"/> instance.</param>
 /// <returns>An <see cref="IntersectionPair"/> instance containing the intersection information.</returns>
 public static IntersectionPair Intersects(Ray ray, AxisAlignedBox aabb)
 {
     // TODO: Implement this.
     throw new NotImplementedException();
 }