This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement pitch and roll reorientation support (#563)
- Loading branch information
1 parent
104871e
commit c58f854
Showing
15 changed files
with
167 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "DeviceUtils.h" | ||
#include "vrb/Matrix.h" | ||
#include "vrb/Quaternion.h" | ||
|
||
namespace crow { | ||
|
||
vrb::Matrix | ||
DeviceUtils::CalculateReorientationMatrix(const vrb::Matrix& aHeadTransform, const vrb::Vector& aHeightPosition) { | ||
const float kPitchUpThreshold = 0.2f; | ||
const float kPitchDownThreshold = 0.5f; | ||
const float kRollThreshold = 0.35f; | ||
|
||
float rx, ry, rz; | ||
vrb::Quaternion quat(aHeadTransform); | ||
quat.ToEulerAngles(rx, ry, rz); | ||
|
||
// Use some thresholds to use default roll and yaw values when the rotation is not enough. | ||
// This makes easier setting a default orientation easier for the user. | ||
if (rx > 0 && rx < kPitchDownThreshold) { | ||
rx = 0.0f; | ||
} else if (rx < 0 && fabsf(rx) < kPitchUpThreshold) { | ||
rx = 0.0f; | ||
} else { | ||
rx -= 0.05f; // It feels better with some extra margin | ||
} | ||
|
||
if (fabsf(rz) < kRollThreshold) { | ||
rz = 0.0f; | ||
} | ||
|
||
if (rx == 0.0f && rz == 0.0f) { | ||
return vrb::Matrix::Identity(); | ||
} | ||
|
||
quat.SetFromEulerAngles(rx, ry, rz); | ||
vrb::Matrix result = vrb::Matrix::Rotation(quat.Inverse()); | ||
|
||
// Rotate UI reorientation matrix from origin so user height translation doesn't affect the sphere. | ||
result.PreMultiplyInPlace(vrb::Matrix::Position(aHeightPosition)); | ||
result.PostMultiplyInPlace(vrb::Matrix::Position(-aHeightPosition)); | ||
|
||
return result; | ||
|
||
} | ||
|
||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef DEVICE_UTILS_DOT_H | ||
#define DEVICE_UTILS_DOT_H | ||
|
||
#include "vrb/MacroUtils.h" | ||
#include "vrb/Forward.h" | ||
|
||
namespace crow { | ||
|
||
class DeviceUtils { | ||
public: | ||
static vrb::Matrix CalculateReorientationMatrix(const vrb::Matrix& aHeadTransform, const vrb::Vector& aHeightPosition); | ||
private: | ||
VRB_NO_DEFAULTS(DeviceUtils) | ||
}; | ||
|
||
} | ||
|
||
#endif // DEVICE_UTILS_DOT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.