public static Matrix VectorMatrix(SDL.SDL_Point point)
 {
     return(new Matrix()
     {
         Values = new[] { new double[] { point.x, 0, 0 }, new double[] { point.y, 0, 0 }, new double[] { 1, 0, 0 } }
     });
 }
示例#2
0
        public static void DrawArc(IntPtr renderer, int posX, int posY, double xWidth, double yWidth, double startAngleRadians, double arcAngleRadians)
        {
            byte _numberOfArcSegments = 255;

            double incrementAngle = (Math.PI * 2.0) / (_numberOfArcSegments);

            int drawX;
            int drawY;
            int totalSegments = (int)(Math.Abs(arcAngleRadians) / incrementAngle);


            SDL.SDL_Point[] points = new SDL.SDL_Point[totalSegments];

            for (int i = 0; i < totalSegments; i++)
            {
                double nextAngle = startAngleRadians + incrementAngle * i;
                drawX     = posX + (int)Math.Round(xWidth * Math.Sin(nextAngle));
                drawY     = posY + (int)Math.Round(yWidth * Math.Cos(nextAngle));
                points[i] = new SDL.SDL_Point()
                {
                    x = drawX, y = drawY
                };
            }

            for (int i = 0; i < points.Length - 1; i++)
            {
                SDL.SDL_RenderDrawLine(renderer, points[i].x, points[i].y, points[i + 1].x, points[i + 1].y);
            }
        }
示例#3
0
    //Renders an image on a static position with the given angle and flip
    public static void RenderAdvancedStatic
        (IntPtr texture, float posX, float posY
        , ushort spriteWidth, ushort spriteHeight
        , ushort spriteX, ushort spriteY
        , float angle, SDL.SDL_Point center,
        SDL.SDL_RendererFlip flip)
    {
        SDL.SDL_Rect source = new SDL.SDL_Rect
        {
            x = spriteX,
            y = spriteY,
            w = spriteWidth,
            h = spriteHeight
        };

        SDL.SDL_Rect target = new SDL.SDL_Rect
        {
            x = (int)(posX),
            y = (int)(posY),
            w = spriteWidth,
            h = spriteHeight
        };

        SDL.SDL_RenderCopyEx(Renderer, texture, ref source, ref target,
                             angle, ref center, flip);
    }
示例#4
0
        public override void OnFrameUpdate(Matrix matrix, Camera camera)
        {
            ViewScreenPos = matrix.Transform(WorldPosition.X, WorldPosition.Y);//sets the zoom position.
            var camerapoint = camera.CameraViewCoordinate();

            _drawPoints = new SDL.SDL_Point[2];


            /*
             * var translated = matrix.Transform(_translateStartPoint.X, _translateStartPoint.Y);
             * int x = (int)(ViewScreenPos.x + translated.x + camerapoint.x);
             * int y = (int)(ViewScreenPos.y + translated.y + camerapoint.y);
             * _drawPoints[0] = new SDL.SDL_Point() { x = x, y = y };
             */

            var translated = matrix.Transform(_currentPosition.X, _currentPosition.Y);
            int x          = (int)(ViewScreenPos.x + translated.x + camerapoint.x);
            int y          = (int)(ViewScreenPos.y + translated.y + camerapoint.y);

            _drawPoints[0] = new SDL.SDL_Point()
            {
                x = x, y = y
            };

            translated     = matrix.Transform(_translateEndPoint.X, _translateEndPoint.Y);
            x              = (int)(ViewScreenPos.x + translated.x + camerapoint.x);
            y              = (int)(ViewScreenPos.y + translated.y + camerapoint.y);
            _drawPoints[1] = new SDL.SDL_Point()
            {
                x = x, y = y
            };
        }
