コード例 #1
0
        public override void Init()
        {
            Content.ContentPath = "Data";

            scene        = new Scene();
            scene.View   = this;
            scene.Camera = new LookatCartesianCamera()
            {
                Position    = new Vector3(10, 10, 10),
                Lookat      = Vector3.Zero,
                ZFar        = 100,
                AspectRatio = AspectRatio
            };
            //heightmap = TextureUtil.ToHeightmap(Content.Peek<Texture>(new TextureFromFile("testheightmap.png")), 100);
            texture = new Graphics.Software.Texture <Graphics.Software.Texel.A8R8G8B8>(
                new Graphics.Software.Texel.A8R8G8B8[250, 250]);

            var r = new Random();

            for (int y = 0; y < texture.Size.Height; y++)
            {
                for (int x = 0; x < texture.Size.Width; x++)
                {
                    texture[y, x] =
                        new Graphics.Software.Texel.A8R8G8B8
                    {
                        //R = 1f,//(float)r.NextDouble(),
                        //G = (float)r.NextDouble(),
                        //B = (float)r.NextDouble(),
                        A = 1f,
                    }
                }
            }
            ;



            scene.Add(ground = new TestGround
            {
                Size = new SizeF(100, 100),
                //Texture = new SingleColorTexture(Color.Orange),
                NPieces = new Size(20, 20),
            });
            ground.ConstructPieces();

            dxTexture = texture.ToTexture9(Device9);
            UpdateTexture();

            groundTextureEditor = new Graphics.Editors.GroundTextureEditor
            {
                Camera          = scene.Camera,
                Viewport        = Viewport,
                SoftwareTexture = new ITexture[] { texture },
                Texture9        = new[] { dxTexture },
                Position        = ground.Translation,
                Size            = ground.Size,
                GroundIntersect = new WorldViewProbe(this, scene.Camera)
                {
                    WorldProbe = new GroundProbe()
                },
                Pencil = new Graphics.Editors.GroundTexturePencil
                {
                    Color  = new Vector4(1, 0, 0, 0),
                    Radius = 30,
                    Type   = Graphics.Editors.GroundTexturePencilType.Add
                }
            };
            groundTextureEditor.TextureValuesChanged += new Graphics.Editors.TextureValuesChangedEventHandler((o, e) =>
            {
                UpdateTexture();
                foreach (var v in ground.Children)
                {
                    v.Invalidate();
                }
            });
            InputHandler = new WalkaroundCameraInputHandler
            {
                Camera       = (LookatCartesianCamera)scene.Camera,
                InputHandler = groundTextureEditor
            };

            renderer = new Graphics.Renderer.Renderer(Device9)
            {
                Scene        = scene,
                StateManager = new Device9StateManager(Device9)
            };
            renderer.Initialize(this);

            sceneRendererConnector = new SortedTestSceneRendererConnector
            {
                Scene    = scene,
                Renderer = renderer
            };
            sceneRendererConnector.Initialize();
        }
コード例 #2
0
        public override void Init()
        {
            Content.ContentPath = "Data";

            scene = new Scene();
            scene.View = this;
            scene.Camera = new LookatCartesianCamera()
            {
                Position = new Vector3(10, 10, 10),
                Lookat = Vector3.Zero,
                ZFar = 100,
                AspectRatio = AspectRatio
            };
            //heightmap = TextureUtil.ToHeightmap(Content.Peek<Texture>(new TextureFromFile("testheightmap.png")), 100);
            texture = new Graphics.Software.Texture<Graphics.Software.Texel.A8R8G8B8>(
                new Graphics.Software.Texel.A8R8G8B8[250, 250]);

            var r = new Random();
            for(int y=0; y < texture.Size.Height; y++)
                for(int x=0; x < texture.Size.Width; x++)
                    texture[y, x] =
                        new Graphics.Software.Texel.A8R8G8B8
                            {
                                //R = 1f,//(float)r.NextDouble(),
                                //G = (float)r.NextDouble(),
                                //B = (float)r.NextDouble(),
                                A = 1f,
                            };

            scene.Add(ground = new TestGround
            {
                Size = new SizeF(100, 100),
                //Texture = new SingleColorTexture(Color.Orange),
                NPieces = new Size(20, 20),
            });
            ground.ConstructPieces();

            dxTexture = texture.ToTexture9(Device9);
            UpdateTexture();

            groundTextureEditor = new Graphics.Editors.GroundTextureEditor
            {
                Camera = scene.Camera,
                Viewport = Viewport,
                SoftwareTexture = new ITexture[] { texture },
                Texture9 = new[] {dxTexture},
                Position = ground.Translation,
                Size = ground.Size,
                GroundIntersect = new WorldViewProbe(this, scene.Camera)
                {
                    WorldProbe = new GroundProbe()
                },
                Pencil = new Graphics.Editors.GroundTexturePencil
                {
                    Color = new Vector4(1, 0, 0, 0),
                    Radius = 30,
                    Type = Graphics.Editors.GroundTexturePencilType.Add
                }
            };
            groundTextureEditor.TextureValuesChanged += new Graphics.Editors.TextureValuesChangedEventHandler((o, e) =>
            {
                UpdateTexture();
                foreach (var v in ground.Children)
                    v.Invalidate();
            });
            InputHandler = new WalkaroundCameraInputHandler
            {
                Camera = (LookatCartesianCamera)scene.Camera,
                InputHandler = groundTextureEditor
            };

            renderer = new Graphics.Renderer.Renderer(Device9) { Scene = scene,
                StateManager = new Device9StateManager(Device9) };
            renderer.Initialize(this);

            sceneRendererConnector = new SortedTestSceneRendererConnector
            {
                Scene =  scene,
                Renderer = renderer
            };
            sceneRendererConnector.Initialize();
        }