mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
implement Reticle.depth using the apparent 3D look at logic instead
This commit is contained in:
parent
715355464f
commit
fc002df5e7
3 changed files with 20 additions and 36 deletions
|
@ -1235,13 +1235,11 @@ Script.update.connect(function(deltaTime) {
|
|||
// + JSON.stringify(result)
|
||||
print("something hovered!! result.distance:" +result.distance);
|
||||
Vec3.print("something hovered!! result.intersection:", result.intersection);
|
||||
//Reticle.setDepth(result.distance);
|
||||
Reticle.setApparentPosition(result.intersection);
|
||||
Reticle.setDepth(result.distance);
|
||||
Overlays.editOverlay(intersectionBeacon, { position: result.intersection, visible: false });
|
||||
|
||||
} else {
|
||||
//Reticle.setDepth(1.0);
|
||||
Reticle.restoreApparentPosition();
|
||||
Reticle.setDepth(100.0);
|
||||
print("NO INTERSECTION...");
|
||||
var pointAt2D = Reticle.position;
|
||||
var pointAt3D = HMD.worldPointFromOverlay(pointAt2D);
|
||||
|
|
|
@ -283,12 +283,18 @@ void ApplicationCompositor::displayOverlayTextureHmd(RenderArgs* renderArgs, int
|
|||
|
||||
//Mouse Pointer
|
||||
if (getReticleVisible()) {
|
||||
if (_drawAt3D) {
|
||||
//auto headPose = qApp->getHMDSensorPose();
|
||||
if (getReticleDepth() != 1.0f) {
|
||||
// calculate the "apparent location" based on the depth and the current ray
|
||||
glm::vec3 origin, direction;
|
||||
auto reticlePosition = getReticlePosition();
|
||||
computeHmdPickRay(reticlePosition, origin, direction);
|
||||
auto apparentPosition = origin + (direction * getReticleDepth());
|
||||
|
||||
// same code as used to render for apparent location
|
||||
auto myCamera = qApp->getCamera();
|
||||
mat4 cameraMat = myCamera->getTransform();
|
||||
auto UITransform = cameraMat * glm::inverse(headPose);
|
||||
auto relativePosition4 = glm::inverse(UITransform) * vec4(_drawAt3DPosition, 1);
|
||||
auto relativePosition4 = glm::inverse(UITransform) * vec4(apparentPosition, 1);
|
||||
auto relativePosition = vec3(relativePosition4) / relativePosition4.w;
|
||||
auto relativeDistance = glm::length(relativePosition);
|
||||
|
||||
|
@ -297,32 +303,19 @@ void ApplicationCompositor::displayOverlayTextureHmd(RenderArgs* renderArgs, int
|
|||
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 {
|
||||
} 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 pointerXfm = 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);
|
||||
|
@ -334,7 +327,7 @@ void ApplicationCompositor::displayOverlayTextureHmd(RenderArgs* renderArgs, int
|
|||
|
||||
QPointF ApplicationCompositor::getMouseEventPosition(QMouseEvent* event) {
|
||||
if (qApp->isHMDMode()) {
|
||||
QMutexLocker locker(&_reticlePositionInHMDLock);
|
||||
QMutexLocker locker(&_reticleLock);
|
||||
return QPointF(_reticlePositionInHMD.x, _reticlePositionInHMD.y);
|
||||
}
|
||||
return event->localPos();
|
||||
|
@ -388,7 +381,7 @@ bool ApplicationCompositor::handleRealMouseMoveEvent(bool sendFakeEvent) {
|
|||
|
||||
// If we're in HMD mode
|
||||
if (shouldCaptureMouse()) {
|
||||
QMutexLocker locker(&_reticlePositionInHMDLock);
|
||||
QMutexLocker locker(&_reticleLock);
|
||||
auto newPosition = QCursor::pos();
|
||||
auto changeInRealMouse = newPosition - _lastKnownRealMouse;
|
||||
auto newReticlePosition = _reticlePositionInHMD + toGlm(changeInRealMouse);
|
||||
|
@ -404,7 +397,7 @@ bool ApplicationCompositor::handleRealMouseMoveEvent(bool sendFakeEvent) {
|
|||
|
||||
glm::vec2 ApplicationCompositor::getReticlePosition() {
|
||||
if (qApp->isHMDMode()) {
|
||||
QMutexLocker locker(&_reticlePositionInHMDLock);
|
||||
QMutexLocker locker(&_reticleLock);
|
||||
return _reticlePositionInHMD;
|
||||
}
|
||||
return toGlm(QCursor::pos());
|
||||
|
@ -412,7 +405,7 @@ glm::vec2 ApplicationCompositor::getReticlePosition() {
|
|||
|
||||
void ApplicationCompositor::setReticlePosition(glm::vec2 position, bool sendFakeEvent) {
|
||||
if (qApp->isHMDMode()) {
|
||||
QMutexLocker locker(&_reticlePositionInHMDLock);
|
||||
QMutexLocker locker(&_reticleLock);
|
||||
const float MOUSE_EXTENTS_VERT_ANGULAR_SIZE = 170.0f; // 5deg from poles
|
||||
const float MOUSE_EXTENTS_VERT_PIXELS = VIRTUAL_SCREEN_SIZE_Y * (MOUSE_EXTENTS_VERT_ANGULAR_SIZE / DEFAULT_HMD_UI_VERT_ANGULAR_SIZE);
|
||||
const float MOUSE_EXTENTS_HORZ_ANGULAR_SIZE = 360.0f; // full sphere
|
||||
|
|
|
@ -29,6 +29,7 @@ class RenderArgs;
|
|||
class ReticleInterface;
|
||||
|
||||
|
||||
const float DEFAULT_RETICLE_DEPTH = 1.0f; // FIXME - probably should be based on UI radius
|
||||
|
||||
const float MAGNIFY_WIDTH = 220.0f;
|
||||
const float MAGNIFY_HEIGHT = 100.0f;
|
||||
|
@ -88,13 +89,11 @@ public:
|
|||
|
||||
float getReticleDepth() { return _reticleDepth; }
|
||||
void setReticleDepth(float depth) { _reticleDepth = depth; }
|
||||
void resetReticleDepth() { _reticleDepth = DEFAULT_RETICLE_DEPTH; }
|
||||
|
||||
glm::vec2 getReticlePosition();
|
||||
void setReticlePosition(glm::vec2 position, bool sendFakeEvent = true);
|
||||
|
||||
void setReticleApparentPosition(glm::vec3 position) { _drawAt3D = true; _drawAt3DPosition = position; }
|
||||
void restoreReticleApparentPosition() { _drawAt3D = false; }
|
||||
|
||||
glm::vec2 getReticleMaximumPosition() const;
|
||||
|
||||
ReticleInterface* getReticleInterface() { return _reticleInterface; }
|
||||
|
@ -150,10 +149,7 @@ private:
|
|||
// application specific position, when it's in desktop mode, the reticle position will simply move
|
||||
// the system mouse.
|
||||
glm::vec2 _reticlePositionInHMD { 0.0f, 0.0f };
|
||||
mutable QMutex _reticlePositionInHMDLock { QMutex::Recursive };
|
||||
|
||||
bool _drawAt3D { false };
|
||||
glm::vec3 _drawAt3DPosition;
|
||||
mutable QMutex _reticleLock { QMutex::Recursive };
|
||||
|
||||
QPointF _lastKnownRealMouse;
|
||||
bool _ignoreMouseMove { false };
|
||||
|
@ -186,9 +182,6 @@ public:
|
|||
|
||||
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