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

Author Topic: .  (Read 5152 times)

0 Members and 3 Guests are viewing this topic.

Helios101

  • Newbie
  • *
  • Posts: 15
    • View Profile
.
« on: January 19, 2015, 04:55:08 am »
.
« Last Edit: May 03, 2018, 05:15:07 am by Helios101 »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Converting an object from global to local space
« Reply #1 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.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
AW: Converting an object from global to local space
« Reply #2 on: January 19, 2015, 08:37:58 am »
Are you aware of the functions getLocalBounds and getGlobalBounds?
« Last Edit: January 19, 2015, 09:18:28 am by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Converting an object from global to local space
« Reply #3 on: January 19, 2015, 09:07:38 am »
sf::Vector2f global = ...;
sf::Vector2f local = entity.getInverseTransform() * global;
Laurent Gomila - SFML developer

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Converting an object from global to local space
« Reply #4 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().
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Converting an object from global to local space
« Reply #5 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.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Carlitox

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: Converting an object from global to local space
« Reply #6 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.


Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Converting an object from global to local space
« Reply #7 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.
Laurent Gomila - SFML developer

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Converting an object from global to local space
« Reply #8 on: January 19, 2015, 11:01:50 pm »
Maybe another badly drawn picture will help you understand the global/local space a bit.



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).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Converting an object from global to local space
« Reply #9 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?
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything