1
Graphics / Converting from Cartesian coordinate system to SFML.
« on: August 25, 2011, 12:17:02 am »
Hi, my project is using the standard Cartesian system for position (X-axis goes right, Y-Axis goes Up) whereas SFML has an inverted Y axis.
I am trying to convert my game coordinates to SFML coordinates for drawing, it was working fine when I wasn't using views but now I have implemented that my algorithm for converting has failed completely.
Here is my current code:
I think I am forgetting something when converting because as soon as GetCenter() moves from the centre of the window the whole thing breaks down and it returns weird results.
I was thinking it might involve RenderWindow::ConvertCoords() but I have no idea really I have never played with views before.
I am trying to convert my game coordinates to SFML coordinates for drawing, it was working fine when I wasn't using views but now I have implemented that my algorithm for converting has failed completely.
Here is my current code:
Code: [Select]
sf::Vector2f BaseEntity::GameCoordsToSFML(sf::Vector2f Pos)
{
Pos.y *= -1;
return pRender->GetView().GetCenter() + Pos;
}
sf::Vector2f BaseEntity::SFMLToGameCoords(sf::Vector2f Pos)
{
Pos = Pos - pRender->GetView().GetCenter();
Pos.y *= -1;
return Pos;
}
I think I am forgetting something when converting because as soon as GetCenter() moves from the centre of the window the whole thing breaks down and it returns weird results.
I was thinking it might involve RenderWindow::ConvertCoords() but I have no idea really I have never played with views before.