openvr icon indicating copy to clipboard operation
openvr copied to clipboard

Help Rotation Overlay Openvr

Open arjdev69 opened this issue 9 years ago • 2 comments

Guys, I'm creating an overlay and I want to always position it in front of the user as the Steam Dashboard does. I'm using the following function created by me:

void SteamVRController::SetPositionOverlay(vr::VROverlayHandle_t m_ulOverlayH, vr::HmdVector2_t sizeOverlay) { SetMatrixPosition(angle, axis, positionX, positionY, positionZ);

vr::VROverlay()->SetOverlayTransformTrackedDeviceRelative(m_ulOverlayH, vr::k_unTrackedDeviceIndex_Hmd, &HmDTransform);
vr::VROverlay()->GetTransformForOverlayCoordinates(m_ulOverlayH, vr::VRCompositor()->GetTrackingSpace(), m_overlayCenter, &HmDTransform);
vr::VROverlay()->SetOverlayTransformAbsolute(m_ulOverlayH, vr::VRCompositor()->GetTrackingSpace(), &HmDTransform);

SetMethodsInOverlay(m_ulOverlayH, sizeOverlay);

}

void SteamVRController::SetMatrixPosition(float angle, int axis, float positionX, float positionY, float positionZ) {

utils::initRotationMatrix(HmDTransform, axis, angle);
HmDTransform.m[0][3] = positionX;
HmDTransform.m[1][3] = positionY;
HmDTransform.m[2][3] = positionZ;

m_overlayCenter = {
	m_overlayCenter.v[0] = 0.0f,
	m_overlayCenter.v[1] = 0.3f
};

}

The verlay is always appearing in front of the user, the problem is that it is with the oculus rotation. If the user has his head tilted the verlay will have the same rotation.

Thank you guys.

arjdev69 avatar Jul 19 '17 13:07 arjdev69

This is what the dashboard uses:

vr::HmdMatrix34_t ComputeHmdFacingTransform( float fDistanceMeters, Vector vSystemOverlayOffset )
{
	vr::TrackedDevicePose_t rPoses[vr::k_unMaxTrackedDeviceCount];
	vr::VRSystem()->GetDeviceToAbsoluteTrackingPose( vr::TrackingUniverseStanding, 0, rPoses, vr::k_unMaxTrackedDeviceCount );


	// figure out where to start putting things
	VMatrix matStandingFromHmd = VMatrixFromHmdMatrix( rPoses[vr::k_unTrackedDeviceIndex_Hmd].mDeviceToAbsoluteTracking );

	const Vector s_vSystemOverlayStartOffset = { 0, 0, -fDistanceMeters };
	static const Vector s_vUp = { 0, 1, 0 };
	Vector vSystemOverlayStart = matStandingFromHmd * s_vSystemOverlayStartOffset;
	Vector vTempForward = (vSystemOverlayStart - matStandingFromHmd.GetTranslation()).Normalized();
	Vector vRight = vTempForward.Cross( s_vUp ).Normalized();
	Vector vForward = s_vUp.Cross( vRight ).Normalized();
	Vector vBackward = vForward * -1.f;

	vSystemOverlayStart = matStandingFromHmd.GetTranslation() + vForward * fDistanceMeters;
	vSystemOverlayStart += vSystemOverlayOffset;

	VMatrix matStandingFromMainDash = VMatrix( vRight, s_vUp, vBackward );
	matStandingFromMainDash.SetTranslation( vSystemOverlayStart );

	return HmdMatrixFromVMatrix( matStandingFromMainDash );
}

It's using our internal Vector and VMatrix classes, which confuses things a bit, but hopefully that helps.

JoeLudwig avatar Jul 19 '17 18:07 JoeLudwig

Thank you. How do I include these class VMatrix and Vector, or would it be download them?. Thank You

arjdev69 avatar Jul 24 '17 14:07 arjdev69