public override void Draw(GameTime gameTime, IDrawContext drawContext)
        {
            base.Draw(gameTime, drawContext);

            if (Workspace.SelectedMaterial == null) return;

            var bounds = new Rect(0, 0, RenderSize.Width, RenderSize.Height);
            using (var draw3d = drawContext.BeginDraw3D())
            using (var localViewport = drawContext.BeginViewport(bounds))
            using (var localClipping = drawContext.BeginNewClip(bounds))
            {
                var graphicsDevice = Screen.GraphicsDevice;
                graphicsDevice.BlendState = BlendState.Opaque;
                graphicsDevice.DepthStencilState = DepthStencilState.Default;

                // View を更新します。
                view.Update();

                // Projection を更新します。
                projection.AspectRatio = graphicsDevice.Viewport.AspectRatio;
                projection.Update();

                var material = Workspace.SelectedMaterial;
                var effect = cubeMesh.Effect;
                effect.View = view.Matrix;
                effect.Projection = projection.Matrix;
                effect.DiffuseColor = material.DiffuseColor.ToVector3();
                effect.EmissiveColor = material.EmissiveColor.ToVector3();
                effect.SpecularColor = material.SpecularColor.ToVector3();
                effect.SpecularPower = material.SpecularPower;

                cubeMesh.Draw();
            }
        }
Exemple #2
0
        public override void Draw(GameTime gameTime, IDrawContext drawContext)
        {
            base.Draw(gameTime, drawContext);

            var bounds = new Rect(0, 0, RenderSize.Width, RenderSize.Height);
            using (var draw3d = drawContext.BeginDraw3D())
            {
                using (var localViewport = drawContext.BeginViewport(bounds))
                {
                    using (var localClipping = drawContext.BeginNewClip(bounds))
                    {
                        ViewModel.Draw();
                    }
                }
            }
        }
Exemple #3
0
        public override void Draw(GameTime gameTime, IDrawContext drawContext)
        {
            base.Draw(gameTime, drawContext);

            var bounds = new Rect(0, 0, RenderSize.Width, RenderSize.Height);

            using (var draw3d = drawContext.BeginDraw3D())
            {
                using (var localViewport = drawContext.BeginViewport(bounds))
                {
                    using (var localClipping = drawContext.BeginNewClip(bounds))
                    {
                        ViewModel.Draw();
                    }
                }
            }
        }
Exemple #4
0
        public override void Draw(GameTime gameTime, IDrawContext drawContext)
        {
            // todo: 先に LaF を描画。
            base.Draw(gameTime, drawContext);

            if (!CubeVisible)
            {
                return;
            }

            drawContext.Flush();

            // わざと Control の領域を越えるように調整。
            var renderSize = RenderSize;

            renderSize.Width  += 64;
            renderSize.Height += 64;

            using (var setViewport = drawContext.BeginViewport(new Rect(-32, -32, renderSize.Width, renderSize.Height)))
            {
                using (var setClip = drawContext.BeginNewClip(new Rect(-32, -32, renderSize.Width, renderSize.Height)))
                {
                    var effect = Screen.BasicEffect;

                    var cameraPosition = new Vector3(0, 0, 2.5f);
                    var aspect         = ((float)renderSize.Width / (float)renderSize.Height);

                    effect.World        = Orientation * Matrix.CreateScale(Scale);
                    effect.View         = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up);
                    effect.Projection   = Matrix.CreatePerspectiveFieldOfView(1, aspect, 0.1f, 10);
                    effect.DiffuseColor = ForegroundColor.ToVector3();
                    // どうもデフォルトで Specular が設定されているようだ。
                    effect.SpecularColor = Color.Black.ToVector3();
                    effect.Alpha         = 1;
                    effect.EnableDefaultLighting();
                    effect.VertexColorEnabled = true;

                    CubePrimitive.Draw(effect);
                }
            }
        }
        public override void Draw(GameTime gameTime, IDrawContext drawContext)
        {
            base.Draw(gameTime, drawContext);

            if (Workspace.SelectedMaterial == null)
            {
                return;
            }

            var bounds = new Rect(0, 0, RenderSize.Width, RenderSize.Height);

            using (var draw3d = drawContext.BeginDraw3D())
                using (var localViewport = drawContext.BeginViewport(bounds))
                    using (var localClipping = drawContext.BeginNewClip(bounds))
                    {
                        var graphicsDevice = Screen.GraphicsDevice;
                        graphicsDevice.BlendState        = BlendState.Opaque;
                        graphicsDevice.DepthStencilState = DepthStencilState.Default;

                        // View を更新します。
                        view.Update();

                        // Projection を更新します。
                        projection.AspectRatio = graphicsDevice.Viewport.AspectRatio;
                        projection.Update();

                        var material = Workspace.SelectedMaterial;
                        var effect   = cubeMesh.Effect;
                        effect.View          = view.Matrix;
                        effect.Projection    = projection.Matrix;
                        effect.DiffuseColor  = material.DiffuseColor.ToVector3();
                        effect.EmissiveColor = material.EmissiveColor.ToVector3();
                        effect.SpecularColor = material.SpecularColor.ToVector3();
                        effect.SpecularPower = material.SpecularPower;

                        cubeMesh.Draw();
                    }
        }
Exemple #6
0
        public override void Draw(GameTime gameTime, IDrawContext drawContext)
        {
            // todo: 先に LaF を描画。
            base.Draw(gameTime, drawContext);

            if (!CubeVisible) return;

            drawContext.Flush();

            // わざと Control の領域を越えるように調整。
            var renderSize = RenderSize;
            renderSize.Width += 64;
            renderSize.Height += 64;

            using (var setViewport = drawContext.BeginViewport(new Rect(-32, -32, renderSize.Width, renderSize.Height)))
            {
                using (var setClip = drawContext.BeginNewClip(new Rect(-32, -32, renderSize.Width, renderSize.Height)))
                {
                    var effect = Screen.BasicEffect;

                    var cameraPosition = new Vector3(0, 0, 2.5f);
                    var aspect = ((float) renderSize.Width / (float) renderSize.Height);

                    effect.World = Orientation * Matrix.CreateScale(Scale);
                    effect.View = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up);
                    effect.Projection = Matrix.CreatePerspectiveFieldOfView(1, aspect, 0.1f, 10);
                    effect.DiffuseColor = ForegroundColor.ToVector3();
                    // どうもデフォルトで Specular が設定されているようだ。
                    effect.SpecularColor = Color.Black.ToVector3();
                    effect.Alpha = 1;
                    effect.EnableDefaultLighting();
                    effect.VertexColorEnabled = true;

                    CubePrimitive.Draw(effect);
                }
            }
        }