Esempio n. 1
0
        public void DrawRectangle(BoundingBox2 boundingBox, Vector2 cornerRadius, PrimitiveBrush brush, Matrix transformMatrix)
        {
            int startIndex = _vertexCount;

            DrawRectangle(boundingBox, cornerRadius, brush);
            ApplyTransformMatrix(startIndex, _vertexCount, transformMatrix);
        }
Esempio n. 2
0
 public void DrawPolygon(Vector2[] points, PrimitiveBrush brush, Matrix transform)
 {
     for (int i = 1; i < points.Length; i++)
     {
         DrawLine(points[i - 1], points[i], brush, transform);
     }
     DrawLine(points[points.Length - 1], points[0], brush, transform);
 }
Esempio n. 3
0
        public void DrawLine(Vector2 start, Vector2 end, PrimitiveBrush brush, Matrix transformMatrix)
        {
            int startIndex = _vertexCount;

            DrawLine(start, end, brush);

            // Apply the transformation matrix.
            ApplyTransformMatrix(startIndex, _vertexCount, transformMatrix);
        }
Esempio n. 4
0
        public void Draw(PrimitiveBatch primitiveBatch)
        {
            PrimitiveBrush pb = new PrimitiveBrush();
            pb.BorderAlignment = BorderAlignment.Center;
            pb.BorderThickness = 4;
            pb.BorderColor = Color.Red;
            pb.FillColor = Color.Transparent;

            primitiveBatch.DrawCircle(Vector2.Zero, Radius, pb, WorldTransform);
        }
Esempio n. 5
0
        public void Draw(PrimitiveBatch primitiveBatch)
        {
            PrimitiveBrush pb = new PrimitiveBrush();

            pb.BorderAlignment = BorderAlignment.Center;
            pb.BorderThickness = 4;
            pb.BorderColor     = Color.Red;
            pb.FillColor       = Color.Transparent;

            primitiveBatch.DrawCircle(Vector2.Zero, Radius, pb, WorldTransform);
        }
Esempio n. 6
0
        public void DrawLine(Vector2 start, Vector2 end, PrimitiveBrush brush)
        {
            int startIndex = _vertexCount;
            int lod        = 16;

            _borderColor = brush.BorderColor;
            _fillColor   = Color.Transparent;

            Vector2 t = end - start;

            t = Vector2.Normalize(new Vector2(-t.Y, t.X)) * brush.BorderThickness * 0.5f;

            Polar2 a = Polar2.CreateFromVector(t);

            _edge = brush.BorderThickness * 0.5f * _edgeSoftness;

            int s0 = _vertexCount;

            PushVertex(start);
            PushVertex(end);

            _edge = 0;

            int s1 = _vertexCount;

            PushVerticesForCircle(start, new Vector2(a.R), a.Theta, a.Theta + MathHelper.Pi, lod);
            int s2 = _vertexCount;

            PushVerticesForCircle(end, new Vector2(a.R), a.Theta + MathHelper.Pi, a.Theta + MathHelper.TwoPi, lod);
            int s3 = _vertexCount;

            PushIndicesForCircle(s0 + 0, s1, lod, false);
            PushIndicesForCircle(s0 + 1, s2, lod, false);

            PushIndicesForRectangle(s3 - 1, s1, s0 + 1, s0);
            PushIndicesForRectangle(s0 + 1, s0, s2, s2 - 1);
        }
Esempio n. 7
0
 public void DrawCircle(Vector2 center, float radius, PrimitiveBrush brush, Matrix transformMatrix)
 {
     // HACK: Untill the real cricle function is implemented.
     DrawRectangle(new BoundingBox2(-radius, radius) + center, new Vector2(radius), brush, transformMatrix);
     //DrawCircle(center, radius, 0, 0, borderColor, fillColor);
 }
Esempio n. 8
0
 public void DrawRectangle(BoundingBox2 boundingBox, Vector2 cornerRadius, PrimitiveBrush brush, Matrix transformMatrix)
 {
     int startIndex = _vertexCount;
     DrawRectangle(boundingBox, cornerRadius, brush);
     ApplyTransformMatrix(startIndex, _vertexCount, transformMatrix);
 }
