mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 08:48:53 +02:00
Fix reticle transform when depth != 1
This commit is contained in:
parent
28103cf5ef
commit
f5acf49e47
3 changed files with 24 additions and 37 deletions
|
@ -26,7 +26,6 @@
|
||||||
|
|
||||||
// Used to animate the magnification windows
|
// Used to animate the magnification windows
|
||||||
|
|
||||||
static const quint64 MSECS_TO_USECS = 1000ULL;
|
|
||||||
//static const quint64 TOOLTIP_DELAY = 500 * MSECS_TO_USECS;
|
//static const quint64 TOOLTIP_DELAY = 500 * MSECS_TO_USECS;
|
||||||
|
|
||||||
static const float reticleSize = TWO_PI / 100.0f;
|
static const float reticleSize = TWO_PI / 100.0f;
|
||||||
|
@ -432,42 +431,31 @@ void CompositorHelper::toggle() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
glm::mat4 CompositorHelper::getReticleTransform(const glm::mat4& eyePose, const glm::mat4& headPose) const {
|
|
||||||
|
glm::mat4 CompositorHelper::getReticleTransform(const glm::mat4& eyePose, const glm::vec3& headPosition) const {
|
||||||
glm::mat4 result;
|
glm::mat4 result;
|
||||||
if (isHMD()) {
|
if (isHMD()) {
|
||||||
vec3 reticleScale = vec3(Cursor::Manager::instance().getScale() * reticleSize);
|
vec3 reticleScale = vec3(Cursor::Manager::instance().getScale() * reticleSize);
|
||||||
auto reticlePosition = getReticlePosition();
|
auto reticlePosition = getReticlePosition();
|
||||||
if (getReticleDepth() != 1.0f) {
|
auto spherical = overlayToSpherical(reticlePosition);
|
||||||
auto spherical = overlayToSpherical(reticlePosition);
|
// The pointer transform relative to the sensor
|
||||||
auto sphereSurfacePoint = getPoint(spherical.x, spherical.y);
|
auto pointerTransform = glm::mat4_cast(quat(vec3(-spherical.y, spherical.x, 0.0f))) * glm::translate(mat4(), vec3(0, 0, -1));
|
||||||
auto origin = vec3(headPose[3]);
|
float reticleDepth = getReticleDepth();
|
||||||
auto direction = glm::normalize(sphereSurfacePoint - origin);
|
if (reticleDepth != 1.0f) {
|
||||||
auto apparentPosition = (direction * getReticleDepth());
|
// Cursor position in UI space
|
||||||
|
auto cursorPosition = vec3(pointerTransform[3]) / pointerTransform[3].w;
|
||||||
// same code as used to render for apparent location
|
// Ray to the cursor, in UI space
|
||||||
auto relativePosition4 = glm::inverse(eyePose) * vec4(apparentPosition, 1);
|
auto cursorRay = glm::normalize(cursorPosition - headPosition) * reticleDepth;
|
||||||
auto relativePosition = vec3(relativePosition4) / relativePosition4.w;
|
// Move the ray to be relative to the head pose
|
||||||
auto relativeDistance = glm::length(relativePosition);
|
pointerTransform[3] = vec4(cursorRay + headPosition, 1);
|
||||||
|
// Scale up the cursor because of distance
|
||||||
// look at borrowed from overlays
|
reticleScale *= reticleDepth;
|
||||||
float elevation = -asinf(relativePosition.y / glm::length(relativePosition));
|
}
|
||||||
float azimuth = atan2f(relativePosition.x, relativePosition.z);
|
glm::mat4 overlayXfm;
|
||||||
glm::quat faceCamera = glm::quat(glm::vec3(elevation, azimuth, 0)) * quat(vec3(0, -PI, 0)); // this extra *quat(vec3(0,-PI,0)) was required to get the quad to flip this seems like we could optimize
|
_modelTransform.getMatrix(overlayXfm);
|
||||||
|
pointerTransform = overlayXfm * pointerTransform;
|
||||||
Transform transform;
|
pointerTransform = glm::inverse(eyePose) * pointerTransform;
|
||||||
transform.setTranslation(relativePosition);
|
result = glm::scale(pointerTransform, reticleScale);
|
||||||
transform.setScale(reticleScale);
|
|
||||||
transform.postScale(relativeDistance);
|
|
||||||
transform.setRotation(faceCamera);
|
|
||||||
transform.getMatrix(result);
|
|
||||||
} else {
|
|
||||||
glm::mat4 overlayXfm;
|
|
||||||
_modelTransform.getMatrix(overlayXfm);
|
|
||||||
glm::vec2 projection = overlayToSpherical(reticlePosition);
|
|
||||||
mat4 pointerXfm = glm::inverse(eyePose) * glm::mat4_cast(quat(vec3(-projection.y, projection.x, 0.0f))) * glm::translate(mat4(), vec3(0, 0, -1));
|
|
||||||
mat4 reticleXfm = overlayXfm * pointerXfm;
|
|
||||||
result = glm::scale(reticleXfm, reticleScale);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
static const float CURSOR_PIXEL_SIZE = 32.0f;
|
static const float CURSOR_PIXEL_SIZE = 32.0f;
|
||||||
static auto renderingWidget = PluginContainer::getInstance().getPrimaryWidget();
|
static auto renderingWidget = PluginContainer::getInstance().getPrimaryWidget();
|
||||||
|
|
|
@ -91,7 +91,7 @@ public:
|
||||||
|
|
||||||
glm::vec2 getReticleMaximumPosition() const;
|
glm::vec2 getReticleMaximumPosition() const;
|
||||||
|
|
||||||
glm::mat4 getReticleTransform(const glm::mat4& eyePose = glm::mat4(), const glm::mat4& headPose = glm::mat4()) const;
|
glm::mat4 getReticleTransform(const glm::mat4& eyePose = glm::mat4(), const glm::vec3& headPosition = glm::vec3()) const;
|
||||||
|
|
||||||
ReticleInterface* getReticleInterface() { return _reticleInterface; }
|
ReticleInterface* getReticleInterface() { return _reticleInterface; }
|
||||||
|
|
||||||
|
|
|
@ -77,12 +77,11 @@ void HmdDisplayPlugin::compositePointer() {
|
||||||
auto compositorHelper = DependencyManager::get<CompositorHelper>();
|
auto compositorHelper = DependencyManager::get<CompositorHelper>();
|
||||||
_plane->Use();
|
_plane->Use();
|
||||||
// Reconstruct the headpose from the eye poses
|
// Reconstruct the headpose from the eye poses
|
||||||
auto currentHeadPose = _currentRenderEyePoses[Left];
|
auto headPosition = (vec3(_currentRenderEyePoses[Left][3]) + vec3(_currentRenderEyePoses[Right][3])) / 2.0f;
|
||||||
currentHeadPose[3] = vec4((vec3(_currentRenderEyePoses[Left][3]) + vec3(_currentRenderEyePoses[Right][3])) / 2.0f, 1.0f);
|
|
||||||
for_each_eye([&](Eye eye) {
|
for_each_eye([&](Eye eye) {
|
||||||
using namespace oglplus;
|
using namespace oglplus;
|
||||||
eyeViewport(eye);
|
eyeViewport(eye);
|
||||||
auto reticleTransform = compositorHelper->getReticleTransform(_currentRenderEyePoses[eye], currentHeadPose);
|
auto reticleTransform = compositorHelper->getReticleTransform(_currentRenderEyePoses[eye], headPosition);
|
||||||
Uniform<glm::mat4>(*_program, _modelViewUniform).Set(reticleTransform);
|
Uniform<glm::mat4>(*_program, _modelViewUniform).Set(reticleTransform);
|
||||||
Uniform<glm::mat4>(*_program, _projectionUniform).Set(_eyeProjections[eye]);
|
Uniform<glm::mat4>(*_program, _projectionUniform).Set(_eyeProjections[eye]);
|
||||||
_plane->Draw();
|
_plane->Draw();
|
||||||
|
|
Loading…
Reference in a new issue