Пример #1
0
        public void DrawInto(float width, float height, Color color, float depth, MeshBatch target)
        {
            var destination = new RectangleF(0, 0, width, height);

            destination.Location -= this.Origin;
            target.Draw(Graphic.PixelTexture, destination, Graphic.PixelTexture.Bounds, this.Color ?? color, depth);
        }
Пример #2
0
        public override void DrawInto(float width, float height, Color color, float depth, MeshBatch target)
        {
            var scale = new Vector2(width / this.SourceRect.Width, height / this.SourceRect.Height);

            var rects       = new List <Tuple <Rectangle, Rectangle> >();
            var sourceRects = this.NinePatchRects;

            GenerateNinePatchRects(
                this.SourceRect,
                this.destinationRects,
                (int)(this.Left / scale.X),
                (int)(this.Right / scale.X),
                (int)(this.Top / scale.Y),
                (int)(this.Bottom / scale.Y));

            for (var i = 0; i < 9; i++)
            {
                var source      = sourceRects[i];
                var destination = this.destinationRects[i];
                destination.Location -= this.SourceRect.Location + (this.Origin?.ToPoint() ?? this.SourceRect.Center);
                destination.Width     = (int)(destination.Width * width / this.SourceRect.Width);
                destination.Height    = (int)(destination.Height * height / this.SourceRect.Height);
                rects.Add(new Tuple <Rectangle, Rectangle>(source, destination));
            }

            for (var i = 0; i < rects.Count; i++)
            {
                var rect        = rects[i];
                var source      = rect.Item1;
                var destination = rect.Item2;

                target.Draw(this.Texture2D, destination, source, color, depth);
            }
        }
Пример #3
0
        public override void Render(MeshBatch meshBatch, Matrix transform)
        {
            meshBatch.Draw(model, transform);
            return;

            for (int i = 0; i < model.Meshes.Count; i++)
            {
                for (int j = 0; j < model.Meshes[i].MeshParts.Count; j++)
                {
                    ModelMeshPart mp = model.Meshes[i].MeshParts[j];

                    if (mp.PrimitiveCount > 0)
                    {
                        Effect effect = model.Meshes[i].Effects[j];
                        effect.SetWorldAndInvTransp(model.Meshes[i].ParentBone.Transform * transform);

                        DrawM.gDevice.SetVertexBuffer(mp.VertexBuffer);
                        DrawM.gDevice.Indices = mp.IndexBuffer;


                        foreach (EffectPass pass in effect.CurrentTechnique.Passes)
                        {
                            pass.Apply();
                            //if the error appears here export with "Std" settings
                            DrawM.gDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList,
                                                                mp.VertexOffset,
                                                                mp.StartIndex,
                                                                mp.PrimitiveCount);
                        }
                    }
                }
            }
        }
Пример #4
0
        public virtual void DrawInto(float width, float height, Color color, float depth, MeshBatch target)
        {
            var source      = this.SourceRect;
            var destination = new RectangleF(
                -(this.Origin?.X ?? this.SourceRect.Width),
                -(this.Origin?.Y ?? this.SourceRect.Height),
                width,
                height);

            target.Draw(this.Texture2D, destination, source, color, depth);
        }
Пример #5
0
        public override void DrawInto(float width, float height, Color color, float depth, MeshBatch target)
        {
            var source      = this.SourceRect;
            var destination = new RectangleF(
                -(this.Origin?.X ?? source.Width / 2),
                -(this.Origin?.Y ?? source.Height / 2),
                source.Width,
                source.Height);

            var repeatX = width / this.SourceRect.Width;
            var repeatY = height / this.SourceRect.Height;

            for (var x = 0; x < repeatX; x++)
            {
                for (var y = 0; y < repeatY; y++)
                {
                    var destination1 = destination;
                    destination1.Location += new Vector2(x * this.SourceRect.Width, y * this.SourceRect.Height);
                    target.Draw(this.Texture2D, destination1, source, color, depth);
                }
            }
        }
