Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Driver Scale Parameter #65

Merged
merged 3 commits into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions OpenVR-SpaceCalibrator/Calibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -338,7 +338,8 @@ void ScanAndApplyProfile(CalibrationContext &ctx)
id,
true,
VRTranslationVec(ctx.calibratedTranslation),
VRRotationQuat(ctx.calibratedRotation)
VRRotationQuat(ctx.calibratedRotation),
ctx.calibratedScale
};
Driver.SendBlocking(req);
}
Expand Down
2 changes: 2 additions & 0 deletions OpenVR-SpaceCalibrator/Calibration.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct CalibrationContext

Eigen::Vector3d calibratedRotation;
Eigen::Vector3d calibratedTranslation;
double calibratedScale;

std::string referenceTrackingSystem;
std::string targetTrackingSystem;
Expand Down Expand Up @@ -57,6 +58,7 @@ struct CalibrationContext

calibratedRotation = Eigen::Vector3d();
calibratedTranslation = Eigen::Vector3d();
calibratedScale = 1.0;
referenceTrackingSystem = "";
targetTrackingSystem = "";
enabled = false;
Expand Down
6 changes: 6 additions & 0 deletions OpenVR-SpaceCalibrator/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ static void ParseProfile(CalibrationContext &ctx, std::istream &stream)
ctx.calibratedTranslation(1) = obj["y"].get<double>();
ctx.calibratedTranslation(2) = obj["z"].get<double>();

if (obj["scale"].is<double>())
ctx.calibratedScale = obj["scale"].get<double>();
else
ctx.calibratedScale = 1.0;

if (obj["calibration_speed"].is<double>())
ctx.calibrationSpeed = (CalibrationContext::Speed)(int) obj["calibration_speed"].get<double>();

Expand Down Expand Up @@ -101,6 +106,7 @@ static void WriteProfile(CalibrationContext &ctx, std::ostream &out)
profile["x"].set<double>(ctx.calibratedTranslation(0));
profile["y"].set<double>(ctx.calibratedTranslation(1));
profile["z"].set<double>(ctx.calibratedTranslation(2));
profile["scale"].set<double>(ctx.calibratedScale);

double speed = (int) ctx.calibrationSpeed;
profile["calibration_speed"].set<double>(speed);
Expand Down
4 changes: 4 additions & 0 deletions OpenVR-SpaceCalibrator/UserInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
7 changes: 7 additions & 0 deletions OpenVR-SpaceCalibratorDriver/ServerTrackedDeviceProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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];
Expand Down
1 change: 1 addition & 0 deletions OpenVR-SpaceCalibratorDriver/ServerTrackedDeviceProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
18 changes: 13 additions & 5 deletions Protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace protocol
{
const uint32_t Version = 1;
const uint32_t Version = 2;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seemed like the cleanest way to handle this was to just break backwards compat on the IPC

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, that's fine. It would be possible to preserve backwards compatibility by making a new message, and using it only if both sides support version 2, but there isn't much of a reason to implement that since there's only one client (that I'm aware of) and it's installed at the same time as the driver.


enum RequestType
{
Expand All @@ -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
Expand Down