/// <summary>
        /// draws a GL quad, textured with an animation.
        /// </summary>
        /// <param name="rectangle">coordinates ofthe GL quad</param>
        /// <param name="totalSeconds">animation position in seconds</param>
        public void Draw(AABR rectangle, float totalSeconds)
        {
            spriteSheet.BeginUse();
            var id = CalcAnimationSpriteID(FromID, ToID, AnimationLength, totalSeconds);

            spriteSheet.Draw(id, rectangle);
            spriteSheet.EndUse();
        }
Exemplo n.º 2
0
        public void Draw(uint spriteID, AABR rectangle)
        {
            AABR texCoords = CalcSpriteTexCoords(spriteID);

            GL.Begin(PrimitiveType.Quads);
            GL.TexCoord2(texCoords.X, texCoords.Y); GL.Vertex2(rectangle.X, rectangle.Y);
            GL.TexCoord2(texCoords.MaxX, texCoords.Y); GL.Vertex2(rectangle.MaxX, rectangle.Y);
            GL.TexCoord2(texCoords.MaxX, texCoords.MaxY); GL.Vertex2(rectangle.MaxX, rectangle.MaxY);
            GL.TexCoord2(texCoords.X, texCoords.MaxY); GL.Vertex2(rectangle.X, rectangle.MaxY);
            GL.End();
        }
Exemplo n.º 3
0
        /// <summary>
        /// draws a GL quad, textured with an animation.
        /// </summary>
        /// <param name="rectangle">coordinates ofthe GL quad</param>
        /// <param name="totalSeconds">animation position in seconds</param>
        public void Draw(AABR rectangle, float totalSeconds)
        {
            var id = (int)CalcAnimationFrame(totalSeconds);

            textures[id].BeginUse();
            GL.Begin(PrimitiveType.Quads);
            GL.TexCoord2(0, 0); GL.Vertex2(rectangle.X, rectangle.Y);
            GL.TexCoord2(1, 0); GL.Vertex2(rectangle.MaxX, rectangle.Y);
            GL.TexCoord2(1, 1); GL.Vertex2(rectangle.MaxX, rectangle.MaxY);
            GL.TexCoord2(0, 1); GL.Vertex2(rectangle.X, rectangle.MaxY);
            GL.End();
            textures[id].EndUse();
        }
Exemplo n.º 4
0
 public static bool PushXRangeInside(this AABR rectangleA, AABR rectangleB)
 {
     if (rectangleA.SizeX > rectangleB.SizeX)
     {
         return(false);
     }
     if (rectangleA.X < rectangleB.X)
     {
         rectangleA.X = rectangleB.X;
     }
     if (rectangleA.MaxX > rectangleB.MaxX)
     {
         rectangleA.MaxX = rectangleB.MaxX;
     }
     return(true);
 }
Exemplo n.º 5
0
 public static bool PushYRangeInside(this AABR rectangleA, AABR rectangleB)
 {
     if (rectangleA.SizeY > rectangleB.SizeY)
     {
         return(false);
     }
     if (rectangleA.Y < rectangleB.Y)
     {
         rectangleA.Y = rectangleB.Y;
     }
     if (rectangleA.MaxY > rectangleB.MaxY)
     {
         rectangleA.MaxY = rectangleB.MaxY;
     }
     return(true);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Calculates the AABR in the overlap
        /// Returns null if no intersection
        /// </summary>
        /// <param name="rectangleB"></param>
        /// <returns>AABR in the overlap</returns>
        public static AABR Overlap(this AABR rectangleA, AABR rectangleB)
        {
            AABR overlap = null;

            if (rectangleA.Intersects(rectangleB))
            {
                overlap = new AABR(0.0f, 0.0f, 0.0f, 0.0f);

                overlap.X = (rectangleA.X < rectangleB.X) ? rectangleB.X : rectangleA.X;
                overlap.Y = (rectangleA.Y < rectangleB.Y) ? rectangleB.Y : rectangleA.Y;

                overlap.SizeX = (rectangleA.MaxX < rectangleB.MaxX) ? rectangleA.MaxX - overlap.X : rectangleB.MaxX - overlap.X;
                overlap.SizeY = (rectangleA.MaxY < rectangleB.MaxY) ? rectangleA.MaxY - overlap.Y : rectangleB.MaxY - overlap.Y;
            }

            return(overlap);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Create a new font that can be printed in OpenGL
        /// </summary>
        /// <param name="texture">texture containing a equally spaced grid of characters</param>
        /// <param name="charactersPerLine">number of characters per grid row</param>
        /// <param name="firstAsciiCode">ascii code of upper left most character in the grid</param>
        /// <param name="characterBoundingBoxWidth">bounding box width of each character cell, allows to zoom in/out of each character</param>
        /// <param name="characterBoundingBoxHeight">bounding box height of each character cell, allows to zoom in/out of each character</param>
        /// <param name="characterSpacing">how much to move to the right after drawing a single character</param>
        public TextureFont(Texture texture, uint charactersPerLine = 16, byte firstAsciiCode                = 0
                           , float characterBoundingBoxWidth       = 1.0f, float characterBoundingBoxHeight = 1.0f, float characterSpacing = 1.0f)
        {
            this.texFont = new SpriteSheet(texture, charactersPerLine, characterBoundingBoxWidth, characterBoundingBoxHeight);
            // Creating 256 Display Lists
            this.baseList = (uint)GL.GenLists(256);
            //foreach of the 256 possible characters create a a quad
            //with texture coordinates and store it in a display list
            var rect = new AABR(0, 0, 1, 1);

            for (uint asciiCode = 0; asciiCode < 256; ++asciiCode)
            {
                GL.NewList((this.baseList + asciiCode), ListMode.Compile);
                texFont.Draw(asciiCode - firstAsciiCode, rect);
                GL.Translate(characterSpacing, 0, 0);                   // Move To The next character
                GL.EndList();
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// If an intersection with the frame occurs do the minimal translation to undo the overlap
        /// </summary>
        /// <param name="rectangleB">The AABR to check for intersect</param>
        public static void UndoOverlap(this AABR rectangleA, AABR rectangleB)
        {
            if (rectangleA.Intersects(rectangleB))
            {
                Vector2[] directions = new Vector2[]
                {
                    new Vector2(rectangleB.MaxX - rectangleA.X, 0),
                    new Vector2(rectangleB.X - rectangleA.MaxX, 0),
                    new Vector2(0, rectangleB.MaxY - rectangleA.Y),
                    new Vector2(0, rectangleB.Y - rectangleA.MaxY)
                };

                Vector2 minimum = directions.Aggregate((curMin, x) => (curMin == null || (x.Length) < curMin.Length) ? x : curMin);

                rectangleA.X += minimum.X;
                rectangleA.Y += minimum.Y;
            }
        }