Exemplo n.º 1
0
        public void OnFrameUpdate(Matrix matrix, Camera camera)
        {
            _departIcon.OnFrameUpdate(matrix, camera);
            if (_arriveIcon != null)
            {
                _arriveIcon.OnFrameUpdate(matrix, camera);

                var camerapoint = camera.CameraViewCoordinate();

                _linePoints = new SDL_Point[2];

                var depart = matrix.Transform(_departIcon.WorldPosition.X, _departIcon.WorldPosition.Y);
                _linePoints[0] = new SDL_Point()
                {
                    x = (depart.x + camerapoint.x),
                    y = (depart.y + camerapoint.y)
                };

                var arrive = matrix.Transform(_arriveIcon.WorldPosition.X, _arriveIcon.WorldPosition.Y);
                _linePoints[1] = new SDL_Point()
                {
                    x = (arrive.x + camerapoint.x),
                    y = (arrive.y + camerapoint.y)
                };
            }
        }
Exemplo n.º 2
0
    public void DrawTexture(Texture texture, Transform transform)
    {
        Vector2 pos        = transform.DoTransform();
        Vector2 translated = Translate(pos);

        translated.x *= Width;
        translated.y *= Height;

        SDL_Rect dest = new SDL_Rect
        {
            x = (int)(translated.x - transform.center.x * transform.scale),
            y = (int)(translated.y - transform.center.y * transform.scale),
            w = (int)(texture.Width * transform.scale),
            h = (int)(texture.Height * transform.scale),

            //w = texture.Width,
            //h = texture.Height,
            //x = (int)translated.x,
            //y = (int)translated.y,
        };
        SDL_Point center = new SDL_Point
        {
            x = (int)transform.center.x,
            y = (int)transform.center.y,
            //x = 0, y = 0,
        };

        SDL_RenderCopyEx(SDLRenderer, texture.SDLTexture, IntPtr.Zero, ref dest, transform.rotation, IntPtr.Zero, SDL_RendererFlip.SDL_FLIP_NONE);
    }
Exemplo n.º 3
0
        public void DrawSprite(Sprite sprite, Rect rect, float angle = 0.0f)
        {
            var src_rect = new SDL_Rect {
                x = 0,
                y = 0,
                w = sprite.size.x,
                h = sprite.size.y,
            };

            var screen_rect = WorldToScreen(rect);
            var dest_rect   = new SDL_Rect {
                x = screen_rect.x,
                y = screen_rect.y,
                w = screen_rect.w,
                h = screen_rect.h,
            };

            int err;

            if (angle == 0.0f)
            {
                err = SDL_RenderCopy(
                    renderer, sprite.handle,
                    ref src_rect, ref dest_rect
                    );
                if (err != 0)
                {
                    throw new SDLException(SDL_GetError());
                }
                return;
            }

            var rotation_origin = new SDL_Point {
                x = screen_rect.w / 2,
                y = screen_rect.h / 2,
            };

            err = SDL_RenderCopyEx(
                renderer, sprite.handle,
                ref src_rect, ref dest_rect,
                (double)angle * 180.0 / Math.PI,
                ref rotation_origin,
                SDL_RendererFlip.SDL_FLIP_NONE
                );
            if (err != 0)
            {
                throw new SDLException(SDL_GetError());
            }
        }
Exemplo n.º 4
0
        public void RotateAndRender(Coordinate screenPosition, double angleRad, double originX, double originY)
        {
            SDL_Point centerOfRotation = new SDL_Point()
            {
                x = (int)Math.Round(originX),
                y = (int)Math.Round(originY)
            };

            position.x = (int)Math.Round(screenPosition.x - subDrawRect.w / 2);
            position.y = (int)Math.Round(screenPosition.y - subDrawRect.h / 2);

            double angleDeg = angleRad * 180 / Math.PI;

            SDL_RenderCopyEx(renderer, textureList[name].texture,
                             ref subDrawRect,
                             ref position,
                             angleDeg,
                             ref centerOfRotation,
                             SDL_RendererFlip.SDL_FLIP_NONE);
        }
Exemplo n.º 5
0
 public static SDL_bool SDL_EnclosePoints(ref SDL_Point points, int count, ref SDL_Rect clip, ref SDL_Rect result) => s_SDL_EnclosePoints_SDL_Point_int_SDL_Rect_SDL_Rect_t(ref points, count, ref clip, ref result);
Exemplo n.º 6
0
		public static extern SDL_bool SDL_EnclosePoints(
			SDL_Point[] points,
			int count,
			ref SDL_Rect clip,
			ref SDL_Rect result
		);
Exemplo n.º 7
0
		public static extern int SDL_RenderDrawPoints(
			IntPtr renderer,
			SDL_Point[] points,
			int count
		);
