예제 #1
0
 public static void DrawPolygonExtent(this SpriteBatch spriteBatch, IPolygonExtent extent, RenderParams renderParams)
 {
     DrawPolygonExtent(spriteBatch, extent, Matrix.Identity, renderParams);
 }
예제 #2
0
        public static void DrawPolygonExtent(this SpriteBatch spriteBatch, IPolygonExtent extent, Matrix transformFromWorldToCamera, RenderParams renderParams)
        {
            if (RenderMode.TraceBoundingBox == (renderParams.Mode & RenderMode.TraceBoundingBox))
            {
                DrawBoundingBox(spriteBatch, extent, renderParams.TraceBoundingBoxColor, transformFromWorldToCamera);
                DrawCircle(spriteBatch, extent.ActualCenter, extent.InnerRadius, renderParams.TraceBoundingBoxColor, transformFromWorldToCamera);
                DrawCircle(spriteBatch, extent.ActualCenter, extent.OuterRadius, renderParams.TraceBoundingBoxColor, transformFromWorldToCamera);
            }

            if (RenderMode.TraceRenderingExtent == (renderParams.Mode & RenderMode.TraceRenderingExtent))
            {
                DrawPolygon(spriteBatch, extent, renderParams.TraceRenderingExtentColor, transformFromWorldToCamera);
                DrawKeyPoints(spriteBatch, extent, renderParams, transformFromWorldToCamera);
            }
        }
예제 #3
0
        public static void Draw(this SpriteBatch spriteBatch, Texture2D texture, Vector2 position, Rectangle?sourceRectangle, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth, Matrix transformFromWorldToCamera, RenderParams renderParams)
        {
            position = Vector2.Transform(position, transformFromWorldToCamera);

            Vector3    vecScale, translate;
            Quaternion rotate;

            transformFromWorldToCamera.Decompose(out vecScale, out rotate, out translate);
            transformFromWorldToCamera.Translation = Vector3.Zero;

            float angle = rotation + XenMath.GetAngleFloat(Vector2.Transform(Vector2.UnitX, transformFromWorldToCamera));

            spriteBatch.Draw(
                texture,                                     // The sprite texture.
                position,                                    // The location, in screen coordinates, where the sprite will be drawn.
                sourceRectangle,                             // A rectangle specifying, in texels, which section of the rectangle to draw.  Use null to draw the entire texture.
                color,                                       // The color channel modulation to use. Use Color.White for full color with no tinting.
                angle,                                       // The angle, in radians, to rotate the sprite around the origin.
                origin,                                      // The origin of the sprite. Specify (0,0) for the upper-left corner.
                new Vector2(vecScale.X, vecScale.Y) * scale, // Vector containing separate scalar multiples for the x- and y-axes of the sprite.
                effects,                                     // Rotations to apply before rendering.
                layerDepth);                                 // The sorting depth of the sprite, between 0 (front) and 1 (back). You must
                                                             // specify either SpriteSortMode.FrontToBack or SpriteSortMode.BackToFront for
                                                             // this parameter to affect sprite drawing.
        }
예제 #4
0
        private static void DrawSpriteInternal(this SpriteBatch spriteBatch, ISprite sprite, Matrix transformFromWorldToCamera, RenderParams renderParams)
        {
            Matrix  transformFromSpriteToWorld = sprite.RenderingExtent.TranslateFrom;
            Matrix  fromSpriteToCamera         = transformFromSpriteToWorld * transformFromWorldToCamera;
            Vector2 position = Vector2.Transform(sprite.RenderingExtent.ReferenceTopLeft, fromSpriteToCamera);

            Vector3    scale, translate;
            Quaternion rotate;

            fromSpriteToCamera.Decompose(out scale, out rotate, out translate);
            fromSpriteToCamera.Translation = Vector3.Zero;

            float angle = XenMath.GetAngleFloat(Vector2.Transform(Vector2.UnitX, fromSpriteToCamera));

            spriteBatch.Draw(
                sprite.TextureInfo.Asset,               // The sprite texture.
                position,                               // The location, in screen coordinates, where the sprite will be drawn.
                sprite.TextureInfo.SourceRectangle,     // A rectangle specifying, in texels, which section of the rectangle to draw.  Use null to draw the entire texture.
                sprite.ModulationColorWithOpacity,      // The color channel modulation to use. Use Color.White for full color with no tinting.
                angle,                                  // The angle, in radians, to rotate the sprite around the origin.
                Vector2.Zero,                           // The origin of the sprite. Specify (0,0) for the upper-left corner.
                new Vector2(scale.X, scale.Y),          // Vector containing separate scalar multiples for the x- and y-axes of the sprite.
                sprite.SpriteEffects,                   // Rotations to apply before rendering.
                sprite.LayerDepth);                     // The sorting depth of the sprite, between 0 (front) and 1 (back). You must
                                                        // specify either SpriteSortMode.FrontToBack or SpriteSortMode.BackToFront for
                                                        // this parameter to affect sprite drawing.
        }
예제 #5
0
        public static void DrawSprite(this SpriteBatch spriteBatch, ISprite sprite, Matrix transformFromWorldToCamera, RenderParams renderParams)
        {
            if (RenderMode.Texture == (renderParams.Mode & RenderMode.Texture))
            {
                DrawSpriteInternal(spriteBatch, sprite, transformFromWorldToCamera, renderParams);
            }

            DrawPolygonExtent(spriteBatch, sprite.RenderingExtent, transformFromWorldToCamera, renderParams);
        }
예제 #6
0
 public static void DrawSprite(this SpriteBatch spriteBatch, ISprite sprite, RenderParams renderParams)
 {
     DrawSprite(spriteBatch, sprite, Matrix.Identity, renderParams);
 }
예제 #7
0
        public static void DrawKeyPoints(this SpriteBatch spriteBatch, IPolygonExtent extent, RenderParams renderParams, Matrix transformFromWorldToCamera)
        {
            ISprite marker;

            if (null != renderParams.GetTexture_MarkCenter)
            {
                marker = renderParams.GetTexture_MarkCenter();
                marker.RenderingExtent.Anchor = Vector2.Transform(extent.ReferenceRegion.Center, extent.TranslateFrom);
                DrawSprite(spriteBatch, marker, transformFromWorldToCamera);
            }
            if (null != renderParams.GetTexture_MarkOrigin)
            {
                marker = renderParams.GetTexture_MarkOrigin();
                marker.RenderingExtent.Anchor = Vector2.Transform(extent.Origin, extent.TranslateFrom);
                DrawSprite(spriteBatch, marker, transformFromWorldToCamera);
            }
        }