Click or drag to resize
Ab4d.SharpEngine logo

SceneViewLine3DTo2D(Vector3, Vector3, Boolean) Method

Converts a 3D line that is defined by startPositionWorld and endPositionWorld to a line on the screen that is defined by startPositionScreen and endPositionScreen. This method correctly handles the case when the 3D line crosses the camera near plane (goes behind the camera). In this case the line needs to be cropped at the camera's near plane.

Namespace: Ab4d.SharpEngine
Assembly: Ab4d.SharpEngine (in Ab4d.SharpEngine.dll) Version: 2.0.8956+4c7684e186ca1be74e7a284fbe739d9a1b843d3c
Syntax
C#
public (Vector2 startPositionScreen, Vector2 endPositionScreen) Line3DTo2D(
	Vector3 startPositionWorld,
	Vector3 endPositionWorld,
	bool adjustByDpiScale = false
)

Parameters

startPositionWorld  Vector3
start position of the 3D line as Vector3
endPositionWorld  Vector3
end position of the 3D line as Vector3
adjustByDpiScale  Boolean  (Optional)
when true (false by default), then the 2D positions will be adjusted by DPI scale (to get positions on the final UI element)

Return Value

ValueTupleVector2, Vector2
(Vector2 startPositionScreen, Vector2 endPositionScreen) with the line's start and end position on the screen
Remarks

Converts a 3D line that is defined by startPositionWorld and endPositionWorld to a line on the screen that is defined by startPositionScreen and endPositionScreen.

This method correctly handles the case when the 3D line crosses the camera near plane (goes behind the camera). In this case the line needs to be cropped at the camera near plane.

The matrix to convert 3D point to 2D point is calculated from the used Ab4d.Camera. The matrix value is cached and is only recalculated when the camera is changed or when the size of the view is changed.

If the matrix to convert 3D point to 2D point cannot be calculated (for example if the size of this SceneView is not set), the returned points will be Vector2(float.NaN, float.NaN). To check if the conversion can be done you can call CanConvertPoint3DTo2D method before calling this method.

To use Line3DTo2D method without creating the SceneView, then you can use the static Line3DTo2D(Vector3, Vector3, Camera, Single, Single).

See Also