コード例 #1
0
ファイル: Example.cs プロジェクト: akav/PTSharp
        public void cube()
        {
            var scene = new Scene();

            var meshes = new IShape[]
            {
                Util.CreateCubeMesh(Material.GlossyMaterial(Colour.HexColor(0x3B596A), 1.5, Util.Radians(20))),
                Util.CreateCubeMesh(Material.GlossyMaterial(Colour.HexColor(0x427676), 1.5, Util.Radians(20))),
                Util.CreateCubeMesh(Material.GlossyMaterial(Colour.HexColor(0x3F9A82), 1.5, Util.Radians(20))),
                Util.CreateCubeMesh(Material.GlossyMaterial(Colour.HexColor(0xA1CD73), 1.5, Util.Radians(20))),
                Util.CreateCubeMesh(Material.GlossyMaterial(Colour.HexColor(0xECDB60), 1.5, Util.Radians(20)))
            };

            for (int x = -8; x <= 8; x++)
            {
                for (int z = -12; z <= 12; z++)
                {
                    var fx = (double)x;
                    var fy = ThreadSafeRandom.NextDouble() * 2;
                    var fz = (double)z;
                    scene.Add(TransformedShape.NewTransformedShape(meshes[new Random().Next(meshes.Length)], new Matrix().Translate(new Vector(fx, fy, fz))));
                    scene.Add(TransformedShape.NewTransformedShape(meshes[new Random().Next(meshes.Length)], new Matrix().Translate(new Vector(fx, fy - 1, fz))));
                }
            }

            scene.Add(Sphere.NewSphere(new Vector(8, 10, 0), 3, Material.LightMaterial(Colour.White, 30)));
            var camera   = Camera.LookAt(new Vector(-10, 10, 0), new Vector(-2, 0, 0), new Vector(0, 1, 0), 45);
            var sampler  = DefaultSampler.NewSampler(4, 4);
            var renderer = Renderer.NewRenderer(scene, camera, sampler, 960, 540, false);

            renderer.IterativeRender("cube.png", 100);
        }
コード例 #2
0
ファイル: Example.cs プロジェクト: akav/PTSharp
        public void cylinder()
        {
            Scene scene  = new Scene();
            var   meshes = new Mesh[]
            {
                Util.CreateMesh(Material.GlossyMaterial(Colour.HexColor(0x730046), 1.6, Util.Radians(45))),
                Util.CreateMesh(Material.GlossyMaterial(Colour.HexColor(0xBFBB11), 1.6, Util.Radians(45))),
                Util.CreateMesh(Material.GlossyMaterial(Colour.HexColor(0xFFC200), 1.6, Util.Radians(45))),
                Util.CreateMesh(Material.GlossyMaterial(Colour.HexColor(0xE88801), 1.6, Util.Radians(45))),
                Util.CreateMesh(Material.GlossyMaterial(Colour.HexColor(0xC93C00), 1.6, Util.Radians(45))),
            };

            for (int x = -6; x <= 3; x++)
            {
                var mesh = meshes[(x + 6) % meshes.Length];
                for (int y = -5; y <= 4; y++)
                {
                    var fx = (double)x / 2;
                    var fy = (double)y;
                    var fz = (double)x / 2;

                    scene.Add(TransformedShape.NewTransformedShape(mesh, new Matrix().Translate(new Vector(fx, fy, fz))));
                }
            }
            scene.Add(Sphere.NewSphere(new Vector(1, 0, 10), 3, Material.LightMaterial(Colour.White, 20)));
            var camera   = Camera.LookAt(new Vector(-5, 0, 5), new Vector(1, 0, 0), new Vector(0, 0, 1), 45);
            var sampler  = DefaultSampler.NewSampler(4, 4);
            var renderer = Renderer.NewRenderer(scene, camera, sampler, 960, 540, true);

            renderer.IterativeRender("cylinder.png", 1000);
        }
