public static void DrawPixelFast(this SpriteBatch spriteBatch, Color color, Vector2 position) { int thickness = 1; _destinationRect.X = (int)(position.X - (float)thickness / 2.0f); _destinationRect.Y = (int)(position.Y + (float)thickness / 2.0f); _destinationRect.Width = thickness; if (_destinationRect.Width == 0) { _destinationRect.Width = 1; } _destinationRect.Height = thickness; SinglePixel pixel = SinglePixel.WhitePixel; spriteBatch.Draw( pixel.Asset, _destinationRect, pixel.SourceRectangle, color, 0.0f, Vector2.UnitY / 2.0f, SpriteEffects.None, 0.0f); }
public static void DrawPixel(this SpriteBatch spriteBatch, Color color, Vector2 position, int thickness, I2DDisplayModifiers attributes, Matrix transformFromWorldToCamera) { //float scale = Camera.GetScale( 1, Camera.Zoom, attributes.ParallaxDepth ); //Vector2 position = Camera.TranslateAbsoluteVectorToCamera( start, attributes.ParallaxDepth ); position = Vector2.Transform(position, transformFromWorldToCamera); thickness = (int)Math.Max(1, thickness); _destinationRect.X = (int)(position.X - (float)thickness / 2.0f); _destinationRect.Y = (int)(position.Y + (float)thickness / 2.0f); _destinationRect.Width = thickness; if (_destinationRect.Width == 0) { _destinationRect.Width = 1; } _destinationRect.Height = thickness; SinglePixel pixel = SinglePixel.WhitePixel; spriteBatch.Draw( pixel.Asset, _destinationRect, pixel.SourceRectangle, #if SILVERLIGHT new Color(color, attributes.Opacity), #else color *attributes.OpacityFinal, #endif 0.0f, Vector2.UnitY / 2.0f, attributes.SpriteEffects, attributes.LayerDepth); }
public static void DrawLine(this SpriteBatch spriteBatch, Color color, Vector2 start, Vector2 stop, int thickness, I2DDisplayModifiers attributes, Matrix transformFromWorldToCamera) { //float scale = Camera.GetScale( 1, Camera.Zoom, attributes.ParallaxDepth ); //Vector2 position = Camera.TranslateAbsoluteVectorToCamera( start, attributes.ParallaxDepth ); float originalLength = Vector2.Distance(start, stop); start = Vector2.Transform(start, transformFromWorldToCamera); stop = Vector2.Transform(stop, transformFromWorldToCamera); float newLength = Vector2.Distance(start, stop); float scale = newLength / originalLength; //originalLength might be 0 thickness = (int)Math.Max(1, thickness * scale); Vector2 position = start; _destinationRect.X = (int)position.X; _destinationRect.Y = (int)(position.Y + (float)thickness / 2.0f); _destinationRect.Width = (int)(Math.Ceiling(Vector2.Distance(start, stop))); if (_destinationRect.Width == 0) { _destinationRect.Width = 1; } _destinationRect.Height = thickness; SinglePixel pixel = SinglePixel.WhitePixel; float angle = XenMath.GetAngleFloat(stop - start); spriteBatch.Draw( pixel.Asset, _destinationRect, pixel.SourceRectangle, #if SILVERLIGHT new Color(color, attributes.OpacityFinal), #else color *attributes.OpacityFinal, #endif angle, Vector2.UnitY / 2.0f, attributes.SpriteEffects, attributes.LayerDepth); }