How do i get oculus mhd position and other properties via c++ ?

I’v implemented the “HeadMountedDisplay” module in my projectName.Build.cs class.
I’v added this header at the top of my h and cpp files:


#include "Runtime/HeadMountedDisplay/Public/IHeadMountedDisplay.h"

I’v tried these:


auto riftHMD = GEngine->HMDDevice.Get();

Compiles but i can’t get anything out of riftHMD, it doesn’t giving me options when trying riftHMD. or riftHMD → .


auto riftHMD = GEngine->HMDDevice;

Gives:



auto riftHMD = Cast<IHeadMountedDisplay>(GEngine->HMDDevice);

Gives:



auto riftHMD = Cast<IHeadMountedDisplay>(GEngine->.Get());

Gives:


How is it supposed to be done?

Ok it seems like this one works:


riftHMD = GEngine->HMDDevice.Get(); 

Don’t know why it didn’t give me options like any other variable/funciton…

Ok and now the values it giving me making no sense.

I’v looked into this page:

and i tried:


GetPositionalTrackingCameraProperties
(
    FVector & OutOrigin,
    FRotator & OutOrientation,
    float & OutHFOV,
    float & OutVFOV,
    float & OutCameraDistance,
    float & OutNearPlane,
    float & OutFarPlane
)

and:


GetCurrentOrientationAndPosition
(
    FQuat & CurrentOrientation,
    FVector & CurrentPosition
)

And both are giving me values that doesn’t really have anything to do with where the mountedHeadDevice in the world.

Ok GetCurrentOrientationAndPosition gives me position “RELATED” to the character! I guess there is no way to get the world position right? i will just have to add it to the character position.

Ok GetCurrentOrientationAndPosition gives me the position relative to the character and will not change if the character is rotating, so just adding them would do the trick, why is there no simple “GetWorldPosition” function ?! Isn’t it obvious that the world position is one of the most wanted value developers will look for between all that functions in that big list?
I need to make some actor to look at me, why does it have to be so difficult?

Use camera location. In VR, the camera location and rotation end up being the actual HMD. That should help you. Its what im doing to trace the view target and use the head to aim.
Just get CameraManager->GetCameraLocation() to get the world location of the camera, in VR, its also the updated camera with the HMD offsets.

I Tried that, and it doesn’t consider my head movements.

It will show a line from it to my character’s head start location but won’t follow it around.

You were indeed right, so i went and tried to find a way to get it to work
and found it.




FVector Loc;
	
	FQuat quat;
	
	//get local space HMD orientation
	GEngine->HMDDevice->GetCurrentOrientationAndPosition(quat, Loc);

        //get player controller 
	APlayerController *PlayerController = Cast<APlayerController>(Controller);

        //rotate the local space hmd position, then sum the camera 0 location to it
	FVector finalloc = GetActorRotation().RotateVector(Loc) + PlayerController->PlayerCameraManager->GetCameraLocation(); 



You get the local position of the HMD, then rotate it with your current pawn rotation, then you add the camera location to it. We use actor rotation and not camera rotation becouse the camera rotation actualy DOES change with the HMD rotation, we want the “Zero” rotation, so we get the pawn one.
In this, finalloc ends up being the final HMD position in world rotation, exactly in the middle beetween both eyes. This is on a vehicle-like oculus implementation, where the pawn doenst turn when you turn the head.

Thanks! Great and simple solution! Have my like XD