Esempio n. 9
0
        public void DrawRectangle(BoundingBox2 boundingBox, Vector2 cornerRadius, PrimitiveBrush brush)
        {
            int startIndex = _vertexCount;

            float bi = -1;

            Vector2 half = (boundingBox.Max - boundingBox.Min) * 0.5f;

            if (brush.BorderThickness == 0)
            {
                brush.BorderAlignment = BorderAlignment.Inner;
                brush.BorderThickness = Math.Min(half.X, half.Y);
                brush.BorderColor = brush.FillColor;
                bi = 1;
            }

            _borderColor = brush.BorderColor;
            _fillColor = brush.FillColor;

            bi *= brush.BorderThickness * _edgeSoftness;

            if (cornerRadius.X < 0) cornerRadius.X = 0;
            if (cornerRadius.Y < 0) cornerRadius.Y = 0;
            if (cornerRadius.X > half.X) cornerRadius.X = half.X;
            if (cornerRadius.Y > half.Y) cornerRadius.Y = half.Y;

            boundingBox.Min += cornerRadius;
            boundingBox.Max -= cornerRadius;
            boundingBox.GetCorners(_corners);

            // Setting the inner and outer border radius based on BorderAlignment.
            Vector2 innerRadius = cornerRadius;
            Vector2 outerRadius = cornerRadius;

            if (brush.BorderAlignment == BorderAlignment.Inner)
            {
                innerRadius -= new Vector2(brush.BorderThickness);
            }
            else if (brush.BorderAlignment == BorderAlignment.Outer)
            {
                outerRadius += new Vector2(brush.BorderThickness);
            }
            else
            {
                innerRadius -= new Vector2(brush.BorderThickness * 0.5f);
                outerRadius += new Vector2(brush.BorderThickness * 0.5f);
            }

            if (innerRadius.X < 0 && cornerRadius.X > half.X) innerRadius.X = 0;
            if (innerRadius.Y < 0 && cornerRadius.Y > half.Y) innerRadius.Y = 0;

            //int lod = (int)outerRadius;
            //int lod = (int)(2 * MathHelper.Pi * (cornerRadius.X + cornerRadius.Y) / 16);
            int lod = 16;

            if (Math.Min(cornerRadius.X, cornerRadius.Y) == 0)
            {
                BoundingBox2 innerBox = new BoundingBox2(boundingBox.Min - innerRadius, boundingBox.Max + innerRadius);
                BoundingBox2 outerBox = new BoundingBox2(boundingBox.Min - outerRadius, boundingBox.Max + outerRadius);

                _edge = bi;

                innerBox.GetCorners(_corners);
                PushVerticesForRectangle(_corners);

                _edge = 0;

                outerBox.GetCorners(_corners);
                PushVerticesForRectangle(_corners);

                if (_fillColor.A > 0)
                    PushIndicesForRectangle(startIndex + 3, startIndex + 0, startIndex + 2, startIndex + 1);

                PushIndicesForStrip(startIndex, startIndex + 4, 4, true);
            }
            else if (Math.Min(innerRadius.X, innerRadius.Y) <= 0)
            {
                //_borderColor = Color.GreenYellow;

                _edge = bi;

                // Center rectangle.
                PushVerticesForRectangle(_corners);

                if (_fillColor.A > 0)
                    PushIndicesForRectangle(startIndex + 3, startIndex, startIndex + 2, startIndex + 1);

                _edge = 0;

                // Create border.
                PushVerticesAndIndicesForBorder(startIndex, _corners, outerRadius, lod, true);

                // Reposition inner corner.
                _vertexBuffer[startIndex + 0].Position.X -= innerRadius.X;
                _vertexBuffer[startIndex + 0].Position.Y -= innerRadius.Y;
                _vertexBuffer[startIndex + 1].Position.X += innerRadius.X;
                _vertexBuffer[startIndex + 1].Position.Y -= innerRadius.Y;
                _vertexBuffer[startIndex + 2].Position.X += innerRadius.X;
                _vertexBuffer[startIndex + 2].Position.Y += innerRadius.Y;
                _vertexBuffer[startIndex + 3].Position.X -= innerRadius.X;
                _vertexBuffer[startIndex + 3].Position.Y += innerRadius.Y;
            }
            // If the inner radius is greater than zero, we need to create a inner and outer border.
            else if (Math.Min(innerRadius.X, innerRadius.Y) > 0)
            {
                //_borderColor = Color.Orange;

                _edge = bi;

                // Center rectangle.
                if (_fillColor.A > 0)
                {
                    PushVerticesForRectangle(_corners);
                    PushIndicesForRectangle(startIndex + 3, startIndex, startIndex + 2, startIndex + 1);
                }

                int innerStartIndex = _vertexCount;

                // Create inner border.
                PushVerticesAndIndicesForBorder(startIndex, _corners, innerRadius, lod, _fillColor.A > 0);

                _edge = 0;

                int outerStartIndex = _vertexCount;

                // Create outer border.
                PushVerticesForCircle(_corners[0], outerRadius, -MathHelper.Pi, -MathHelper.PiOver2, lod);
                PushVerticesForCircle(_corners[1], outerRadius, -MathHelper.PiOver2, 0, lod);
                PushVerticesForCircle(_corners[2], outerRadius, 0, MathHelper.PiOver2, lod);
                PushVerticesForCircle(_corners[3], outerRadius, MathHelper.PiOver2, MathHelper.Pi, lod);

                PushIndicesForStrip(innerStartIndex, outerStartIndex, lod * 4 + 4, true);
            }
        }