コード例 #3
0
ファイル: Example.cs プロジェクト: akav/PTSharp
        public void ellipsoid()
        {
            var scene = new Scene();
            var wall  = Material.GlossyMaterial(Colour.HexColor(0xFCFAE1), 1.333, Util.Radians(30));

            scene.Add(Sphere.NewSphere(new Vector(10, 10, 10), 2, Material.LightMaterial(Colour.White, 50)));
            scene.Add(Cube.NewCube(new Vector(-100, -100, -100), new Vector(-12, 100, 100), wall));
            scene.Add(Cube.NewCube(new Vector(-100, -100, -100), new Vector(100, -1, 100), wall));
            var material = Material.GlossyMaterial(Colour.HexColor(0x167F39), 1.333, Util.Radians(30));
            var sphere   = Sphere.NewSphere(new Vector(), 1, material);

            for (int i = 0; i < 180; i += 30)
            {
                var m = Matrix.Identity;
                m = m.Scale(new Vector(0.3, 1, 5)).Mul(m);
                m = m.Rotate(new Vector(0, 1, 0), Util.Radians((double)i)).Mul(m);
                var shape = TransformedShape.NewTransformedShape(sphere, m);
                scene.Add(shape);
            }
            var camera   = Camera.LookAt(new Vector(8, 8, 0), new Vector(1, 0, 0), new Vector(0, 1, 0), 45);
            var sampler  = DefaultSampler.NewSampler(4, 4);
            var renderer = Renderer.NewRenderer(scene, camera, sampler, 960, 540, true);

            renderer.IterativeRender("ellipsoid.png", 1000);
        }
コード例 #4
0
        internal static IShape NewTransformedCylinder(Vector v0, Vector v1, double radius, Material material)
        {
            var up = new Vector(0, 0, 1);
            var d  = v1.Sub(v0);
            var z  = d.Length();
            var a  = Math.Acos(d.Normalize().Dot(up));
            var m  = new Matrix().Translate(v0);

            if (a != 0)
            {
                var u = d.Cross(up).Normalize();
                m = new Matrix().Rotate(u, a).Translate(v0);
            }
            var c = NewCylinder(radius, 0, z, material);

            return(TransformedShape.NewTransformedShape(c, m));
        }
コード例 #5
0
ファイル: Example.cs プロジェクト: akav/PTSharp
        public void toybrick()
        {
            const double H     = 1.46875;
            var          scene = new Scene();

            scene.Color = Colour.White;
            var meshes = new Mesh[]
            {
                Util.CreateBrick(0xF2F3F2), // white
                Util.CreateBrick(0xC4281B), // bright red
                Util.CreateBrick(0x0D69AB), // bright blue
                Util.CreateBrick(0xF5CD2F), // bright yellow
                Util.CreateBrick(0x1B2A34), // black
                Util.CreateBrick(0x287F46), // dark green
            };

            for (int x = -30; x <= 50; x += 2)
            {
                for (int y = -50; y <= 20; y += 4)
                {
                    var h = new Random().Next(5) + 1;
                    for (int i = 0; i < h; i++)
                    {
                        var dy = 0;

                        if (((x / 2 + i) % 2) == 0)
                        {
                            dy = 2;
                        }
                        var z    = i * H;
                        var mnum = new Random().Next(meshes.Length);
                        var mesh = meshes[mnum];
                        var m    = new Matrix().Translate(new Vector((double)x, (double)(y + dy), (double)z));
                        scene.Add(TransformedShape.NewTransformedShape(mesh, m));
                    }
                }
            }
            var camera   = Camera.LookAt(new Vector(-23, 13, 20), new Vector(0, 0, 0), new Vector(0, 0, 1), 45);
            var sampler  = DefaultSampler.NewSampler(4, 4);
            var renderer = Renderer.NewRenderer(scene, camera, sampler, 960, 540, true);

            renderer.IterativeRender("toybrick.png", 1000);
        }