Origin not working as expected?

Hello guys,

I am currently writing a “Sprite” class and I have one problem with the origin and the coordinate system in general.
First of all I calculate the origin based on the code provided below but the origin seems to be always at the top left of the window (it rotates around the topleft of the screen all the time, no matter where my sprite is positioned).

Another problem I have is that the coordinate system seems to be off. Maybe this is intended but when I for example move my sprite to the right side of my window my x coordinate goes into negative. Shooldn’t it go into positive numbers? Same problem applys to Y.

Would be nice if anyone could help me get on the right track at least :slight_smile:

private void ApplyChanges()
    {
        boundingRect.Width = (int)(texture.Width * scaleX);
        boundingRect.Height = (int)(texture.Height * scaleY);
        boundingRect.X = position.X;
        boundingRect.Y = position.Y;
        //Determines the origin based on originMode
        switch (originMode)
        {
            case OriginMode.Center:
                origin = new Vector2(position.X+(boundingRect.X + boundingRect.Width / 2) / scaleX, position.Y+(boundingRect.Y + boundingRect.Height / 2) / scaleY);
                break;
            case OriginMode.BottomLeft:
                origin = new Vector2(position.X+boundingRect.X, position.Y+boundingRect.Y + boundingRect.Height);
                break;
            case OriginMode.BottomRight:
                origin = new Vector2(position.X+boundingRect.X + boundingRect.Width, position.Y+boundingRect.Y + boundingRect.Height);
                break;
            case OriginMode.TopLeft:
                origin = new Vector2(position.X+boundingRect.X, position.Y+boundingRect.Y);
                break;
            case OriginMode.TopRight:
                origin = new Vector2(position.X+boundingRect.X + boundingRect.Width, position.Y+ boundingRect.Y);
                break;
            default:
                break;
        }
    }

If you want The center of a sprite you only need to get half the height a with. The position is irrelevant.

This will also be throwing your coordinates off to

I don’t really understand what you want to achieve here. Think of origin as the opposite of position: position MINUS origin EQUAS final position.

Wow. Thanks guys. I was really thinking that this would be more complex then it is…
Solved it now by just not considering any positions at all.
Thank You!