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

Author Topic: Converting from world to screen coordinates  (Read 3525 times)

0 Members and 1 Guest are viewing this topic.

LiChE

  • Newbie
  • *
  • Posts: 2
    • View Profile
Converting from world to screen coordinates
« on: September 20, 2012, 01:15:04 am »
I am using a view to zoom + translate a tile map and it works fine. The problem is, I have light position's in world coordinates and am using a light attenuation shader to draw the light - I need to convert the light's position in world coordinates to screen coordinates. I have tried using view.getInverseTransform().transformPoint but it gives odd results.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11004
    • View Profile
    • development blog
    • Email
Re: Converting from world to screen coordinates
« Reply #1 on: September 20, 2012, 01:53:06 am »
The documentation marks the getTransform and getInverseTransform of the sf::View as 'This function is meant for internal use only.'. So I guess it's not advised to use it as a developer.

I think there's a way to do it with existing SFML functions, but I don't remember/can't find it at the moment...
As a alternative you can perform the transformations not only on the view but also on your own sf::Transform object and then use getInverse() to get the inverse...
On the other hand you may find a way to make things work if you get the transformation from the window coordinates to the view coordinates. This is possible through the sf::RenderWindow::convertCoords() function.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

LiChE

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Converting from world to screen coordinates
« Reply #2 on: September 20, 2012, 08:53:15 pm »
Damn, I was trying to avoid having to do that, but I guess there is no other choice.

Maybe I can get it to work with sf::RenderWindow::convertCoords()...from my understanding, it converts mouse coordinates to world coordinates by passing in your world view...so if I pass in a view with a view made from the inverse of the world view, it should convert world coordinates to screen coordinates...

maybe.

e: that convertCoords() idea I had definitely didn't work.
« Last Edit: September 20, 2012, 09:37:50 pm by LiChE »

 

anything