Closed wirelessdreamer closed 6 years ago
I've tried using
SteamVR_TrackedObject trackedObj;
trackedObj = gameObject.GetComponent
and then pulling velocity off of the tracked object, but the index's don't appear to match up.
Hi wirelessdreamer,
Basically VIU replaces the need to use SteamVR_TrackedObject. See the ViveCameraRig or ViveRig prefabs for reference. Also take a look at the guide pdf for details. Basically VivePoseTracker replaces SteamVR_TrackedObject using a role instead of an index. A benefit of using roles allows one to persist devices so that bindings can be re-established across starts easily.
I don't see a replacement method to get velocity in VIU, the only reason I tried the above was trying to find ways to get angular and rotational velocity. what is the method to get it with VUI?
In short cut:
using UnityEngine;
using HTC.UnityPlugin.Vive;
public class GetDeviceVelocity : MonoBehaviour
{
public ViveRoleProperty role = ViveRoleProperty.New(HandRole.RightHand);
public Vector3 velocity;
public Vector3 angularVelocity;
private void Update()
{
velocity = VivePose.GetVelocity(role);
angularVelocity = VivePose.GetAngularVelocity(role);
}
}
If you need more detail, you can get them from the device state, which returned from VRModule.GetCurrentDeviceState under HTC.UnityPlugin.VRModuleManagement. We will add VRModule in the document later.
using UnityEngine;
using HTC.UnityPlugin.Vive;
using HTC.UnityPlugin.VRModuleManagement;
public class PrintDeviceState : MonoBehaviour
{
public ViveRoleProperty role = ViveRoleProperty.New(HandRole.RightHand);
private void Update()
{
IVRModuleDeviceState deviceState = VRModule.GetCurrentDeviceState(role.GetDeviceIndex());
Debug.Log("isConnected=" + deviceState.isConnected);
Debug.Log("velocity=" + deviceState.velocity);
Debug.Log("angularVelocity=" + deviceState.angularVelocity);
Debug.Log("serialNumber=" + deviceState.serialNumber);
Debug.Log("modelNumber=" + deviceState.modelNumber);
Debug.Log("deviceClass=" + deviceState.deviceClass);
}
}
Thank you, thats what I was looking for.
I didn't see anything in the examples about how to read velocity or angular velocity of devices.