Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Custom Transforms; Origins, Translation, & Rotation  (Read 1209 times)

0 Members and 1 Guest are viewing this topic.

egg82

  • Newbie
  • *
  • Posts: 2
    • View Profile
Custom Transforms; Origins, Translation, & Rotation
« on: January 29, 2017, 09:29:15 pm »
It's been years since I've made an account anywhere to ask a questions I can normally, Google, but I'm genuinely a bit stuck and can't find the solution that seems like it should be staring me in the face.

The below code is in C# using the NuGet wrapper, though it probably doesn't matter. Long story short, I have an abstract "BaseSprite" class that's allowed to have its own children. It has a Draw function which takes a RenderTarget and a Transform. (its parent's global transform, of which the window passes in an Identity for the topmost children)
I then have a Sprite, a RenderState, and a local transform that's used in the RenderState instead of the sprite's transform (the sprite's transform isn't used at all. The local transform completely replaces it.)
The global transform is the parentTransform * localTransform, and the renderState uses the globalTransform.

I can move the sprite around, rotate it, scale it, etc just fine. The problem comes with origins and (at least rotation, but I suspect scale won't work either.)
If I translate the local transform anywhere on screen and set the origin anywhere, then rotate it, it rotates on the origin just fine. If I start translating the transform further, the rotation starts to become quite off, even if I move the origin point with the translation. I'm sure I'm missing something obvious, but I've tried everything I can for now and I really need some ideas to bounce off of.

Paste can be found here: https://gist.github.com/egg82/8ce4235dabef9ca31b7d62a63b287e05. PrecisePoint and PreciseRectangle are just Point and Rectangle using doubles. BaseWindow is just the SFML Window, which is also the RenderTarget.

Edit
A video displaying the odd properties can be found here: https://www.youtube.com/watch?v=Pc1YqDM1iC8&feature=youtu.be
« Last Edit: January 29, 2017, 10:59:18 pm by egg82 »

egg82

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Custom Transforms; Origins, Translation, & Rotation
« Reply #1 on: January 29, 2017, 11:35:29 pm »
Bounced a few ideas off of a friend of mine and eventually we figured out that rotating the matrix rotates the entire matrix (which seems obvious) - thus, translating the matrix across the x-axis just moves it in whatever direction the rotation is pointing it in. I moved to translating the sprite's rotation and scale instead of the localTransform's, and everything works as expected.