# NNS_G3dScrPosToWorldLine

## Syntax

      #include <nnsys/g3d/util.h>

      int
      NNS_G3dScrPosToWorldLine(
          int px,
          int py,
          VecFx32* pNear,
          VecFx32* pFar
      );

## Arguments

px | Pointer to the `x` coordinate on the screen
py | Pointer to the `y` coordinate on the screen
pNear | Position in the world coordinate system of the point on the near clip plane corresponding to the screen coordinates
pFar | Position in the world coordinate system of the point on the far clip plane corresponding to the screen coordinates

## Return Values

Returns 0 if `px` and `py` are inside the viewport. Returns -1 if they are outside of the viewport.

## Description

Returns the point on the near and far clip planes corresponding to the position on the screen in the world coordinate system. When `pFar` is NULL, the calculation of the point on the far clip plane is omitted. The camera matrix and the projection matrix must be configured in the `NNS_G3dGlb` structure. Even if the return value is -1, values are stored in `*pNear` and `*pFar`, and can be used as a directional guide. Bear in mind that for perspective projections, the `*pFar` value will have a larger margin of error than `*pNear`. This is because the far clip plane is bigger than the near clip plane, so when looking for the original point from the point in the normalized screen coordinate system, the far plane is enlarged more than the near plane. When applying a horizontal offset to the 3D plane by using the Nitro-SDK `G3X_SetHOffset` function, it is necessary to move the x coordinate of the arguments by the amount of the offset, in advance.

## See Also

`NNS_G3dLocalOriginToScrPos`, `NNS_G3dWorldPosToScrPos`

## Revision History

2004/11/01 Initial version.

CONFIDENTIAL