示例#5
0
        public static void Build_Rectangle(RectangleData rectangle, double widthScale, double heightScale, AnimationData param)
        {
            var tempPoints = new SDL.SDL_Point[4];

            int x0 = rectangle.OldPoints[0].x + rectangle.Width / 2;
            int y0;

            if (rectangle.OldPoints[0].y > rectangle.OldPoints[3].y)
            {
                y0 = rectangle.OldPoints[0].y - rectangle.Height / 2;
            }
            else
            {
                y0 = rectangle.OldPoints[0].y + rectangle.Height / 2;
            }

            for (int i = 0; i < 4; i++)
            {
                tempPoints[i].x = (int)Math.Floor((x0 + (rectangle.OldPoints[i].x - x0) * Math.Cos(param.fi) -
                                                   (rectangle.OldPoints[i].y - y0) * Math.Sin(param.fi) - 20 + param.RectOffsetX) /** widthScale*/);
                tempPoints[i].y = (int)Math.Floor((y0 + (rectangle.OldPoints[i].x - x0) * Math.Sin(param.fi) +
                                                   (rectangle.OldPoints[i].y - y0) * Math.Cos(param.fi) + param.RectOffSetY) - 20 /** heightScale*/);
            }
            rectangle.Points = tempPoints;
        }
            private SDL.SDL_Point[][] InitCircleShape()
            {
                var    result        = new SDL.SDL_Point[InnerShapeCount][];
                var    step          = 2 * Math.PI / 4;
                double currentRadius = Radius;

                for (int i = 0; i < InnerShapeCount; i++)
                {
                    result[i] = new SDL.SDL_Point[4];
                    if (i % 2 == 0)
                    {
                        for (int j = 0; j < 4; j++)
                        {
                            result[i][j].x = Convert.ToInt32(currentRadius * Math.Cos(step * j));
                            result[i][j].y = Convert.ToInt32(currentRadius * Math.Sin(step * j));
                        }
                        currentRadius = currentRadius / Math.Sqrt(2);
                    }
                    else
                    {
                        result[i][0].x = 0;
                        result[i][0].y = 0;
                        Radiuses[i]    = Convert.ToInt32(currentRadius);
                    }
                }
                return(result);
            }
            private SDL.SDL_Point[][] InitShape()
            {
                var result = new SDL.SDL_Point[InnerShapeCount][];
                var step   = 2 * Math.PI / Angle;

                for (int i = 0; i < InnerShapeCount; i++)
                {
                    result[i] = new SDL.SDL_Point[Angle];
                    for (int j = 0; j < Angle; j++)
                    {
                        if (i == 0)
                        {
                            result[i][j].x = Convert.ToInt32(Radius * Math.Cos(step * j));
                            result[i][j].y = Convert.ToInt32(Radius * Math.Sin(step * j));
                        }
                        else
                        {
                            result[i][j].x =
                                Convert.ToInt32((1 - U) * result[i - 1][j].x + U * result[i - 1][(j + 1) % Angle].x);
                            result[i][j].y =
                                Convert.ToInt32((1 - U) * result[i - 1][j].y + U * result[i - 1][(j + 1) % Angle].y);
                        }
                    }
                }
                return(result);
            }
示例#8
0
 /// <summary>
 ///   Creates a point with the specified X and Y values.
 /// </summary>
 /// <param name="pointX">The X value of the point.</param>
 /// <param name="pointY">The Y value of the point.</param>
 public Point(int pointX, int pointY)
 {
     _sdlPoint = new SDL.SDL_Point()
     {
         x = pointX, y = pointY
     };
 }
示例#9
0
        public override void Draw(IntPtr renderer)
        {
            int x;
            int y;


            int numSides = 3;

            SDL.SDL_Point[] points = new SDL.SDL_Point[numSides + 1];     //+1 as the final point
                                                                          //is the same as the last point
                                                                          //to close the shape

            for (int i = 0; i < (numSides + 1); i++)
            {
                var angleRadians = DegreesToRadians(Physics.Angle + i * (360.0f / (float)numSides));
                x = (int)(Cos(angleRadians) * size);
                y = (int)(Sin(angleRadians) * size);

                SDL.SDL_Point point;
                point.x   = Position.X + x;
                point.y   = Position.Y + y;
                points[i] = point;
            }

            SDL.SDL_SetRenderDrawColor(renderer, 0x00, 0xFF, 0x00, 0xFF);
            SDL.SDL_RenderDrawPoint(renderer, Position.X, Position.Y);
            SDL.SDL_RenderDrawLines(renderer, points, numSides + 1);
        }
