RenderTarget.mapPixelToCoords

Convert a point from target coordinates to world coordinates.

This function finds the 2D position that matches the given pixel of the render-target. In other words, it does the inverse of what the graphics card does, to find the initial position of a rendered pixel.

Initially, both coordinate systems (world units and target pixels) match perfectly. But if you define a custom view or resize your render-target, this assertion is not true anymore, ie. a point located at (10, 50) in your render-target may map to the point (150, 75) in your 2D world – if the view is translated by (140, 25).

For render-windows, this function is typically used to find which point (or object) is located below the mouse cursor.

This version uses a custom view for calculations, see the other overload of the function if you want to use the current view of the render-target.

  1. Vector2f mapPixelToCoords(Vector2i point)
  2. Vector2f mapPixelToCoords(Vector2i point, View theView)
    interface RenderTarget
    final inout
    mapPixelToCoords

Parameters

point Vector2i

Pixel to convert

theView View

The view to use for converting the point

Return Value

Type: Vector2f

The converted point, in "world" coordinates.

Meta