Ejemplo n.º 1
0
        void DrawAxes(Camera camera)
        {
            var device = this.GraphicsDevice;

            var view = new Matrix()
            {
                Column1 = new Vector4(camera.Right, 0),
                Column2 = new Vector4(camera.Up, 0),
                Column3 = new Vector4(camera.Look, 1),
                Column4 = new Vector4(0, 0, 0, 1),
            };

            m_basicEffect.World = view;
            m_basicEffect.View = Matrix.Identity;
            m_basicEffect.Projection = Matrix.OrthoLH(2, 2, 0, 2);

            m_basicEffect.TextureEnabled = false;
            m_basicEffect.VertexColorEnabled = true;

            m_basicEffect.Alpha = 1;

            m_basicEffect.CurrentTechnique.Passes[0].Apply();

            device.SetDepthStencilState(device.DepthStencilStates.None);
            device.SetRasterizerState(device.RasterizerStates.CullNone);

            device.SetVertexBuffer(m_buffer);
            device.SetVertexInputLayout(m_layout);
            device.Draw(PrimitiveType.LineList, 6);

            device.SetRasterizerState(device.RasterizerStates.Default);
            device.SetDepthStencilState(device.DepthStencilStates.Default);
        }
Ejemplo n.º 2
0
        public override void Draw(Camera camera)
        {
            m_basicEffect.View = camera.View;
            m_basicEffect.Projection = camera.Projection;

            var chunks = m_chunkManager.DebugChunks;

            m_basicEffect.Texture = m_cubeTexture;

            var device = this.GraphicsDevice;
            device.SetBlendState(device.BlendStates.NonPremultiplied);

            device.SetRasterizerState(m_rasterizerState);

            foreach (var cp in m_chunkManager.Size.Range())
            {
                var chunk = chunks[m_chunkManager.Size.GetIndex(cp)];
                if (chunk == null)
                    continue;

                if (chunk.IsAllEmpty)
                    m_basicEffect.DiffuseColor = new Vector4(1, 0, 0, 0);
                else if (chunk.IsAllUndefined)
                    m_basicEffect.DiffuseColor = new Vector4(0, 1, 0, 0);
                else
                    m_basicEffect.DiffuseColor = new Vector4(1, 1, 1, 0);

                m_basicEffect.World = Matrix.Translation((cp * Chunk.CHUNK_SIZE + Chunk.CHUNK_SIZE / 2).ToVector3());
                m_cube.Draw(m_basicEffect);
            }

            device.SetRasterizerState(device.RasterizerStates.Default);
            device.SetBlendState(device.BlendStates.Default);
        }
Ejemplo n.º 3
0
        public TerrainRenderer(MyGame game, Camera camera, ViewGridProvider viewGridProvider)
            : base(game)
        {
            m_chunkManager = ToDispose(new ChunkManager(this, camera, viewGridProvider));

            LoadContent();
        }
Ejemplo n.º 4
0
        public override void Draw(Camera camera)
        {
            m_basicEffect.View = Matrix.Translation(0, 0, 10);
            m_basicEffect.Projection = camera.Projection;

            m_basicEffect.Texture = m_cubeTexture;
            m_basicEffect.World = m_cubeTransform;
            m_cube.Draw(m_basicEffect);
        }
Ejemplo n.º 5
0
        public override void Draw(Camera camera)
        {
            if (!this.IsEnabled)
                return;

            IntVector3? cursorPos = null;

            if (m_game.CursorService.IsEnabled)
                cursorPos = m_game.CursorService.Location;

            var selection = m_game.SelectionService.Selection;
            var selDir = Direction.Up; // XXX

            if (cursorPos.HasValue == false && selection.IsSelectionValid == false)
                return;

            var device = this.GraphicsDevice;

            var viewProjMatrix = Matrix.Transpose(camera.View * camera.Projection);
            viewProjMatrix.Transpose();
            m_effect.Parameters["viewProjMatrix"].SetValue(ref viewProjMatrix);

            device.SetBlendState(device.BlendStates.NonPremultiplied);
            device.SetDepthStencilState(device.DepthStencilStates.DepthRead);

            var renderPass = m_effect.CurrentTechnique.Passes[0];
            renderPass.Apply();

            device.SetVertexBuffer(m_vertexBuffer);
            device.SetVertexInputLayout(m_layout);

            if (cursorPos.HasValue)
            {
                m_effect.Parameters["s_cubeColor"].SetValue(Color.Red.ToVector3());
                SetWorlMatrix(cursorPos.Value, new IntSize3(1, 1, 1), Direction.Up);
                m_effect.ConstantBuffers["PerObject"].Update();

                device.Draw(PrimitiveType.TriangleList, 6 * 6);
            }

            if (selection.IsSelectionValid)
            {
                var grid = selection.SelectionBox;
                SetWorlMatrix(grid.Corner1, grid.Size, selDir);

                m_effect.Parameters["s_cubeColor"].SetValue(Color.Blue.ToVector3());
                m_effect.ConstantBuffers["PerObject"].Update();

                device.Draw(PrimitiveType.TriangleList, 6 * 6);
            }

            device.SetBlendState(device.BlendStates.Default);
            device.SetDepthStencilState(device.DepthStencilStates.Default);
        }
