Skip to content

Commit

Permalink
RenderTarget::convertCoords now takes a Vector2i argument
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentGomila committed Mar 27, 2012
1 parent 74f9388 commit 859074b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
12 changes: 5 additions & 7 deletions include/SFML/Graphics/RenderTarget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,12 @@ public :
/// This version uses the current view of the render target.
/// See the other overload to specify a custom view.
///
/// \param x X coordinate of the point to convert, relative to the render target
/// \param y Y coordinate of the point to convert, relative to the render target
/// \param point Point to convert, relative to the render target
///
/// \return The converted point, in "world" units
///
////////////////////////////////////////////////////////////
Vector2f convertCoords(unsigned int x, unsigned int y) const;
Vector2f convertCoords(const Vector2i& point) const;

////////////////////////////////////////////////////////////
/// \brief Convert a point from target coordinates to view coordinates
Expand All @@ -169,14 +168,13 @@ public :
/// overload of the function to use the current view of the render
/// target.
///
/// \param x X coordinate of the point to convert, relative to the render target
/// \param y Y coordinate of the point to convert, relative to the render target
/// \param view The view to use for converting the point
/// \param point Point to convert, relative to the render target
/// \param view The view to use for converting the point
///
/// \return The converted point, in "world" units
///
////////////////////////////////////////////////////////////
Vector2f convertCoords(unsigned int x, unsigned int y, const View& view) const;
Vector2f convertCoords(const Vector2i& point, const View& view) const;

////////////////////////////////////////////////////////////
/// \brief Draw a drawable object to the render-target
Expand Down
10 changes: 5 additions & 5 deletions src/SFML/Graphics/RenderTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,20 @@ IntRect RenderTarget::getViewport(const View& view) const


////////////////////////////////////////////////////////////
Vector2f RenderTarget::convertCoords(unsigned int x, unsigned int y) const
Vector2f RenderTarget::convertCoords(const Vector2i& point) const
{
return convertCoords(x, y, getView());
return convertCoords(point, getView());
}


////////////////////////////////////////////////////////////
Vector2f RenderTarget::convertCoords(unsigned int x, unsigned int y, const View& view) const
Vector2f RenderTarget::convertCoords(const Vector2i& point, const View& view) const
{
// First, convert from viewport coordinates to homogeneous coordinates
Vector2f coords;
IntRect viewport = getViewport(view);
coords.x = -1.f + 2.f * (static_cast<int>(x) - viewport.left) / viewport.width;
coords.y = 1.f - 2.f * (static_cast<int>(y) - viewport.top) / viewport.height;
coords.x = -1.f + 2.f * (point.x - viewport.left) / viewport.width;
coords.y = 1.f - 2.f * (point.y - viewport.top) / viewport.height;

// Then transform by the inverse of the view matrix
return view.getInverseTransform().transformPoint(coords);
Expand Down

0 comments on commit 859074b

Please sign in to comment.