Name String
XR_ANDROID_raycast
Extension Type
Instance extension
Registered Extension Number
464
Revision
1
Extension and Version Dependencies
Last Modified Date
2024-10-02
IP Status
No known IP claims.
Contributors
Spencer Quin, Google
Nihav Jain, Google
John Pursey, Google
Jared Finder, Google
Levana Chen, Google
Kenny Vercaemer, Google
Overview
This extension allows the application to perform raycasts against trackables in the environment. Raycasts can be useful for detecting objects in the environment that a ray would intersect with. For example:
- To determine where a floating object would fall when dropped, by using a vertical raycast.
- To determine where a user is looking, by using a forward-facing raycast.
Query supported raycast capabilities
The xrEnumerateRaycastSupportedTrackableTypesANDROID function is defined as:
XrResult xrEnumerateRaycastSupportedTrackableTypesANDROID(
XrInstance instance,
XrSystemId systemId,
uint32_t trackableTypeCapacityInput,
uint32_t* trackableTypeCountOutput,
XrTrackableTypeANDROID* trackableTypes);
Parameter Descriptions
instance
is the XrInstance from whichsystemId
was retrieved.systemId
is theXrSystemId
whose supported trackable types for raycasting are being enumerated.trackableTypeCapacityInput
is the capacity of thetrackableTypes
, or 0 to retrieve the required capacity.trackableTypeCountOutput
is a pointer to the count of the array, or a pointer to the required capacity in the case thattrackableTypeCapacityInput
is insufficient.trackableTypes
is a pointer to an array of XrTrackableTypeANDROID, but can beNULL
iftrackableTypeCapacityInput
is0
.
- See the Buffer Size Parameters section for a detailed description of
retrieving the required
trackableTypes
size.
xrEnumerateRaycastSupportedTrackableTypesANDROID enumerates the trackable types that support raycasting by the current session.
Valid Usage (Implicit)
- The
XR_ANDROID_raycast
extension must be enabled prior to calling xrEnumerateRaycastSupportedTrackableTypesANDROID instance
must be a valid XrInstance handletrackableTypeCountOutput
must be a pointer to auint32_t
value- If
trackableTypeCapacityInput
is not0
,trackableTypes
must be a pointer to an array oftrackableTypeCapacityInput
XrTrackableTypeANDROID values
Return Codes
XR_SUCCESS
XR_ERROR_VALIDATION_FAILURE
XR_ERROR_RUNTIME_FAILURE
XR_ERROR_HANDLE_INVALID
XR_ERROR_INSTANCE_LOST
XR_ERROR_SIZE_INSUFFICIENT
XR_ERROR_SYSTEM_INVALID
XR_ERROR_FUNCTION_UNSUPPORTED
Perform a raycast
The xrRaycastANDROID function is defined as:
XrResult xrRaycastANDROID(
XrSession session,
const XrRaycastInfoANDROID* rayInfo,
XrRaycastHitResultsANDROID* results);
Parameter Descriptions
session
is the XrSession that performs the raycast.rayInfo
is the XrRaycastInfoANDROID that describes the ray to cast.results
is a pointer to the XrRaycastHitResultsANDROID that receives the results of the raycast.
The application can perform raycasts by calling xrRaycastANDROID.
- If a raycast intersects more trackables than XrRaycastHitResultsANDROID::maxResults, the runtime must return the hit results that are closest to the XrRaycastHitResultsANDROID::origin of the ray.
- If a raycast intersects a trackable of type
XR_TRACKABLE_TYPE_ANDROID_PLANE
, that is subsumed by another plane, the runtime must return the hit result for the subsuming plane only. - The runtime must return the hit results in closest-to-farthest order from XrRaycastInfoANDROID::origin along the XrRaycastInfoANDROID::trajectory vector.
- The runtime must return
XR_ERROR_TRACKABLE_TYPE_NOT_SUPPORTED_ANDROID
if the trackable type corresponding to the XrTrackableTrackerANDROID handles in XrRaycastInfoANDROID::trackers are not enumerated by xrEnumerateRaycastSupportedTrackableTypesANDROID.
Valid Usage (Implicit)
- The
XR_ANDROID_raycast
extension must be enabled prior to calling xrRaycastANDROID session
must be a valid XrSession handlerayInfo
must be a pointer to a valid XrRaycastInfoANDROID structureresults
must be a pointer to an XrRaycastHitResultsANDROID structure
Return Codes
XR_SUCCESS
XR_SESSION_LOSS_PENDING
XR_ERROR_FUNCTION_UNSUPPORTED
XR_ERROR_TRACKABLE_TYPE_NOT_SUPPORTED_ANDROID
XR_ERROR_VALIDATION_FAILURE
XR_ERROR_RUNTIME_FAILURE
XR_ERROR_HANDLE_INVALID
XR_ERROR_INSTANCE_LOST
XR_ERROR_SESSION_LOST
XR_ERROR_OUT_OF_MEMORY
XR_ERROR_LIMIT_REACHED
XR_ERROR_POSE_INVALID
XR_ERROR_TIME_INVALID
XR_ERROR_FEATURE_UNSUPPORTED
The XrRaycastInfoANDROID structure is defined as:
typedef struct XrRaycastInfoANDROID {
XrStructureType type;
void* next;
uint32_t maxResults;
uint32_t trackerCount;
const XrTrackableTrackerANDROID* trackers;
XrVector3f origin;
XrVector3f trajectory;
XrSpace space;
XrTime time;
} XrRaycastInfoANDROID;
Member Descriptions
type
is the XrStructureType of this structure.next
isNULL
or a pointer to the next structure in a structure chain. No such structures are defined in core OpenXR or this extension.maxResults
is theuint32_t
maximum number of results to return.trackerCount
is theuint32_t
count of thetrackers
array.trackers
is the array of XrTrackableTrackerANDROID that the casted ray should be tested against.origin
is the XrVector3f that the ray is cast from.trajectory
is the XrVector3f that the ray is targeted at.space
is the XrSpace that the ray is cast in.time
is theXrTime
the ray is cast at.
The XrRaycastInfoANDROID structure describes the ray to cast.
- The XrRaycastInfoANDROID::trackers array may contain trackers of different types.
- The XrRaycastInfoANDROID::trackers array must not contain multiple
trackers of the same type, otherwise the runtime must return
XR_ERROR_VALIDATION_FAILURE
.
Valid Usage (Implicit)
- The
XR_ANDROID_raycast
extension must be enabled prior to using XrRaycastInfoANDROID type
must beXR_TYPE_RAYCAST_INFO_ANDROID
next
must beNULL
or a valid pointer to the next structure in a structure chaintrackers
must be a pointer to an array oftrackerCount
valid XrTrackableTrackerANDROID handlesspace
must be a valid XrSpace handle- The
trackerCount
parameter must be greater than0
- Both of
space
and the elements oftrackers
must have been created, allocated, or retrieved from the same XrSession
The XrRaycastHitResultsANDROID structure is defined as:
typedef struct XrRaycastHitResultsANDROID {
XrStructureType type;
void* next;
uint32_t resultsCapacityInput;
uint32_t resultsCountOutput;
XrRaycastHitResultANDROID* results;
} XrRaycastHitResultsANDROID;
Member Descriptions
type
is the XrStructureType of this structure.next
isNULL
or a pointer to the next structure in a structure chain. No such structures are defined in core OpenXR or this extension.resultsCapacityInput
is the capacity of theresults
array, or 0 to indicate a request to retrieve the required capacity.resultsCountOutput
is a pointer to the count ofresults
written, or a pointer to the required capacity in the case thatresultsCapacityInput
is insufficient.results
is a pointer to an array of XrRaycastHitResultANDROID structures. It can beNULL
ifresultsCapacityInput
is 0.- See the Buffer Size Parameters section for a detailed description of
retrieving the required
results
size.
The XrRaycastHitResultsANDROID contains the array of hits of a raycast.
The runtime must set resultsCountOutput
to be less than or equal to
XrRaycastInfoANDROID::maxResults.
Valid Usage (Implicit)
- The
XR_ANDROID_raycast
extension must be enabled prior to using XrRaycastHitResultsANDROID type
must beXR_TYPE_RAYCAST_HIT_RESULTS_ANDROID
next
must beNULL
or a valid pointer to the next structure in a structure chainresults
must be a pointer to an array ofresultsCapacityInput
XrRaycastHitResultANDROID-based structures- The
resultsCapacityInput
parameter must be greater than0
The XrRaycastHitResultANDROID structure is defined as:
typedef struct XrRaycastHitResultANDROID {
XrTrackableTypeANDROID type;
XrTrackableANDROID trackable;
XrPosef pose;
} XrRaycastHitResultANDROID;
Member Descriptions
type
is the XrTrackableTypeANDROID of the trackable that the raycast hit.trackable
is theXrTrackableANDROID
that the raycast hit, orXR_NULL_TRACKABLE_ANDROID
if the trackabletype
wasXR_TRACKABLE_TYPE_DEPTH_ANDROID
.pose
is the XrPosef that the raycast hit.
The XrRaycastHitResultANDROID contains the details of a raycast hit.
The XrRaycastHitResultANDROID::pose for a plane hit must be such that X and Z are parallel to the plane, and the Y axis is normal to the plane.
Type of trackable hit |
Description |
|
Hits horizontal and/or vertical surfaces to determine a point's correct depth and orientation. |
|
Uses depth information from the entire scene to determine a point's correct depth and orientation. |
Valid Usage (Implicit)
- The
XR_ANDROID_raycast
extension must be enabled prior to using XrRaycastHitResultANDROID type
must be a valid XrTrackableTypeANDROID value
Example code for raycasting
The following example code demonstrates how to perform raycasts.
XrSession session; // previously initialized
XrTime updateTime; // previously initialized
XrSpace appSpace; // space created for XR_REFERENCE_SPACE_TYPE_LOCAL.
XrPosef headPose; // latest pose of the HMD.
XrTrackableTrackerANDROID planeTracker; // tracker for plane trackables.
XrTrackableTrackerANDROID depthTracker; // tracker for depth trackables.
// Perform a raycast against multiple trackers.
XrTrackableTrackerANDROID trackers[] = {
&planeTracker,
&depthTracker,
};
XrRaycastInfoANDROID rayInfo = {XR_TYPE_RAYCAST_INFO_ANDROID};
rayInfo.trackerCount = sizeof(trackers) / sizeof(XrTrackableTrackerANDROID);
rayInfo.trackers = trackers;
rayInfo.origin = headPose.position;
rayInfo.trajectory = CalculateForwardDirectionFromHeadPose(headPose);
rayInfo.space = appSpace;
rayInfo.time = updateTime;
uint32_t totalHitResults = 0;
constexpr uint32 NUM_DESIRED_RESULTS = 2;
XrRaycastHitResultANDROID hitResult[NUM_DESIRED_RESULTS];
XrRaycastHitResultsANDROID hitResults = {XR_TYPE_RAYCAST_HIT_RESULTS_ANDROID};
hitResults.maxResults = NUM_DESIRED_RESULTS;
hitResults.resultsCapacityInput = NUM_DESIRED_RESULTS;
hitResults.results = hitResult;
XrResult result = xrRaycastANDROID(session, &rayInfo, &hitResults);
if (result == XR_SUCCESS && hitResults.resultsCountOutput >= 1) {
// Hit results are returned in closest-to-farthest order in
// hitResults.results[0] .. hitResults.results[hitResults.resultsCountOutput - 1]
}
New Enum Constants
XrStructureType enumeration is extended with:
XR_TYPE_RAYCAST_INFO_ANDROID
XR_TYPE_RAYCAST_HIT_RESULTS_ANDROID
New Structures
New Functions
Issues
Version History
- Revision 1, 2024-10-02 (Kenny Vercaemer)
- Initial extension description