private void TheOneRing()
        {
            const double r1 = 1;
            const double r2 = 0.2;

            void CirclePath(double t, out double x, out double y, out double z)
            {
                x = r1 * Math.Cos(2 * Pi * t);
                y = 0;
                z = r1 * Math.Sin(2 * Pi * t);
            }

            void CircleCurve(double u, double v, out double x, out double y)
            {
                x = r2 * 0.5 * Math.Cos(2 * Pi * v);
                y = r2 * Math.Sin(2 * Pi * v);
            }

            CurveSweepMesh mesh = new CurveSweepMesh(100, 40, CirclePath, CircleCurve);

            TriangleMeshFactory triFactory = new TriangleMeshFactory();
            var torusTriangle = triFactory.Build(mesh);

            torusTriangle.Material = new Material((Yellow + Brown) / 2, reflective: 1, diffuse: 1, specular: 2, ambient: 0);
            Add(torusTriangle).Translate(ty: r2);
        }
Beispiel #2
0
        public PrismMeshScene()
        {
            DefaultFloor();
            Light(1, 1, -1);

            Add(BuildPolygon(3).Scale(0.2, 0.25, 0.2).Translate(tx: -0.75, tz: 0));
            Add(BuildPolygon(4).Scale(0.2, 0.25, 0.2).Translate(tx: -0, tz: 0.75));
            Add(BuildPolygon(5).Scale(0.2, 0.25, 0.2).Translate(tx: 0.75, tz: 0.5));
            Add(BuildPolygon(6).Scale(0.2, 0.25, 0.2).Translate(tx: 0.5, tz: -0.5));

            IEnumerable <Tuple> points = new Tuple[]
            {
                Helper.CreatePoint(-3, 0, 5),
                Helper.CreatePoint(3, 0, 5),
                Helper.CreatePoint(3, 0, 3),
                Helper.CreatePoint(-1, 0, 3),
                Helper.CreatePoint(-1, 0, 1),
                Helper.CreatePoint(1, 0, 1),

                Helper.CreatePoint(1, 0, -1),
                Helper.CreatePoint(-1, 0, -1),
                Helper.CreatePoint(-1, 0, -3),
                Helper.CreatePoint(3, 0, -3),
                Helper.CreatePoint(3, 0, -5),
                Helper.CreatePoint(-3, 0, -5)
            };

            var mesh = new PrismMesh(points);
            var triangleMeshFactory = new TriangleMeshFactory(false);
            var letterE             = (triangleMeshFactory.Build(mesh).Scale(0.1).Rotate(ry: Math.PI / 4));

            letterE.Material.Pattern = new SolidPattern(Color._Blue);
            Add(letterE);
        }
Beispiel #3
0
        public CurveSweepScene()
        {
            DefaultFloor();
            Light(0, 5, -5);

            var curveSweepMesh  = new CurveSweepMesh(36 * 10, 18, Path, Curve);
            var triangleFactory = new TriangleMeshFactory();
            var curveSweep      = triangleFactory.Build(curveSweepMesh);

            Add(curveSweep.Rotate(rx: Pi / 2).Translate(ty: 0.55));
        }
Beispiel #4
0
        public Prism(IEnumerable <Point2D> points)
        {
            var point2Ds = points as Point2D[] ?? points.ToArray();
            var bottom   = BuildPolygonShape(point2Ds);
            var top      = BuildPolygonShape(point2Ds).Translate(ty: 1);

            var mesh = new PrismMesh(point2Ds);
            var triangleMeshFactory = new TriangleMeshFactory(false);
            var walls = triangleMeshFactory.Build(mesh);

            Add(walls, top, bottom);
        }
Beispiel #5
0
        private IShape BuildPolygon(int n)
        {
            var points = Enumerable.Range(0, n).Select(i =>
            {
                var x = Math.Cos(2 * Math.PI * i / n);
                var z = Math.Sin(2 * Math.PI * i / n);
                return(Helper.CreatePoint(x, 0, z));
            }).ToArray();
            var mesh = new PrismMesh(points, true);
            var triangleMeshFactory = new TriangleMeshFactory(false);
            var prism = triangleMeshFactory.Build(mesh);

            return(prism);
        }
Beispiel #6
0
        public SurfaceOfRevolutionScene()
        {
            DefaultFloor();
            Light(1, 1, -1);

            double Radius(double u, double v)
            {
                double r = Math.Exp(-u);
                double m = (1 + Math.Abs(Math.Cos(2 * Math.PI * 1.5 * u)));

                return(r * m);
            }

            var mesh = new SurfaceOfRevolution(50, 50, Radius);
            var triangleMeshFactory = new TriangleMeshFactory(true, false);

            Add(triangleMeshFactory.Build(mesh).Scale(sy: 0.5, sx: 0.1, sz: 0.1).Translate(tx: 0, tz: 0));
        }
