示例#1
0
        public void Draw(IEditorGame game)
        {
            var arrowMesh = _arrowMesh;

            if (arrowMesh == null)
            {
                Debug.Fail("content has't been loaded, yet draw was called.");
            }

            // ReSharper disable once ImpureMethodCallOnReadonlyValueField - It is a pure call
            var matrix = Matrix.Scaling(Scale) * Matrix.Translation(Position)
                         * game.Camera.ViewMatrix
                         * game.Camera.ProjectionMatrix;

            // x
            _effect.Transform = matrix;
            _effect.Color     = new Color4(1, 0, 0, 1);
            arrowMesh.Draw(game.GraphicsDevice);

            // y
            matrix            = Matrix.RotationZ(MathUtil.PiOverTwo) * matrix;
            _effect.Transform = matrix;
            _effect.Color     = new Color4(0, 1, 0, 1);
            arrowMesh.Draw(game.GraphicsDevice);

            // z
            matrix            = Matrix.RotationY(MathUtil.PiOverTwo + MathUtil.Pi) * matrix;
            _effect.Transform = matrix;
            _effect.Color     = new Color4(0, 0, 1, 1);
            arrowMesh.Draw(game.GraphicsDevice);
        }
示例#2
0
 public TranslationGizmo([NotNull] IEditorGame game)
 {
     if (game == null)
     {
         throw new ArgumentNullException("game");
     }
     _game = game;
     Scale = 1;
     LoadContent(game);
 }
示例#3
0
        void LoadContent(IEditorGame game)
        {
            var arrowDesc = new TruncatedConeDescription(
                new ConeSection(0, 0),
                new ConeSection(.03f, 0),
                new ConeSection(.03f, 2f / 3),
                new ConeSection(.10f, 2f / 3),
                new ConeSection(0, 1f));

            var arrowMesh   = new TruncatedConeBuilder().Build(arrowDesc);
            var arrowBuffer = Buffer.Vertex.New(game.GraphicsDevice, arrowMesh);
            var effect      = new FullColorEffect(game.LoadContent <Effect>("FullColor"));

            _effect    = effect;
            _arrowMesh = new Mesh <VertexPosition>(arrowBuffer, effect.Effect);
        }
示例#4
0
        public void Draw(IEditorGame game)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException("VisualChunk");
            }

            if (_vertexLitEffect == null)
            {
                return;
            }
            _vertexLitEffect.TransformMatrix = Matrix.Translation(ModelOrigin) * _world * game.Camera.ViewMatrix * game.Camera.ProjectionMatrix;
            if (_mesh != null)
            {
                _mesh.Draw(game.GraphicsDevice);
            }
        }
示例#5
0
        public void LoadContent([NotNull] IEditorGame game)
        {
            _game      = game;
            _vertexLit = new VertexLitEffect(game.LoadContent <Effect>("VertexLit"));

            // TODO: settings
            var mesher = _meshalyzers.LastOrDefault();

            if (mesher == null)
            {
                return;
            }

            SwitchMeshalyzer(mesher);
            Policy = ChunkCreationPolicy.Run;
            game.World.ChunksModified += ChunksModified;
        }
示例#6
0
        public virtual void LoadContent(IEditorGame game)
        {
            var effect = new BoxSelectEffect(game.LoadContent <Effect>("BoxSelect"))
            {
                Sampler = game.GraphicsDevice.SamplerStates.PointWrap,
                Main    = _texture
            };

            _effect  = effect;
            _texture = game.LoadContent <Texture2D>("Grid");

            foreach (var face in FacesUtils.AllFaces)
            {
                var mesh = new Mesh <VertexPositionTexture>(Buffer.Vertex.New(game.GraphicsDevice, CreateQuadUv(face)), effect.Effect);
                SetQuad(face, mesh);
            }
        }
示例#7
0
        public void LoadContent([NotNull] IEditorGame game)
        {
            if (Game != null)
            {
                throw new InvalidOperationException("GameComponent.Game can not be set twice.");
            }

            Game           = game;
            World          = game.World;
            Dimension      = game.Dimension;
            GraphicsDevice = game.GraphicsDevice;
            Camera         = game.Camera;
            Keyboard       = game.Keyboard;
            Mouse          = game.Mouse;
            SharpDxElement = game.SharpDxElement;

            LoadContent();
        }