Ejemplo n.º 6
0
        public override void Draw(Camera camera)
        {
            m_chunkManager.PrepareDraw();

            var device = this.GraphicsDevice;

            device.SetRasterizerState(((MyGame)this.Game).RasterizerState);

            // voxels
            {
                m_effect.EyePos = camera.Position;
                m_effect.ViewProjection = camera.View * camera.Projection;

                var renderPass = m_effect.CurrentTechnique.Passes[0];
                renderPass.Apply();

                m_chunkManager.Draw(camera);
            }

            device.SetRasterizerState(device.RasterizerStates.Default);

            // trees
            {
                device.SetRasterizerState(device.RasterizerStates.CullNone);
                device.SetBlendState(device.BlendStates.AlphaBlend);

                m_symbolEffect.EyePos = camera.Position;
                m_symbolEffect.ScreenUp = camera.ScreenUp;
                m_symbolEffect.ViewProjection = camera.View * camera.Projection;

                var angle = (float)System.Math.Acos(Vector3.Dot(-Vector3.UnitZ, camera.Look));
                angle = MathUtil.RadiansToDegrees(angle);
                if (System.Math.Abs(angle) < 45)
                    m_symbolEffect.CurrentTechnique = m_symbolEffect.Techniques["ModeFlat"];
                else
                    m_symbolEffect.CurrentTechnique = m_symbolEffect.Techniques["ModeCross"];

                var renderPass = m_symbolEffect.CurrentTechnique.Passes[0];
                renderPass.Apply();

                m_chunkManager.DrawTrees();

                device.SetBlendState(device.BlendStates.Default);
                device.SetRasterizerState(device.RasterizerStates.Default);
            }
        }
Ejemplo n.º 7
0
        public override void Draw(Camera camera)
        {
            if (m_game.Environment == null)
                return;

            var des = m_game.Environment.Designations;

            var device = this.GraphicsDevice;

            var viewProjMatrix = Matrix.Transpose(camera.View * camera.Projection);
            viewProjMatrix.Transpose();
            m_effect.Parameters["viewProjMatrix"].SetValue(ref viewProjMatrix);

            device.SetBlendState(device.BlendStates.NonPremultiplied);
            device.SetDepthStencilState(device.DepthStencilStates.DepthRead);

            var renderPass = m_effect.CurrentTechnique.Passes[0];
            renderPass.Apply();

            device.SetVertexBuffer(m_vertexBuffer);
            device.SetVertexInputLayout(m_layout);

            float t = (float)(Math.Sin(m_game.Time.TotalTime.TotalSeconds * 4) + 1) / 2;

            var color = Color.Lerp(m_color1, m_color2, t);

            #warning TODO: drawn one cube at a time
            #warning TODO: combine code with SelectionRenderer

            m_effect.Parameters["s_cubeColor"].SetValue(color.ToVector3());

            var designations = des.GetLocations().Where(kvp => m_game.ViewGridProvider.ViewGrid.Contains(kvp.Key));

            foreach (var kvp in designations)
            {
                SetWorlMatrix(kvp.Key, new IntSize3(1, 1, 1), Direction.Up);
                m_effect.ConstantBuffers["PerObject"].Update();

                device.Draw(PrimitiveType.TriangleList, 6 * 6);
            }

            device.SetBlendState(device.BlendStates.Default);
            device.SetDepthStencilState(device.DepthStencilStates.Default);
        }
