2

So I'm completely new to Unity and VR but for a project I need to detect the positions of the base stations.

I tried googling, but since I don't know all the lingo I don't really know where and what to look for.

All I can find is how to detect the controllers.

sollniss
  • 1,895
  • 2
  • 19
  • 36
  • I doubt this is info is exposed, because OpenVR is an abstract API for a variety of hardware. Not all hardware has base stations, e.g. Rift tracks with cameras. Other headsets may use inside-out tracking that doesn't require external sensors/lighthouses at all. This is a hidden implementation detail of tracking. – Vsevolod Golovanov Sep 14 '17 at 20:33
  • 1
    Just noticed this in the `openvr.h` header: `enum ETrackedDeviceClass { ... TrackedDeviceClass_TrackingReference = 4, // Camera and base stations that serve as tracking reference points ...}`. So you can get their positions. The `GetSortedTrackedDeviceIndicesOfClass` method should give the indices for the poses array. Well, that's if you're accessing the API directly - don't know about Unity. – Vsevolod Golovanov Sep 16 '17 at 19:23

2 Answers2

1

Here's one way, all with Unity code:

var nodeStates = new List<XRNodeState>();
InputTracking.GetNodeStates(nodeStates);

foreach (var trackedNode in nodeStates.Where(n => n.nodeType == XRNode.TrackingReference))
{
    bool hasPos = trackedNode.TryGetPosition(out var position);
    bool hasRot = trackedNode.TryGetRotation(out var rotation);

}
0

In OpenVR, base stations are "tracked devices", just like the controllers and HMD. The standard SteamVR plugin for Unity already has a way to get the position of any tracked device, see for example how the controllers are implemented in the standard [CameraRig] prefab.

The only problem is that you need to provide the "index" of the device, which may change every time you reconnect your headset. SteamVR plugin handles this with the SteamVR_ControllerManager component, but as the name suggests - it handles only controllers. You should be able to implement something similar, or just edit the script and find the lines

if (deviceClass == ETrackedDeviceClass.Controller ||
    deviceClass == ETrackedDeviceClass.GenericTracker)

and add ETrackedDeviceClass.TrackingReference to this list. You should then be able to copy the controller objects and attach them in the "additional objects" array in SteamVR_ControllerManager to have the base stations appear in your scene.

krzys_h
  • 123
  • 8