示例#10
0
        private void Draw()
        {
            SDL.SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
            SDL.SDL_RenderClear(renderer);

            SDL.SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);

            UpdateWindowTitle();
            UpdateWindowStat();

            DrawAxis();

            var previousPoint = new SDL.SDL_Point();
            var nextPoint     = new SDL.SDL_Point();

            previousPoint = CalculatePoint(0);

            for (double t = timeStep; t <= Math.PI * 2; t += timeStep)
            {
                nextPoint = CalculatePoint(t);

                //SDL.SDL_RenderDrawPoint(renderer, nextPoint.x, nextPoint.y);

                Select4(previousPoint, nextPoint);

                SDL.SDL_RenderDrawLine(renderer,
                                       previousPoint.x, previousPoint.y,
                                       nextPoint.x, nextPoint.y);

                previousPoint = nextPoint;
            }

            SDL.SDL_RenderPresent(renderer);
        }
示例#11
0
        public void DrawEx(IntPtr rendererId, int x, int y, double angle, Vector?center, SDL.SDL_RendererFlip flipMode)
        {
            var source = new SDL.SDL_Rect()
            {
                x = this.X,
                y = this.Y,
                w = Width,
                h = Height
            };

            var destination = new SDL.SDL_Rect()
            {
                x = x,
                y = y,
                w = Width,
                h = Height
            };

            if (center.HasValue)
            {
                var centerPoint = new SDL.SDL_Point {
                    x = (int)center.Value.X, y = (int)center.Value.Y
                };
                SDL.SDL_RenderCopyEx(rendererId, TextureId, ref source, ref destination, angle, ref centerPoint, flipMode);
            }
            else
            {
                SDL.SDL_RenderCopyEx(rendererId, TextureId, ref source, ref destination, angle, IntPtr.Zero, flipMode);
            }
        }
示例#12
0
        private static bool IsInFigure(List <SDL.SDL_Point> figure, SDL.SDL_Point mousePoint)
        {
            var length = figure.Count;

            if (PointOnLeftOrRightSide(figure[0], figure[1], mousePoint) < 0 ||
                PointOnLeftOrRightSide(figure[0], figure[length - 1], mousePoint) > 0)
            {
                return(false);
            }
            var p = 1;
            var r = length - 1;

            while (r - p > 1)
            {
                var q = (p + r) / 2;
                if (PointOnLeftOrRightSide(figure[0], figure[q], mousePoint) < 0)
                {
                    r = q;
                }
                else
                {
                    p = q;
                }
            }

            return(!IsLinesIntercept(figure[0], mousePoint, figure[p], figure[r]));
        }
示例#13
0
        private void DrawAxis()
        {
            int halfHeight = windowHeight / 2;
            int halfWidth  = windowWidth / 2;
            int arrowSize  = 4;

            SDL.SDL_RenderDrawLine(renderer, TrX(0), TrY(halfHeight), TrX(0), TrY(-halfHeight));
            SDL.SDL_RenderDrawLine(renderer, TrX(halfWidth), TrY(0), TrX(-halfWidth), TrY(0));

            SDL.SDL_Point[] arrow = new SDL.SDL_Point[3];

            arrow[0].x = TrX(-arrowSize);
            arrow[0].y = TrY(halfHeight - 2 * arrowSize);
            arrow[1].x = TrX(0);
            arrow[1].y = TrY(halfHeight);
            arrow[2].x = TrX(arrowSize);
            arrow[2].y = TrY(halfHeight - 2 * arrowSize);
            SDL.SDL_RenderDrawLines(renderer, arrow, arrow.Length);

            arrow[0].x = TrX(halfWidth - 2 * arrowSize);
            arrow[0].y = TrY(-arrowSize);
            arrow[1].x = TrX(halfWidth);
            arrow[1].y = TrY(0);
            arrow[2].x = TrX(halfWidth - 2 * arrowSize);
            arrow[2].y = TrY(arrowSize);
            SDL.SDL_RenderDrawLines(renderer, arrow, arrow.Length);
        }
