Click or drag to resize
Ab4d.SharpEngine logo

SceneViewPoint3DTo2D(Vector3, Boolean) Method

Point3DTo2D converts a world space 3D position (as Vector3) to the 2D screen position (as Vector2). To calculate the 2D position for the final UI element, set the adjustByDpiScale to true otherwise the 2D positions will be positioned inside the view defined by SceneView's Width and Height.

Namespace: Ab4d.SharpEngine
Assembly: Ab4d.SharpEngine (in Ab4d.SharpEngine.dll) Version: 2.0.8956+4c7684e186ca1be74e7a284fbe739d9a1b843d3c
Syntax
C#
public Vector2 Point3DTo2D(
	Vector3 point3D,
	bool adjustByDpiScale = false
)

Parameters

point3D  Vector3
3D point in world space 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

Vector2
Point2D in the screen coordinates or Vector2(float.NaN, float.NaN) when the conversion matrix cannot be created
Remarks

Point3DTo2D converts a world space 3D position (as Vector3) to the 2D screen position (as Vector2). To calculate the 2D position for the final UI element, set the adjustByDpiScale to true otherwise the 2D positions will be positioned inside the view defined by SceneView's Width and Height.

The matrix to convert 3D point to 2D point is calculated from the used 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 point 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 convert multiple 3D points, use the Points3DTo2D(Vector3, Vector2, Transform, Boolean, Boolean) method.

To use Point3DTo2D method without creating the SceneView, then you can use the static Point3DTo2D(Vector3, Camera, Single, Single) or Points3DTo2D(Vector3, Vector2, Camera, Single, Single, Transform, Boolean, Boolean).

See Also