Пример #1
0
 protected abstract void Prerender(SpriteBatch3D sb);
Пример #2
0
 public static void RenderObjects(SpriteBatch3D sb)
 {
     foreach (MapObjectPrerendered obj in m_objects)
         obj.Prerender(sb);
     m_objects.Clear();
 }
Пример #3
0
 internal override bool Draw(SpriteBatch3D sb, Vector3 drawPosition, MouseOverList molist, PickTypes pickType, int maxAlt)
 {
     m_draw_Y = (int)(Z * 4) + m_draw_height - 44;
     if (m_noDraw)
         return false;
     return base.Draw(sb, drawPosition, molist, pickType, maxAlt);
 }
Пример #4
0
 internal override bool Draw(SpriteBatch3D sb, Vector3 drawPosition, MouseOverList molist, PickTypes pickType, int maxAlt)
 {
     return base.Draw(sb, drawPosition, molist, pickType, maxAlt);
 }
Пример #5
0
 internal override bool Draw(SpriteBatch3D sb, Vector3 drawPosition, MouseOverList molist, PickTypes pickType, int maxAlt)
 {
     if (m_noDraw || m_mustUpdateSurroundings || !IsometricRenderer.DrawTerrain)
         return false;
     if (!m_draw_3DStretched)
         return base.Draw(sb, drawPosition, molist, pickType, 255);
     else
         return Draw3DStretched(sb, drawPosition, molist, pickType, 255);
 }
Пример #6
0
        private bool Draw3DStretched(SpriteBatch3D sb, Vector3 drawPosition, MouseOverList molist, PickTypes pickType, int maxAlt)
        {
            // this is an isometric stretched tile and needs a specialized draw routine.
            m_vertexBufferAlternate[0].Position = drawPosition + m_vertex0_yOffset;
            m_vertexBufferAlternate[1].Position = drawPosition + m_vertex1_yOffset;
            m_vertexBufferAlternate[2].Position = drawPosition + m_vertex2_yOffset;
            m_vertexBufferAlternate[3].Position = drawPosition + m_vertex3_yOffset;

            if (!sb.Draw(m_draw_texture, m_vertexBufferAlternate))
                return false;

            if ((pickType & m_pickType) == m_pickType)
                if (molist.IsMouseInObjectIsometric(m_vertexBufferAlternate))
                {
                    MouseOverItem item = new MouseOverItem(m_draw_texture, m_vertexBufferAlternate[0].Position, this);
                    item.Vertices = new Vector3[4] { m_vertexBufferAlternate[0].Position, m_vertexBufferAlternate[1].Position, m_vertexBufferAlternate[2].Position, m_vertexBufferAlternate[3].Position };
                    molist.Add2DItem(item);
                }

            return true;
        }
Пример #7
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 = m_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.Map.GetMapTile(tileX, tileY, false);
                if (tile != null)
                {
                    deferred = new MapObjectDeferred(m_draw_texture, this);
                    deferred.Position.X = tileX;
                    deferred.Position.Y = tileY;
                    verts = deferred.Vertices;

                    if (m_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) / m_draw_texture.Width, 1f - (overlapToHere.Y - verts[0].Position.Y) / m_draw_texture.Height, 0);
                        verts[1].Position = new Vector3(overlapCurrent, 0);
                        verts[1].TextureCoordinate = new Vector3((overlapToHere.X - verts[1].Position.X) / m_draw_texture.Width, 1f - (overlapToHere.Y - verts[1].Position.Y) / m_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) / m_draw_texture.Width, 1f - (overlapToHere.Y - verts[2].Position.Y) / m_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) / m_draw_texture.Width, 1f - (overlapToHere.Y - verts[3].Position.Y) / m_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) / m_draw_texture.Width, 1f - (overlapToHere.Y - verts[1].Position.Y) / m_draw_texture.Height, 0);
                        verts[3].Position = new Vector3(overlapCurrent, 0);
                        verts[3].TextureCoordinate = new Vector3(1f - (overlapToHere.X - verts[3].Position.X) / m_draw_texture.Width, 1f - (overlapToHere.Y - verts[3].Position.Y) / m_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) / m_draw_texture.Width, 1f - (overlapToHere.Y - verts[0].Position.Y) / m_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) / m_draw_texture.Width, 1f - (overlapToHere.Y - verts[2].Position.Y) / m_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.Map.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(m_draw_texture, this);
                deferred.Position.X = tileX;
                deferred.Position.Y = tileY;
                verts = deferred.Vertices;

                if (m_draw_flip)
                {
                    //       0
                    //      /|
                    //    /  1
                    //  /   /
                    // 2---3
                    verts[0].Position = verticalEdgeOverlapPt;
                    verts[0].TextureCoordinate = new Vector3(0f, (verts[0].Position.Y - vertices[0].Position.Y) / m_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) / m_draw_texture.Height, 0);
                    verts[2].Position = horizEdgeOverlapPt;
                    verts[2].TextureCoordinate = new Vector3(1f - (verts[2].Position.X - vertices[2].Position.X) / m_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) / m_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) / m_draw_texture.Width, 1, 0);
                    verts[1].Position = verticalEdgeOverlapPt;
                    verts[1].TextureCoordinate = new Vector3(1, (verts[1].Position.Y - vertices[1].Position.Y) / m_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) / m_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) / m_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);
            }
        }
