some cleanup and standardization in how headPose is gathered

This commit is contained in:
Brad Hefta-Gaub 2016-02-20 11:40:30 -08:00
parent 4e2c514eb1
commit 9c3abd3eb7
4 changed files with 27 additions and 36 deletions

View file

@ -30,6 +30,10 @@ glm::vec2 HMDScriptingInterface::overlayFromWorldPoint(const glm::vec3& position
return qApp->getApplicationCompositor().overlayFromSphereSurface(position);
}
glm::vec3 HMDScriptingInterface::worldPointFromOverlay(const glm::vec2& overlay) const {
return qApp->getApplicationCompositor().sphereSurfaceFromOverlay(overlay);
}
glm::vec2 HMDScriptingInterface::sphericalToOverlay(const glm::vec2 & position) const {
return qApp->getApplicationCompositor().sphericalToOverlay(position);
}

View file

@ -29,6 +29,7 @@ class HMDScriptingInterface : public AbstractHMDScriptingInterface, public Depen
public:
Q_INVOKABLE glm::vec3 calculateRayUICollisionPoint(const glm::vec3& position, const glm::vec3& direction) const;
Q_INVOKABLE glm::vec2 overlayFromWorldPoint(const glm::vec3& position) const;
Q_INVOKABLE glm::vec3 worldPointFromOverlay(const glm::vec2& overlay) const;
Q_INVOKABLE glm::vec2 sphericalToOverlay(const glm::vec2 & sphericalPos) const;
Q_INVOKABLE glm::vec2 overlayToSpherical(const glm::vec2 & overlayPos) const;

View file

@ -257,9 +257,9 @@ void ApplicationCompositor::displayOverlayTextureHmd(RenderArgs* renderArgs, int
mat4 camMat;
_cameraBaseTransform.getMatrix(camMat);
auto displayPlugin = qApp->getActiveDisplayPlugin();
auto headPose = displayPlugin->getHeadPose(qApp->getFrameCount());
auto headPose = qApp->getHMDSensorPose();
auto eyeToHead = displayPlugin->getEyeToHeadTransform((Eye)eye);
camMat = (headPose * eyeToHead) * camMat;
camMat = (headPose * eyeToHead) * camMat; // FIXME - why are not all transforms are doing this aditioanl eyeToHead
batch.setViewportTransform(renderArgs->_viewport);
batch.setViewTransform(camMat);
batch.setProjectionTransform(qApp->getEyeProjection(eye));
@ -425,41 +425,16 @@ glm::vec2 ApplicationCompositor::getReticleMaximumPosition() const {
return result;
}
// FIXME - this probably is hella buggy and probably doesn't work correctly
// we should kill it asap.
void ApplicationCompositor::computeHmdPickRay(glm::vec2 cursorPos, glm::vec3& origin, glm::vec3& direction) const {
const glm::vec2 projection = overlayToSpherical(cursorPos);
// The overlay space orientation of the mouse coordinates
const glm::quat cursorOrientation(glm::vec3(-projection.y, projection.x, 0.0f));
// The orientation and position of the HEAD, not the overlay
glm::vec3 worldSpaceHeadPosition = qApp->getCamera()->getPosition();
glm::quat worldSpaceOrientation = qApp->getCamera()->getOrientation();
auto headPose = qApp->getHMDSensorPose();
auto headOrientation = glm::quat_cast(headPose);
auto headTranslation = extractTranslation(headPose);
auto overlayOrientation = worldSpaceOrientation * glm::inverse(headOrientation);
auto overlayPosition = worldSpaceHeadPosition - (overlayOrientation * headTranslation);
if (Menu::getInstance()->isOptionChecked(MenuOption::StandingHMDSensorMode)) {
overlayPosition = _modelTransform.getTranslation();
overlayOrientation = _modelTransform.getRotation();
}
// Intersection in world space
glm::vec3 worldSpaceIntersection = ((overlayOrientation * (cursorOrientation * Vectors::FRONT)) * _oculusUIRadius) + overlayPosition;
origin = worldSpaceHeadPosition;
direction = glm::normalize(worldSpaceIntersection - worldSpaceHeadPosition);
auto surfacePointAt = sphereSurfaceFromOverlay(cursorPos); // in world space
glm::vec3 worldSpaceCameraPosition = qApp->getCamera()->getPosition();
origin = worldSpaceCameraPosition;
direction = glm::normalize(surfacePointAt - worldSpaceCameraPosition);
}
//Finds the collision point of a world space ray
bool ApplicationCompositor::calculateRayUICollisionPoint(const glm::vec3& position, const glm::vec3& direction, glm::vec3& result) const {
auto displayPlugin = qApp->getActiveDisplayPlugin();
auto headPose = displayPlugin->getHeadPose(qApp->getFrameCount());
auto headPose = qApp->getHMDSensorPose();
auto myCamera = qApp->getCamera();
mat4 cameraMat = myCamera->getTransform();
auto UITransform = cameraMat * glm::inverse(headPose);
@ -604,9 +579,7 @@ glm::vec2 ApplicationCompositor::overlayToSpherical(const glm::vec2& overlayPos
}
glm::vec2 ApplicationCompositor::overlayFromSphereSurface(const glm::vec3& sphereSurfacePoint) const {
auto displayPlugin = qApp->getActiveDisplayPlugin();
auto headPose = displayPlugin->getHeadPose(qApp->getFrameCount());
auto headPose = qApp->getHMDSensorPose();
auto myCamera = qApp->getCamera();
mat4 cameraMat = myCamera->getTransform();
auto UITransform = cameraMat * glm::inverse(headPose);
@ -614,12 +587,24 @@ glm::vec2 ApplicationCompositor::overlayFromSphereSurface(const glm::vec3& spher
auto relativePosition = vec3(relativePosition4) / relativePosition4.w;
auto center = vec3(0); // center of HUD in HUD space
auto direction = relativePosition - center; // direction to relative position in HUD space
glm::vec2 polar = glm::vec2(glm::atan(direction.x, -direction.z), glm::asin(direction.y)) * -1.0f;
auto overlayPos = sphericalToOverlay(polar);
return overlayPos;
}
glm::vec3 ApplicationCompositor::sphereSurfaceFromOverlay(const glm::vec2& overlay) const {
auto spherical = overlayToSpherical(overlay);
auto sphereSurfacePoint = getPoint(spherical.x, spherical.y);
auto headPose = qApp->getHMDSensorPose();
auto myCamera = qApp->getCamera();
mat4 cameraMat = myCamera->getTransform();
auto UITransform = cameraMat * glm::inverse(headPose);
auto position4 = UITransform * vec4(sphereSurfacePoint, 1);
auto position = vec3(position4) / position4.w;
return position;
}
void ApplicationCompositor::updateTooltips() {
if (_hoverItemId != _noItemId) {
quint64 hoverDuration = usecTimestampNow() - _hoverItemEnterUsecs;

View file

@ -66,6 +66,7 @@ public:
uint32_t getOverlayTexture() const;
glm::vec2 overlayFromSphereSurface(const glm::vec3& sphereSurfacePoint) const;
glm::vec3 sphereSurfaceFromOverlay(const glm::vec2& overlay) const;
void setCameraBaseTransform(const Transform& transform) { _cameraBaseTransform = transform; }
const Transform& getCameraBaseTransform() const { return _cameraBaseTransform; }