示例#14
0
        internal void RenderTexture(IntPtr textureHandle, float positionX, float positionY, int sourceWidth, int sourceHeight, double angle, Vector center)
        {
            if (textureHandle == IntPtr.Zero)
            {
                throw new ArgumentNullException("textureHandle", Errors.E_TEXTURE_NULL);
            }

            // SDL only accepts integer positions (x,y) in the rendering Rect
            SDL.SDL_Rect destinationRectangle = new SDL.SDL_Rect()
            {
                x = (int)positionX, y = (int)positionY, w = sourceWidth, h = sourceHeight
            };
            SDL.SDL_Rect sourceRectangle = new SDL.SDL_Rect()
            {
                x = 0, y = 0, w = sourceWidth, h = sourceHeight
            };
            SDL.SDL_Point centerPoint = new SDL.SDL_Point()
            {
                x = (int)center.X, y = (int)center.Y
            };

            int result = SDL.SDL_RenderCopyEx(Handle, textureHandle, ref sourceRectangle, ref destinationRectangle, angle, ref centerPoint, SDL.SDL_RendererFlip.SDL_FLIP_NONE);

            if (Utilities.IsError(result))
            {
                throw new InvalidOperationException(Utilities.GetErrorMessage("SDL_RenderCopyEx"));
            }
        }
示例#15
0
 public static PointD NewFrom(SDL.SDL_Point sDL_Point)
 {
     return(new PointD()
     {
         X = sDL_Point.x, Y = sDL_Point.y
     });
 }
示例#16
0
 public static SDL.SDL_Point Rotate(SDL.SDL_Point point, double angle)
 {
     SDL.SDL_Point rotated_point;
     rotated_point.x = (int)(point.x * Math.Cos(angle) - point.y * Math.Sin(angle));
     rotated_point.y = (int)(point.x * Math.Sin(angle) + point.y * Math.Cos(angle));
     return(rotated_point);
 }
示例#17
0
        public void OnFrameUpdate(Matrix matrix, Camera camera)
        {
            ViewScreenPos = camera.ViewCoordinate_AU(WorldPosition);
            var vsp = new PointD
            {
                X = ViewScreenPos.x,
                Y = ViewScreenPos.y
            };

            PointD[] drawPoints = new PointD[_shape.Points.Length];

            for (int i2 = 0; i2 < _shape.Points.Length; i2++)
            {
                var translatedPoint = matrix.TransformD(_shape.Points[i2].X, _shape.Points[i2].Y);
                int x = (int)(vsp.X + translatedPoint.X);
                int y = (int)(vsp.Y + translatedPoint.Y);
                drawPoints[i2] = new PointD()
                {
                    X = x, Y = y
                };
            }
            _drawShape = new Shape()
            {
                Points = drawPoints, Color = _shape.Color
            };
        }
示例#18
0
 /// <summary>
 ///   Creates a new <see cref="Point"> with the same X and Y values as another Point.
 /// </summary>
 /// <param name="point">The Point to copy.</param>
 public Point(Point point)
 {
     _sdlPoint = new SDL.SDL_Point()
     {
         x = point.X, y = point.Y
     };
 }