Пример #8
0
        internal virtual bool Draw(SpriteBatch3D sb, Vector3 drawPosition, MouseOverList molist, PickTypes pickType, int maxAlt)
        {
            VertexPositionNormalTextureHue[] vertexBuffer;

            if (Z >= maxAlt)
                return false;

            if (m_draw_flip)
            {
                // 2   0
                // |\  |
                // |  \|
                // 3   1
                vertexBuffer = VertexPositionNormalTextureHue.PolyBufferFlipped;
                vertexBuffer[0].Position = drawPosition;
                vertexBuffer[0].Position.X += m_draw_X + 44;
                vertexBuffer[0].Position.Y -= m_draw_Y;

                vertexBuffer[1].Position = vertexBuffer[0].Position;
                vertexBuffer[1].Position.Y += m_draw_height;

                vertexBuffer[2].Position = vertexBuffer[0].Position;
                vertexBuffer[2].Position.X -= m_draw_width;

                vertexBuffer[3].Position = vertexBuffer[1].Position;
                vertexBuffer[3].Position.X -= m_draw_width;
            }
            else
            {
                // 0---1
                //    /
                //  /
                // 2---3
                vertexBuffer = VertexPositionNormalTextureHue.PolyBuffer;
                vertexBuffer[0].Position = drawPosition;
                vertexBuffer[0].Position.X -= m_draw_X;
                vertexBuffer[0].Position.Y -= m_draw_Y;

                vertexBuffer[1].Position = vertexBuffer[0].Position;
                vertexBuffer[1].Position.X += m_draw_width;

                vertexBuffer[2].Position = vertexBuffer[0].Position;
                vertexBuffer[2].Position.Y += m_draw_height;

                vertexBuffer[3].Position = vertexBuffer[1].Position;
                vertexBuffer[3].Position.Y += m_draw_height;
            }

            if (vertexBuffer[0].Hue != m_draw_hue)
                vertexBuffer[0].Hue = vertexBuffer[1].Hue = vertexBuffer[2].Hue = vertexBuffer[3].Hue = m_draw_hue;

            if (!sb.Draw(m_draw_texture, vertexBuffer))
            {
                return false;
            }

            if (m_draw_IsometricOverlap)
            {
                drawIsometricOverlap(sb, vertexBuffer, new Vector2(drawPosition.X, drawPosition.Y - (Z * 4)));
            }

            if ((pickType & m_pickType) == m_pickType)
            {
                if (((!m_draw_flip) && molist.IsMouseInObject(vertexBuffer[0].Position, vertexBuffer[3].Position)) ||
                    ((m_draw_flip) && molist.IsMouseInObject(vertexBuffer[2].Position, vertexBuffer[1].Position)))
                {
                    MouseOverItem item;
                    if (!m_draw_flip)
                    {
                        item = new MouseOverItem(m_draw_texture, vertexBuffer[0].Position, this);
                        item.Vertices = new Vector3[4] { vertexBuffer[0].Position, vertexBuffer[1].Position, vertexBuffer[2].Position, vertexBuffer[3].Position };
                    }
                    else
                    {
                        item = new MouseOverItem(m_draw_texture, vertexBuffer[2].Position, this);
                        item.Vertices = new Vector3[4] { vertexBuffer[2].Position, vertexBuffer[0].Position, vertexBuffer[3].Position, vertexBuffer[1].Position };
                    }
                    molist.Add2DItem(item);
                }
            }

            return true;
        }
Пример #9
0
 public SpriteBatchUI(Game game)
 {
     m_SpriteBatch = new SpriteBatch3D(game);
 }