Exemplo n.º 8
0
		public static extern int SDL_RenderCopyEx(
			IntPtr renderer,
			IntPtr texture,
			ref SDL_Rect srcrect,
			ref SDL_Rect dstrect,
			double angle,
			ref SDL_Point center,
			SDL_RendererFlip flip
		);
Exemplo n.º 9
0
        /// <summary>
        /// Renders an individual sprite.
        /// </summary>
        /// <param name="s">The sprite to render.</param>
        public void RenderSprite(Sprite s, Bitmap bmp, int XOffset, int YOffset)
        {
            Graphics.Log($"Rendering sprite {(!string.IsNullOrEmpty(s.Name) ? "'" + s.Name + "' " : "")}-- color: {s.Color} x: {s.X} y: {s.Y} bmp({bmp.Width},{bmp.Height}{(s.Bitmap is SolidBitmap ? ", " + ((SolidBitmap) s.Bitmap).Color.ToString() : "")}) ox: {s.OX} oy: {s.OY}");
            IntPtr Texture = IntPtr.Zero;

            if (s.Tone.Red == 0 && s.Tone.Green == 0 && s.Tone.Blue == 0 && s.Tone.Gray == 0 &&
                s.Color.Alpha == 0)
            {
                Texture = bmp.Texture;
            }
            else
            {
                Texture = bmp.ColorToneTexture(s.Color, s.Tone);
            }

            if (Texture == IntPtr.Zero)
            {
                throw new Exception("Attempted to render a zero-pointer texture.");
            }

            // Sprite Opacity + Renderer opacity
            byte Alpha = Convert.ToByte(255d * (s.Opacity / 255d) * (this.Opacity / 255d));

            SDL_SetTextureAlphaMod(Texture, Alpha);

            List <Point> Points;

            if (s.MultiplePositions.Count == 0) // Normal X,Y positions
            {
                Points = new List <Point>()
                {
                    new Point(s.X, s.Y)
                };
            }
            else // Multiple positions; used to prevent the need for hundreds of identical sprites that only differ in position (e.g. in a background grid)
            {
                Graphics.Log("Multiple positions!");
                Points = s.MultiplePositions;
            }

            SDL_Rect Src  = new SDL_Rect();
            SDL_Rect Dest = new SDL_Rect();

            if (bmp is SolidBitmap)
            {
                Src.x  = 0;
                Src.y  = 0;
                Src.w  = 1;
                Src.h  = 1;
                Dest.w = (bmp as SolidBitmap).BitmapWidth;
                Dest.h = (bmp as SolidBitmap).BitmapHeight;
            }
            else
            {
                Src = s.SrcRect.SDL_Rect;

                // Additional checks, since ZoomX/ZoomY are 1 99% of the time, this way it skips the extra calculation.
                if (s.ZoomX == 1)
                {
                    Dest.w = Src.w;
                }
                else
                {
                    Dest.w = (int)Math.Round(Src.w * s.ZoomX);
                }
                if (s.ZoomY == 1)
                {
                    Dest.h = Src.h;
                }
                else
                {
                    Dest.h = (int)Math.Round(Src.h * s.ZoomY);
                }
            }

            if (!bmp.Locked && !(bmp is SolidBitmap))
            {
                Graphics.Log("ERR: Bitmap is locked");
                throw new BitmapLockedException();
            }
            foreach (Point p in Points)
            {
                int oxoffset = s.FactorZoomIntoOrigin ? (int)Math.Round((double)s.OX * s.ZoomX) : s.OX;
                int oyoffset = s.FactorZoomIntoOrigin ? (int)Math.Round((double)s.OY * s.ZoomY) : s.OY;
                Dest.x = p.X - oxoffset + XOffset;
                Dest.y = p.Y - oyoffset + YOffset;

                if (s.Angle % 360 == 0 && s.OX == 0 && s.OY == 0 && !s.MirrorX && !s.MirrorY)
                {
                    SDL_RenderCopy(this.SDL_Renderer, Texture, ref Src, ref Dest);
                }
                else
                {
                    SDL_Point Center = new SDL_Point();
                    Center.x = s.OX;
                    Center.y = s.OY;

                    SDL_RendererFlip MirrorState = SDL_RendererFlip.SDL_FLIP_NONE;
                    if (s.MirrorX)
                    {
                        MirrorState |= SDL_RendererFlip.SDL_FLIP_HORIZONTAL;
                    }
                    if (s.MirrorY)
                    {
                        MirrorState |= SDL_RendererFlip.SDL_FLIP_VERTICAL;
                    }

                    SDL_RenderCopyEx(this.SDL_Renderer, Texture, ref Src, ref Dest, s.Angle % 360, ref Center, MirrorState);
                }
                // Don't destroy the texture as it can be reused next render
            }
        }
Exemplo n.º 10
0
 public static Point ToPoint(this SDL_Point point) => new Point(point.x, point.y);