OVR: Move player with controller to the direction it points to
[mercenary-reloaded.git] / src / libovr / ovr.c
index 9083471..204f10b 100755 (executable)
@@ -100,6 +100,7 @@ static int mirror_width;
 static int mirror_height;
 static ovrEyeRenderDesc eyeRenderDesc[2];
 static ovrPosef hmdToEyeViewPose[2];
+static ovrPosef headPose;
 static ovrPosef handPoses[2];
 static ovrInputState inputState;
 static ovrLayerEyeFov layer;
@@ -239,7 +240,7 @@ error:
        return -EINVAL;
 }
 
-void get_poses_ovr(int *button_a, int *button_b, int *button_x, int *button_y, int *button_menu, int *button_trigger, int *button_left_thumb, int *button_right_thumb, double *hand_right_x, double *hand_right_y, double *hand_right_z, double *hand_right_yaw, double *hand_right_pitch, double *hand_right_roll, double *stick_left_x, double *stick_left_y, double *stick_right_x, double *stick_right_y)
+void get_poses_ovr(int *button_a, int *button_b, int *button_x, int *button_y, int *button_menu, int *button_trigger, int *button_left_thumb, int *button_right_thumb, double *hand_right_x, double *hand_right_y, double *hand_right_z, double *hand_right_yaw, double *hand_right_pitch, double *hand_right_roll, double *stick_left_x, double *stick_left_y, double *stick_right_x, double *stick_right_y, double *head_yaw, double *head_pitch, double *head_roll)
 {      
        ovrResult result;
        float yaw, pitch, roll;
@@ -249,7 +250,8 @@ void get_poses_ovr(int *button_a, int *button_b, int *button_x, int *button_y, i
        double displayMidpointSeconds = ovr_GetPredictedDisplayTime(session, frameIndex);
        ovrTrackingState hmdState = ovr_GetTrackingState(session, displayMidpointSeconds, ovrTrue);
        ovr_CalcEyePoses(hmdState.HeadPose.ThePose, hmdToEyeViewPose, layer.RenderPose);
-       /* Grab hand poses useful for rendering hand or controller representation */
+       /* Grab hand poses useful for rendering head/hand or controller representation */
+       headPose = hmdState.HeadPose.ThePose;
        handPoses[ovrHand_Left]  = hmdState.HandPoses[ovrHand_Left].ThePose;
        handPoses[ovrHand_Right] = hmdState.HandPoses[ovrHand_Right].ThePose;
        x = handPoses[ovrHand_Right].Position.x;
@@ -261,6 +263,10 @@ void get_poses_ovr(int *button_a, int *button_b, int *button_x, int *button_y, i
        *hand_right_x = x / 0.0254;
        *hand_right_y = y / 0.0254;
        *hand_right_z = z / 0.0254;
+       ovrOrientation2yawpitchroll(headPose.Orientation, &yaw, &pitch, &roll);
+       *head_yaw = yaw;
+       *head_pitch = pitch;
+       *head_roll = roll;
        ovrOrientation2yawpitchroll(handPoses[ovrHand_Right].Orientation, &yaw, &pitch, &roll);
        *hand_right_yaw = yaw;
        *hand_right_pitch = pitch;