Exemple #1
0
        public bool Draw(Texture2D texture, VertexPositionNormalTextureHue[] vertices)
        {
            bool draw = false;

            if (texture == null)
                return false;

            for (int i = 0; i < 4; i++) // only draws a 2 triangle tristrip.
            {
                if (_boundingBox.Contains(vertices[i].Position) == ContainmentType.Contains)
                {
                    draw = true;
                    break;
                }
            }

            if (!draw)
                return false;

            vertices[0].Position.Z = _z;
            vertices[1].Position.Z = _z;
            vertices[2].Position.Z = _z;
            vertices[3].Position.Z = _z;
            _z += 1;

            List<VertexPositionNormalTextureHue> vertexList;

            if (_drawQueue.ContainsKey(texture))
            {
                vertexList = _drawQueue[texture];
            }
            else
            {
                if (_vertexListQueue.Count > 0)
                {
                    vertexList = _vertexListQueue.Dequeue();

                    vertexList.Clear();
                }
                else
                {
                    vertexList = new List<VertexPositionNormalTextureHue>(1024);
                }

                _drawQueue.Add(texture, vertexList);
            }

            for (int i = 0; i < vertices.Length; i++)
            {
                vertexList.Add(vertices[i]);
            }

            return true;
        }
Exemple #2
0
        public bool DrawSimple(Texture2D texture, Rectangle destRect, Vector2 hue)
        {
            VertexPositionNormalTextureHue[] v = new VertexPositionNormalTextureHue[] {
                new VertexPositionNormalTextureHue(new Vector3(destRect.X, destRect.Y, 0), new Vector3(0, 0, 1), new Vector3(0, 0, 0)),
                new VertexPositionNormalTextureHue(new Vector3(destRect.X + destRect.Width, destRect.Y, 0), new Vector3(0, 0, 1), new Vector3(1, 0, 0)),
                new VertexPositionNormalTextureHue(new Vector3(destRect.X, destRect.Y + destRect.Height, 0), new Vector3(0, 0, 1), new Vector3(0, 1, 0)),
                new VertexPositionNormalTextureHue(new Vector3(destRect.X + destRect.Width, destRect.Y + destRect.Height, 0), new Vector3(0, 0, 1), new Vector3(1, 1, 0))
            };

            v[0].Hue = v[1].Hue = v[2].Hue =  v[3].Hue = hue;
            return Draw(texture, v);
        }
Exemple #3
0
        public bool DrawSimple(Texture2D texture, Rectangle destRect, Rectangle sourceRect, Vector2 hue)
        {
            float minX = (float)sourceRect.X / (float)texture.Width, maxX = (float)(sourceRect.X + sourceRect.Width) / (float)texture.Width;
            float minY = (float)sourceRect.Y / (float)texture.Height, maxY = (float)(sourceRect.Y + sourceRect.Height) / (float)texture.Height;

            VertexPositionNormalTextureHue[] v = new VertexPositionNormalTextureHue[] {
                new VertexPositionNormalTextureHue(new Vector3(destRect.X, destRect.Y, 0), new Vector3(0, 0, 1), new Vector3(minX, minY, 0)),
                new VertexPositionNormalTextureHue(new Vector3(destRect.X + destRect.Width, destRect.Y, 0), new Vector3(0, 0, 1), new Vector3(maxX, minY, 0)),
                new VertexPositionNormalTextureHue(new Vector3(destRect.X, destRect.Y + destRect.Height, 0), new Vector3(0, 0, 1), new Vector3(minX, maxY, 0)),
                new VertexPositionNormalTextureHue(new Vector3(destRect.X + destRect.Width, destRect.Y + destRect.Height, 0), new Vector3(0, 0, 1), new Vector3(maxX, maxY, 0))
            };

            v[0].Hue = v[1].Hue = v[2].Hue = v[3].Hue = hue;
            return Draw(texture, v);
        }
Exemple #4
0
        public bool DrawSimple(Texture2D texture, Vector3 position, Vector2 hue)
        {
            VertexPositionNormalTextureHue[] v = new VertexPositionNormalTextureHue[] {
                new VertexPositionNormalTextureHue(new Vector3(position.X, position.Y, 0), new Vector3(0, 0, 1), new Vector3(0, 0, 0)),
                new VertexPositionNormalTextureHue(new Vector3(position.X + texture.Width, position.Y, 0), new Vector3(0, 0, 1), new Vector3(1, 0, 0)),
                new VertexPositionNormalTextureHue(new Vector3(position.X, position.Y + texture.Height, 0), new Vector3(0, 0, 1), new Vector3(0, 1, 0)),
                new VertexPositionNormalTextureHue(new Vector3(position.X + texture.Width, position.Y + texture.Height, 0), new Vector3(0, 0, 1), new Vector3(1, 1, 0))
            };

            v[0].Hue = v[1].Hue = v[2].Hue = v[3].Hue = hue;
            return Draw(texture, v);
        }