示例#8
0
 public abstract Buffer <VertexPositionColorTexture> Meshalyze(IEditorGame game, BlockSelection volume);
示例#9
0
 public virtual void UnloadContent(IEditorGame game)
 {
 }
示例#10
0
        // TODO: let consumers of IChunkMesh set its effect, so consumers can let it be transparent.
        public override Buffer <VertexPositionColorTexture> Meshalyze(IEditorGame game, BlockSelection volume)
        {
            var chunkVerticesList = new List <VertexPositionColorTexture>(13000);

            volume.GetChunks(AccessMode.Read, portions =>
            {
                foreach (var partition in portions)
                {
                    var chunk  = partition.Chunk;
                    var blocks = chunk.Blocks;

                    for (var y = partition.YMin; y < partition.YMax; y++)
                    {
                        for (var x = partition.XMin; x < partition.XMax; x++)
                        {
                            for (var z = partition.ZMin; z < partition.ZMax; z++)
                            {
                                var block = blocks.GetBlock(x, y, z);
                                if (block.Info.State == BlockState.NONSOLID || block.Info.State == BlockState.FLUID)
                                {
                                    continue;
                                }

                                var blockVector = new Vector3(x, y, z);
                                // block isn't air, assume its solid.
                                // at this point, texture coordinates should be calculated
                                // block specific shapes should happen (eg water)
                                if (x + 1 < blocks.XDim)
                                {
                                    // face with normal x+
                                    var xPlusBlock = blocks.GetBlock(x + 1, y, z);
                                    if (xPlusBlock.Info.State == BlockState.NONSOLID || block.Info.State == BlockState.FLUID)
                                    {
                                        AddTriangleQuad(blockVector, GeometricPrimitives.RightQuad, chunkVerticesList,
                                                        GetVertexColor(chunk, new LocalBlockPosition(x, y, z),
                                                                       new LocalBlockPosition(x + 1, y, z)));
                                    }
                                }

                                if (y + 1 < blocks.YDim)
                                {
                                    var yPlusBlock = blocks.GetBlock(x, y + 1, z);
                                    if (yPlusBlock.Info.State == BlockState.NONSOLID || block.Info.State == BlockState.FLUID)
                                    {
                                        AddTriangleQuad(blockVector, GeometricPrimitives.TopQuad, chunkVerticesList,
                                                        GetVertexColor(chunk, new LocalBlockPosition(x, y, z),
                                                                       new LocalBlockPosition(x, y + 1, z)));
                                    }
                                }

                                if (z + 1 < blocks.ZDim)
                                {
                                    var zPlusBlock = blocks.GetBlock(x, y, z + 1);
                                    if (zPlusBlock.Info.State == BlockState.NONSOLID || block.Info.State == BlockState.FLUID)
                                    {
                                        AddTriangleQuad(blockVector, GeometricPrimitives.BackwardQuad,
                                                        chunkVerticesList,
                                                        GetVertexColor(chunk, new LocalBlockPosition(x, y, z),
                                                                       new LocalBlockPosition(x, y, z + 1)));
                                    }
                                }

                                if (x - 1 >= 0)
                                {
                                    var xMinusBlock = blocks.GetBlock(x - 1, y, z);
                                    if (xMinusBlock.Info.State == BlockState.NONSOLID || block.Info.State == BlockState.FLUID)
                                    {
                                        AddTriangleQuad(blockVector, GeometricPrimitives.LeftQuad, chunkVerticesList,
                                                        GetVertexColor(chunk, new LocalBlockPosition(x, y, z),
                                                                       new LocalBlockPosition(x - 1, y, z)));
                                    }
                                }

                                if (y - 1 >= 0)
                                {
                                    var yMinusBlock = blocks.GetBlock(x, y - 1, z);
                                    if (yMinusBlock.Info.State == BlockState.NONSOLID || block.Info.State == BlockState.FLUID)
                                    {
                                        AddTriangleQuad(blockVector, GeometricPrimitives.BottomQuad, chunkVerticesList,
                                                        GetVertexColor(chunk, new LocalBlockPosition(x, y, z),
                                                                       new LocalBlockPosition(x, y - 1, z)));
                                    }
                                }

                                if (z - 1 >= 0)
                                {
                                    var zMinusBlock = blocks.GetBlock(x, y, z - 1);
                                    if (zMinusBlock.Info.State == BlockState.NONSOLID || block.Info.State == BlockState.FLUID)
                                    {
                                        AddTriangleQuad(blockVector, GeometricPrimitives.ForwardQuad, chunkVerticesList,
                                                        GetVertexColor(chunk, new LocalBlockPosition(x, y, z),
                                                                       new LocalBlockPosition(x, y, z - 1)));
                                    }
                                }
                            }
                        }
                    }
                }
            });

            return(chunkVerticesList.Count == 0
                ? null
                : Buffer.Vertex.New(game.GraphicsDevice, chunkVerticesList.ToArray()));
        }
