Click or drag to resize
Ab4d.SharpEngine logo

SceneViewGetClosestHitObject(Single, Single, Boolean, HitTestOptions) Method

GetClosestHitObject method executes a hit testing from the specified x and y positions on the SceneNodes that are shown by this SceneView and returns a RayHitTestResult object with the closest triangle hit. When no triangle is hit, null is returned.

Namespace: Ab4d.SharpEngine
Assembly: Ab4d.SharpEngine (in Ab4d.SharpEngine.dll) Version: 2.0.8956+4c7684e186ca1be74e7a284fbe739d9a1b843d3c
Syntax
C#
public RayHitTestResult? GetClosestHitObject(
	float x,
	float y,
	bool adjustForDpiScale = true,
	HitTestOptions? customHitTestOptions = null
)

Parameters

x  Single
x position in this view (for example, a mouse x position)
y  Single
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 SceneView object. When x any y are from the SceneView.Width and SceneView.Height, then this parameter needs to be false.
customHitTestOptions  HitTestOptions  (Optional)
Optional HitTestOptions that will be used for this hit test. When null (by default), then DefaultHitTestOptions from Scene will be used.

Return Value

RayHitTestResult
RayHitTestResult with the closest hit object or null if no object was hit
Remarks

GetClosestHitObject method executes a hit testing on the SceneNodes that are shown by this SceneView and returns a RayHitTestResult object with the closest triangle hit. When no triangle is hit, null is returned.

This method is first creating the ray by calling GetRayFromCamera(Single, Single, Boolean, Boolean) method and then calling the GetClosestHitObject(Ray, SceneNode, HitTestOptions) method.

To control advanced hit-testing options set the customHitTestOptions parameter (HitTestOptions) or change the Scene.[!:DefaultHitTestOptions] that is used when customHitTestOptions parameter is not set (null by default).

To get all hit results (ant not just the closest hit), use the [!:GetAllHitObjects(float, float, bool)] or [!:GetAllHitObjects(Ray)] methods.

See Also