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

Author Topic: [Answered] Get translate/scale/rotation from sf::Transform?  (Read 3039 times)

0 Members and 3 Guests are viewing this topic.

Cory Parsnipson

  • Newbie
  • *
  • Posts: 8
    • View Profile
[Answered] Get translate/scale/rotation from sf::Transform?
« on: April 18, 2016, 11:26:39 am »
The documentation does not seem to have anything about getting individual transform values from an sf::Transform struct. Is it possible, given an sf::Transform to isolate a single "attribute" from it? For example, if I wanted to know what the scaling of a specific transform was, is there anything I could do?

Also, it seems like you can get the raw 3x3 matrix. Is there any reading I can do for how to manipulate these matrices?

Thanks.
« Last Edit: April 21, 2016, 08:26:33 pm by Cory Parsnipson »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Get translate/scale/rotation from sf::Transform?
« Reply #1 on: April 18, 2016, 11:39:01 am »
In the general case, no. You can't extract individual transformations from a combined matrix.

However if you work with specific matrices, this may be possible. It all depends on how the matrix is constructed. If you tell us more about this, maybe we can help.
Laurent Gomila - SFML developer

Cory Parsnipson

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Get translate/scale/rotation from sf::Transform?
« Reply #2 on: April 19, 2016, 12:51:53 am »
I'm not sure what you mean by "specific matrix", but I'll describe the situation that made me think of this question.

I have a class that contains an sf::View and I want to allow users to modify it through scaling, translation, rotating, etc. I also want this class to have member functions for getting the transform such as "get_scale" or "get_position" etc. I could keep separate variables that keep track of scale and positioning and stuff alongside the raw transform, but I thought it would be nicer if I could just obtain it from the sf::Transform object inside the sf::View.

EDIT: I just realized that the sf::View transform is the "projection transform" and for internal use only? Regardless, my question still applies for other objects like sf::Transformables, Sprites, etc.
« Last Edit: April 19, 2016, 02:17:21 am by Cory Parsnipson »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Get translate/scale/rotation from sf::Transform?
« Reply #3 on: April 19, 2016, 06:22:15 am »
sf::Transformable stores its components separated, so there's no problem for it and all its derived classes.
Laurent Gomila - SFML developer

Cory Parsnipson

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Get translate/scale/rotation from sf::Transform?
« Reply #4 on: April 21, 2016, 04:32:28 am »
Ah you're right, my bad. I take it from your response, though, that that if you have an object that is not transformable but has sf::Transform as a member, you cannot obtain a separate transform component from it.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Get translate/scale/rotation from sf::Transform?
« Reply #5 on: April 21, 2016, 06:24:10 am »
As I said, not in the general case. But if you know that your transform is only made of, let's say, a scale and a translation, and in which order, then you can extract them. That's why I said it depends on how you create those transforms.
Laurent Gomila - SFML developer

Cory Parsnipson

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Get translate/scale/rotation from sf::Transform?
« Reply #6 on: April 21, 2016, 08:26:17 pm »
Ok I see. Thanks for your help!

 

anything