Forum Discussion
9of9
11 years agoExpert Protege
Getting IR Camera Transform
Just curious if anyone's poked around and found a way to get the transform for the IR camera in worldspace? It's the sort of thing that would be quite nice to have, similar to the way you can enable camera bounds in the demo scene, to help inform the player of the bounds of their movement.
26 Replies
Replies have been turned off for this discussion
- 9of9Expert ProtegeYay! At last, this works. It kinda sucks that the Unity integration doesn't seem to have any obvious methods for doing this - unlike UE4, for instance - but it's proven reasonably simple to add.
You'll want to create a function something like this one - I've included with the appropriate references so you can stick it into an arbitrary component, but it really makes the most sense for it to be part of OVRDevice.cs:using OVR;
bool GetIRCamera(ref Vector3 position,
ref Quaternion rotation,
ref float cameraHFov,
ref float cameraVFov,
ref float cameraNearZ,
ref float cameraFarZ)
{
if (OVRDevice.HMD == null || !OVRDevice.SupportedPlatform)
return false;
ovrTrackingState ss = OVRDevice.HMD.GetTrackingState();
rotation = new Quaternion( ss.CameraPose.Orientation.x,
ss.CameraPose.Orientation.y,
ss.CameraPose.Orientation.z,
ss.CameraPose.Orientation.w);
position = new Vector3( ss.CameraPose.Position.x,
ss.CameraPose.Position.y,
ss.CameraPose.Position.z);
ovrHmdDesc desc = OVRDevice.HMD.GetDesc();
cameraHFov = desc.CameraFrustumHFovInRadians;
cameraVFov = desc.CameraFrustumVFovInRadians;
cameraNearZ = desc.CameraFrustumNearZInMeters;
cameraFarZ = desc.CameraFrustumFarZInMeters;
OVRDevice.OrientSensor (ref rotation);
return true;
}
For the sake of convenience, I've also uploaded a hastily thrown-together .unitypackage with everything anyone else might need in order to set up a quick and effective viewCone, to show the user the bounds of the camera cone - or just to salvage for reusable code. To set it up with an OVRCameraController just stick the OVRHelper/ViewCone prefab as a child under the OVRCameraController in your scene/prefab and make sure its transform is properly zeroed out. Then add in the OVRCameraController component of its parent into the Camera Controller slot on the ViewCone's own OVRViewCone component.
The result will be that as you lean toward the outer boundaries of the camera's view cone, little squares will fade in when you get too close, indicating that it's a boundary. You can tweak the included material to change the colour, tiling and the distance at which they start to fade in.
The ViewCone script also includes by default mapping the Enter key and the 'A' button on the controller to resetting the view, which needs to trigger updating the ViewCone position.
The correct setup:
The expected result.
You should be able to grab the .unitypackage itself from here. - sholeHonored GuestThanks!
I was just about to post my own implementation of this, but this is better than mine.
I suggest you make updateCameraTracker() public, so it can be hooked to view-reset functions elsewhere. - drashHeroic ExplorerAwesome! Very flexible approach. I'm going to drop this into my demos right now until I get my own version working.
Thank you for this! :) - FanghExplorerHi I am above the cone, I don't know why.
What are the value of your CameraRootPosition and NeckPosition in the inspector for your OVRCameraController ?
Thank you =) - BoffExplorerThank you so much for this 9of9!
Does this use the OVR settings for the bounds of the positional tracking camera/are they configurable?
In Unity there seems to be much less room for movement than in the Desk demo scene (from my experience anyway).
I'm pretty close to the camera and when I lean back in my chair I always get the 'Out of Range' message.
Edit:
Looking at the code you posted you're just getting the OVR values already used - so this is just for displaying the camera bounds without being able to change the values? - drashHeroic Explorer
"Boff" wrote:
Edit:
Looking at the code you posted you're just getting the OVR values already used - so this is just for displaying the camera bounds without being able to change the values?
Yeah it just displays the bounds based on what the OVR SDK reports -- seems fairly future proof re different tracking cameras that may be used in the future. There is one thing you can configure though: the material 9of9 provides will smoothly reveal an alpha-clipped texture as a function of distance to the camera. You can change *that* value. Too small and it won't give the player enough warning before they go out of bounds, too large and it will annoy the player by getting in the way needlessly. This value also depends on the range of values present in the texture you use.
If you're getting the "out of range" message, then you are probably using OVRMainMenu which has a different way of checking for the player going out of bounds. If you wanted to keep the OVRMainMenu functionality but not have the warning messages, you could probably get into the OVRMainMenu code and comment out the part where it instantiates an OVRVisionGuide (for now, at least). - BoffExplorer
"drash" wrote:
.....
If you're getting the "out of range" message, then you are probably using OVRMainMenu which has a different way of checking for the player going out of bounds. If you wanted to keep the OVRMainMenu functionality but not have the warning messages, you could probably get into the OVRMainMenu code and comment out the part where it instantiates an OVRVisionGuide (for now, at least).
Thanks Drash that's very helpful! I was indeed using OVRMainMenu. To be honest I'm only using it for FPS display as the script I'm using (actually your FPS script with some colour added) doesn't seem to work with the 0.4.x SDKs. - 9of9Expert ProtegeYeah, OVRMainMenu's method for checking bounds is pretty simple - it just seems to define a bounding box, which isn't really that accurate given that you're talking about a viewcone. The only thing you might want to keep is some check for when you're going too far back - the script resizes the camera's viewcone to the current Z-depth of the camera as reported by OVRDevice, but that's currently not too helpful unless you're looking back to check :P
"Fangh" wrote:
Hi I am above the cone, I don't know why.
What are the value of your CameraRootPosition and NeckPosition in the inspector for your OVRCameraController ?
Thank you =)
Try pressing Enter (or A on a gamepad) after you've loaded up, to reset camera orientation. Sometimes when it's initialising it can't quite get the headset location and therefore the IR camera location ends up being off like that - resetting the camera orientation should fix it. All the relative positions and measurements it gets, it gets directly from the Oculus software, so as far as I know the only thing that can go wrong is that it can get them too early at the start, when the Rift's drivers haven't worked out the tracking info properly yet. - poxaHonored GuestThank you so much 9of9!,
very useful, helped me out so much!
Thanks again for sharing this! - SirTexMurphyHonored GuestThanks as well!
Can anybody tell me why the pose of the camera is only updated once in about 2 seconds?
ovrTrackingState ss = ovrHmd_GetTrackingState(HMD, 0.0);
printf("%f\n", ss.CameraPose.Orientation.x);
TIA
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 10 months ago
- 2 months ago