Exemplo n.º 1
0
        public void TestrayIntersectionList()
        {
            Sphere   s1 = new Sphere();
            Sphere   s2 = new Sphere(Transformation.Translation(new Vec(0.0f, 0.5f, 0.0f)));
            CSGUnion u1 = new CSGUnion(s1, s2);

            Ray r = new Ray(origin: new Point(0.0f, 2.0f, 0f), dir: -Constant.VEC_Y);

            Assert.True(u1.rayIntersection(r) != null, "TestHit failed! - Assert 1/2");

            List <HitRecord?> intersection = u1.rayIntersectionList(r);
            List <HitRecord>  hits         = new List <HitRecord>();

            hits.Add(new HitRecord(
                         new Point(0.0f, -1.0f, 0f),
                         new Normal(0.0f, 1.0f, 0f),
                         new Vec2D(0.75f, 0.5f),
                         3.0f,
                         r)
                     );
            hits.Add(new HitRecord(
                         new Point(0.0f, 1.5f, 0f),
                         new Normal(0.0f, 1.0f, 0f),
                         new Vec2D(0.25f, 0.5f),
                         0.5f,
                         r)
                     );
            hits.Sort();

            for (int i = 0; i < 2; i++)
            {
                Assert.True(hits[i].isClose((HitRecord)intersection[i]), "TestRayIntersectionList failed - assert 2/2");
            }
        }
Exemplo n.º 2
0
        public void TestrayIntersctionInner()
        {
            Sphere s1 = new Sphere();
            Sphere s2 = new Sphere(Transformation.Translation(new Vec(0.5f, 0.0f, 0.0f)));

            CSGUnion u1   = new CSGUnion(s1, s2);
            Ray      ray1 = new Ray(origin: new Point(0.5f, 0f, 0f), dir: Constant.VEC_X);

            HitRecord?intersection1 = u1.rayIntersection(ray1);

            Assert.True(intersection1 != null, "TestInnerHit failed! - Assert 1/4");
            HitRecord hit1 = new HitRecord(
                new Point(1.5f, 0.0f, 0.0f),
                new Normal(-1.0f, 0.0f, 0.0f),
                new Vec2D(0.0f, 0.5f),
                1.0f,
                ray1
                );

            Assert.True(hit1.isClose(intersection1), "TestInnerHit failed! - Assert 2/4");

            // now from the other side
            Ray ray2 = new Ray(origin: new Point(0.5f, 0f, 0f), dir: -Constant.VEC_X);

            HitRecord?intersection2 = u1.rayIntersection(ray2);

            Assert.True(intersection2 != null, "TestInnerHit failed! - Assert 3/4");
            HitRecord hit2 = new HitRecord(
                new Point(-1.0f, 0.0f, 0.0f),
                new Normal(1.0f, 0.0f, 0.0f),
                new Vec2D(0.5f, 0.5f),
                1.5f,
                ray2
                );

            Assert.True(hit2.isClose(intersection2), "TestInnerHit failed! - Assert 4/4");
        }
Exemplo n.º 3
0
        public void TestrayIntersection()
        {
            Sphere s1 = new Sphere();
            Sphere s2 = new Sphere(Transformation.Translation(new Vec(0.0f, 1.7f, 0.0f)));

            CSGUnion  u1            = new CSGUnion(s1, s2);
            Ray       ray1          = new Ray(origin: new Point(3f, 0f, 0f), dir: -Constant.VEC_X);
            HitRecord?intersection1 = u1.rayIntersection(ray1);

            Assert.True(intersection1 != null, "TestHit failed! - Assert 1/5");
            HitRecord hit1 = new HitRecord(
                new Point(1f, 0.0f, 0.0f),
                Constant.VEC_X_N,
                new Vec2D(0.0f, 0.5f),
                3.0f,
                ray1
                );

            Assert.True(hit1.isClose(intersection1), "TestHit failed! - Assert 2/5");

            Ray       ray2          = new Ray(new Point(6f, 1.7f, 0f), -Constant.VEC_X);
            HitRecord?intersection2 = u1.rayIntersection(ray2);

            Assert.True(intersection2 != null, "TestHit failed! - Assert 3/5");
            HitRecord hit2 = new HitRecord(
                new Point(1.0f, 1.7f, 0.0f),
                Constant.VEC_X_N,
                new Vec2D(0.0f, 0.5f),
                6.0f,
                ray2
                );

            Assert.True(hit2.isClose(intersection2), "TestHit failed! - Assert 4/5");

            Assert.True(u1.rayIntersection(new Ray(new Point(0f, 10f, 2f), -Constant.VEC_Z)) == null, "TestHit failed! - Assert 5/5 ");
        }