Esempio n. 10
0
 public void DrawRectangle(Rectangle rectangle, Vector2 cornerRadius, PrimitiveBrush brush)
 {
     DrawRectangle(new BoundingBox2(rectangle), cornerRadius, brush);
 }
Esempio n. 11
0
 public void DrawRectangle(Rectangle rectangle, Vector2 cornerRadius, PrimitiveBrush brush, Matrix transformMatrix)
 {
     DrawRectangle(new BoundingBox2(rectangle), cornerRadius, brush, transformMatrix);
 }
Esempio n. 12
0
        public void DrawLine(Vector2 start, Vector2 end, PrimitiveBrush brush, Matrix transformMatrix)
        {
            int startIndex = _vertexCount;

            DrawLine(start, end, brush);

            // Apply the transformation matrix.
            ApplyTransformMatrix(startIndex, _vertexCount, transformMatrix);
        }
Esempio n. 13
0
 public void DrawPolygon(Vector2[] points, PrimitiveBrush brush, Matrix transform)
 {
     for (int i = 1; i < points.Length; i++)
     {
         DrawLine(points[i - 1], points[i], brush, transform);
     }
     DrawLine(points[points.Length - 1], points[0], brush, transform);
 }
Esempio n. 14
0
        public void DrawLine(Vector2 start, Vector2 end, PrimitiveBrush brush)
        {
            int startIndex = _vertexCount;
            int lod = 16;

            _borderColor = brush.BorderColor;
            _fillColor = Color.Transparent;

            Vector2 t = end - start;
            t = Vector2.Normalize(new Vector2(-t.Y, t.X)) * brush.BorderThickness * 0.5f;

            Polar2 a = Polar2.CreateFromVector(t);

            _edge = brush.BorderThickness * 0.5f * _edgeSoftness;

            int s0 = _vertexCount;
            PushVertex(start);
            PushVertex(end);

            _edge = 0;

            int s1 = _vertexCount;
            PushVerticesForCircle(start, new Vector2(a.R), a.Theta, a.Theta + MathHelper.Pi, lod);
            int s2 = _vertexCount;
            PushVerticesForCircle(end, new Vector2(a.R), a.Theta + MathHelper.Pi, a.Theta + MathHelper.TwoPi, lod);
            int s3 = _vertexCount;

            PushIndicesForCircle(s0 + 0, s1, lod, false);
            PushIndicesForCircle(s0 + 1, s2, lod, false);

            PushIndicesForRectangle(s3 - 1, s1, s0 + 1, s0);
            PushIndicesForRectangle(s0 + 1, s0, s2, s2 - 1);
        }
Esempio n. 15
0
 public void DrawCircle(Vector2 center, float radius, PrimitiveBrush brush, Matrix transformMatrix)
 {
     // HACK: Untill the real cricle function is implemented.
     DrawRectangle(new BoundingBox2(-radius, radius) + center, new Vector2(radius), brush, transformMatrix);
     //DrawCircle(center, radius, 0, 0, borderColor, fillColor);
 }
Esempio n. 16
0
 public void DrawRectangle(Rectangle rectangle, Vector2 cornerRadius, PrimitiveBrush brush)
 {
     DrawRectangle(new BoundingBox2(rectangle), cornerRadius, brush);
 }
