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

Author Topic: reset Transform?  (Read 2841 times)

0 Members and 1 Guest are viewing this topic.

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
reset Transform?
« on: July 25, 2018, 02:14:31 pm »
hello everybody

how can I reset a transform? i noticed that if i use
state.transform.translate =  sf::Vector2f(10, 0);
twice, the final position will be (20, 0). i know that it is expected, but, how can i make it to be always (10, 0)?

what i'm trying to do is move some vertexArrays to specific positions on the screen, so i can't just combine the "translate" values.

thanks in advance :D
Visit my game site (and hopefully help funding it? )
Website | IndieDB

verdog

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Email
Re: reset Transform?
« Reply #1 on: July 25, 2018, 03:27:48 pm »
As far as I know, that's not the proper way to use a transform. I think you should be doing it like this:
state.transform.translate(sf::Vector2f(10, 0));

And to reset it, I think you could do
state.transform = sf::Transform::Identity;

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: reset Transform?
« Reply #2 on: July 25, 2018, 08:07:55 pm »
you are right, the correct usage indeed is
state.transform.translate(sf::Vector2f(10, 0));
i was in a rush and typed it wrong.  :P

now, sf::Transform::Identity is a good idea, but it also resets scale and rotation. what if i want to reset only the translate value?
Visit my game site (and hopefully help funding it? )
Website | IndieDB

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: reset Transform?
« Reply #3 on: July 25, 2018, 10:30:47 pm »
sf::Transform is a matrix. It does not remember how it was built: whether it was with translations, rotations, scales, or a combination of those... in the end you have a combined matrix from which you can't get back information (almost).

So, while technically there's a way to cancel the translation by directly accessing the elements of the matrix, I can't imagine why you would have to do that in the context of render states.
Laurent Gomila - SFML developer

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: reset Transform?
« Reply #4 on: July 26, 2018, 01:17:41 pm »
well, i have a vertexArray, which i want to rotate, move, and then put it back in it's original position and rotation. so i was using render states for that.

but it just figured out how stupid it is, since i could just create a class inheriting from VertexArray and sf::Transformable, and then have access to functions like getRotation() :-[

thanks for the answers!
Visit my game site (and hopefully help funding it? )
Website | IndieDB

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: reset Transform?
« Reply #5 on: July 26, 2018, 01:19:44 pm »
You can also use an instance of sf::Transformable as a member, rather than as a base class. This has the benefit of not polluting your class API with all the sf::Transformable functions, if you don't need to expose them.

sf::Transformable transforms;
transforms.setPosition(...);
window.draw(vertexArray, transforms.getTransform());
Laurent Gomila - SFML developer

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: reset Transform?
« Reply #6 on: July 26, 2018, 06:20:21 pm »
even better. i'll do it, then. thanks for the help :D
Visit my game site (and hopefully help funding it? )
Website | IndieDB