示例#1
0
        private static float?CheckSphereAt(Vector3 spherePosition, Vector3 origin, Vector3 direction)
        {
            var sphere = new Sphere(spherePosition, Color.red);
            var r      = new Ray(origin, direction);

            return(sphere.Intersect(r));
        }
示例#2
0
        public void RayMissesSphere()
        {
            var ray    = new Ray(Tuple3D.Point(0, 2, -5), Tuple3D.Vector(0, 0, 1));
            var sphere = new Sphere();

            var xs = sphere.Intersect(ray);

            Assert.That(xs.Count, Is.EqualTo(0), "intersection point count");
        }
示例#3
0
        public void IntersectSetsObjectOnIntersection()
        {
            var r  = new Ray(Tuple3D.Point(0, 0, -5), Tuple3D.Vector(0, 0, 1));
            var s  = new Sphere();
            var xs = s.Intersect(r);

            Assert.That(xs.Count, Is.EqualTo(2), "list count");
            Assert.That(xs[0].TheObject, Is.EqualTo(s), "intersection 1");
            Assert.That(xs[1].TheObject, Is.EqualTo(s), "intersection 2");
        }
示例#4
0
        public void IntersectTranslatedSphereWithRay()
        {
            var ray    = new Ray(Tuple3D.Point(0, 0, -5), Tuple3D.Vector(0, 0, 1));
            var sphere = new Sphere();

            sphere.Transform = Transformation.Translation(5, 0, 0);
            var xs = sphere.Intersect(ray);

            Assert.That(xs.Count, Is.EqualTo(0), "intersection point count");
        }
示例#5
0
        public void SphereBehindRay()
        {
            var ray    = new Ray(Tuple3D.Point(0, 0, 5), Tuple3D.Vector(0, 0, 1));
            var sphere = new Sphere();

            var xs = sphere.Intersect(ray);

            Assert.That(xs.Count, Is.EqualTo(2), "intersection point count");
            Assert.That(xs[0].Time, Is.EqualTo(-6), "xs[0]");
            Assert.That(xs[1].Time, Is.EqualTo(-4), "xs[1]");
        }
示例#6
0
        public void RayOriginatesInsideSphere()
        {
            var ray    = new Ray(Tuple3D.Point(0, 0, 0), Tuple3D.Vector(0, 0, 1));
            var sphere = new Sphere();

            var xs = sphere.Intersect(ray);

            Assert.That(xs.Count, Is.EqualTo(2), "intersection point count");
            Assert.That(xs[0].Time, Is.EqualTo(-1), "xs[0]");
            Assert.That(xs[1].Time, Is.EqualTo(1), "xs[1]");
        }
示例#7
0
        public void RayIntersectsSphereAtTangent()
        {
            var ray    = new Ray(Tuple3D.Point(0, 1, -5), Tuple3D.Vector(0, 0, 1));
            var sphere = new Sphere();

            var xs = sphere.Intersect(ray);

            Assert.That(xs.Count, Is.EqualTo(2), "intersection point count");
            Assert.That(xs[0].Time, Is.EqualTo(5), "xs[0]");
            Assert.That(xs[1].Time, Is.EqualTo(5), "xs[1]");
        }
示例#8
0
        public void IntersectScaledSphereWithRay()
        {
            var ray    = new Ray(Tuple3D.Point(0, 0, -5), Tuple3D.Vector(0, 0, 1));
            var sphere = new Sphere
            {
                Transform = Transformation.Scaling(2, 2, 2)
            };
            var xs = sphere.Intersect(ray);

            Assert.That(xs.Count, Is.EqualTo(2), "intersection point count");
            Assert.That(xs[0].Time, Is.EqualTo(3), "xs[0]");
            Assert.That(xs[1].Time, Is.EqualTo(7), "xs[1]");
        }