示例#1
0
        public override void InitWorld()
        {
            DefaultFloor();
            Light(0, 4, 0);
            Light(5, 15, -5, Color.White);

            var cube            = new Cube();
            var sphere          = new Sphere().Scale(1.4);
            var csgIntersection = new CsgIntersection(sphere, cube);

            var cyl1 = new Cylinder(-4, 4)
            {
                Material = new Material(Red)
            }.Scale(sx: 0.75, sz: 0.75);
            var cyl2 = new Cylinder(-4, 4)
            {
                Material = new Material(Green)
            }.Scale(sx: 0.75, sz: 0.75).Rotate(rx: Pi / 2);
            var cyl3 = new Cylinder(-4, 4)
            {
                Material = new Material(Blue)
            }.Scale(sx: 0.75, sz: 0.75).Rotate(rz: Pi / 2);
            var csgUnion = new CsgUnion(cyl1, new CsgUnion(cyl2, cyl3));

            var csgDifference = new CsgDifference(csgIntersection, csgUnion);

            csgDifference.Translate(ty: 1).Rotate(ry: Pi / 4);
            Add(csgDifference);
        }
示例#2
0
        public void CsgIntersectionTest()
        {
            var csgIntersection = new CsgIntersection().Add(sphere).Add(box);

            Check.That(csgIntersection.Type).IsEqualTo("intersection");
            var povCode = csgIntersection.ToPovCode();

            Check.That(povCode).IsEqualTo("intersection {\n sphere {\n < 0, 0, 0>, 1\n}\nobject {\n MyBox\n}\n}");
        }
示例#3
0
        public void CsgDemoTest()
        {
            scene.Name = "TestCsg";

            var cylinderX = scene.Declare("cylinderX", new Cylinder()
            {
                BasePoint = _V(-2, 0, 0), CapPoint = _V(2, 0, 0), Radius = 0.5
            });
            var cylinderY = scene.Declare("cylinderY", new Cylinder()
            {
                BasePoint = _V(0, -2, 0), CapPoint = _V(0, 2, 0), Radius = 0.5
            });
            var cylinderZ = scene.Declare("cylinderZ", new Cylinder()
            {
                BasePoint = _V(0, 0, -2), CapPoint = _V(0, 0, 2), Radius = 0.5
            });

            var csgUnion = new CsgUnion()
                           .Add(cylinderX)
                           .Add(cylinderY)
                           .Add(cylinderZ)
                           .AddModifiers(new Pigment(_Red));

            scene.Add(csgUnion);

            var csgIntersection = new CsgIntersection()
                                  .Add(cylinderX)
                                  .Add(cylinderY)
                                  .Add(cylinderZ)
                                  .AddModifiers(new Pigment(_Green))
                                  .Translate(0, 0, 3);

            scene.Add(csgIntersection);

            var csgDifference = new CsgDifference(cylinderX)
                                .Add(cylinderY)
                                .Add(cylinderZ)
                                .AddModifiers(new Pigment(_Blue))
                                .Translate(3, 0, -3);

            scene.Add(csgDifference);
            var path = engine.Render(scene, options, false);
        }
示例#4
0
        public void FilteringIntersections_Intersection_Test()
        {
            var csg = new CsgIntersection(s1, s2);

            FilteringIntersectionsTest(csg, 1, 2);
        }
示例#5
0
        public void IntersectionAllowedTest(bool leftHit, bool insideLeft, bool insideRight, bool expected)
        {
            var intersectionCsg = new CsgIntersection(new Sphere(), new Sphere());

            Check.That(intersectionCsg.IntersectionAllowed(leftHit, insideLeft, insideRight)).IsEqualTo(expected);
        }
