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(Transformation.Translation(new Vec(-0.5f, 0.0f, 0.0f)));
            CSGIntersection u1 = new CSGIntersection(s1, s2);

            Ray r1 = new Ray(origin: new Point(1.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 - Assert 2/");

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

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

            Ray r4 = new Ray(origin: new Point(0.0f, 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(0.0f, 0.0f, 0.0f), dir: Constant.VEC_X);

            Assert.True(u1.quickRayIntersection(r5), "TestQuickRayIntersection failed! - Assert 5/5");
        }
Esempio n. 2
0
        public void TestrayIntersectionList()
        {
            Sphere          s1 = new Sphere(Transformation.Translation(new Vec(0.5f, 0.0f, 0.0f)));
            Sphere          s2 = new Sphere(Transformation.Translation(new Vec(-0.5f, 0.0f, 0.0f)));
            CSGIntersection u1 = new CSGIntersection(s1, s2);
            Ray             r1 = new Ray(origin: new Point(1.0f, 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(-0.5f, 0.0f, 0.0f),
                         new Normal(1.0f, 0.0f, 0f),
                         new Vec2D(0.5f, 0.5f),
                         1.5f,
                         r1)
                     );
            hits.Add(new HitRecord(
                         new Point(0.5f, 0f, 0f),
                         new Normal(1.0f, 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.{i}/2");
            }
        }
Esempio n. 3
0
        public void TestrayIntersctionInner()
        {
            Sphere          s1 = new Sphere(Transformation.Translation(new Vec(0.5f, 0.0f, 0.0f)));
            Sphere          s2 = new Sphere(Transformation.Translation(new Vec(-0.5f, 0.0f, 0.0f)));
            CSGIntersection u1 = new CSGIntersection(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/5");
            HitRecord hit1 = new HitRecord(
                new Point(-0.5f, 0.0f, 0.0f),
                new Normal(1.0f, 0.0f, 0.0f),
                new Vec2D(0.5f, 0.5f),
                0.5f,
                r1
                );

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

            Ray       r2            = new Ray(origin: new Point(0.0f, 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(0.5f, 0.0f, 0.0f),
                new Normal(-1.0f, 0.0f, 0.0f),
                new Vec2D(0.0f, 0.5f),
                0.5f,
                r2
                );

            Assert.True(hit2.isClose(intersection2), "TestHit failed! - Assert 4/5");
        }
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(Transformation.Translation(new Vec(-0.5f, 0.0f, 0.0f)));
            CSGIntersection u1 = new CSGIntersection(s1, s2);

            Ray       r1            = new Ray(origin: new Point(1.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(0.5f, 0.0f, 0.0f),
                new Normal(1.0f, 0.0f, 0.0f),
                new Vec2D(0.0f, 0.5f),
                0.5f,
                r1
                );

            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 - Assert 3/");

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

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


            Point p1 = new Point(0.25f, 0f, 0f);
            Point p2 = new Point(0.25f, 0.1f, 0.1f);
            Point p3 = new Point(0.5f, 0.3f, 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");
        }
Esempio n. 6
0
        public void TestCSGCubeSphere()
        {
            Shape S1 = new Sphere(transformation: Transformation.Scaling(1.2f));
            Shape B1 = new Box();

            CSGIntersection IntCubeSphere = S1 * B1;

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

            Assert.True(intersection1 != null, "TestCSGCubeSphere 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.125f, 0.5f),
                4f,
                r1
                );

            // Console.WriteLine("hit : " + hit1.ToString());
            // Console.WriteLine("intersection : " + intersection1.ToString());

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

            Ray       r2            = new Ray(origin: new Point(2f, 2f, 0.0f), dir: (-Constant.VEC_X - Constant.VEC_Y).Normalize());
            HitRecord?intersection2 = IntCubeSphere.rayIntersection(r2);

            Assert.True(intersection2 != null, "TestCSGCubeSphere failed! - Assert 1/5");
            HitRecord hit2 = new HitRecord(
                (S1.transformation * new Point(MathF.Sqrt(2) / 2f, MathF.Sqrt(2) / 2f, 0.0f)),
                (S1.transformation * new Normal(MathF.Sqrt(2) / 2f, MathF.Sqrt(2) / 2f, 0.0f)),
                new Vec2D(0.125f, 0.5f),
                1.6284273f,
                r2
                );


            // Console.WriteLine(MathF.Sqrt(2) / 2f / 0.5892556f);

            Assert.True(hit2.isClose(intersection2), "TestCSGCubeSphere failed! - Assert 2/5");
        }