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

Author Topic: Shear Transform on sf::Text  (Read 1580 times)

0 Members and 2 Guests are viewing this topic.

Avonclese

  • Newbie
  • *
  • Posts: 7
    • View Profile
Shear Transform on sf::Text
« on: June 15, 2018, 07:07:32 pm »
Hello!

Let me start by saying I am new to matrices, so I apologise if I am missing something very obvious.

This statement found on the Graphics Transform tutorial says:
"If your entity is a sf::Transformable (sprite, text, shape), which contains its own internal transform, both the internal and the passed transform are combined to produce the final transform."

Sounds great. So I create an sf::Text I use setPosition(200,200) to put it where I want.
If I draw the sf::Text with a custom transform, e.g. window.draw(textentity, customtransform), for shearing....the result is not as expected. However, if I use my custom transform to shear and translate to where I want....it works perfectly. What am I missing?

I tested this in very simple code, not in a bigger project. PICTURE 1 shows desired 200,200 location.

PICTURE 2...odd positioning:
textentity.setPosition(200,200);
sf::Transform shearme(
    1, 0, 0,
    0.5, 1, 0,
    0, 0, 1);
window.draw(textentity, shearme)

PICTURE 3...perfect outcome:
textentity.setPosition(0,0);
sf::Transform shearme(
    1, 0, 200,
    0.5, 1, 200,
    0, 0, 1);
window.draw(textentity, shearme)

Thank you for reading!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Shear Transform on sf::Text
« Reply #1 on: June 15, 2018, 10:46:11 pm »
The matrices are probably not applied in the order that you expect:
shearme * textentity.getTransform() gives the "odd positioning"
textentity.getTransform() * shearme would give the "perfect outcome"

But unfortunately you can't change the order of that multiplication, since it happens inside sf::Text.
Laurent Gomila - SFML developer

Avonclese

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Shear Transform on sf::Text
« Reply #2 on: June 16, 2018, 03:43:01 am »
Thank you Laurent for educating me! I have worked around it using a Transformable for all my text transforms, working perfectly.