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

Author Topic: [solved] transform vector to screen coord, outside the shaders  (Read 1813 times)

0 Members and 1 Guest are viewing this topic.

TheNess

  • Newbie
  • *
  • Posts: 17
    • View Profile
    • Email
[solved] transform vector to screen coord, outside the shaders
« on: January 26, 2015, 02:46:53 pm »
hi all :)

How can get the worldview matrix in sfml?
or more specifically - I have a raw vector which I want to convert to screen position, i.e. the actual 2d pixel it will take on the screen if it was pushed through the rendering pipeline.

I tried the following (light.position is the raw position):
sf::Vector2f pos = m_window.getView().getTransform().transformPoint(light.position.x, light.position.y);
 
but from the shader it doesn't look right. I have a sprite and a light at the same position yet they seem far away. also, when I move the view (and update the shader) it doesn't move the light.

what am I doing wrong here?
thanks!  8)
« Last Edit: January 26, 2015, 04:39:28 pm by TheNess »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: transform vector to screen coord, outside the shaders
« Reply #1 on: January 26, 2015, 03:21:49 pm »
sf::Vector2i pixel = m_window.mapCoordToPixel(light.position);
Laurent Gomila - SFML developer

TheNess

  • Newbie
  • *
  • Posts: 17
    • View Profile
    • Email
Re: transform vector to screen coord, outside the shaders
« Reply #2 on: January 26, 2015, 03:39:06 pm »
this seems to work perfectly on X axis but weird on Y axis.
it looks like the view position on Y axis is not calculated correctly: when view position is 0 the light position is at the bottom of the screen, and as I move the camera around the light move around on Y axis differently then the rest of the sprites.

EDIT:
ok this solves it:
pixel.y = m_window.getSize().y - pos.y;
 

thanks! :)
« Last Edit: January 26, 2015, 03:56:02 pm by TheNess »

 

anything