Пример #10
0
        protected override void Prerender(SpriteBatch3D sb)
        {
            if (m_layerCount == 1)
            {
                m_draw_hue = Utility.GetHueVector(m_layers[0].Hue);
                m_draw_texture = m_layers[0].Frame.Texture;
                m_mobile_drawCenterX = m_layers[0].Frame.Center.X;
                m_mobile_drawCenterY = m_layers[0].Frame.Center.Y;
            }
            else
            {
                m_draw_hue = Utility.GetHueVector(0);
                long hash = createHashFromLayers();
                m_draw_texture = MapObjectPrerendered.RestorePrerenderedTexture(hash, out m_mobile_drawCenterX, out m_mobile_drawCenterY);
                if (m_draw_texture == null)
                {
                    int minX = 0, minY = 0;
                    int maxX = 0, maxY = 0;
                    for (int i = 0; i < m_layerCount; i++)
                    {
                        if (m_layers[i].Frame != null)
                        {
                            int x, y, w, h;
                            x = m_layers[i].Frame.Center.X;
                            y = m_layers[i].Frame.Center.Y;
                            w = m_layers[i].Frame.Texture.Width;
                            h = m_layers[i].Frame.Texture.Height;

                            if (minX < x)
                                minX = x;
                            if (maxX < w - x)
                                maxX = w - x;

                            if (minY < h + y)
                                minY = h + y;
                            if (maxY > y)
                                maxY = y;
                        }
                    }

                    m_mobile_drawCenterX = minX;
                    m_mobile_drawCenterY = maxY;

                    RenderTarget2D renderTarget = new RenderTarget2D(sb.GraphicsDevice,
                            minX + maxX, minY - maxY, false, SurfaceFormat.Color, DepthFormat.None);

                    sb.GraphicsDevice.SetRenderTarget(renderTarget);
                    sb.GraphicsDevice.Clear(Color.Transparent);

                    for (int i = 0; i < m_layerCount; i++)
                        if (m_layers[i].Frame != null)
                            sb.DrawSimple(m_layers[i].Frame.Texture,
                                new Vector3(
                                    minX - m_layers[i].Frame.Center.X,
                                    renderTarget.Height - m_layers[i].Frame.Texture.Height + maxY - m_layers[i].Frame.Center.Y,
                                    0),
                                    Utility.GetHueVector(m_layers[i].Hue));

                    sb.Flush();
                    m_draw_texture = renderTarget;
                    MapObjectPrerendered.SavePrerenderedTexture(m_draw_texture, hash, m_mobile_drawCenterX, m_mobile_drawCenterY);
                    sb.GraphicsDevice.SetRenderTarget(null);
                }
            }
        }
Пример #11
0
        internal override bool Draw(SpriteBatch3D sb, Vector3 drawPosition, MouseOverList molist, PickTypes pickType, int maxAlt)
        {
            m_draw_width = m_draw_texture.Width;
            m_draw_height = m_draw_texture.Height;
            if (m_draw_flip)
            {
                m_draw_X = m_mobile_drawCenterX - 22 + (int)((Position.X_offset - Position.Y_offset) * 22);
                m_draw_Y = m_mobile_drawCenterY + (int)((Position.Z_offset + Z) * 4) + m_draw_height - 22 - (int)((Position.X_offset + Position.Y_offset) * 22);
            }
            else
            {
                m_draw_X = m_mobile_drawCenterX - 22 - (int)((Position.X_offset - Position.Y_offset) * 22);
                m_draw_Y = m_mobile_drawCenterY + (int)((Position.Z_offset + Z) * 4) + m_draw_height - 22 - (int)((Position.X_offset + Position.Y_offset) * 22);
            }

            if (UltimaVars.EngineVars.LastTarget != null && UltimaVars.EngineVars.LastTarget == OwnerSerial)
                m_draw_hue = new Vector2(((Mobile)OwnerEntity).NotorietyHue - 1, 1);

            // !!! Test highlight code.
            bool isHighlight = false;
            if (isHighlight)
            {
                Vector2 savedHue = m_draw_hue;
                int savedX = m_draw_X, savedY = m_draw_Y;
                m_draw_hue = Utility.GetHueVector(1288);
                int offset = 1;
                m_draw_X = savedX - offset;
                base.Draw(sb, drawPosition, molist, pickType, maxAlt);
                m_draw_X = savedX + offset;
                base.Draw(sb, drawPosition, molist, pickType, maxAlt);
                m_draw_X = savedX;
                m_draw_Y = savedY - offset;
                base.Draw(sb, drawPosition, molist, pickType, maxAlt);
                m_draw_Y = savedY + offset;
                base.Draw(sb, drawPosition, molist, pickType, maxAlt);
                m_draw_hue = savedHue;
                m_draw_X = savedX;
                m_draw_Y = savedY;
            }

            bool isDrawn = base.Draw(sb, drawPosition, molist, pickType, maxAlt);
            return isDrawn;
        }
Пример #12
0
        public static void Initialize(Game game)
        {
            m_spriteBatch = new SpriteBatch3D(game);
            m_vectors = new VectorRenderer(game.GraphicsDevice, game.Content);

            PickType = PickTypes.PickNothing;
            m_vertexBufferStretched = new VertexPositionNormalTextureHue[] {
                new VertexPositionNormalTextureHue(new Vector3(), new Vector3(),  new Vector3(0, 0, 0)),
                new VertexPositionNormalTextureHue(new Vector3(), new Vector3(),  new Vector3(1, 0, 0)),
                new VertexPositionNormalTextureHue(new Vector3(), new Vector3(),  new Vector3(0, 1, 0)),
                new VertexPositionNormalTextureHue(new Vector3(), new Vector3(),  new Vector3(1, 1, 0))
            };
        }
Пример #13
0
 internal override bool Draw(SpriteBatch3D sb, Vector3 drawPosition, MouseOverList molist, PickTypes pickType, int maxAlt)
 {
     sb.Draw(m_texture, Vertices);
     return false;
 }