Beispiel #1
0
        public Point ViewCoordinate_m(ECSLib.Vector3 worldCoord_m)
        {
            int   x         = (int)((Distance.MToAU(worldCoord_m.X) - CameraWorldPosition_m.X) * ZoomLevel + ViewPortCenter.X);
            int   y         = -(int)((Distance.MToAU(worldCoord_m.Y) - CameraWorldPosition_m.Y) * ZoomLevel - ViewPortCenter.Y);
            Point viewCoord = new Point()
            {
                x = x, y = y
            };

            return(viewCoord);
        }
Beispiel #2
0
        public Point ViewCoordinate_AU(ECSLib.Vector3 worldCoord_AU)
        {
            int   x         = (int)((worldCoord_AU.X - CameraWorldPosition_AU.X) * ZoomLevel + ViewPortCenter.X);
            int   y         = -(int)((worldCoord_AU.Y - CameraWorldPosition_AU.Y) * ZoomLevel - ViewPortCenter.Y);
            Point viewCoord = new Point()
            {
                x = x, y = y
            };

            return(viewCoord);
        }
Beispiel #3
0
        public static SDL2.SDL.SDL_Point[] ToNativePoints(this SdlVector[] points)
        {
            var result = new SDL2.SDL.SDL_Point[points.Length];

            for (var i = 0; i < result.Length; i++)
            {
                result[i] = (SDL2.SDL.SDL_Point)points[i];
            }

            return(result);
        }
Beispiel #4
0
        public Point ViewCoordinate_m(ECSLib.Vector3 worldCoord_m)
        {
            //we're converting to AU here because zoom works best at AU...
            int   x         = (int)(Distance.MToAU(worldCoord_m.X - CameraWorldPosition_m.X) * ZoomLevel + ViewPortCenter.X);
            int   y         = -(int)(Distance.MToAU(worldCoord_m.Y - CameraWorldPosition_m.Y) * ZoomLevel - ViewPortCenter.Y);
            Point viewCoord = new Point()
            {
                x = x, y = y
            };

            return(viewCoord);
        }
Beispiel #5
0
            public override void DrawPixels(List <Vec2> points, Color color, IAnchor2d anchor = null)
            {
                SDL2.SDL.SDL_SetRenderDrawColor(SDLRenderer, (byte)color.R, (byte)color.G, (byte)color.B, (byte)color.A);
                var sdlpoints = new SDL2.SDL.SDL_Point[points.Count];
                int i         = 0;

                foreach (var point in points)
                {
                    var tpoint = point + (anchor?.ScreenBounds.Pos ?? Vec2.Zero);
                    sdlpoints[i] = new SDL2.SDL.SDL_Point
                    {
                        x = (int)tpoint.X,
                        y = (int)tpoint.Y
                    };
                    i++;
                }
                SDL2.SDL.SDL_RenderDrawPoints(SDLRenderer, sdlpoints, points.Count);
            }
Beispiel #6
0
            private void InternalDrawImage(Texture texture, Vec2 pos, Vec2 scale, double rotation, Vec2 origin, Color color, Flipped flipped, Rectangle?source, IAnchor2d anchor)
            {
                const double degreeToRadianConst = 57.2957795131;

                if (!(texture is SDLTexture sdltexture))
                {
                    Logger.Log(LogLevel.Warning, "Texture is not of type SDLTexture");
                    return;
                }

                pos += anchor?.ScreenBounds.Pos ?? Vec2.Zero;
                if (anchor is Entity2d entityAnchor)
                {
                    scale    *= entityAnchor?.Scale ?? Vec2.One;
                    rotation += entityAnchor?.Rotation ?? 0;
                    origin   += entityAnchor?.Origin ?? Vec2.Zero;
                    //TODO: Blend color and flip entity
                }

                var drect = new SDL2.SDL.SDL_Rect
                {
                    x = (int)(pos.X - origin.X),
                    y = (int)(pos.Y - origin.Y),
                    w = (int)(texture.Size.X * scale.X),
                    h = (int)(texture.Size.Y * scale.Y)
                };

                var sdlPoint = new SDL2.SDL.SDL_Point
                {
                    x = (int)origin.X,
                    y = (int)origin.Y
                };

                SDL2.SDL.SDL_SetTextureColorMod(sdltexture.SDL_Image, (byte)color.R, (byte)color.G, (byte)color.B);
                SDL2.SDL.SDL_SetTextureAlphaMod(sdltexture.SDL_Image, (byte)color.A);

                var sdlRenderFlip = SDL2.SDL.SDL_RendererFlip.SDL_FLIP_NONE;

                if (flipped == Flipped.Horizontal)
                {
                    sdlRenderFlip = SDL2.SDL.SDL_RendererFlip.SDL_FLIP_HORIZONTAL;
                }
                else if (flipped == Flipped.Vertical)
                {
                    sdlRenderFlip = SDL2.SDL.SDL_RendererFlip.SDL_FLIP_VERTICAL;
                }
                else if (flipped == Flipped.Both)
                {
                    sdlRenderFlip = SDL2.SDL.SDL_RendererFlip.SDL_FLIP_HORIZONTAL | SDL2.SDL.SDL_RendererFlip.SDL_FLIP_VERTICAL;
                }

                if (!source.HasValue)
                {
                    SDL2.SDL.SDL_RenderCopyEx(this.SDLRenderer, sdltexture.SDL_Image, (IntPtr)null, ref drect, rotation * degreeToRadianConst, ref sdlPoint, sdlRenderFlip);
                }
                else
                {
                    SDL2.SDL.SDL_Rect srect = new SDL2.SDL.SDL_Rect
                    {
                        x = (int)source?.Pos.X,
                        y = (int)source?.Pos.Y,
                        w = (int)source?.Size.X,
                        h = (int)source?.Size.Y
                    };

                    SDL2.SDL.SDL_RenderCopyEx(this.SDLRenderer, sdltexture.SDL_Image, ref srect, ref drect, rotation * degreeToRadianConst, ref sdlPoint, sdlRenderFlip);
                }
            }