Пример #6
0
        public void Draw(TiledMapComponent map, float layerDepth, MeshBatch batch, Matrix transformMatrix)
        {
            if (map.TiledMap.Orientation != TiledMapOrientation.Orthogonal)
            {
                throw new NotImplementedException();
            }

            for (var i = 0; i < map.TiledMap.Layers.Count; i++)
            {
                if (!map.TiledMap.Layers[i].Visible ||
                    (map.LayerIndicesToRender != null && !map.LayerIndicesToRender.Contains(i)))
                {
                    continue;
                }

                var layer = (TiledTileLayer)map.TiledMap.Layers[i];
                for (var y = 0; y < layer.Height; y++)
                {
                    for (var x = 0; x < layer.Width; x++)
                    {
                        var tile = layer.GetTile(x, y);
                        if (tile == null)
                        {
                            continue;
                        }

                        if (tile.TileSet == null || tile.TileSetTile == null || tile.OldId != tile.Id)
                        {
                            tile.OldId             = tile.Id;
                            tile.TileSet           = map.TiledMap.TileSets.First(a => a.Tiles.Any(b => b.Id + a.FirstGid == tile.Id));
                            tile.TileSetTile       = tile.TileSet.Tiles.First(b => b.Id + tile.TileSet.FirstGid == tile.Id);
                            tile.RenderTileSetTile = tile.TileSetTile;
                            tile.CurrentFrame      = 0;
                            tile.ElapsedTime       = 0;
                        }

                        // for the y position, we need to take into account if the tile is larger than the tileHeight and shift. Tiled uses
                        // a bottom-left coordinate system and MonoGame a top-left
                        var tx       = x * map.TiledMap.TileWidth;
                        var ty       = y * map.TiledMap.TileHeight;
                        var rotation = 0f;

                        var spriteEffects = SpriteEffects.None;
                        if (tile.FlippedHorizonally)
                        {
                            spriteEffects |= SpriteEffects.FlipHorizontally;
                        }
                        if (tile.FlippedVertically)
                        {
                            spriteEffects |= SpriteEffects.FlipVertically;
                        }
                        if (tile.FlippedDiagonally)
                        {
                            if (tile.FlippedHorizonally && tile.FlippedVertically)
                            {
                                spriteEffects ^= SpriteEffects.FlipVertically;
                                rotation       = MathHelper.PiOver2;
                                tx            += map.TiledMap.TileHeight + (tile.RenderTileSetTile.SourceRect.Height - map.TiledMap.TileHeight);
                                ty            -= (tile.RenderTileSetTile.SourceRect.Width - map.TiledMap.TileWidth);
                            }
                            else if (tile.FlippedHorizonally)
                            {
                                spriteEffects ^= SpriteEffects.FlipVertically;
                                rotation       = -MathHelper.PiOver2;
                                ty            += map.TiledMap.TileHeight;
                            }
                            else if (tile.FlippedVertically)
                            {
                                spriteEffects ^= SpriteEffects.FlipHorizontally;
                                rotation       = MathHelper.PiOver2;
                                tx            += map.TiledMap.TileWidth + (tile.RenderTileSetTile.SourceRect.Height - map.TiledMap.TileHeight);
                                ty            += (map.TiledMap.TileWidth - tile.RenderTileSetTile.SourceRect.Width);
                            }
                            else
                            {
                                spriteEffects ^= SpriteEffects.FlipHorizontally;
                                rotation       = -MathHelper.PiOver2;
                                ty            += map.TiledMap.TileHeight;
                            }
                        }

                        // if we had no rotations (diagonal flipping) shift our y-coord to account for any non-tileSized tiles to account for
                        // Tiled being bottom-left origin
                        if (rotation == 0)
                        {
                            ty += map.TiledMap.TileHeight - tile.RenderTileSetTile.SourceRect.Height;
                        }

                        var destRect = tile.RenderTileSetTile.SourceRect;
                        destRect.Location = new Point(0, 0);

                        var meshItem = batch.Draw(tile.TileSet.ImageTexture, destRect, tile.RenderTileSetTile.SourceRect, Color.White, layerDepth);
                        meshItem.RotateMesh(rotation);
                        meshItem.ApplyEffectToMesh(spriteEffects);
                        meshItem.MoveMesh(new Vector3(tx + layer.Offset.X, ty + layer.Offset.Y, 0));
                        meshItem.ApplyTransformMesh(transformMatrix);
                    }
                }
            }
        }