Esempio n. 17
0
        public void DrawRectangle(BoundingBox2 boundingBox, Vector2 cornerRadius, PrimitiveBrush brush)
        {
            int startIndex = _vertexCount;

            float bi = -1;

            Vector2 half = (boundingBox.Max - boundingBox.Min) * 0.5f;

            if (brush.BorderThickness == 0)
            {
                brush.BorderAlignment = BorderAlignment.Inner;
                brush.BorderThickness = Math.Min(half.X, half.Y);
                brush.BorderColor     = brush.FillColor;
                bi = 1;
            }

            _borderColor = brush.BorderColor;
            _fillColor   = brush.FillColor;

            bi *= brush.BorderThickness * _edgeSoftness;

            if (cornerRadius.X < 0)
            {
                cornerRadius.X = 0;
            }
            if (cornerRadius.Y < 0)
            {
                cornerRadius.Y = 0;
            }
            if (cornerRadius.X > half.X)
            {
                cornerRadius.X = half.X;
            }
            if (cornerRadius.Y > half.Y)
            {
                cornerRadius.Y = half.Y;
            }

            boundingBox.Min += cornerRadius;
            boundingBox.Max -= cornerRadius;
            boundingBox.GetCorners(_corners);

            // Setting the inner and outer border radius based on BorderAlignment.
            Vector2 innerRadius = cornerRadius;
            Vector2 outerRadius = cornerRadius;

            if (brush.BorderAlignment == BorderAlignment.Inner)
            {
                innerRadius -= new Vector2(brush.BorderThickness);
            }
            else if (brush.BorderAlignment == BorderAlignment.Outer)
            {
                outerRadius += new Vector2(brush.BorderThickness);
            }
            else
            {
                innerRadius -= new Vector2(brush.BorderThickness * 0.5f);
                outerRadius += new Vector2(brush.BorderThickness * 0.5f);
            }

            if (innerRadius.X < 0 && cornerRadius.X > half.X)
            {
                innerRadius.X = 0;
            }
            if (innerRadius.Y < 0 && cornerRadius.Y > half.Y)
            {
                innerRadius.Y = 0;
            }

            //int lod = (int)outerRadius;
            //int lod = (int)(2 * MathHelper.Pi * (cornerRadius.X + cornerRadius.Y) / 16);
            int lod = 16;

            if (Math.Min(cornerRadius.X, cornerRadius.Y) == 0)
            {
                BoundingBox2 innerBox = new BoundingBox2(boundingBox.Min - innerRadius, boundingBox.Max + innerRadius);
                BoundingBox2 outerBox = new BoundingBox2(boundingBox.Min - outerRadius, boundingBox.Max + outerRadius);

                _edge = bi;

                innerBox.GetCorners(_corners);
                PushVerticesForRectangle(_corners);

                _edge = 0;

                outerBox.GetCorners(_corners);
                PushVerticesForRectangle(_corners);

                if (_fillColor.A > 0)
                {
                    PushIndicesForRectangle(startIndex + 3, startIndex + 0, startIndex + 2, startIndex + 1);
                }

                PushIndicesForStrip(startIndex, startIndex + 4, 4, true);
            }
            else if (Math.Min(innerRadius.X, innerRadius.Y) <= 0)
            {
                //_borderColor = Color.GreenYellow;

                _edge = bi;

                // Center rectangle.
                PushVerticesForRectangle(_corners);

                if (_fillColor.A > 0)
                {
                    PushIndicesForRectangle(startIndex + 3, startIndex, startIndex + 2, startIndex + 1);
                }

                _edge = 0;

                // Create border.
                PushVerticesAndIndicesForBorder(startIndex, _corners, outerRadius, lod, true);

                // Reposition inner corner.
                _vertexBuffer[startIndex + 0].Position.X -= innerRadius.X;
                _vertexBuffer[startIndex + 0].Position.Y -= innerRadius.Y;
                _vertexBuffer[startIndex + 1].Position.X += innerRadius.X;
                _vertexBuffer[startIndex + 1].Position.Y -= innerRadius.Y;
                _vertexBuffer[startIndex + 2].Position.X += innerRadius.X;
                _vertexBuffer[startIndex + 2].Position.Y += innerRadius.Y;
                _vertexBuffer[startIndex + 3].Position.X -= innerRadius.X;
                _vertexBuffer[startIndex + 3].Position.Y += innerRadius.Y;
            }
            // If the inner radius is greater than zero, we need to create a inner and outer border.
            else if (Math.Min(innerRadius.X, innerRadius.Y) > 0)
            {
                //_borderColor = Color.Orange;

                _edge = bi;

                // Center rectangle.
                if (_fillColor.A > 0)
                {
                    PushVerticesForRectangle(_corners);
                    PushIndicesForRectangle(startIndex + 3, startIndex, startIndex + 2, startIndex + 1);
                }

                int innerStartIndex = _vertexCount;

                // Create inner border.
                PushVerticesAndIndicesForBorder(startIndex, _corners, innerRadius, lod, _fillColor.A > 0);

                _edge = 0;

                int outerStartIndex = _vertexCount;

                // Create outer border.
                PushVerticesForCircle(_corners[0], outerRadius, -MathHelper.Pi, -MathHelper.PiOver2, lod);
                PushVerticesForCircle(_corners[1], outerRadius, -MathHelper.PiOver2, 0, lod);
                PushVerticesForCircle(_corners[2], outerRadius, 0, MathHelper.PiOver2, lod);
                PushVerticesForCircle(_corners[3], outerRadius, MathHelper.PiOver2, MathHelper.Pi, lod);

                PushIndicesForStrip(innerStartIndex, outerStartIndex, lod * 4 + 4, true);
            }
        }
Esempio n. 18
0
 public void DrawRectangle(Rectangle rectangle, Vector2 cornerRadius, PrimitiveBrush brush, Matrix transformMatrix)
 {
     DrawRectangle(new BoundingBox2(rectangle), cornerRadius, brush, transformMatrix);
 }