示例#19
0
        public virtual void OnFrameUpdate(Matrix matrix, Camera camera)
        {
            ViewScreenPos = camera.ViewCoordinate_m(WorldPosition_m);

            var    mirrorMtx     = Matrix.NewMirrorMatrix(true, false);
            var    scaleMtx      = Matrix.NewScaleMatrix(Scale, Scale);
            Matrix nonZoomMatrix = mirrorMtx * scaleMtx;

            DrawShapes = new Shape[this.Shapes.Count];
            for (int i = 0; i < Shapes.Count; i++)
            {
                var      shape      = Shapes[i];
                PointD[] drawPoints = new PointD[shape.Points.Length];

                for (int i2 = 0; i2 < shape.Points.Length; i2++)
                {
                    int x;
                    int y;

                    var tranlsatedPoint = nonZoomMatrix.TransformD(shape.Points[i2].X, shape.Points[i2].Y);
                    x = (int)(ViewScreenPos.x + tranlsatedPoint.X);
                    y = (int)(ViewScreenPos.y + tranlsatedPoint.Y);
                    drawPoints[i2] = new PointD()
                    {
                        X = x, Y = y
                    };
                }
                DrawShapes[i] = new Shape()
                {
                    Points = drawPoints, Color = shape.Color
                };
            }
        }
            public void Add(int x, int y, int offsetX, int offsetY)
            {
                var ymx = y - offsetX;
                var ymy = y - offsetY;
                var ypy = y + offsetY;
                var ypx = y + offsetX;

                var xmx = x - offsetX;
                var xmy = x - offsetY;
                var xpy = x + offsetY;
                var xpx = x + offsetX;

                Points[Count + 0] = new SDL.SDL_Point(xmx, ypy);
                Points[Count + 1] = new SDL.SDL_Point(xmx, ymy);

                Points[Count + 2] = new SDL.SDL_Point(xmy, ypx);
                Points[Count + 3] = new SDL.SDL_Point(xmy, ymx);

                Points[Count + 4] = new SDL.SDL_Point(xpx, ypy);
                Points[Count + 5] = new SDL.SDL_Point(xpx, ymy);

                Points[Count + 6] = new SDL.SDL_Point(xpy, ypx);
                Points[Count + 7] = new SDL.SDL_Point(xpy, ymx);

                Count += 8;
            }
 private static void DrawDashLine(IntPtr renderer, SDL.SDL_Point p1, SDL.SDL_Point p2)
 {
     {
         int dx = Math.Abs(p2.x - p1.x);
         int dy = Math.Abs(p2.y - p1.y);
         int sx = p2.x >= p1.x ? 1 : -1;
         int sy = p2.y >= p1.y ? 1 : -1;
         if (dy <= dx)
         {
             int d  = (dy << 1) - dx;
             int d1 = dy << 1;
             int d2 = (dy - dx) << 1;
             SDL.SDL_RenderDrawPoint(renderer, p1.x, p1.y);
             int count = 0;
             for (int x = p1.x + sx, y = p1.y, i = 1; i <= dx; i++, x += sx)
             {
                 if (d > 0)
                 {
                     d += d2;
                     y += sy;
                 }
                 else
                 {
                     d += d1;
                 }
                 if ((count / 10) % 2 == 0)
                 {
                     SDL.SDL_RenderDrawPoint(renderer, x, y);
                 }
                 count++;
             }
         }
         else
         {
             int d  = (dx << 1) - dy;
             int d1 = dx << 1;
             int d2 = (dx - dy) << 1;
             SDL.SDL_RenderDrawPoint(renderer, p1.x, p1.y);
             int count = 0;
             for (int x = p1.x, y = p1.y + sy, i = 1; i <= dy; i++, y += sy)
             {
                 if (d > 0)
                 {
                     d += d2;
                     x += sx;
                 }
                 else
                 {
                     d += d1;
                 }
                 if ((count / 10) % 2 == 0)
                 {
                     SDL.SDL_RenderDrawPoint(renderer, x, y);
                 }
                 count++;
             }
         }
     }
 }
