Head orientation/position in stage space

I’m trying to get an object to appear in front of the viewer (and then stay there). I’ve got this to work by calculating the center point between the two eyes and using the direction of the left eye (using data from xrLocateViews with a Stage space) to offset the object, but shouldn’t there be a cleaner way to do this by getting the head orientation/position? I’ve tried getting the pose of "/user/head", but that doesn’t work on my Quest.

In another thread I’ve seen that I should use a XR_REFERENCE_SPACE_TYPE_VIEW, but how? xrLocateViews still returns two orientations/positions. I’ve also tried to use xrLocateSpace with the view space and stage space as parameters, but that results in a fixed position and orientation, regardless of how I move the headset.

I guess my issue boils down to: how do I get ‘the’ orientation/position of the headset in the stage space?

1 Like

XR_REFERENCE_SPACE_TYPE_VIEW is indeed intended for this use.

VIEW space is primarily useful when projecting from the user’s perspective into another space to obtain a targeting ray, or when rendering small head-locked content such as a reticle. Content rendered in VIEW space will stay at a fixed point on head-mounted displays and may be uncomfortable to view if too large.

I just tried it out on SteamVR, first creating a stage reference space and a view reference space

	XrReferenceSpaceCreateInfo stage_space_info = {
		{ {0, 0, 0, 1}, {0, 0, 0} }
	XrSpace stage_space;
	xrCreateReferenceSpace(session, &stage_space_info, &stage_space);

	XrReferenceSpaceCreateInfo view_space_info = {
		{ {0, 0, 0, 1}, {0, 0, 0} }
	XrSpace view_space;
	xrCreateReferenceSpace(session, &view_space_info, &view_space);

And then after xrWaitFrame (to get the predictedDisplayTime)

		XrSpaceLocation view_in_stage = { XR_TYPE_SPACE_LOCATION, NULL, 0, {{0, 0, 0, 1}, {0, 0, 0}} };
		xrLocateSpace(view_space, stage_space, frame_state.predictedDisplayTime, &view_in_stage);

At least on SteamVR this works as expected and prints x, y, z coordinates that correspond to how I move the headset.

Thanks for your quick reply, after the reassurance that this is supposed to be the correct method, I actually did get it to work!