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

Adding the ability to offset the reference from the target device pose. #37

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Draft
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
56 changes: 56 additions & 0 deletions OpenVR-SpaceCalibrator/Calibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

static IPCClient Driver;
CalibrationContext CalCtx;
CalibrationState LastState = CalibrationState::None;
Eigen::Vector3d ReferenceTranslation;
Eigen::Vector3d ReferenceRotation;

void InitCalibrator()
{
Expand All @@ -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;
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion OpenVR-SpaceCalibrator/Calibration.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ enum class CalibrationState
Rotation,
Translation,
Editing,
Referencing
};

struct CalibrationContext
Expand Down Expand Up @@ -118,4 +119,5 @@ void InitCalibrator();
void CalibrationTick(double time);
void StartCalibration();
void LoadChaperoneBounds();
void ApplyChaperoneBounds();
void ApplyChaperoneBounds();
void SetReferenceOffset();
20 changes: 20 additions & 0 deletions OpenVR-SpaceCalibrator/OpenVR-SpaceCalibrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
{
Expand Down
12 changes: 11 additions & 1 deletion OpenVR-SpaceCalibrator/UserInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

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