Beispiel #7
0
        public override void InitWorld()
        {
            Light(-10, 10, -10);
            const double r0 = 0.05;
            const double r1 = 3;
            const double r2 = 1;

            void CirclePath(double t, out double x, out double y, out double z)
            {
                x = r1 * Math.Cos(2 * Pi * t);
                y = 0;
                z = r1 * Math.Sin(2 * Pi * t);
            }

            void CircleCurve(double u, double v, out double x, out double y)
            {
                x = r2 * Math.Cos(2 * Pi * v);
                y = r2 * Math.Sin(2 * Pi * v);
            }

            CurveSweepMesh       mesh    = new CurveSweepMesh(40, 10, CirclePath, CircleCurve);
            WireFrameMeshFactory factory = new WireFrameMeshFactory(r0, true, true);
            var torusWire = factory.Build(mesh);

            torusWire.Material = new Material(Magenta);
            Add(torusWire).Translate(ty: r2 + r0);

            TriangleMeshFactory triFactory = new TriangleMeshFactory();
            var torusTriangle = triFactory.Build(mesh);

            torusTriangle.Material = new Material(Cyan)
            {
                Transparency = 0.99
            };
            Add(torusTriangle).Translate(ty: r2 + r0);

            SphereMeshFactory sphereFactory = new SphereMeshFactory(2 * r0);
            var torusSphere = sphereFactory.Build(mesh);

            torusSphere.Material = new Material(Yellow);
            Add(torusSphere).Translate(ty: r2 + r0);

            DefaultFloor();
        }
Beispiel #8
0
        public override void InitWorld()
        {
            Light(100, 150, -150, White / 10);
            Light(-100, 300, -150, White);
            var floor = DefaultFloor();

            floor.Material.Reflective = 0;
            floor.Material.Ambient    = 0;
            floor.Material.Specular   = 0;

            var wall = new Plane().Rotate(rx: Pi / 2 - 0.175).Translate(tz: 2);

            wall.Material = new Material(White, reflective: 1);
            Add(wall);

            var mesh = new SurfaceMesh(60, 60);

            // thanks to TJ Wei ( https://www.youtube.com/channel/UCLA68RSY6peX50b-Dw8mEpQ)
            // cf https://www.youtube.com/watch?v=vUz4kov3K1c
            // Surface[cos(s) + sgn(s - π / 2) (abs(sin(s)) - 1), 2sin(s), cos(s) - sgn(s - π / 2) (abs(sin(s)) - 1) + d, s, (-π) / 2, π + π / 2, d, 0.5, 3]

            double Interp(double t, double t0, double t1) => t0 + (t1 - t0) * t;
            double FuncD(double t) => Interp(t, 0.5, 3);
            double FuncS(double t) => Interp(t, -Pi / 2, 3 * Pi / 2);

            double FuncX(double u, double v) => Math.Cos(FuncS(u)) + Math.Sign(FuncS(u) - Pi / 2) * (Math.Abs(Math.Sin(FuncS(u))) - 1);
            double FuncZ(double u, double v) => 2 * Math.Sin(FuncS(u));
            double FuncY(double u, double v) => Math.Cos(FuncS(u)) - Math.Sign(FuncS(u) - Pi / 2) * (Math.Abs(Math.Sin(FuncS(u))) - 1) + FuncD(v);

            mesh.Build(FuncX, FuncY, FuncZ);
            var factory = new TriangleMeshFactory();
            var surf    = factory.Build(mesh);

            surf.HasShadow = false;
            Add(surf.Rotate(ry: Pi / 2 + 0.0).Translate(tz: -2));

            Add(new Cube {
                Material = new Material(Blue)
            }.Scale(sx: 2).Rotate(ry: Pi / 4).Translate(tx: -4.5, tz: -2));
            Add(new Sphere {
                Material = new Material(Red)
            }.Scale(sx: 2).Rotate(ry: -Pi / 4).Translate(tx: 4.5, tz: -2));
        }
Beispiel #9
0
        public WireFrameScene()
        {
            DefaultFloor();
            Light(1, 1, -1);

            double Altitude(double u, double v)
            {
                var r = 8 * Helper.Radius(u - 0.5, v - 0.5);

                return(0.05 * (1 + Math.Cos(2 * Pi * r)));
            }

            var mesh = new HeightField(50, 50, Altitude);
            var triangleMeshFactory = new TriangleMeshFactory(false, false);

            Add(triangleMeshFactory.Build(mesh).Translate(tx: 0.5, tz: 0));
            var wireFrameMeshFactory = new WireFrameMeshFactory(0.001, 0.0025);

            Add(wireFrameMeshFactory.Build(mesh).Translate(tx: -0.5, tz: 0));
        }
Beispiel #10
0
        public override void InitWorld()
        {
            DefaultFloor();
            Light(1, 1, -1);

            double Altitude(double u, double v)
            {
                var r = 8 * Helper.Radius(u - 0.5, v - 0.5);

                return(0.2 * Math.Exp(-r / 4) * (1 + Math.Cos(2 * Pi * r)));
            }

            var mesh = new HeightField(50, 50, Altitude);
            var triangleMeshFactory = new TriangleMeshFactory(false, false);

            Add(triangleMeshFactory.Build(mesh).Translate(-0.5));
            var sphereMeshFactory = new SphereMeshFactory(0.05);

            Add(sphereMeshFactory.Build(mesh).Translate(0.5));
        }