Exemplo n.º 1
0
        public void DefaultMaterial()
        {
            var s        = new TestShape();
            var expected = new Material();

            Assert.Equal(expected, s.Material);
        }
Exemplo n.º 2
0
        public void AddChildToGroup()
        {
            var g = new Group();
            var s = new TestShape();

            g.Add(s);
            Assert.NotEmpty(g);
            Assert.Contains(s, g);
            Assert.Equal(g, s.Parent);
        }
Exemplo n.º 3
0
        public void AssignTransformation()
        {
            var s = new TestShape()
            {
                Transform = Transform.Translate(2, 3, 4),
            };

            var expected = Transform.Translate(2, 3, 4);

            Assert.Equal(expected, s.Transform);
        }
Exemplo n.º 4
0
        public void IntersectTranslatedShapeWithRay()
        {
            var r = new Ray(Vector4.CreatePosition(0, 0, -5), Vector4.CreateDirection(0, 0, 1));
            var s = new TestShape();

            s.Transform = Transform.Translate(5, 0, 0);
            var xs       = s.Intersect(r);
            var savedRay = s.SavedRay.Value;

            Assert.Equal(Vector4.CreatePosition(-5, 0, -5), savedRay.Origin);
            Assert.Equal(Vector4.CreateDirection(0, 0, 1), savedRay.Direction);
        }
Exemplo n.º 5
0
        public void TestShapeHasArbitraryBounds()
        {
            var s   = new TestShape();
            var box = s.GetBounds();

            Assert.Equal(
                Vector4.CreatePosition(-1, -1, -1),
                box.Min);
            Assert.Equal(
                Vector4.CreatePosition(1, 1, 1),
                box.Max);
        }
Exemplo n.º 6
0
        public void IntersectGroupTestsChildrenIfBoxHit()
        {
            var child = new TestShape();
            var shape = new Group();

            shape.Add(child);
            var r = new Ray(
                Vector4.CreatePosition(0, 0, -5),
                Vector4.CreateDirection(0, 0, 1));
            var xs = shape.Intersect(r);

            Assert.NotNull(child.SavedRay);
        }
Exemplo n.º 7
0
        public void IntersectCsgTestsChildrenIfBoxHit()
        {
            var left  = new TestShape();
            var right = new TestShape();
            var shape = new Csg(Operation.Difference, left, right);
            var r     = new Ray(
                Vector4.CreatePosition(0, 0, -5),
                Vector4.CreateDirection(0, 0, 1));
            var xs = shape.Intersect(r);

            Assert.NotNull(left.SavedRay);
            Assert.NotNull(right.SavedRay);
        }
Exemplo n.º 8
0
        public void ComputeNormalOnTranslatedShape()
        {
            var s = new TestShape()
            {
                Transform = Transform.Translate(0, 1, 0),
            };

            var          n        = s.GetNormal(Vector4.CreatePosition(0, 1.70711, -0.70711));
            var          expected = Vector4.CreateDirection(0, 0.70711, -0.70711);
            const double eps      = 0.00001;
            var          comparer = Vector4.GetEqualityComparer(eps);

            Assert.Equal(expected, n, comparer);
        }
Exemplo n.º 9
0
        public void AssigningMaterial()
        {
            var m = new Material
            {
                Ambient = 1,
            };

            var s = new TestShape()
            {
                Material = m,
            };

            Assert.Equal(m, s.Material);
        }
Exemplo n.º 10
0
        public void ComputeNormalOnTransformedShape()
        {
            var s = new TestShape()
            {
                Transform =
                    Transform.Scale(1, 0.5, 1) *
                    Transform.RotateZ(Math.PI / 5),
            };

            var          n        = s.GetNormal(Vector4.CreatePosition(0, Math.Sqrt(2) / 2, -Math.Sqrt(2) / 2));
            var          expected = Vector4.CreateDirection(0, 0.97014, -0.24254);
            const double eps      = 0.00001;
            var          comparer = Vector4.GetEqualityComparer(eps);

            Assert.Equal(expected, n, comparer);
        }
Exemplo n.º 11
0
        public void DefaultTransformation()
        {
            var s = new TestShape();

            Assert.Equal(Matrix4x4.Identity, s.Transform);
        }
Exemplo n.º 12
0
        public void ShapeHasParentAttribute()
        {
            var s = new TestShape();

            Assert.Null(s.Parent);
        }