示例#6
0
        public DroidHead(Pigment mainPigment, Pigment decoPigmentMajor, Pigment decoPigmentMinor)
        {
            double yBottomSkull = 2 * rSkull - hSkull;
            double rBottomSkull = Math.Sqrt(Math.Pow(rSkull, 2) - Math.Pow(hSkull - rSkull, 2));

            #region SkullNeck
            var skull = new CsgDifference(
                new Sphere()
            {
                Center = _V(0, rSkull, 0), Radius = rSkull
            })
                        .Add(new Box()
            {
                Corner1 = _V(-1), Corner2 = _V(1, yBottomSkull, 1)
            });
            Local(nameof(skull), skull);

            var neck = new CsgDifference(
                new Cone()
            {
                BaseRadius = rBottomSkull,
                BasePoint  = _V(0, yBottomSkull, 0),
                CapPoint   = _V(0, yBottomSkull - 0.5, 0)
            })
                       .Add(new Box()
            {
                Corner1 = _V(-1, yBottomSkull - hNeck, -1), Corner2 = _V(1, -1, 1)
            })
            ;
            Local(nameof(neck), neck);
            #endregion
            #region Deco
            var smallDecoBox = new Box()
            {
                Corner1 = _V(-1, 0, -1), Corner2 = _V(1, 1, 1)
            };
            Local(nameof(smallDecoBox), smallDecoBox);

            var topRing    = smallDecoBox.Obj().ScaleY(hTopRing).TranslateY(yTopRing);
            var bottomRing = smallDecoBox.Obj().ScaleY(hBottomRing);

            var middleRing = new CsgDifference(
                smallDecoBox.Obj()
                .ScaleY(hBottomRing)
                .TranslateY(yMiddleRing))
                             .Add(new Cylinder {
                BasePoint = yBigEye * _Y, CapPoint = yBigEye * _Y + 2 * _Z, Radius = rBigEye * 1.2
            })
            ;

            var minorDecoElements = new CsgUnion()
                                    .Add(topRing)
                                    .Add(bottomRing)
                                    .TranslateY(yBottomSkull)
            ;

            var minorDeco = new CsgIntersection()
                            .Add(new Sphere()
            {
                Center = rSkull * _Y, Radius = rSkull * 1.0005
            })
                            .Add(minorDecoElements)
                            .AddModifiers(decoPigmentMinor);
            ;

            var miscDeco = new CsgUnion();
            for (int i = 0; i < 10; i++)
            {
                miscDeco.Add(
                    smallDecoBox.Obj().Scale(1, hTopRing, 0.02).RotateY(30 * i + 15),
                    smallDecoBox.Obj().Scale(1, hTopRing, 0.05).RotateY(30 * i));
            }

            miscDeco.TranslateY(hBottomRing);

            var majorDecoElements = new CsgUnion().Add(
                middleRing,
                miscDeco)
                                    .TranslateY(yBottomSkull)
            ;
            var majorDeco = new CsgIntersection()
                            .Add(new Sphere()
            {
                Center = rSkull * _Y, Radius = rSkull * 1.0005
            })
                            .Add(majorDecoElements)
                            .AddModifiers(decoPigmentMajor);
            ;
            #endregion

            double zBigEye = Math.Sqrt(Math.Pow(rSkull, 2) - Math.Pow(yBigEye, 2));
            var    bigEye  = new Sphere {
                Center = _V(0, yBigEye + yBottomSkull, zBigEye), Radius = rBigEye
            }
            .AddModifiers(new Pigment(_Black));
            double zSmallEye = Math.Sqrt(Math.Pow(rSkull, 2) - Math.Pow(ySmallEye, 2));
            var    smallEye  = new Sphere {
                Center = _V(0, ySmallEye + yBottomSkull, zSmallEye), Radius = rSmallEye
            }
            .RotateY(aSmallEye)
            .AddModifiers(new Pigment(_Black));

            Add(bigEye, smallEye, majorDeco, minorDeco, skull, neck);
            AddModifiers(mainPigment);
            this.TranslateY(-yBottomSkull + hNeck);
        }