OculusControllerCode

From Immersive Visualization Lab Wiki
Revision as of 16:43, 9 April 2018 by Jschulze (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
// Query Touch controllers. Query their parameters:
double displayMidpointSeconds = ovr_GetPredictedDisplayTime(_session, 0);
ovrTrackingState trackState = ovr_GetTrackingState(_session, displayMidpointSeconds, ovrTrue);

// Process controller status. Useful to know if controller is being used at all, and if the cameras can see it. 
// Bits reported:
// Bit 1: ovrStatus_OrientationTracked  = Orientation is currently tracked (connected and in use)
// Bit 2: ovrStatus_PositionTracked     = Position is currently tracked (false if out of range)
unsigned int handStatus[2];
handStatus[0] = trackState.HandStatusFlags[0];
handStatus[1] = trackState.HandStatusFlags[1];
// Display status for debug purposes:
cerr << "handStatus[left]  = " << handStatus[ovrHand_Left]  << endl;
cerr << "handStatus[right] = " << handStatus[ovrHand_Right] << endl;

// Process controller position and orientation:
ovrPosef handPoses[2];  // These are position and orientation in meters in room coordinates, relative to tracking origin. Right-handed cartesian coordinates.
                        // ovrQuatf     Orientation;
                        // ovrVector3f  Position;
handPoses[0] = trackState.HandPoses[0].ThePose;
handPoses[1] = trackState.HandPoses[1].ThePose;
ovrVector3f handPosition[2];
handPosition[0] = handPoses[0].Position;
handPosition[1] = handPoses[1].Position;
// Display positions for debug purposes:
cerr << "left hand position  = " << handPosition[ovrHand_Left].x  << ", " <<  handPosition[ovrHand_Left].y  << ", " << handPosition[ovrHand_Left].z  << endl;
cerr << "right hand position = " << handPosition[ovrHand_Right].x << ", " <<  handPosition[ovrHand_Right].y << ", " << handPosition[ovrHand_Right].z << endl;