SFML community forums

Help => General => Topic started by: Helios101 on January 19, 2015, 04:55:08 am

Title: .
Post by: Helios101 on January 19, 2015, 04:55:08 am
.
Title: Re: Converting an object from global to local space
Post by: Hapax on January 19, 2015, 05:28:23 am
I think getting the rect's inverse transform would be like this:
rect.getInverseTransform()
Hope this helps.
Title: AW: Converting an object from global to local space
Post by: eXpl0it3r on January 19, 2015, 08:37:58 am
Are you aware of the functions getLocalBounds and getGlobalBounds?
Title: Re: Converting an object from global to local space
Post by: Laurent on January 19, 2015, 09:07:38 am
sf::Vector2f global = ...;
sf::Vector2f local = entity.getInverseTransform() * global;
Title: Re: Converting an object from global to local space
Post by: eXpl0it3r on January 19, 2015, 09:12:48 pm
What is your definition of "local" and "global", because I think you're misunderstanding something.

If you move an object, you're moving it in the global space, so your local position won't change.
If you want to change the local position, you have to change the origin.

If you set the position in the global space to a specific value, it will always have that value.
If you want to move it by 250.f units, then you have to call move().
Title: Re: Converting an object from global to local space
Post by: Hapax on January 19, 2015, 09:42:12 pm
its new local position is not updating
You will need to update it using the two lines of code you created from Laurent's example. Those variables (local and global) don't update themselves.
Title: Re: Converting an object from global to local space
Post by: Carlitox on January 19, 2015, 10:43:42 pm
I don't know exactly what do you want to do but usually you need the global transform to handle collision for example.

Look  getGlobalBounds() function.

Title: Re: Converting an object from global to local space
Post by: Laurent on January 19, 2015, 10:53:34 pm
Quote
I don't know exactly what do you want to do
Good point.

This is a typical example of the XY problem: you describe what you think is the solution to your problem, instead of your actual problem.
Title: Re: Converting an object from global to local space
Post by: eXpl0it3r on January 19, 2015, 11:01:50 pm
Maybe another badly drawn picture will help you understand the global/local space a bit.

(https://i.imgur.com/nL0XhmP.png)

The position of the orange box is in local space at (0,0), this is also known as origin.
The position of the orange box is in global space at (10,15), this can be changed with setPosition() or move().
The bottom right corner of the orange box is in local space at the position (30,30).
The bottom right corner of the orange box is in global space at the position (40, 45).
Title: Re: Converting an object from global to local space
Post by: Hapax on January 20, 2015, 02:46:27 am
                rect.Update();

                sf::Vector2f global = player.getPosition();
                sf::Vector2f local = player.getInverseTransform() * global;
@Hapax
I'm updating the two lines in the while loop.
I meant that you need to update them before you use them. These variables aren't getting used at all. They should probably be inside the Player class.
As with everyone else here, I'm not sure what you trying to do with them, though. Is it that you want the Player::update()'s move to be moved using local co-ordinates, maybe?