mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-14 12:23:15 +02:00
depth reticle work
This commit is contained in:
parent
9c3abd3eb7
commit
31b895058b
2 changed files with 53 additions and 9 deletions
|
@ -283,16 +283,51 @@ void ApplicationCompositor::displayOverlayTextureHmd(RenderArgs* renderArgs, int
|
|||
|
||||
//Mouse Pointer
|
||||
if (getReticleVisible()) {
|
||||
glm::mat4 overlayXfm;
|
||||
_modelTransform.getMatrix(overlayXfm);
|
||||
if (_drawAt3D) {
|
||||
//auto headPose = qApp->getHMDSensorPose();
|
||||
auto myCamera = qApp->getCamera();
|
||||
mat4 cameraMat = myCamera->getTransform();
|
||||
auto cameraOrientation = myCamera->getOrientation();
|
||||
auto UITransform = cameraMat * glm::inverse(headPose);
|
||||
auto relativePosition4 = glm::inverse(UITransform) * vec4(_drawAt3DPosition, 1);
|
||||
auto relativePosition = vec3(relativePosition4) / relativePosition4.w;
|
||||
auto relativeDistance = glm::length(relativePosition);
|
||||
|
||||
auto reticlePosition = getReticlePosition();
|
||||
glm::vec2 projection = overlayToSpherical(reticlePosition);
|
||||
float cursorDepth = getReticleDepth();
|
||||
mat4 pointerXfm = glm::scale(mat4(), vec3(cursorDepth)) * glm::mat4_cast(quat(vec3(-projection.y, projection.x, 0.0f))) * glm::translate(mat4(), vec3(0, 0, -1));
|
||||
mat4 reticleXfm = overlayXfm * pointerXfm;
|
||||
reticleXfm = glm::scale(reticleXfm, reticleScale);
|
||||
batch.setModelTransform(reticleXfm);
|
||||
// look at borrowed from overlays
|
||||
float elevation = -asinf(relativePosition.y / glm::length(relativePosition));
|
||||
float azimuth = atan2f(relativePosition.x, relativePosition.z);
|
||||
glm::quat faceCamera = glm::quat(glm::vec3(elevation, azimuth, 0)) * quat(vec3(0, 0, -1)); // this extra *quat(vec3(0,0,-1)) was required to get the quad to flip this seems like we could optimize
|
||||
|
||||
qDebug() << "_drawAt3DPosition:" << _drawAt3DPosition;
|
||||
qDebug() << "relativePosition:" << relativePosition;
|
||||
qDebug() << "relativeDistance:" << relativeDistance;
|
||||
|
||||
Transform transform;
|
||||
transform.setTranslation(relativePosition);
|
||||
transform.setScale(reticleScale);
|
||||
transform.postScale(relativeDistance); // scale not quite working, distant things too large
|
||||
transform.setRotation(faceCamera);
|
||||
batch.setModelTransform(transform);
|
||||
|
||||
/*
|
||||
// this definitely doesn't work
|
||||
mat4 pointerXfm = glm::scale(mat4(), vec3(relativeDistance)) * glm::mat4_cast(faceCamera) * glm::translate(mat4(), relativePosition);
|
||||
batch.setModelTransform(pointerXfm);
|
||||
*/
|
||||
|
||||
}
|
||||
else {
|
||||
glm::mat4 overlayXfm;
|
||||
_modelTransform.getMatrix(overlayXfm);
|
||||
|
||||
auto reticlePosition = getReticlePosition();
|
||||
glm::vec2 projection = overlayToSpherical(reticlePosition);
|
||||
float cursorDepth = getReticleDepth();
|
||||
mat4 pointerXfm = glm::scale(mat4(), vec3(cursorDepth)) * glm::mat4_cast(quat(vec3(-projection.y, projection.x, 0.0f))) * glm::translate(mat4(), vec3(0, 0, -1));
|
||||
mat4 reticleXfm = overlayXfm * pointerXfm;
|
||||
reticleXfm = glm::scale(reticleXfm, reticleScale);
|
||||
batch.setModelTransform(reticleXfm);
|
||||
}
|
||||
geometryCache->renderUnitQuad(batch, glm::vec4(1), _reticleQuad);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -90,6 +90,9 @@ public:
|
|||
Q_INVOKABLE glm::vec2 getReticlePosition();
|
||||
Q_INVOKABLE void setReticlePosition(glm::vec2 position, bool sendFakeEvent = true);
|
||||
|
||||
Q_INVOKABLE void setReticleApparentPosition(glm::vec3 position) { _drawAt3D = true; _drawAt3DPosition = position; }
|
||||
Q_INVOKABLE void restoreReticleApparentPosition() { _drawAt3D = false; }
|
||||
|
||||
Q_INVOKABLE glm::vec2 getReticleMaximumPosition() const;
|
||||
|
||||
ReticleInterface* getReticleInterface() { return _reticleInterface; }
|
||||
|
@ -140,6 +143,8 @@ private:
|
|||
|
||||
bool _reticleVisible { true };
|
||||
float _reticleDepth { 1.0f };
|
||||
bool _drawAt3D { false };
|
||||
glm::vec3 _drawAt3DPosition;
|
||||
|
||||
// NOTE: when the compositor is running in HMD mode, it will control the reticle position as a custom
|
||||
// application specific position, when it's in desktop mode, the reticle position will simply move
|
||||
|
@ -174,6 +179,10 @@ public:
|
|||
Q_INVOKABLE void setPosition(glm::vec2 position) { _compositor->setReticlePosition(position); }
|
||||
|
||||
Q_INVOKABLE glm::vec2 getMaximumPosition() { return _compositor->getReticleMaximumPosition(); }
|
||||
|
||||
Q_INVOKABLE void setApparentPosition(glm::vec3 position) { _compositor->setReticleApparentPosition(position); }
|
||||
Q_INVOKABLE void restoreApparentPosition() { _compositor->restoreReticleApparentPosition(); }
|
||||
|
||||
private:
|
||||
ApplicationCompositor* _compositor;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue