예제 #1
0
        public void TestRayAABBIntersect()
        {
            Vector3 rayStart = new Vector3(0, 0, 0);
            Vector3 rayDir   = new Vector3(0, 0, 1);

            double s, t;

            Bounds bounds = new Bounds(new Vector3(-1, -1, -1), new Vector3(1, 1, 1));

            // Check that ray hits AABB (ray starts inside the bounds)
            Assert.IsTrue(GeometryMath.IntersectAABB(rayStart, rayDir, bounds.Min, bounds.Max, out s, out t), "Expected to hit AABB but did not (ray starts inside AABB)");

            rayStart = new Vector3(0, 0, -2);
            // Check that ray hits AABB (ray starts outside the bounds)
            Assert.IsTrue(GeometryMath.IntersectAABB(rayStart, rayDir, bounds.Min, bounds.Max, out s, out t), "Expected to hit AABB but did not (ray starts outside AABB)");

            rayDir = new Vector3(0, 0, -1);
            // Check that ray does not hit AABB (ray goes to other direction)
            Assert.IsFalse(GeometryMath.IntersectAABB(rayStart, rayDir, bounds.Min, bounds.Max, out s, out t), "Expected to miss AABB but did not (ray goes away from AABB)");

            rayStart = new Vector3(1, 0, -2);
            rayDir   = new Vector3(1, 0, 1);
            // Check that ray does not hit AABB (ray is co-linear with one side of the AABB)
            Assert.IsFalse(GeometryMath.IntersectAABB(rayStart, rayDir, bounds.Min, bounds.Max, out s, out t), "Expected to miss AABB but did not (ray is co-linear with one side of the AABB)");
        }
예제 #2
0
        protected virtual bool RayCheckInternal(int time, Vector3 rayStart, Vector3 rayDirection, out int triangleIndex, out bool hitOpaque, out Vector3 intersection)
        {
            hitOpaque     = false;
            triangleIndex = -1;
            double tmin, tmax;
            Bounds bounds = WorldBounds;

            GeometryMath.IntersectAABB(rayStart, rayDirection, bounds.Min, bounds.Max, out tmin, out tmax);
            intersection = WorldBounds.Center - rayDirection.GetNormalized() * Math.Min(tmin, tmax);
            return(true);
        }
예제 #3
0
        public bool RayCheck(int time, Vector3 rayStart, Vector3 rayDirection, out int triangleIndex, out bool hitOpaque, out Vector3 intersection)
        {
            hitOpaque     = false;
            triangleIndex = 0;
            intersection  = new Vector3(0, 0, 0);
            double tmin, tmax;
            Bounds bounds = WorldBounds;

            if (GeometryMath.IntersectAABB(rayStart, rayDirection, bounds.Min, bounds.Max, out tmin, out tmax))
            {
                return(RayCheckInternal(time, rayStart, rayDirection, out triangleIndex, out hitOpaque, out intersection));
            }

            return(false);
        }