Beispiel #7
0
            private void InternalDrawText(Font font, string text, Vec2 pos, Vec2 scale, double rotation, Vec2 origin, Color color, Flipped flipped, Rectangle?source, IAnchor2d anchor)
            {
                const double degreeToRadianConst = 57.2957795131;

                if (!(font is SDLFont sdlFont))
                {
                    Logger.Log(LogLevel.Warning, "Font is not of type SDLFont");
                    return;
                }

                pos += anchor?.ScreenBounds.Pos ?? Vec2.Zero;

                var sdlColor = new SDL2.SDL.SDL_Color
                {
                    r = (byte)color.R,
                    g = (byte)color.G,
                    b = (byte)color.B,
                    a = (byte)color.A
                };
                var fontSur = SDL_ttf.TTF_RenderText_Solid(sdlFont.SDL_Font, text, sdlColor);
                var fontTex = SDL2.SDL.SDL_CreateTextureFromSurface(this.SDLRenderer, fontSur);

                SDL2.SDL.SDL_QueryTexture(fontTex, out _, out _, out int w, out int h);
                var fontSize = new Vec2(w, h);
                var drect    = new SDL2.SDL.SDL_Rect
                {
                    x = (int)(pos.X - origin.X),
                    y = (int)(pos.Y - origin.Y),
                    w = (int)(fontSize.X * scale.X),
                    h = (int)(fontSize.Y * scale.Y)
                };

                var sdlPoint = new SDL2.SDL.SDL_Point
                {
                    x = (int)origin.X,
                    y = (int)origin.Y
                };

                var sdlRenderFlip = SDL2.SDL.SDL_RendererFlip.SDL_FLIP_NONE;

                if (flipped == Flipped.Horizontal)
                {
                    sdlRenderFlip = SDL2.SDL.SDL_RendererFlip.SDL_FLIP_HORIZONTAL;
                }
                else if (flipped == Flipped.Vertical)
                {
                    sdlRenderFlip = SDL2.SDL.SDL_RendererFlip.SDL_FLIP_VERTICAL;
                }
                else if (flipped == Flipped.Both)
                {
                    sdlRenderFlip = SDL2.SDL.SDL_RendererFlip.SDL_FLIP_HORIZONTAL | SDL2.SDL.SDL_RendererFlip.SDL_FLIP_VERTICAL;
                }

                if (!source.HasValue)
                {
                    SDL2.SDL.SDL_RenderCopyEx(this.SDLRenderer, fontTex, (IntPtr)null, ref drect, rotation * degreeToRadianConst, ref sdlPoint, sdlRenderFlip);
                }
                else
                {
                    SDL2.SDL.SDL_Rect srect = new SDL2.SDL.SDL_Rect
                    {
                        x = (int)source?.Pos.X,
                        y = (int)source?.Pos.Y,
                        w = (int)source?.Size.X,
                        h = (int)source?.Size.Y
                    };

                    SDL2.SDL.SDL_RenderCopyEx(this.SDLRenderer, fontTex, ref srect, ref drect, rotation * degreeToRadianConst, ref sdlPoint, sdlRenderFlip);
                }

                SDL2.SDL.SDL_FreeSurface(fontSur);
                SDL2.SDL.SDL_DestroyTexture(fontTex);
            }