diff --git a/OpenVR-SpaceCalibrator/Calibration.cpp b/OpenVR-SpaceCalibrator/Calibration.cpp index 5472b8e..c8e017c 100644 --- a/OpenVR-SpaceCalibrator/Calibration.cpp +++ b/OpenVR-SpaceCalibrator/Calibration.cpp @@ -12,6 +12,9 @@ static IPCClient Driver; CalibrationContext CalCtx; +CalibrationState LastState = CalibrationState::None; +Eigen::Vector3d ReferenceTranslation; +Eigen::Vector3d ReferenceRotation; void InitCalibrator() { @@ -36,6 +39,8 @@ struct Pose Pose(double x, double y, double z) : trans(Eigen::Vector3d(x,y,z)) { } }; +Pose ReferencePose; + struct Sample { Pose ref, target; @@ -364,6 +369,14 @@ void StartCalibration() CalCtx.messages.clear(); } +void SetReferenceOffset() { + auto &ctx = CalCtx; + Pose pose(ctx.devicePoses[ctx.referenceID].mDeviceToAbsoluteTracking); + ReferencePose = pose; + ReferenceTranslation = ctx.calibratedTranslation; + ReferenceRotation = ctx.calibratedRotation; +} + void CalibrationTick(double time) { if (!vr::VRSystem()) @@ -400,6 +413,49 @@ void CalibrationTick(double time) return; } + if (ctx.state == CalibrationState::Referencing) + { + Pose pose(ctx.devicePoses[ctx.referenceID].mDeviceToAbsoluteTracking); + Eigen::Vector3d deltaTrans = pose.trans - ReferencePose.trans; + ctx.calibratedTranslation = (ReferenceTranslation + (deltaTrans * 100)); + + // Attempt # 1, getting teh euler delta and adding it to the original reference rotation - does not work. + //auto rotation = pose.rot.eulerAngles(2, 1, 0) * 180.0 / EIGEN_PI; + /*ctx.calibratedRotation[0] = ReferenceRotation(0) + rotation(0); + ctx.calibratedRotation[1] = ReferenceRotation(1) + rotation(1); + ctx.calibratedRotation[2] = ReferenceRotation(2) + rotation(2);*/ + //ctx.calibratedRotation[0] = rotation(0); + //ctx.calibratedRotation[1] = rotation(1); + //ctx.calibratedRotation[2] = rotation(2); + + + // Attempt #2, convert it all to quaternions ?? didnt get far with this one. + /*Eigen::Quaterniond currentQuat = + Eigen::AngleAxisd(ctx.calibratedRotation(0), Eigen::Vector3d::UnitZ()) * + Eigen::AngleAxisd(ctx.calibratedRotation(1), Eigen::Vector3d::UnitY()) * + Eigen::AngleAxisd(ctx.calibratedRotation(2), Eigen::Vector3d::UnitX()); + Eigen::Matrix3d deltaRot = pose.rot - ReferencePose.rot; + Eigen::Quaternionf delta(deltaRot); + vr::HmdQuaternion_t deltaQuat; + deltaQuat.x = delta.coeffs()[0]; + deltaQuat.y = delta.coeffs()[1]; + deltaQuat.z = delta.coeffs()[2]; + deltaQuat.w = delta.coeffs()[3];*/ + //currentQuat.normalize(); + // Eigen::Matrix3d updatedRot = currentQuat.toRotationMatrix() + deltaRot; + + + ctx.wantedUpdateInterval = 0.025; + + if ((time - ctx.timeLastScan) >= 0.025) + { + ScanAndApplyProfile(ctx); + ctx.timeLastScan = time; + } + return; + } + LastState = ctx.state; + if (ctx.state == CalibrationState::Begin) { bool ok = true; diff --git a/OpenVR-SpaceCalibrator/Calibration.h b/OpenVR-SpaceCalibrator/Calibration.h index 3a49f5c..7221aa2 100644 --- a/OpenVR-SpaceCalibrator/Calibration.h +++ b/OpenVR-SpaceCalibrator/Calibration.h @@ -11,6 +11,7 @@ enum class CalibrationState Rotation, Translation, Editing, + Referencing }; struct CalibrationContext @@ -118,4 +119,5 @@ void InitCalibrator(); void CalibrationTick(double time); void StartCalibration(); void LoadChaperoneBounds(); -void ApplyChaperoneBounds(); \ No newline at end of file +void ApplyChaperoneBounds(); +void SetReferenceOffset(); \ No newline at end of file diff --git a/OpenVR-SpaceCalibrator/OpenVR-SpaceCalibrator.cpp b/OpenVR-SpaceCalibrator/OpenVR-SpaceCalibrator.cpp index f05c505..0379d84 100644 --- a/OpenVR-SpaceCalibrator/OpenVR-SpaceCalibrator.cpp +++ b/OpenVR-SpaceCalibrator/OpenVR-SpaceCalibrator.cpp @@ -235,6 +235,26 @@ void RunLoop() keyboardOpen = true; } + vr::VREvent_t event; + while (vr::VRSystem()->PollNextEvent(&event, sizeof(event))) { + if (event.eventType == vr::VREvent_ButtonPress || event.eventType == vr::VREvent_ButtonUnpress) { + vr::VRControllerState_t state; + vr::VRSystem()->GetControllerState(CalCtx.referenceID, &state, sizeof(state)); + bool pushed = (state.ulButtonPressed & vr::ButtonMaskFromId(vr::EVRButtonId::k_EButton_Grip)) != 0; + + if (pushed) { + if (CalCtx.state == CalibrationState::Editing) { + SetReferenceOffset(); + CalCtx.state = CalibrationState::Referencing; + } + } + else if (CalCtx.state == CalibrationState::Referencing) { + SaveProfile(CalCtx); + CalCtx.state = CalibrationState::Editing; + } + } + } + vr::VREvent_t vrEvent; while (vr::VROverlay()->PollNextOverlayEvent(overlayMainHandle, &vrEvent, sizeof(vrEvent))) { diff --git a/OpenVR-SpaceCalibrator/UserInterface.cpp b/OpenVR-SpaceCalibrator/UserInterface.cpp index c19f6af..a73986d 100644 --- a/OpenVR-SpaceCalibrator/UserInterface.cpp +++ b/OpenVR-SpaceCalibrator/UserInterface.cpp @@ -156,7 +156,7 @@ void BuildMenu(bool runningInOverlay) ImGui::Columns(1); } - else if (CalCtx.state == CalibrationState::Editing) + else if (CalCtx.state == CalibrationState::Editing || CalCtx.state == CalibrationState::Referencing) { BuildProfileEditor(); @@ -165,6 +165,16 @@ void BuildMenu(bool runningInOverlay) SaveProfile(CalCtx); CalCtx.state = CalibrationState::None; } + + ImGui::Text("\n"); + ImGui::Text("Close the steam menu to grab the target space and fine adjust with the reference grip button.\n"); + ImGui::Text("When you let go it will save the profile.\n"); + ImGui::Text("\n"); + + if (ImGui::Button("Back", ImVec2(ImGui::GetWindowContentRegionWidth(), ImGui::GetTextLineHeight() * 2))) + { + CalCtx.state = CalibrationState::None; + } } else {