I apologies for the long winded topic. I got stuck on a problem for a few days, and I think what would help me is to write the situation somewhere to straighten my thoughts.
The problem is that I misinterpreted the origin attribute for transformable objects.
I interpreted that the origin was the spot where whenever you call setPosition, the origin will be placed at that pixel location.
By default, it's the top left corner. Setting the origin would shift the rendered object. This would allow the dev to easily center a sprite over a specified position.
Scale and rotation by seems to work fine, too. It rotates about the origin, and it scales relative to the origin.
My issue is introduced when I tried to apply all three transforms for a test game (Solitaire).
I'm setting a card's origin to the middle to allow it to spin around its center.
I'm setting the center's position equal to the center of a specific spot.
Lastly, the sprite is scaled by 50%. Here I'm expecting the card's borders to squeeze closer to the origin equally.
Although the card gets smaller, the position is 'shifted' from desired location. I've attached a screenshot to help visualize the scenario. I've also disabled spinning to simplify the problem.
Looking at the 9 of spades, there's a card outline to the top left of it. That's the desired location.
CardSize.X = 90
Pivot = CardSize * 0.5 (Pivot.X = 90/2 => 45)
Position.X = 8 + Pivot (53) <--- The intention is to place the center of the card at the center of the outline.
Size = 0.5
Result Position of top left corner of card (X-axis) = 31 ((-Pivot.X*0.5) + Position.X) <-- The 0.5 is coming from size
Expected Position of top left corner of card (X-axis) = 8 (-Pivot.X + Position.X)
The easiest solution is to simply adjust the position, but that would weaken my internal usage behind origin where the origin is always at the location where setPosition is specified.
My objective is that when I call SetPosition on an object, the origin of that object is found at that location regardless of scale and rotation.
I've considered a handful of hacky solutions, but I'm too embarrassed to bring them up.
-----------------------------------
Edit: I sat on my post for a few hours before publishing it. Writing it down did help me understand the problem. It's an order of operation error. It's applying origin shift, scaling, then translating when I need to scale, shift it, then translate it.
For the example above (looking at left border X coordinate of sprite):
Actual:
Absolute Pos = 0
Apply Origin Shift (45)
Absolute Pos = -45
Apply scaling (0.5)
Absolute Pos = -22.5
Apply translation (53)
Absolute Pos = 31
Needed:
Absolute Pos = 0
Apply scale (0.5)
Absolute Pos = 0 <--- but the card is half size
Apply translation (53)
Absolute Pos = 53
Apply Origin Shift (45)
Absolute Pos = 8
Perhaps changing my setPosition setOrigin setSize calls with using a sf::Transform object may help resolve my issue. I'll give this a try, and I'll post again. I decided to make this post anyways in case others are running into similar problems.