Esempio n. 1
0
        public void TestQuickRayIntersection()
        {
            Sphere        s1 = new Sphere(Transformation.Translation(new Vec(0.5f, 0.0f, 0.0f)));
            Sphere        s2 = new Sphere();
            CSGDifference u1 = new CSGDifference(s1, s2);

            Ray r1 = new Ray(origin: new Point(0.0f, 0.0f, 0.0f), dir: Constant.VEC_X);

            Assert.True(u1.quickRayIntersection(r1), "TestQuickRayIntersection failed! - Assert 1/");

            Ray r2 = new Ray(origin: new Point(12.0f, 12.0f, 10.0f), dir: Constant.VEC_Z);

            Assert.False(u1.quickRayIntersection(r2), "Far away ray test failed - Asser 2/");

            Ray r3 = new Ray(origin: new Point(0.0f, 0.0f, 1.0f), dir: -Constant.VEC_Z);

            Assert.False(u1.quickRayIntersection(r3), "Ray through secondShape only test failed - Asser 3/");

            Ray r4 = new Ray(origin: new Point(1.25f, 0.0f, 0.0f), dir: -Constant.VEC_X);

            Assert.True(u1.quickRayIntersection(r4), "TestQuickRayIntersection failed! - Assert 4/5");

            Ray r5 = new Ray(origin: new Point(1.25f, 0.0f, 0.0f), dir: Constant.VEC_X);

            Assert.True(u1.quickRayIntersection(r5), "TestQuickRayIntersection failed! - Assert 5/5");
        }
Esempio n. 2
0
        public void TestrayIntersctionInner()
        {
            Sphere        s1 = new Sphere(Transformation.Translation(new Vec(0.5f, 0.0f, 0.0f)));
            Sphere        s2 = new Sphere();
            CSGDifference u1 = new CSGDifference(s1, s2);

            Ray       r1            = new Ray(origin: new Point(1.25f, 0.0f, 0.0f), dir: -Constant.VEC_X);
            HitRecord?intersection1 = u1.rayIntersection(r1);

            Assert.True(intersection1 != null, "TestHit failed! - Assert 1/5");
            HitRecord hit1 = new HitRecord(
                new Point(1.0f, 0.0f, 0.0f),
                new Normal(1.0f, 0.0f, 0.0f),
                new Vec2D(0.0f, 0.5f),
                0.25f,
                r1
                );

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

            Ray       r2            = new Ray(origin: new Point(1.25f, 0.0f, 0.0f), dir: Constant.VEC_X);
            HitRecord?intersection2 = u1.rayIntersection(r2);

            Assert.True(intersection2 != null, "TestHit failed! - Assert 3/5");
            HitRecord hit2 = new HitRecord(
                new Point(1.5f, 0.0f, 0.0f),
                new Normal(-1.0f, 0.0f, 0.0f),
                new Vec2D(0.0f, 0.5f),
                0.25f,
                r2
                );

            Assert.True(hit2.isClose(intersection2), "TestHit failed! - Assert 4/5");
        }
Esempio n. 3
0
        public void TestrayIntersectionList()
        {
            Sphere        s1 = new Sphere(Transformation.Translation(new Vec(0.5f, 0.0f, 0.0f)));
            Sphere        s2 = new Sphere();
            CSGDifference u1 = new CSGDifference(s1, s2);
            Ray           r1 = new Ray(origin: new Point(0.5f, 0.0f, 0.0f), dir: Constant.VEC_X);

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


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

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

            Ray       r1            = new Ray(origin: new Point(0.0f, 0.0f, 0.0f), dir: Constant.VEC_X);
            HitRecord?intersection1 = u1.rayIntersection(r1);

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

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

            Ray       r2            = new Ray(origin: new Point(12.0f, 12.0f, 10.0f), dir: Constant.VEC_Z);
            HitRecord?intersection2 = u1.rayIntersection(r2);

            Assert.True(intersection2 == null, "Far away ray test failed - Asser 3/");

            Ray       r3            = new Ray(origin: new Point(0.0f, 0.0f, 1.0f), dir: -Constant.VEC_Z);
            HitRecord?intersection3 = u1.rayIntersection(r3);

            Assert.True(intersection3 == null, "Ray through secondShape only test failed - Asser 4/");
        }
Esempio n. 5
0
        public void TestisPointInside()
        {
            Sphere        s1 = new Sphere();
            Sphere        s2 = new Sphere(Transformation.Translation(new Vec(0.5f, 0.0f, 0.0f)));
            CSGDifference u1 = new CSGDifference(s2, s1);


            Point p1 = new Point(1.25f, 0f, 0f);
            Point p2 = new Point(1.25f, 0.2f, 0.2f);
            Point p3 = new Point(0.95f, 0f, 0f);

            Assert.True(u1.isPointInside(p1), "Test isPointInside failed - assert 1/4");
            Assert.True(u1.isPointInside(p2), "Test isPointInside failed - assert 2/4");
            Assert.False(u1.isPointInside(p3), "Test isPointInside failed - assert 4/4");
        }