Exemplo n.º 1
0
        public void CanFailToInsersectWithRayFacingAwayFromSphere()
        {
            // Arrange
            var sphere = new Sphere() { Center = new Vector(0, 0, 0), Radius = 1 };
            var ray = new Ray() { Start = new Vector(0, 0, -2), Direction = new Vector(0, 0, -1) };

            // Act
            var isect = sphere.Intersect(ray);

            // Assert
            Assert.IsNull(isect);
        }
Exemplo n.º 2
0
        public void CanCalculateNormalToSphere()
        {
            // Arrange
            var sphere = new Sphere() { Center = new Vector(0, 0, 0), Radius = 1 };
            var position = new Vector(1,0,0);

            // Act
            var normal = sphere.Normal(position);

            // Assert
            Assert.NotNull(normal);
            Assert.IsTrue(normal.Equals(new Vector(1,0,0)));
        }
Exemplo n.º 3
0
        public void CanIntersectEdgeOfSphere()
        {
            // Arrange
            var sphere = new Sphere() { Center = new Vector(0, 0, 0), Radius = 1 };
            var ray = new Ray() { Start = new Vector(1, 0, -2), Direction = new Vector(0, 0, 1) };

            // Act
            var isect = sphere.Intersect(ray);

            // Assert
            Assert.NotNull(isect);
            Assert.AreEqual(2, isect.Distance);
            Assert.AreEqual(sphere, isect.Element);
        }