Click or drag to resize
Ab4d.SharpEngine logo

SceneViewGetRayFromCamera(Int32, Int32, Boolean, Boolean) Method

Returns a Ray that goes into a direction that is calculated from the specified x and y position in screen coordinates. For perspective camera the ray starts at the current camera position. The ray can be used for hit testing from the mouse position defined by x and y (relative to this SceneView object). When the Ray cannot be created (size is zero or camera matrix is not valid), then a Ray with zero Direction is returned (Ray.IsValid would return false).

Namespace: Ab4d.SharpEngine
Assembly: Ab4d.SharpEngine (in Ab4d.SharpEngine.dll) Version: 2.0.8956+4c7684e186ca1be74e7a284fbe739d9a1b843d3c
Syntax
C#
public Ray GetRayFromCamera(
	int x,
	int y,
	bool adjustForDpiScale = true,
	bool adjustForSupersamplingFactor = true
)

Parameters

x  Int32
x position in this view (for example, a mouse x position)
y  Int32
y position in this view (for example, a mouse y position)
adjustForDpiScale  Boolean  (Optional)
when true (by default) the x and y positions are multiplied by the DpiScaleX and DpiScaleY. This should be used when x and y are get from mouse location on the SharpEngineSceneView object. When x any y are from the SceneView.Width and SceneView.Height, then this parameter needs to be false.
adjustForSupersamplingFactor  Boolean  (Optional)
when true (by default) the x and y positions are multiplied by the SupersamplingFactor. This should be used when x and y are get from mouse location on the SharpEngineSceneView object. When x any y are from the SceneView.Width and SceneView.Height, then this parameter needs to be false.

Return Value

Ray
Ray in world coordinates that is defined from x and y screen positions (the ray stars at camera's position). When the Ray cannot be created (size is zero or camera matrix is not valid), then a Ray with zero Direction is returned (Ray.IsValid would return false).
Remarks

Returns a Ray that goes into a direction that is calculated from the specified x and y position in screen coordinates. For perspective camera the ray starts at the current camera position. The ray can be used for hit testing from the mouse position defined by x and y (relative to this SceneView object).

When the Ray cannot be created (size is zero or camera matrix is not valid), then a Ray with zero Direction is returned (Ray.IsValid would return false).

When the adjustForDpiScale parameter is set to true (by default), the x and y positions are multiplied by the DpiScaleX and DpiScaleY. This should be used when x and y are get from mouse location on the SharpEngineSceneView object. When x any y are from the SceneView (in pixel and not screen units), then this parameter needs to be false. For example: when DpiScale is 1.5 (144 DPI) and the width of the SharpEngineSceneView object is 1000, then the SceneView.Width is 1500. To correctly use the x from SharpEngineSceneView on the SceneView, the x value needs to be multiplied by the DpiScale (1.5).

The difference between the ray that is returned from this method and the ray from the GetRayFromNearPlane(Int32, Int32, Boolean, Boolean) method is that in case of perspective camera the position of the ray from this method is set to the position of the camera. The position of the ray from GetRayFromNearPlane(Int32, Int32, Boolean, Boolean) method is set to a position on the camera's near plane. Both rays can be get for hit-testing. The difference is only in the distance from the hit origin in the hit test result.

See Also