示例#22
0
        private static SDL.SDL_Point FromParametric(SDL.SDL_Point pointA, SDL.SDL_Point pointB, double param)
        {
            var result = new SDL.SDL_Point();

            result.x = (int)(pointA.x + (pointB.x - pointA.x) * param);
            result.y = (int)(pointA.y + (pointB.y - pointA.y) * param);
            return(result);
        }
示例#23
0
 /// <summary>
 /// Returns a string representation of an SDL_Point
 /// </summary>
 public static string ToString(this SDL.SDL_Point left, string format = null)
 {
     if (string.IsNullOrEmpty(format))
     {
         format = "({0},{1})";
     }
     return(string.Format(format, left.x, left.y));
 }
示例#24
0
 public static SDL.SDL_Point[] FindNewRotetedPoints(SDL.SDL_Point[] points, double angle)
 {
     SDL.SDL_Point[] newPoints = new SDL.SDL_Point[points.Length];
     for (int i = 0; i < points.Length; i++)
     {
         newPoints[i] = Rotate(points[i], angle);
     }
     return(newPoints);
 }
示例#25
0
        private SDL.SDL_Point CalculatePoint(double t)
        {
            var point = new SDL.SDL_Point();

            point.x = TrX((a * Math.Pow(Math.Cos(t), 2) + l * Math.Cos(t)) * scale);
            point.y = TrY((a * Math.Cos(t) * Math.Sin(t) + l * Math.Sin(t)) * scale);

            return(point);
        }
示例#26
0
 /// <summary>
 /// This method will checks whatever AB line intercept CD line
 /// </summary>
 private static bool IsLinesIntercept(SDL.SDL_Point A, SDL.SDL_Point B,
                                      SDL.SDL_Point C, SDL.SDL_Point D)
 {
     return((double)PointOnLeftOrRightSide(A, B, C) *
            PointOnLeftOrRightSide(A, B, D) <= 0
            &&
            (double)PointOnLeftOrRightSide(C, D, A) *
            PointOnLeftOrRightSide(C, D, B) < 0);
 }
示例#27
0
        public SDL.SDL_Point Transform(double itemx, double itemy)
        {
            SDL.SDL_Point newPoint  = new SDL.SDL_Point();
            var           newPointd = TransformD(itemx, itemy);

            newPoint.x = (int)newPointd.X;
            newPoint.y = (int)newPointd.Y;
            return(newPoint);
        }
示例#28
0
        public void DrawObject(GameObject gameObject, SDL.SDL_RendererFlip flip = SDL.SDL_RendererFlip.SDL_FLIP_NONE)
        {
            var texture = gameObject.Texture;
            var center  = new SDL.SDL_Point();

            center.x = gameObject.Rect.w / 2;
            center.y = gameObject.Rect.h / 2;
            SDL.SDL_RenderCopyEx(_render, texture.Pointer, ref texture.Rect, ref gameObject.Rect, gameObject.Rotation, ref center, flip);
        }
示例#29
0
文件: Program.cs 项目: Lolik21/AKG
 private static void FindCenter(out SDL.SDL_Point centerPoint)
 {
     SDL.SDL_GetWindowSize(_window, out var width, out var height);
     centerPoint = new SDL.SDL_Point
     {
         x = width / 2,
         y = height / 2
     };
 }
示例#30
0
文件: Program.cs 项目: Lolik21/AKG
        private static void MapToPoint(int x, int y, ref SDL.SDL_Point newPoint)
        {
            FindCenter(out var centralPoint);
            var tx = (int)(x * Math.Cos(_angle) - y * Math.Sin(_angle));
            var ty = (int)(x * Math.Sin(_angle) + y * Math.Cos(_angle));

            newPoint.x = centralPoint.x + (int)(tx * _scale) + _transX;
            newPoint.y = centralPoint.y + (int)(ty * _scale) + _transY;
        }