Пример #7
0
        //public void Init()
        //{

        //    if (player1 != null)
        //    {
        //        player1.InitTransform();
        //        player1.Update(0, 1);

        //        player1.ApplyCompleteTransform();
        //    }
        //}


        #endregion

        #region Drawing

        /// <summary>
        /// Draw the model
        /// </summary>
        /// <param name="graphics">The graphics device to draw on</param>
        /// <param name="world">A world matrix to place the model</param>
        public void Render(MeshBatch meshBatch, Matrix world)
        {
            if (model == null)
            {
                return;
            }

            //// Compute all of the bone absolute transforms
            //Matrix[] boneTransforms = new Matrix[bones.Count];

            bool uniformScalingAnimation = true;

            for (int i = 0; i < bones.Count; i++)
            {
                if (bones[i].Parent == null)
                {
                    uniformScalingAnimation = bones[i].ComputeAbsoluteTransformRecursive(Vector3.Zero);
                }
            }

            //for (int i = 0; i < bones.Count; i++)
            //{
            //    boneTransforms[i] = bones[i].AbsoluteTransform;
            //}

            // Determine the skin transforms from the skeleton

            Dictionary <string, int> uvBones = new Dictionary <string, int>();

            Matrix[] skeleton = new Matrix[modelExtra.Skeleton.Count];
            for (int s = 0; s < modelExtra.Skeleton.Count; s++)
            {
                Bone bone = bones[modelExtra.Skeleton[s]];
                skeleton[s] = bone.SkinTransform * bone.AbsoluteTransform; //TODO: check (skintransform?)
                if (bone.Name.StartsWith("UV_"))                           // && !bone.Name.EndsWith("_end"))
                {
                    skeleton[s].Translation *= 0.1f;
                    uvBones.Add(bone.Name.Substring(3), s);
                    //skeleton[s] = Matrix.CreateTranslation(new Vector3(0.5f, 0, 0));
                }

                //if (skeleton[s].Scale == Vector3.One)
                //{
                //skeleton[s] = Matrix.CreateScale(10, -10, -10) * skeleton[s]; //TODO: TEST
                //}

                //if (bone.Name == "Bone.004" || bone.Name == "Bone.005")
                //    skeleton[s].Translation = new Vector3(skeleton[s].Translation.X, skeleton[s].Translation.Y, skeleton[s].Translation.Z); //TODO: TEST
            }

            meshBatch.Draw(model, world, skeleton, uniformScalingAnimation, uvBones);
            //meshBatch.Draw(model, world);


            /*for (int i = 0; i < model.Meshes.Count; i++)
             * {
             *  for (int j = 0; j < model.Meshes[i].MeshParts.Count; j++)
             *  {
             *      ModelMeshPart mp = model.Meshes[i].MeshParts[j];
             *
             *      if (mp.PrimitiveCount > 0)
             *      {
             *          Effect effect = model.Meshes[i].Effects[j];
             *
             *          effect.SetWorldAndInvTransp(world); //TODO: check
             *          //effect.SetWorldAndInvTransp(boneTransforms[model.Meshes[i].ParentBone.Index] * world); //TODO: check
             *
             *          effect.Parameters["Bones"].SetValue(skeleton);
             *          effect.Parameters["uniformScalingAnimation"].SetValue(uniformScalingAnimation);
             *
             *          DrawM.gDevice.SetVertexBuffer(mp.VertexBuffer);
             *          DrawM.gDevice.Indices = mp.IndexBuffer;
             *
             *          foreach (EffectPass pass in effect.CurrentTechnique.Passes)
             *          {
             *              pass.Apply();
             *              DrawM.gDevice.SamplerStates[0] = SamplerState.PointClamp; //RELEASE: REMOVE
             *              DrawM.gDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList,
             *                                                     mp.VertexOffset,
             *                                                     mp.StartIndex,
             *                                                     mp.PrimitiveCount);
             *
             *          }
             *      }
             *  }
             * }*/
        }