From 4619a4ab3bddc3b36527c20c737a1026ce0056e7 Mon Sep 17 00:00:00 2001 From: Shane Harris Date: Fri, 13 Nov 2020 18:13:11 +0000 Subject: [PATCH 01/13] added in calibration state Reference and gui buttons to enable and disable, added in reference sync in the calibration tick to offset the delta from the first pose --- OpenVR-SpaceCalibrator/Calibration.cpp | 26 +++++++++++++++++++ OpenVR-SpaceCalibrator/Calibration.h | 2 ++ .../OpenVR-SpaceCalibrator.vcxproj | 1 + OpenVR-SpaceCalibrator/UserInterface.cpp | 11 ++++++++ 4 files changed, 40 insertions(+) diff --git a/OpenVR-SpaceCalibrator/Calibration.cpp b/OpenVR-SpaceCalibrator/Calibration.cpp index 5472b8e..973fde9 100644 --- a/OpenVR-SpaceCalibrator/Calibration.cpp +++ b/OpenVR-SpaceCalibrator/Calibration.cpp @@ -12,6 +12,8 @@ static IPCClient Driver; CalibrationContext CalCtx; +Pose ReferencePose; +CalibrationState LastState = CalibrationState::None; void InitCalibrator() { @@ -400,6 +402,30 @@ void CalibrationTick(double time) return; } + + if (ctx.state == CalibrationState::Referencing) + { + Pose pose = Pose(ctx.devicePoses[ctx.targetID].mDeviceToAbsoluteTracking); + if (ctx.state != LastState) { + ReferencePose = pose; + } + Eigen::Vector3d deltaTrans = pose.trans - ReferencePose.trans; + Eigen::Matrix3d deltaRot = pose.rot - ReferencePose.rot; + protocol::Request req(protocol::RequestSetDeviceTransform); + ctx.calibratedTranslation = ReferencePose.trans + deltaTrans; + ctx.calibratedRotation = (ReferencePose.rot + deltaRot).eulerAngles(2, 1, 0) * 180.0 / EIGEN_PI; + ctx.wantedUpdateInterval = 0.1; + + if ((time - ctx.timeLastScan) >= 0.1) + { + 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..f9555c1 100644 --- a/OpenVR-SpaceCalibrator/Calibration.h +++ b/OpenVR-SpaceCalibrator/Calibration.h @@ -11,6 +11,7 @@ enum class CalibrationState Rotation, Translation, Editing, + Referencing }; struct CalibrationContext @@ -26,6 +27,7 @@ struct CalibrationContext bool enabled = false; bool validProfile = false; + bool isReferenceTracking = false; double timeLastTick = 0, timeLastScan = 0; double wantedUpdateInterval = 1.0; diff --git a/OpenVR-SpaceCalibrator/OpenVR-SpaceCalibrator.vcxproj b/OpenVR-SpaceCalibrator/OpenVR-SpaceCalibrator.vcxproj index 742c6ad..1152b18 100644 --- a/OpenVR-SpaceCalibrator/OpenVR-SpaceCalibrator.vcxproj +++ b/OpenVR-SpaceCalibrator/OpenVR-SpaceCalibrator.vcxproj @@ -96,6 +96,7 @@ NotUsing + NotUsing NotUsing diff --git a/OpenVR-SpaceCalibrator/UserInterface.cpp b/OpenVR-SpaceCalibrator/UserInterface.cpp index c19f6af..9447400 100644 --- a/OpenVR-SpaceCalibrator/UserInterface.cpp +++ b/OpenVR-SpaceCalibrator/UserInterface.cpp @@ -165,6 +165,17 @@ void BuildMenu(bool runningInOverlay) SaveProfile(CalCtx); CalCtx.state = CalibrationState::None; } + + if (CalCtx.state != CalibrationState::Referencing && ImGui::Button("Reference Offset", ImVec2(ImGui::GetWindowContentRegionWidth(), ImGui::GetTextLineHeight() * 2))) + { + CalCtx.state = CalibrationState::Referencing; + } + + if (CalCtx.state == CalibrationState::Referencing && ImGui::Button("Stop Reference Offset", ImVec2(ImGui::GetWindowContentRegionWidth(), ImGui::GetTextLineHeight() * 2))) + { + SaveProfile(CalCtx); + CalCtx.state = CalibrationState::None; + } } else { From f897b92c61b67914cdcf5b3aadfeb212bf98c8f6 Mon Sep 17 00:00:00 2001 From: Shane Harris Date: Fri, 13 Nov 2020 18:14:35 +0000 Subject: [PATCH 02/13] removed uneeded variable --- OpenVR-SpaceCalibrator/Calibration.h | 1 - 1 file changed, 1 deletion(-) diff --git a/OpenVR-SpaceCalibrator/Calibration.h b/OpenVR-SpaceCalibrator/Calibration.h index f9555c1..3dc13ef 100644 --- a/OpenVR-SpaceCalibrator/Calibration.h +++ b/OpenVR-SpaceCalibrator/Calibration.h @@ -27,7 +27,6 @@ struct CalibrationContext bool enabled = false; bool validProfile = false; - bool isReferenceTracking = false; double timeLastTick = 0, timeLastScan = 0; double wantedUpdateInterval = 1.0; From 0449a36413f970908b28329ec409e599c3e23f9b Mon Sep 17 00:00:00 2001 From: Shane Harris Date: Fri, 13 Nov 2020 18:22:05 +0000 Subject: [PATCH 03/13] rmeoved precomipled headers that got added for debug --- OpenVR-SpaceCalibrator/OpenVR-SpaceCalibrator.vcxproj | 1 - 1 file changed, 1 deletion(-) diff --git a/OpenVR-SpaceCalibrator/OpenVR-SpaceCalibrator.vcxproj b/OpenVR-SpaceCalibrator/OpenVR-SpaceCalibrator.vcxproj index 1152b18..742c6ad 100644 --- a/OpenVR-SpaceCalibrator/OpenVR-SpaceCalibrator.vcxproj +++ b/OpenVR-SpaceCalibrator/OpenVR-SpaceCalibrator.vcxproj @@ -96,7 +96,6 @@ NotUsing - NotUsing NotUsing From 9e1d63b2c9fe63bdef8468883d09baad3dca8600 Mon Sep 17 00:00:00 2001 From: Shane Harris Date: Fri, 13 Nov 2020 18:35:20 +0000 Subject: [PATCH 04/13] removed uneeded line and using construct in place for pose --- OpenVR-SpaceCalibrator/Calibration.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/OpenVR-SpaceCalibrator/Calibration.cpp b/OpenVR-SpaceCalibrator/Calibration.cpp index 973fde9..45e145d 100644 --- a/OpenVR-SpaceCalibrator/Calibration.cpp +++ b/OpenVR-SpaceCalibrator/Calibration.cpp @@ -405,13 +405,12 @@ void CalibrationTick(double time) if (ctx.state == CalibrationState::Referencing) { - Pose pose = Pose(ctx.devicePoses[ctx.targetID].mDeviceToAbsoluteTracking); + Pose pose(ctx.devicePoses[ctx.targetID].mDeviceToAbsoluteTracking); if (ctx.state != LastState) { ReferencePose = pose; } Eigen::Vector3d deltaTrans = pose.trans - ReferencePose.trans; Eigen::Matrix3d deltaRot = pose.rot - ReferencePose.rot; - protocol::Request req(protocol::RequestSetDeviceTransform); ctx.calibratedTranslation = ReferencePose.trans + deltaTrans; ctx.calibratedRotation = (ReferencePose.rot + deltaRot).eulerAngles(2, 1, 0) * 180.0 / EIGEN_PI; ctx.wantedUpdateInterval = 0.1; From aa56fd5bd3a1add6705f437c6b036ed7cbbd156e Mon Sep 17 00:00:00 2001 From: Shane Harris Date: Fri, 13 Nov 2020 18:38:55 +0000 Subject: [PATCH 05/13] moves Pose reference down --- OpenVR-SpaceCalibrator/Calibration.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/OpenVR-SpaceCalibrator/Calibration.cpp b/OpenVR-SpaceCalibrator/Calibration.cpp index 45e145d..b8d71fc 100644 --- a/OpenVR-SpaceCalibrator/Calibration.cpp +++ b/OpenVR-SpaceCalibrator/Calibration.cpp @@ -12,7 +12,6 @@ static IPCClient Driver; CalibrationContext CalCtx; -Pose ReferencePose; CalibrationState LastState = CalibrationState::None; void InitCalibrator() @@ -38,6 +37,8 @@ struct Pose Pose(double x, double y, double z) : trans(Eigen::Vector3d(x,y,z)) { } }; +Pose ReferencePose; + struct Sample { Pose ref, target; From 15caa03f59ee83b380bc75eb94f36c91fa9bacd2 Mon Sep 17 00:00:00 2001 From: Shane Harris Date: Fri, 13 Nov 2020 20:15:17 +0000 Subject: [PATCH 06/13] now using correct reference offset translation/rotation --- OpenVR-SpaceCalibrator/Calibration.cpp | 10 +++++++--- OpenVR-SpaceCalibrator/UserInterface.cpp | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/OpenVR-SpaceCalibrator/Calibration.cpp b/OpenVR-SpaceCalibrator/Calibration.cpp index b8d71fc..3ec7007 100644 --- a/OpenVR-SpaceCalibrator/Calibration.cpp +++ b/OpenVR-SpaceCalibrator/Calibration.cpp @@ -13,6 +13,8 @@ static IPCClient Driver; CalibrationContext CalCtx; CalibrationState LastState = CalibrationState::None; +Eigen::Vector3d ReferenceTranslation; +Eigen::Vector3d ReferenceRotation; void InitCalibrator() { @@ -406,14 +408,16 @@ void CalibrationTick(double time) if (ctx.state == CalibrationState::Referencing) { - Pose pose(ctx.devicePoses[ctx.targetID].mDeviceToAbsoluteTracking); + Pose pose(ctx.devicePoses[ctx.referenceID].mDeviceToAbsoluteTracking); if (ctx.state != LastState) { ReferencePose = pose; + ReferenceTranslation = ctx.calibratedTranslation; + ReferenceRotation = ctx.calibratedRotation; } Eigen::Vector3d deltaTrans = pose.trans - ReferencePose.trans; Eigen::Matrix3d deltaRot = pose.rot - ReferencePose.rot; - ctx.calibratedTranslation = ReferencePose.trans + deltaTrans; - ctx.calibratedRotation = (ReferencePose.rot + deltaRot).eulerAngles(2, 1, 0) * 180.0 / EIGEN_PI; + ctx.calibratedTranslation = ReferenceTranslation + deltaTrans; + ctx.calibratedRotation = ReferenceRotation + AxisFromRotationMatrix3(deltaRot); ctx.wantedUpdateInterval = 0.1; if ((time - ctx.timeLastScan) >= 0.1) diff --git a/OpenVR-SpaceCalibrator/UserInterface.cpp b/OpenVR-SpaceCalibrator/UserInterface.cpp index 9447400..39a17ac 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(); From df3f8d8c11060575e312de71df54cd2959c20a64 Mon Sep 17 00:00:00 2001 From: Shane Harris Date: Fri, 13 Nov 2020 20:28:07 +0000 Subject: [PATCH 07/13] reverted the previous change, since it seemed to break everything --- OpenVR-SpaceCalibrator/Calibration.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/OpenVR-SpaceCalibrator/Calibration.cpp b/OpenVR-SpaceCalibrator/Calibration.cpp index 3ec7007..4a66550 100644 --- a/OpenVR-SpaceCalibrator/Calibration.cpp +++ b/OpenVR-SpaceCalibrator/Calibration.cpp @@ -416,11 +416,11 @@ void CalibrationTick(double time) } Eigen::Vector3d deltaTrans = pose.trans - ReferencePose.trans; Eigen::Matrix3d deltaRot = pose.rot - ReferencePose.rot; - ctx.calibratedTranslation = ReferenceTranslation + deltaTrans; - ctx.calibratedRotation = ReferenceRotation + AxisFromRotationMatrix3(deltaRot); - ctx.wantedUpdateInterval = 0.1; + ctx.calibratedTranslation = ReferencePose.trans + deltaTrans; + ctx.calibratedRotation = AxisFromRotationMatrix3(ReferencePose.rot + deltaRot); + ctx.wantedUpdateInterval = 0.05; - if ((time - ctx.timeLastScan) >= 0.1) + if ((time - ctx.timeLastScan) >= 0.05) { ScanAndApplyProfile(ctx); ctx.timeLastScan = time; From e2796f4c8fbce802306e40461b0307f2a7417834 Mon Sep 17 00:00:00 2001 From: PatrickQ96 Date: Sat, 14 Nov 2020 16:28:55 +0000 Subject: [PATCH 08/13] translation is now working, just need to figure out how to get the grip event somehow and how to rotate. I figure it could work with rotation offset, but it needs to rotate the tracking space wth a different origin, the position of the reference controller essentially --- OpenVR-SpaceCalibrator/Calibration.cpp | 39 ++++++++++++++++-------- OpenVR-SpaceCalibrator/Calibration.h | 6 ++-- OpenVR-SpaceCalibrator/UserInterface.cpp | 14 ++++++--- 3 files changed, 40 insertions(+), 19 deletions(-) diff --git a/OpenVR-SpaceCalibrator/Calibration.cpp b/OpenVR-SpaceCalibrator/Calibration.cpp index 4a66550..0588db0 100644 --- a/OpenVR-SpaceCalibrator/Calibration.cpp +++ b/OpenVR-SpaceCalibrator/Calibration.cpp @@ -15,6 +15,7 @@ CalibrationContext CalCtx; CalibrationState LastState = CalibrationState::None; Eigen::Vector3d ReferenceTranslation; Eigen::Vector3d ReferenceRotation; +char ReferenceBuf[256]; void InitCalibrator() { @@ -369,6 +370,19 @@ void StartCalibration() CalCtx.messages.clear(); } +char* GetReferenceTrans() { + snprintf(ReferenceBuf, sizeof ReferenceBuf, "Refference offset point: %.8f %.8f %.8f\n", ReferenceTranslation(0), ReferenceTranslation(1), ReferenceTranslation(2)); + return ReferenceBuf; +} + +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()) @@ -409,24 +423,25 @@ void CalibrationTick(double time) if (ctx.state == CalibrationState::Referencing) { Pose pose(ctx.devicePoses[ctx.referenceID].mDeviceToAbsoluteTracking); - if (ctx.state != LastState) { - ReferencePose = pose; - ReferenceTranslation = ctx.calibratedTranslation; - ReferenceRotation = ctx.calibratedRotation; - } Eigen::Vector3d deltaTrans = pose.trans - ReferencePose.trans; - Eigen::Matrix3d deltaRot = pose.rot - ReferencePose.rot; - ctx.calibratedTranslation = ReferencePose.trans + deltaTrans; - ctx.calibratedRotation = AxisFromRotationMatrix3(ReferencePose.rot + deltaRot); - ctx.wantedUpdateInterval = 0.05; - - if ((time - ctx.timeLastScan) >= 0.05) + //Eigen::Matrix3d deltaRot = pose.rot - ReferencePose.rot; + ctx.calibratedTranslation = ReferenceTranslation + (deltaTrans * 100); + //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); + + ctx.wantedUpdateInterval = 0.025; + + if ((time - ctx.timeLastScan) >= 0.025) { ScanAndApplyProfile(ctx); ctx.timeLastScan = time; } return; - } LastState = ctx.state; diff --git a/OpenVR-SpaceCalibrator/Calibration.h b/OpenVR-SpaceCalibrator/Calibration.h index 3dc13ef..313d154 100644 --- a/OpenVR-SpaceCalibrator/Calibration.h +++ b/OpenVR-SpaceCalibrator/Calibration.h @@ -100,7 +100,7 @@ struct CalibrationContext messages.push_back(Message(Message::String)); messages.back().str += msg; - std::cerr << msg; + // std::cerr << msg; } void Progress(int current, int target) @@ -119,4 +119,6 @@ void InitCalibrator(); void CalibrationTick(double time); void StartCalibration(); void LoadChaperoneBounds(); -void ApplyChaperoneBounds(); \ No newline at end of file +void ApplyChaperoneBounds(); +void SetReferenceOffset(); +char* GetReferenceTrans(); \ No newline at end of file diff --git a/OpenVR-SpaceCalibrator/UserInterface.cpp b/OpenVR-SpaceCalibrator/UserInterface.cpp index 39a17ac..ab5518d 100644 --- a/OpenVR-SpaceCalibrator/UserInterface.cpp +++ b/OpenVR-SpaceCalibrator/UserInterface.cpp @@ -166,15 +166,19 @@ void BuildMenu(bool runningInOverlay) CalCtx.state = CalibrationState::None; } - if (CalCtx.state != CalibrationState::Referencing && ImGui::Button("Reference Offset", ImVec2(ImGui::GetWindowContentRegionWidth(), ImGui::GetTextLineHeight() * 2))) + if (CalCtx.state == CalibrationState::Referencing && ImGui::Button("Stop Reference Offset", ImVec2(ImGui::GetWindowContentRegionWidth(), ImGui::GetTextLineHeight() * 2))) { - CalCtx.state = CalibrationState::Referencing; + SaveProfile(CalCtx); + CalCtx.state = CalibrationState::Editing; } - if (CalCtx.state == CalibrationState::Referencing && ImGui::Button("Stop Reference Offset", ImVec2(ImGui::GetWindowContentRegionWidth(), ImGui::GetTextLineHeight() * 2))) + if (CalCtx.state != CalibrationState::Referencing && ImGui::Button("Reference Offset", ImVec2(ImGui::GetWindowContentRegionWidth(), ImGui::GetTextLineHeight() * 2))) { - SaveProfile(CalCtx); - CalCtx.state = CalibrationState::None; + SetReferenceOffset(); + CalCtx.state = CalibrationState::Referencing; + } + if (CalCtx.state == CalibrationState::Referencing) { + ImGui::TextWrapped(GetReferenceTrans()); } } else From 5f1235e01c1055ed209fc0f745f7cad0bb45f351 Mon Sep 17 00:00:00 2001 From: PatrickQ96 Date: Sat, 14 Nov 2020 19:32:40 +0000 Subject: [PATCH 09/13] added grip to drag, only working when the vr overlay is not open though --- OpenVR-SpaceCalibrator/Calibration.h | 3 ++- .../OpenVR-SpaceCalibrator.cpp | 21 +++++++++++++++++++ OpenVR-SpaceCalibrator/UserInterface.cpp | 3 ++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/OpenVR-SpaceCalibrator/Calibration.h b/OpenVR-SpaceCalibrator/Calibration.h index 313d154..48bf1fc 100644 --- a/OpenVR-SpaceCalibrator/Calibration.h +++ b/OpenVR-SpaceCalibrator/Calibration.h @@ -29,6 +29,7 @@ struct CalibrationContext bool validProfile = false; double timeLastTick = 0, timeLastScan = 0; double wantedUpdateInterval = 1.0; + char ButtonBuf[1024]; enum Speed { @@ -100,7 +101,7 @@ struct CalibrationContext messages.push_back(Message(Message::String)); messages.back().str += msg; - // std::cerr << msg; + std::cerr << msg; } void Progress(int current, int target) diff --git a/OpenVR-SpaceCalibrator/OpenVR-SpaceCalibrator.cpp b/OpenVR-SpaceCalibrator/OpenVR-SpaceCalibrator.cpp index f05c505..fa42e14 100644 --- a/OpenVR-SpaceCalibrator/OpenVR-SpaceCalibrator.cpp +++ b/OpenVR-SpaceCalibrator/OpenVR-SpaceCalibrator.cpp @@ -235,7 +235,28 @@ void RunLoop() keyboardOpen = true; } + vr::VREvent_t event; + while (vr::VRSystem()->PollNextEvent(&event, sizeof(event))) { + vr::VRControllerState_t state; + vr::VRSystem()->GetControllerState(CalCtx.referenceID, &state, sizeof(state)); + bool pushed = (state.ulButtonPressed & vr::ButtonMaskFromId(vr::EVRButtonId::k_EButton_Grip)) != 0; + //snprintf(CalCtx.ButtonBuf, sizeof CalCtx.ButtonBuf, "VREvent_ButtonPress: %d\n", (state.ulButtonPressed & vr::ButtonMaskFromId(vr::EVRButtonId::k_EButton_A))); + + if (pushed) { + //snprintf(CalCtx.ButtonBuf, sizeof CalCtx.ButtonBuf, "pushed\n"); + 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; + vr::VRControllerState_t state; + bool pushed = false; while (vr::VROverlay()->PollNextOverlayEvent(overlayMainHandle, &vrEvent, sizeof(vrEvent))) { switch (vrEvent.eventType) { diff --git a/OpenVR-SpaceCalibrator/UserInterface.cpp b/OpenVR-SpaceCalibrator/UserInterface.cpp index ab5518d..a1e2452 100644 --- a/OpenVR-SpaceCalibrator/UserInterface.cpp +++ b/OpenVR-SpaceCalibrator/UserInterface.cpp @@ -171,7 +171,7 @@ void BuildMenu(bool runningInOverlay) SaveProfile(CalCtx); CalCtx.state = CalibrationState::Editing; } - + if (CalCtx.state != CalibrationState::Referencing && ImGui::Button("Reference Offset", ImVec2(ImGui::GetWindowContentRegionWidth(), ImGui::GetTextLineHeight() * 2))) { SetReferenceOffset(); @@ -179,6 +179,7 @@ void BuildMenu(bool runningInOverlay) } if (CalCtx.state == CalibrationState::Referencing) { ImGui::TextWrapped(GetReferenceTrans()); + ImGui::TextWrapped(CalCtx.ButtonBuf); } } else From 31ed4450b6a29a9a737a286166ad2bb7b8665c34 Mon Sep 17 00:00:00 2001 From: PatrickQ96 Date: Sat, 14 Nov 2020 19:40:00 +0000 Subject: [PATCH 10/13] removed uneeded debug stuff --- OpenVR-SpaceCalibrator/Calibration.cpp | 5 --- OpenVR-SpaceCalibrator/Calibration.h | 4 +-- .../OpenVR-SpaceCalibrator.cpp | 31 ++++++++++--------- OpenVR-SpaceCalibrator/UserInterface.cpp | 4 --- 4 files changed, 17 insertions(+), 27 deletions(-) diff --git a/OpenVR-SpaceCalibrator/Calibration.cpp b/OpenVR-SpaceCalibrator/Calibration.cpp index 0588db0..3c96b5f 100644 --- a/OpenVR-SpaceCalibrator/Calibration.cpp +++ b/OpenVR-SpaceCalibrator/Calibration.cpp @@ -370,11 +370,6 @@ void StartCalibration() CalCtx.messages.clear(); } -char* GetReferenceTrans() { - snprintf(ReferenceBuf, sizeof ReferenceBuf, "Refference offset point: %.8f %.8f %.8f\n", ReferenceTranslation(0), ReferenceTranslation(1), ReferenceTranslation(2)); - return ReferenceBuf; -} - void SetReferenceOffset() { auto &ctx = CalCtx; Pose pose(ctx.devicePoses[ctx.referenceID].mDeviceToAbsoluteTracking); diff --git a/OpenVR-SpaceCalibrator/Calibration.h b/OpenVR-SpaceCalibrator/Calibration.h index 48bf1fc..7221aa2 100644 --- a/OpenVR-SpaceCalibrator/Calibration.h +++ b/OpenVR-SpaceCalibrator/Calibration.h @@ -29,7 +29,6 @@ struct CalibrationContext bool validProfile = false; double timeLastTick = 0, timeLastScan = 0; double wantedUpdateInterval = 1.0; - char ButtonBuf[1024]; enum Speed { @@ -121,5 +120,4 @@ void CalibrationTick(double time); void StartCalibration(); void LoadChaperoneBounds(); void ApplyChaperoneBounds(); -void SetReferenceOffset(); -char* GetReferenceTrans(); \ No newline at end of file +void SetReferenceOffset(); \ No newline at end of file diff --git a/OpenVR-SpaceCalibrator/OpenVR-SpaceCalibrator.cpp b/OpenVR-SpaceCalibrator/OpenVR-SpaceCalibrator.cpp index fa42e14..a3b24ca 100644 --- a/OpenVR-SpaceCalibrator/OpenVR-SpaceCalibrator.cpp +++ b/OpenVR-SpaceCalibrator/OpenVR-SpaceCalibrator.cpp @@ -237,26 +237,27 @@ void RunLoop() vr::VREvent_t event; while (vr::VRSystem()->PollNextEvent(&event, sizeof(event))) { - vr::VRControllerState_t state; - vr::VRSystem()->GetControllerState(CalCtx.referenceID, &state, sizeof(state)); - bool pushed = (state.ulButtonPressed & vr::ButtonMaskFromId(vr::EVRButtonId::k_EButton_Grip)) != 0; - //snprintf(CalCtx.ButtonBuf, sizeof CalCtx.ButtonBuf, "VREvent_ButtonPress: %d\n", (state.ulButtonPressed & vr::ButtonMaskFromId(vr::EVRButtonId::k_EButton_A))); - - if (pushed) { - //snprintf(CalCtx.ButtonBuf, sizeof CalCtx.ButtonBuf, "pushed\n"); - if (CalCtx.state == CalibrationState::Editing) { - SetReferenceOffset(); - CalCtx.state = CalibrationState::Referencing; + 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; + //snprintf(CalCtx.ButtonBuf, sizeof CalCtx.ButtonBuf, "VREvent_ButtonPress: %d\n", (state.ulButtonPressed & vr::ButtonMaskFromId(vr::EVRButtonId::k_EButton_A))); + + if (pushed) { + //snprintf(CalCtx.ButtonBuf, sizeof CalCtx.ButtonBuf, "pushed\n"); + if (CalCtx.state == CalibrationState::Editing) { + SetReferenceOffset(); + CalCtx.state = CalibrationState::Referencing; + } + } + else if (CalCtx.state == CalibrationState::Referencing) { + SaveProfile(CalCtx); + CalCtx.state = CalibrationState::Editing; } - }else if(CalCtx.state == CalibrationState::Referencing){ - SaveProfile(CalCtx); - CalCtx.state = CalibrationState::Editing; } } vr::VREvent_t vrEvent; - vr::VRControllerState_t state; - bool pushed = false; while (vr::VROverlay()->PollNextOverlayEvent(overlayMainHandle, &vrEvent, sizeof(vrEvent))) { switch (vrEvent.eventType) { diff --git a/OpenVR-SpaceCalibrator/UserInterface.cpp b/OpenVR-SpaceCalibrator/UserInterface.cpp index a1e2452..9797163 100644 --- a/OpenVR-SpaceCalibrator/UserInterface.cpp +++ b/OpenVR-SpaceCalibrator/UserInterface.cpp @@ -177,10 +177,6 @@ void BuildMenu(bool runningInOverlay) SetReferenceOffset(); CalCtx.state = CalibrationState::Referencing; } - if (CalCtx.state == CalibrationState::Referencing) { - ImGui::TextWrapped(GetReferenceTrans()); - ImGui::TextWrapped(CalCtx.ButtonBuf); - } } else { From 9ce213355fa921aedc5efcea20d3dd4d231dd901 Mon Sep 17 00:00:00 2001 From: PatrickQ96 Date: Sat, 14 Nov 2020 19:42:05 +0000 Subject: [PATCH 11/13] removed one last unused line --- OpenVR-SpaceCalibrator/Calibration.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/OpenVR-SpaceCalibrator/Calibration.cpp b/OpenVR-SpaceCalibrator/Calibration.cpp index 3c96b5f..58f90cc 100644 --- a/OpenVR-SpaceCalibrator/Calibration.cpp +++ b/OpenVR-SpaceCalibrator/Calibration.cpp @@ -15,7 +15,6 @@ CalibrationContext CalCtx; CalibrationState LastState = CalibrationState::None; Eigen::Vector3d ReferenceTranslation; Eigen::Vector3d ReferenceRotation; -char ReferenceBuf[256]; void InitCalibrator() { From 500d2ecb7acce5907813eab390e75615bac99d1c Mon Sep 17 00:00:00 2001 From: PatrickQ96 Date: Sun, 15 Nov 2020 14:53:22 +0000 Subject: [PATCH 12/13] more attempts at the rotaition calculations, unsuccessfully. Added explanation to edit screen on how to fine adjust --- OpenVR-SpaceCalibrator/Calibration.cpp | 23 ++++++++++++++++++++--- OpenVR-SpaceCalibrator/UserInterface.cpp | 16 +++++++--------- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/OpenVR-SpaceCalibrator/Calibration.cpp b/OpenVR-SpaceCalibrator/Calibration.cpp index 58f90cc..c8e017c 100644 --- a/OpenVR-SpaceCalibrator/Calibration.cpp +++ b/OpenVR-SpaceCalibrator/Calibration.cpp @@ -413,13 +413,13 @@ void CalibrationTick(double time) return; } - if (ctx.state == CalibrationState::Referencing) { Pose pose(ctx.devicePoses[ctx.referenceID].mDeviceToAbsoluteTracking); Eigen::Vector3d deltaTrans = pose.trans - ReferencePose.trans; - //Eigen::Matrix3d deltaRot = pose.rot - ReferencePose.rot; - ctx.calibratedTranslation = ReferenceTranslation + (deltaTrans * 100); + 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); @@ -428,6 +428,23 @@ void CalibrationTick(double time) //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) diff --git a/OpenVR-SpaceCalibrator/UserInterface.cpp b/OpenVR-SpaceCalibrator/UserInterface.cpp index 9797163..a73986d 100644 --- a/OpenVR-SpaceCalibrator/UserInterface.cpp +++ b/OpenVR-SpaceCalibrator/UserInterface.cpp @@ -166,16 +166,14 @@ void BuildMenu(bool runningInOverlay) CalCtx.state = CalibrationState::None; } - if (CalCtx.state == CalibrationState::Referencing && ImGui::Button("Stop Reference Offset", ImVec2(ImGui::GetWindowContentRegionWidth(), ImGui::GetTextLineHeight() * 2))) - { - SaveProfile(CalCtx); - CalCtx.state = CalibrationState::Editing; - } - - if (CalCtx.state != CalibrationState::Referencing && ImGui::Button("Reference Offset", ImVec2(ImGui::GetWindowContentRegionWidth(), ImGui::GetTextLineHeight() * 2))) + 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))) { - SetReferenceOffset(); - CalCtx.state = CalibrationState::Referencing; + CalCtx.state = CalibrationState::None; } } else From 439aff9a5a21a679df0bbb36ed2ee2e4dd3b236e Mon Sep 17 00:00:00 2001 From: PatrickQ96 Date: Sun, 15 Nov 2020 14:57:09 +0000 Subject: [PATCH 13/13] removed some uneeded logs --- OpenVR-SpaceCalibrator/OpenVR-SpaceCalibrator.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/OpenVR-SpaceCalibrator/OpenVR-SpaceCalibrator.cpp b/OpenVR-SpaceCalibrator/OpenVR-SpaceCalibrator.cpp index a3b24ca..0379d84 100644 --- a/OpenVR-SpaceCalibrator/OpenVR-SpaceCalibrator.cpp +++ b/OpenVR-SpaceCalibrator/OpenVR-SpaceCalibrator.cpp @@ -241,10 +241,8 @@ void RunLoop() vr::VRControllerState_t state; vr::VRSystem()->GetControllerState(CalCtx.referenceID, &state, sizeof(state)); bool pushed = (state.ulButtonPressed & vr::ButtonMaskFromId(vr::EVRButtonId::k_EButton_Grip)) != 0; - //snprintf(CalCtx.ButtonBuf, sizeof CalCtx.ButtonBuf, "VREvent_ButtonPress: %d\n", (state.ulButtonPressed & vr::ButtonMaskFromId(vr::EVRButtonId::k_EButton_A))); - + if (pushed) { - //snprintf(CalCtx.ButtonBuf, sizeof CalCtx.ButtonBuf, "pushed\n"); if (CalCtx.state == CalibrationState::Editing) { SetReferenceOffset(); CalCtx.state = CalibrationState::Referencing;