Change rendering of reticle when in HMD mode

Properly take the overlay model matrix into account.
Reticle depth is now relative to the eye, not relative to the overlay sphere.
This commit is contained in:
Anthony J. Thibault 2016-06-17 12:10:26 -07:00
parent 4f6d65a961
commit e04d86a75a

View file

@ -409,30 +409,25 @@ void CompositorHelper::updateTooltips() {
//} //}
} }
// eyePose and headPosition are in sensor space.
// the resulting matrix should be in view space.
glm::mat4 CompositorHelper::getReticleTransform(const glm::mat4& eyePose, const glm::vec3& headPosition) 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); vec2 spherical = overlayToSpherical(getReticlePosition());
auto reticlePosition = getReticlePosition(); vec3 overlaySurfacePoint = getPoint(spherical.x, spherical.y); // overlay space
auto spherical = overlayToSpherical(reticlePosition); vec3 sensorSurfacePoint = _modelTransform.transform(overlaySurfacePoint); // sensor space
// The pointer transform relative to the sensor vec3 d = sensorSurfacePoint - headPosition;
auto pointerTransform = glm::mat4_cast(quat(vec3(-spherical.y, spherical.x, 0.0f))) * glm::translate(mat4(), vec3(0, 0, -1)); vec3 reticlePosition;
float reticleDepth = getReticleDepth(); if (glm::length(d) >= EPSILON) {
if (reticleDepth != 1.0f) { d = glm::normalize(d);
// Cursor position in UI space } else {
auto cursorPosition = vec3(pointerTransform[3]) / pointerTransform[3].w; d = glm::normalize(overlaySurfacePoint);
// Ray to the cursor, in UI space
auto cursorRay = glm::normalize(cursorPosition - headPosition) * reticleDepth;
// Move the ray to be relative to the head pose
pointerTransform[3] = vec4(cursorRay + headPosition, 1);
// Scale up the cursor because of distance
reticleScale *= reticleDepth;
} }
glm::mat4 overlayXfm; reticlePosition = headPosition + (d * getReticleDepth());
_modelTransform.getMatrix(overlayXfm); quat reticleOrientation = quat(vec3(-spherical.y, spherical.x, 0.0f));
pointerTransform = overlayXfm * pointerTransform; vec3 reticleScale = vec3(Cursor::Manager::instance().getScale() * reticleSize * getReticleDepth());
pointerTransform = glm::inverse(eyePose) * pointerTransform; return glm::inverse(eyePose) * createMatFromScaleQuatAndPos(reticleScale, reticleOrientation, reticlePosition);
result = glm::scale(pointerTransform, reticleScale);
} else { } else {
static const float CURSOR_PIXEL_SIZE = 32.0f; static const float CURSOR_PIXEL_SIZE = 32.0f;
const auto canvasSize = vec2(toGlm(_renderingWidget->size()));; const auto canvasSize = vec2(toGlm(_renderingWidget->size()));;