diff --git a/OpenVR-SpaceCalibrator/Calibration.cpp b/OpenVR-SpaceCalibrator/Calibration.cpp index 5472b8e..cac0fbb 100644 --- a/OpenVR-SpaceCalibrator/Calibration.cpp +++ b/OpenVR-SpaceCalibrator/Calibration.cpp @@ -269,7 +269,7 @@ void ResetAndDisableOffsets(uint32_t id) zeroQ.x = 0; zeroQ.y = 0; zeroQ.z = 0; zeroQ.w = 1; protocol::Request req(protocol::RequestSetDeviceTransform); - req.setDeviceTransform = { id, false, zeroV, zeroQ }; + req.setDeviceTransform = { id, false, zeroV, zeroQ, 1.0 }; Driver.SendBlocking(req); } @@ -338,7 +338,8 @@ void ScanAndApplyProfile(CalibrationContext &ctx) id, true, VRTranslationVec(ctx.calibratedTranslation), - VRRotationQuat(ctx.calibratedRotation) + VRRotationQuat(ctx.calibratedRotation), + ctx.calibratedScale }; Driver.SendBlocking(req); } diff --git a/OpenVR-SpaceCalibrator/Calibration.h b/OpenVR-SpaceCalibrator/Calibration.h index 3a49f5c..df55484 100644 --- a/OpenVR-SpaceCalibrator/Calibration.h +++ b/OpenVR-SpaceCalibrator/Calibration.h @@ -20,6 +20,7 @@ struct CalibrationContext Eigen::Vector3d calibratedRotation; Eigen::Vector3d calibratedTranslation; + double calibratedScale; std::string referenceTrackingSystem; std::string targetTrackingSystem; @@ -57,6 +58,7 @@ struct CalibrationContext calibratedRotation = Eigen::Vector3d(); calibratedTranslation = Eigen::Vector3d(); + calibratedScale = 1.0; referenceTrackingSystem = ""; targetTrackingSystem = ""; enabled = false; diff --git a/OpenVR-SpaceCalibrator/Configuration.cpp b/OpenVR-SpaceCalibrator/Configuration.cpp index e068c27..1d27fdb 100644 --- a/OpenVR-SpaceCalibrator/Configuration.cpp +++ b/OpenVR-SpaceCalibrator/Configuration.cpp @@ -54,6 +54,11 @@ static void ParseProfile(CalibrationContext &ctx, std::istream &stream) ctx.calibratedTranslation(1) = obj["y"].get(); ctx.calibratedTranslation(2) = obj["z"].get(); + if (obj["scale"].is()) + ctx.calibratedScale = obj["scale"].get(); + else + ctx.calibratedScale = 1.0; + if (obj["calibration_speed"].is()) ctx.calibrationSpeed = (CalibrationContext::Speed)(int) obj["calibration_speed"].get(); @@ -101,6 +106,7 @@ static void WriteProfile(CalibrationContext &ctx, std::ostream &out) profile["x"].set(ctx.calibratedTranslation(0)); profile["y"].set(ctx.calibratedTranslation(1)); profile["z"].set(ctx.calibratedTranslation(2)); + profile["scale"].set(ctx.calibratedScale); double speed = (int) ctx.calibrationSpeed; profile["calibration_speed"].set(speed); diff --git a/OpenVR-SpaceCalibrator/UserInterface.cpp b/OpenVR-SpaceCalibrator/UserInterface.cpp index c19f6af..8676673 100644 --- a/OpenVR-SpaceCalibrator/UserInterface.cpp +++ b/OpenVR-SpaceCalibrator/UserInterface.cpp @@ -489,6 +489,10 @@ void BuildProfileEditor() ImGui::InputDouble("##Y", &CalCtx.calibratedTranslation(1), 1.0, 10.0, "%.8f"); ImGui::SameLine(); ImGui::InputDouble("##Z", &CalCtx.calibratedTranslation(2), 1.0, 10.0, "%.8f"); + + TextWithWidth("ScaleLabel", "Scale", width); + + ImGui::InputDouble("##Scale", &CalCtx.calibratedScale, 0.0001, 0.01, "%.8f"); ImGui::PopItemWidth(); } diff --git a/OpenVR-SpaceCalibratorDriver/ServerTrackedDeviceProvider.cpp b/OpenVR-SpaceCalibratorDriver/ServerTrackedDeviceProvider.cpp index eafa62a..55b0951 100644 --- a/OpenVR-SpaceCalibratorDriver/ServerTrackedDeviceProvider.cpp +++ b/OpenVR-SpaceCalibratorDriver/ServerTrackedDeviceProvider.cpp @@ -49,6 +49,9 @@ void ServerTrackedDeviceProvider::SetDeviceTransform(const protocol::SetDeviceTr if (newTransform.updateRotation) tf.rotation = newTransform.rotation; + + if (newTransform.updateScale) + tf.scale = newTransform.scale; } bool ServerTrackedDeviceProvider::HandleDevicePoseUpdated(uint32_t openVRID, vr::DriverPose_t &pose) @@ -58,6 +61,10 @@ bool ServerTrackedDeviceProvider::HandleDevicePoseUpdated(uint32_t openVRID, vr: { pose.qWorldFromDriverRotation = tf.rotation * pose.qWorldFromDriverRotation; + pose.vecPosition[0] *= tf.scale; + pose.vecPosition[1] *= tf.scale; + pose.vecPosition[2] *= tf.scale; + vr::HmdVector3d_t rotatedTranslation = quaternionRotateVector(tf.rotation, pose.vecWorldFromDriverTranslation); pose.vecWorldFromDriverTranslation[0] = rotatedTranslation.v[0] + tf.translation.v[0]; pose.vecWorldFromDriverTranslation[1] = rotatedTranslation.v[1] + tf.translation.v[1]; diff --git a/OpenVR-SpaceCalibratorDriver/ServerTrackedDeviceProvider.h b/OpenVR-SpaceCalibratorDriver/ServerTrackedDeviceProvider.h index 9c50a05..04e2edd 100644 --- a/OpenVR-SpaceCalibratorDriver/ServerTrackedDeviceProvider.h +++ b/OpenVR-SpaceCalibratorDriver/ServerTrackedDeviceProvider.h @@ -46,6 +46,7 @@ class ServerTrackedDeviceProvider : public vr::IServerTrackedDeviceProvider bool enabled = false; vr::HmdVector3d_t translation; vr::HmdQuaternion_t rotation; + double scale; }; DeviceTransform transforms[vr::k_unMaxTrackedDeviceCount]; diff --git a/Protocol.h b/Protocol.h index 8fc89ae..ff0b8e7 100644 --- a/Protocol.h +++ b/Protocol.h @@ -10,7 +10,7 @@ namespace protocol { - const uint32_t Version = 1; + const uint32_t Version = 2; enum RequestType { @@ -37,20 +37,28 @@ namespace protocol bool enabled; bool updateTranslation; bool updateRotation; + bool updateScale; vr::HmdVector3d_t translation; vr::HmdQuaternion_t rotation; + double scale; SetDeviceTransform(uint32_t id, bool enabled) : - openVRID(id), enabled(enabled), updateTranslation(false), updateRotation(false) { } + openVRID(id), enabled(enabled), updateTranslation(false), updateRotation(false), updateScale(false) { } SetDeviceTransform(uint32_t id, bool enabled, vr::HmdVector3d_t translation) : - openVRID(id), enabled(enabled), updateTranslation(true), updateRotation(false), translation(translation) { } + openVRID(id), enabled(enabled), updateTranslation(true), updateRotation(false), updateScale(false), translation(translation) { } SetDeviceTransform(uint32_t id, bool enabled, vr::HmdQuaternion_t rotation) : - openVRID(id), enabled(enabled), updateTranslation(false), updateRotation(true), rotation(rotation) { } + openVRID(id), enabled(enabled), updateTranslation(false), updateRotation(true), updateScale(false), rotation(rotation) { } + + SetDeviceTransform(uint32_t id, bool enabled, double scale) : + openVRID(id), enabled(enabled), updateTranslation(false), updateRotation(false), updateScale(true), scale(scale) { } SetDeviceTransform(uint32_t id, bool enabled, vr::HmdVector3d_t translation, vr::HmdQuaternion_t rotation) : - openVRID(id), enabled(enabled), updateTranslation(true), updateRotation(true), translation(translation), rotation(rotation) { } + openVRID(id), enabled(enabled), updateTranslation(true), updateRotation(true), updateScale(false), translation(translation), rotation(rotation) { } + + SetDeviceTransform(uint32_t id, bool enabled, vr::HmdVector3d_t translation, vr::HmdQuaternion_t rotation, double scale) : + openVRID(id), enabled(enabled), updateTranslation(true), updateRotation(true), updateScale(true), translation(translation), rotation(rotation), scale(scale) { } }; struct Request