Exemple #1
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");
        }
Exemple #2
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/");
        }
Exemple #3
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");
        }