Exemple #5
0
 private static void releaseVerticesToBuffer(VertexPositionNormalTextureHue[] v)
 {
     deferredVertexBuffer.Add(v);
 }
Exemple #6
0
        /// <summary>
        /// drawIsometricOverlap will create deferred objects that will be drawn in places where a MapObject
        /// might be overlapped by subsequently drawn objects in the world. NOTE that the vertices of the
        /// deferred objects created by this routine are NOT perfect - they may have UV coords that are greater
        /// than 1.0f or less than 0.0f. This would create graphical artifacts, but we rely on our HLSL shader
        /// to ignore these.
        /// </summary>
        /// <param name="sb">The SpriteBatch3D instance passed to the calling Draw() routine.</param>
        /// <param name="vertices">The Vertices that were drawn by the calling MapObject.</param>
        /// <param name="drawPosition">The upper-left hand corner of the tile where the calling MapObject was drawn.</param>
        private void drawIsometricOverlap(SpriteBatch3D sb, VertexPositionNormalTextureHue[] vertices, Vector2 screenPosition)
        {
            Vector2 overlapCurrent = new Vector2(screenPosition.X + 22, screenPosition.Y + 44);
            Vector2 overlapToHere = _draw_flip ?
                new Vector2(vertices[1].Position.X, vertices[1].Position.Y) :
                new Vector2(vertices[3].Position.X, vertices[3].Position.Y);

            int tileX, tileY;
            MapTile tile;
            MapObjectDeferred deferred;
            VertexPositionNormalTextureHue[] verts;

            if (overlapToHere.Y > (overlapCurrent.Y - 22))
            {
                tileX = Position.X;
                tileY = Position.Y + (int)Math.Ceiling((overlapToHere.Y - (overlapCurrent.Y - 22)) / 22f);

                // Get the tile associated with this (x, y) position. If the tile is not loaded, don't add a deferred object
                // (it'll be offscreen so it doesn't matter).
                tile = IsometricRenderer.InternalMap.GetMapTile(tileX, tileY, false);
                if (tile != null)
                {
                    deferred = new MapObjectDeferred(_draw_texture, this);
                    deferred.Position.X = tileX;
                    deferred.Position.Y = tileY;
                    verts = deferred.Vertices;

                    if (_draw_flip)
                    {
                        //     0
                        //    / \
                        //   /   1
                        //  /   /
                        // 2---3
                        verts[0].Position = new Vector3(overlapCurrent, 0) + new Vector3(-22, -22, 0);
                        verts[0].TextureCoordinate = new Vector3((overlapToHere.X - verts[0].Position.X) / _draw_texture.Width, 1f - (overlapToHere.Y - verts[0].Position.Y) / _draw_texture.Height, 0);
                        verts[1].Position = new Vector3(overlapCurrent, 0);
                        verts[1].TextureCoordinate = new Vector3((overlapToHere.X - verts[1].Position.X) / _draw_texture.Width, 1f - (overlapToHere.Y - verts[1].Position.Y) / _draw_texture.Height, 0);
                        verts[2].Position = new Vector3(verts[0].Position.X - (overlapToHere.Y - verts[0].Position.Y), overlapToHere.Y, 0);
                        verts[2].TextureCoordinate = new Vector3((overlapToHere.X - verts[2].Position.X) / _draw_texture.Width, 1f - (overlapToHere.Y - verts[2].Position.Y) / _draw_texture.Height, 0);
                        verts[3].Position = new Vector3(verts[1].Position.X - (overlapToHere.Y - verts[1].Position.Y), overlapToHere.Y, 0);
                        verts[3].TextureCoordinate = new Vector3((overlapToHere.X - verts[3].Position.X) / _draw_texture.Width, 1f - (overlapToHere.Y - verts[3].Position.Y) / _draw_texture.Height, 0);
                    }
                    else
                    {
                        //     1
                        //    / \
                        //   /   3
                        //  /   /
                        // 0---2
                        verts[1].Position = new Vector3(overlapCurrent, 0) + new Vector3(-22, -22, 0);
                        verts[1].TextureCoordinate = new Vector3(1f - (overlapToHere.X - verts[1].Position.X) / _draw_texture.Width, 1f - (overlapToHere.Y - verts[1].Position.Y) / _draw_texture.Height, 0);
                        verts[3].Position = new Vector3(overlapCurrent, 0);
                        verts[3].TextureCoordinate = new Vector3(1f - (overlapToHere.X - verts[3].Position.X) / _draw_texture.Width, 1f - (overlapToHere.Y - verts[3].Position.Y) / _draw_texture.Height, 0);
                        verts[0].Position = new Vector3(verts[1].Position.X - (overlapToHere.Y - verts[1].Position.Y), overlapToHere.Y, 0);
                        verts[0].TextureCoordinate = new Vector3(1f - (overlapToHere.X - verts[0].Position.X) / _draw_texture.Width, 1f - (overlapToHere.Y - verts[0].Position.Y) / _draw_texture.Height, 0);
                        verts[2].Position = new Vector3(verts[3].Position.X - (overlapToHere.Y - verts[3].Position.Y), overlapToHere.Y, 0);
                        verts[2].TextureCoordinate = new Vector3(1f - (overlapToHere.X - verts[2].Position.X) / _draw_texture.Width, 1f - (overlapToHere.Y - verts[2].Position.Y) / _draw_texture.Height, 0);
                    }

                    verts[0].Normal = verts[1].Normal = verts[2].Normal = verts[3].Normal = vertices[0].Normal;
                    verts[0].Hue = verts[1].Hue = verts[2].Hue = verts[3].Hue = vertices[0].Hue;

                    tile.AddMapObject(deferred);
                }
            }

            // reset the tile position for the upcoming loop.
            tileX = Position.X;
            tileY = Position.Y;

            while (true)
            {
                // We are drawing each subsequent deferred object at (x+1, y+1) relative to the last one.
                tileX += 1;
                tileY += 1;

                // Get the tile associated with this (x, y) position. If the tile is not loaded, don't add a deferred object
                // (it'll be offscreen so it doesn't matter).
                tile = IsometricRenderer.InternalMap.GetMapTile(tileX, tileY, false);
                if (tile == null)
                    break;

                // find the vertical and            |
                // horizontal edges that            | <- V
                // we are drawing to.    H -> ------+
                Vector3 verticalEdgeOverlapPt = new Vector3(overlapToHere.X, overlapCurrent.Y - (overlapToHere.X - overlapCurrent.X), 0);
                Vector3 horizEdgeOverlapPt = new Vector3(overlapCurrent.X - (overlapToHere.Y - overlapCurrent.Y), overlapToHere.Y, 0);
                if (horizEdgeOverlapPt.X > overlapToHere.X && verticalEdgeOverlapPt.Y > overlapToHere.Y)
                    break;

                float extendX = overlapToHere.X - horizEdgeOverlapPt.X;
                if (extendX > 44)
                    extendX = 44;
                float extendY = overlapToHere.Y - verticalEdgeOverlapPt.Y;
                if (extendY > 44)
                    extendY = 44;

                deferred = new MapObjectDeferred(_draw_texture, this);
                deferred.Position.X = tileX;
                deferred.Position.Y = tileY;
                verts = deferred.Vertices;

                if (_draw_flip)
                {
                    //       0
                    //      /|
                    //    /  1
                    //  /   /
                    // 2---3
                    verts[0].Position = verticalEdgeOverlapPt;
                    verts[0].TextureCoordinate = new Vector3(0f, (verts[0].Position.Y - vertices[0].Position.Y) / _draw_texture.Height, 0);
                    verts[1].Position = verticalEdgeOverlapPt + new Vector3(0, extendY, 0);
                    verts[1].TextureCoordinate = new Vector3(0f, (verts[1].Position.Y - vertices[0].Position.Y) / _draw_texture.Height, 0);
                    verts[2].Position = horizEdgeOverlapPt;
                    verts[2].TextureCoordinate = new Vector3(1f - (verts[2].Position.X - vertices[2].Position.X) / _draw_texture.Width, 1f, 0);
                    verts[3].Position = horizEdgeOverlapPt + new Vector3(extendX, 0, 0);
                    verts[3].TextureCoordinate = new Vector3(1f - (verts[3].Position.X - vertices[2].Position.X) / _draw_texture.Width, 1f, 0);
                }
                else
                {
                    //       1
                    //      /|
                    //    /  3
                    //  /   /
                    // 0---2
                    verts[0].Position = horizEdgeOverlapPt;
                    verts[0].TextureCoordinate = new Vector3((verts[0].Position.X - vertices[0].Position.X) / _draw_texture.Width, 1, 0);
                    verts[1].Position = verticalEdgeOverlapPt;
                    verts[1].TextureCoordinate = new Vector3(1, (verts[1].Position.Y - vertices[1].Position.Y) / _draw_texture.Height, 0);
                    verts[2].Position = horizEdgeOverlapPt + new Vector3(extendX, 0, 0);
                    verts[2].TextureCoordinate = new Vector3((verts[2].Position.X - vertices[0].Position.X) / _draw_texture.Width, 1, 0);
                    verts[3].Position = verticalEdgeOverlapPt + new Vector3(0, extendY, 0);
                    verts[3].TextureCoordinate = new Vector3(1, (verts[3].Position.Y - vertices[1].Position.Y) / _draw_texture.Height, 0);
                }

                verts[0].Normal = verts[1].Normal = verts[2].Normal = verts[3].Normal = vertices[0].Normal;
                verts[0].Hue = verts[1].Hue = verts[2].Hue = verts[3].Hue = vertices[0].Hue;

                overlapCurrent.X += 22;
                overlapCurrent.Y += 22;

                tile.AddMapObject(deferred);
            }
        }