HTC Vive Tracker Developer Manuallines page 35

Hide thumbs Also See for Vive Tracker:
Table of Contents

Advertisement

Another Unity sample code shows how to transform the accessory by comparing vectors
parallel to y-axis and z-axis of the Vive Tracker (AxisY_Tracker, AxisZ_Tracker in example
below) and the accessory (AxisY_Accessory, AxisZ_Accessory in example below).
public class Accessory : MonoBehaviour {
const Vector3 AxisY_Tracker = new Vectors(AxisY_Tracker_X, AxisY_Tracker_Y,
AxisY_Tracker_Z);
const Vector3 AxisZ_Tracker = new Vectors(AxisZ_Tracker_X, AxisZ_Tracker_Y,
AxisZ_Tracker_Z);
const Vector3 AxisY_Accessory = new Vectors(AxisY_ Accessory _X, AxisY_ Accessory _Y,
AxisY_ Accessory _Z);
const Vector3 AxisZ_ Accessory = new Vectors(AxisZ_ Accessory _X, AxisZ_ Accessory _Y,
AxisZ_ Accessory _Z);
void Update () {
//Calculate delta rotation by comparing vectors parallel to Y axes of Tracker and the accessory
Quaternion delta_rotY = Quaternion.FromToRotation(AxisY_Tracker, AxisY_Accessory);
AxisZ_Tracker = delta_rotY * AxisZ_Tracker;
Quaternion delta_rotZ = Quaternion.FromToRotation(AxisZ_Tracker, AxisZ_Accessory);
//Collect delta rotation and displacement between Tracker and Accessory
Vector3 delta_displacement = new Vector3(dX, dY, dZ);
Quaternion delta_rotation = delta_rotZ * delta_rotY;
//Get current Tracker pose
Vector3 tracker_position
Quaternion tracker_rotation = SteamVR_Controller.Input(3).transform.rot;
//Transform current Tracker pose to Accessory pose
GameObject.Find("Accessory ").transform.rotation = delta_rotation * tracker_rotation;
GameObject.Find("Accessory ").transform.position = tracker_position + (delta_rotation *
tracker_rotation) * delta_displacement;
}
}
Vive Tracker
HTC Corporation
= SteamVR_Controller.Input(3).transform.pos;
Figure: Unity sample code for accessory integration (2)
Developer Guidelines
07/17/2017
Ver. 1.5
32
HTC Confidential and Proprietary

Advertisement

Table of Contents
loading

Table of Contents