示例#11
0
 public override void UnloadContent([NotNull] IEditorGame game)
 {
 }
示例#12
0
        public void Draw(IEditorGame game)
        {
            game.GraphicsDevice.SetBlendState(game.GraphicsDevice.BlendStates.NonPremultiplied);
            var viewProj = game.Camera.ViewMatrix * game.Camera.ProjectionMatrix;

            // CullNone, if the camera is inside the selection.
            var cullNone = Cuboid.Within((Point3)game.Camera.Position);

            if (cullNone)
            {
                game.GraphicsDevice.SetRasterizerState(game.GraphicsDevice.RasterizerStates.CullNone);
            }

            foreach (var face in FacesUtils.AllFaces)
            {
                var quad      = GetQuad(face);
                var leftFace  = face.GetLeftVisualFace();
                var topFace   = face.GetTopVisualFace();
                var transform = new Vector4(
                    Cuboid.GetLengthComponent(leftFace),
                    Cuboid.GetLengthComponent(topFace),
                    Cuboid.GetPositionComponent(leftFace),
                    Cuboid.GetPositionComponent(topFace));

                // TODO: texture scaling on the bottom face is fudged

                // invert in certain edge cases
                if (face.HasSideFaces())
                {
                    transform.Y = -transform.Y;
                    if (face == Faces.Right)
                    {
                        transform.X = -transform.X;
                    }
                    else if (face == Faces.Forward)
                    {
                        transform.X = -transform.X;
                    }
                }

                switch (face)
                {
                case Faces.Left:
                    _effect.TransformMatrix = Matrix.Scaling(0, Cuboid.Height, Cuboid.Width) *
                                              Matrix.Translation(Cuboid.Left - _zBias, Cuboid.Bottom, Cuboid.Forward) *
                                              viewProj;
                    break;

                case Faces.Bottom:
                    _effect.TransformMatrix = Matrix.Scaling(Cuboid.Length, 0, Cuboid.Width) *
                                              Matrix.Translation(Cuboid.Left, Cuboid.Bottom - _zBias, Cuboid.Forward) *
                                              viewProj;
                    break;

                case Faces.Forward:
                    _effect.TransformMatrix = Matrix.Scaling(Cuboid.Length, Cuboid.Height, 0) *
                                              Matrix.Translation(Cuboid.Left, Cuboid.Bottom, Cuboid.Forward - _zBias) *
                                              viewProj;
                    break;

                case Faces.Right:
                    _effect.TransformMatrix = Matrix.Scaling(0, Cuboid.Height, Cuboid.Width) *
                                              Matrix.Translation(Cuboid.Left + Cuboid.Length + _zBias, Cuboid.Bottom, Cuboid.Forward) *
                                              viewProj;
                    break;

                case Faces.Top:
                    _effect.TransformMatrix = Matrix.Scaling(Cuboid.Length, 0, Cuboid.Width) *
                                              Matrix.Translation(Cuboid.Left, Cuboid.Bottom + Cuboid.Height + _zBias, Cuboid.Forward) *
                                              viewProj;
                    break;

                case Faces.Backward:
                    _effect.TransformMatrix = Matrix.Scaling(Cuboid.Length, Cuboid.Height, 0) *
                                              Matrix.Translation(Cuboid.Left, Cuboid.Bottom, Cuboid.Forward + Cuboid.Width + _zBias) *
                                              viewProj;
                    break;

                default:
                    Debug.Assert(false);
                    break;
                }

                _effect.MainTransform = transform * _textureScaling;

                quad.Draw(game.GraphicsDevice);
            }

            // reset to default
            if (cullNone)
            {
                game.GraphicsDevice.SetRasterizerState(game.GraphicsDevice.RasterizerStates.CullBack);
            }
        }
示例#13
0
 public void UnloadContent(IEditorGame game)
 {
     Dispose();
 }