Ejemplo n.º 8
0
        public ChunkManager(TerrainRenderer scene, Camera camera, ViewGridProvider viewGridProvider)
        {
            m_scene = scene;
            m_camera = camera;
            m_viewGridProvider = viewGridProvider;

            // XXX
            m_game = (MyGame)scene.Game;
            m_game.EnvironmentChanged += Data_MapChanged;

            viewGridProvider.ViewGridCornerChanged += OnViewGridCornerChanged;

            m_cameraPos = m_camera.Position;
            m_cameraLook = m_camera.Look;
            m_cameraChunkPos = (m_cameraPos / Chunk.CHUNK_SIZE).ToFloorIntVector3();

            m_forceNearListUpdate = true;
            m_forceDrawListUpdate = true;
        }
Ejemplo n.º 9
0
        public override void Draw(Camera camera)
        {
            if (m_invalid)
            {
                UpdateVertexBuffer();
                m_invalid = false;
            }

            if (m_vertexList == null || m_vertexList.Count == 0)
                return;

            var device = this.GraphicsDevice;

            m_effect.EyePos = camera.Position;
            m_effect.ScreenUp = camera.ScreenUp;
            m_effect.ViewProjection = camera.View * camera.Projection;

            var angle = (float)System.Math.Acos(Vector3.Dot(-Vector3.UnitZ, camera.Look));
            angle = MathUtil.RadiansToDegrees(angle);
            if (System.Math.Abs(angle) < 45)
                m_effect.CurrentTechnique = m_effect.Techniques["ModeFlat"];
            else
                m_effect.CurrentTechnique = m_effect.Techniques["ModeFollow"];

            m_effect.CurrentTechnique.Passes[0].Apply();

            var offset = new IntVector3();
            m_effect.SetPerObjectConstBuf(offset);

            device.SetRasterizerState(device.RasterizerStates.CullNone);
            device.SetBlendState(device.BlendStates.AlphaBlend);
            //device.SetDepthStencilState(device.DepthStencilStates.None);

            device.SetVertexBuffer(m_vertexBuffer);
            device.Draw(PrimitiveType.PointList, m_vertexList.Count);

            device.SetRasterizerState(device.RasterizerStates.Default);
            device.SetBlendState(device.BlendStates.Default);
            //device.SetDepthStencilState(device.DepthStencilStates.Default);
        }
Ejemplo n.º 10
0
 public abstract void Draw(Camera camera);
Ejemplo n.º 11
0
 public SelectionService(MyGame game, SharpDXHost control, Camera camera)
 {
     m_game = game;
     m_control = control;
 }
Ejemplo n.º 12
0
        void DrawPlane(Camera camera)
        {
            var device = this.GraphicsDevice;

            m_basicEffect.World = Matrix.Identity;
            m_basicEffect.View = Matrix.Identity;
            m_basicEffect.Projection = Matrix.Identity;

            m_basicEffect.TextureEnabled = false;
            m_basicEffect.VertexColorEnabled = false;

            m_basicEffect.Alpha = 0.8f;
            m_basicEffect.DiffuseColor = new Vector4(1f, 1f, 1f, 1);

            device.SetBlendState(device.BlendStates.NonPremultiplied);

            device.SetDepthStencilState(device.DepthStencilStates.None);
            device.SetRasterizerState(device.RasterizerStates.CullNone);

            m_basicEffect.CurrentTechnique.Passes[0].Apply();
            m_plane.Draw(m_basicEffect);

            device.SetBlendState(device.BlendStates.Default);
            device.SetRasterizerState(device.RasterizerStates.Default);
            device.SetDepthStencilState(device.DepthStencilStates.Default);
        }
Ejemplo n.º 13
0
 public override void Draw(Camera camera)
 {
     DrawPlane(camera);
     DrawAxes(camera);
 }
Ejemplo n.º 14
0
 public CameraMoveService(Camera camera)
 {
     m_camera = camera;
 }
Ejemplo n.º 15
0
        public void Draw(Camera camera)
        {
            var device = m_scene.GraphicsDevice;

            int numVertices = 0;

            foreach (var chunk in m_drawList)
            {
                if (chunk.VertexCount == 0)
                    continue;

                m_scene.Effect.SetPerObjectConstBuf(chunk.ChunkOffset);

                chunk.DrawTerrain(device);

                numVertices += chunk.VertexCount;
            }

            this.VerticesRendered = numVertices;
        }