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")); } }
public void Draw(int x, int y, double angle, Vector center) { Assert.IsNotNull(Handle, Errors.E_TEXTURE_NULL); Assert.IsNotNull(renderer, Errors.E_RENDERER_NULL); renderer.RenderTexture(Handle, x, y, Width, Height, angle, center); }
public Vector GetIntersectionDepth(Rectangle rectangle) { // Calculate half sizes. float halfWidthA = this.Width / 2.0f; float halfHeightA = this.Height / 2.0f; float halfWidthB = rectangle.Width / 2.0f; float halfHeightB = rectangle.Height / 2.0f; // Calculate centers. Vector centerA = new Vector(this.Left + halfWidthA, this.Top + halfHeightA); Vector centerB = new Vector(rectangle.Left + halfWidthB, rectangle.Top + halfHeightB); // Calculate current and minimum-non-intersecting distances between centers. float distanceX = centerA.X - centerB.X; float distanceY = centerA.Y - centerB.Y; float minDistanceX = halfWidthA + halfWidthB; float minDistanceY = halfHeightA + halfHeightB; // If we are not intersecting at all, return (0, 0). if (Math.Abs(distanceX) >= minDistanceX || Math.Abs(distanceY) >= minDistanceY) return Vector.Zero; // Calculate and return intersection depths. float depthX = distanceX > 0 ? minDistanceX - distanceX : -minDistanceX - distanceX; float depthY = distanceY > 0 ? minDistanceY - distanceY : -minDistanceY - distanceY; return new Vector(depthX, depthY); }
public bool Contains(Vector vector) { if (Left <= vector.X && Right >= vector.X && Top <= vector.Y && Bottom >= vector.Y) return true; else return false; }
public Vector Subtract(Vector vector) { float x = X - vector.X; float y = Y - vector.Y; return new Vector(x, y); }
public Vector Add(Vector vector) { float x = X + vector.X; float y = Y + vector.Y; return new Vector(x, y); }