Exemplo n.º 1
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");
        }
Exemplo n.º 2
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/");
        }