Пример #1
0
        public static SDL.SDL_Point[] GenerateCircularPolygon(int numVertices, double radius)
        {
            SDL.SDL_Point[] points = new SDL.SDL_Point[numVertices + 1];
            double[] angles = new double[numVertices];
            double angleStep = (2 * Math.PI) / numVertices;

            // create angles
            for (int index = 0; index < angles.Length; index++)
            {
                angles[index] = angleStep * index;
            }

            // create a vertex for each angle
            for (int index = 0; index < numVertices; index++)
            {
                double angle = angles[index];
                int x = (int)Math.Round(radius * Math.Cos(angle));
                int y = (int)Math.Round(radius * Math.Sin(angle));
                points[index] = new SDL.SDL_Point { x = x, y = y };
            }

            // duplicate the first vertex to create a closed polygon
            points[points.Length - 1] = points[0];

            return points;
        }
Пример #2
0
        internal void RenderTexture(IntPtr textureHandle, float positionX, float positionY, int sourceWidth, int sourceHeight, double angle, Vector center)
        {
            Debug.Assert(textureHandle != IntPtr.Zero, 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 Exception(Utilities.GetErrorMessage("SDL_RenderCopyEx"));
            }
        }
Пример #3
0
 public static void TranslatePoints(SDL.SDL_Point[] points, int transX, int transY)
 {
     for (int index = 0; index < points.Length; index++)
     {
         SDL.SDL_Point point = points[index];
         points[index] = new SDL.SDL_Point { x = point.x + transX, y = point.y + transY };
     }
 }