Merge pull request #1174 from ey6es/321contact

Use Faceshift gaze data to deflect the existing mouse lookat behavior.
This commit is contained in:
Philip Rosedale 2013-11-04 11:58:14 -08:00
commit 0f93c7417a
4 changed files with 47 additions and 49 deletions

View file

@ -1946,8 +1946,7 @@ void Application::updateMouseRay(float deltaTime, glm::vec3& mouseRayOrigin, glm
_myAvatar.setMouseRay(mouseRayOrigin, mouseRayDirection); _myAvatar.setMouseRay(mouseRayOrigin, mouseRayDirection);
} }
void Application::updateFaceshift(float deltaTime, glm::vec3& mouseRayOrigin, glm::vec3& mouseRayDirection, void Application::updateFaceshift() {
glm::vec3& lookAtRayOrigin, glm::vec3& lookAtRayDirection) {
bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
PerformanceWarning warn(showWarnings, "Application::updateFaceshift()"); PerformanceWarning warn(showWarnings, "Application::updateFaceshift()");
@ -1959,13 +1958,6 @@ void Application::updateFaceshift(float deltaTime, glm::vec3& mouseRayOrigin, gl
if (_faceshift.isActive()) { if (_faceshift.isActive()) {
_myAvatar.getHead().setAngularVelocity(_faceshift.getHeadAngularVelocity()); _myAvatar.getHead().setAngularVelocity(_faceshift.getHeadAngularVelocity());
} }
// if we have faceshift, use that to compute the lookat direction
if (_faceshift.isActive()) {
lookAtRayOrigin = _myAvatar.getHead().calculateAverageEyePosition();
lookAtRayDirection = _myAvatar.getHead().getOrientation() * glm::quat(glm::radians(glm::vec3(
_faceshift.getEstimatedEyePitch(), _faceshift.getEstimatedEyeYaw(), 0.0f))) * glm::vec3(0.0f, 0.0f, -1.0f);
}
} }
void Application::updateMyAvatarLookAtPosition(glm::vec3& lookAtSpot, glm::vec3& lookAtRayOrigin, void Application::updateMyAvatarLookAtPosition(glm::vec3& lookAtSpot, glm::vec3& lookAtRayOrigin,
@ -1974,24 +1966,31 @@ void Application::updateMyAvatarLookAtPosition(glm::vec3& lookAtSpot, glm::vec3&
bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
PerformanceWarning warn(showWarnings, "Application::updateMyAvatarLookAtPosition()"); PerformanceWarning warn(showWarnings, "Application::updateMyAvatarLookAtPosition()");
if (_lookatTargetAvatar && !_faceshift.isActive()) { if (!_lookatTargetAvatar) {
// If the mouse is over another avatar's head... if (_isHoverVoxel) {
_myAvatar.getHead().setLookAtPosition(lookAtSpot); // Look at the hovered voxel
lookAtSpot = getMouseVoxelWorldCoordinates(_hoverVoxel);
} else if (_isHoverVoxel && !_faceshift.isActive()) {
// Look at the hovered voxel } else if (_myCamera.getMode() == CAMERA_MODE_MIRROR) {
lookAtSpot = getMouseVoxelWorldCoordinates(_hoverVoxel); lookAtSpot = _myCamera.getPosition();
_myAvatar.getHead().setLookAtPosition(lookAtSpot);
} else if (_myCamera.getMode() == CAMERA_MODE_MIRROR && !_faceshift.isActive()) { } else {
_myAvatar.getHead().setLookAtPosition(_myCamera.getPosition()); // Just look in direction of the mouse ray
const float FAR_AWAY_STARE = TREE_SCALE;
} else { lookAtSpot = lookAtRayOrigin + lookAtRayDirection * FAR_AWAY_STARE;
// Just look in direction of the mouse ray }
const float FAR_AWAY_STARE = TREE_SCALE;
lookAtSpot = lookAtRayOrigin + lookAtRayDirection * FAR_AWAY_STARE;
_myAvatar.getHead().setLookAtPosition(lookAtSpot);
} }
if (_faceshift.isActive()) {
// deflect using Faceshift gaze data
glm::vec3 origin = _myAvatar.getHead().calculateAverageEyePosition();
float pitchSign = (_myCamera.getMode() == CAMERA_MODE_MIRROR) ? -1.0f : 1.0f;
const float PITCH_SCALE = 0.5f;
const float YAW_SCALE = 0.5f;
lookAtSpot = origin + _myCamera.getRotation() * glm::quat(glm::radians(glm::vec3(
_faceshift.getEstimatedEyePitch() * pitchSign * PITCH_SCALE, _faceshift.getEstimatedEyeYaw() * YAW_SCALE, 0.0f))) *
glm::inverse(_myCamera.getRotation()) * (lookAtSpot - origin);
}
_myAvatar.getHead().setLookAtPosition(lookAtSpot);
} }
void Application::updateHoverVoxels(float deltaTime, glm::vec3& mouseRayOrigin, glm::vec3& mouseRayDirection, void Application::updateHoverVoxels(float deltaTime, glm::vec3& mouseRayOrigin, glm::vec3& mouseRayDirection,
@ -2347,11 +2346,10 @@ void Application::update(float deltaTime) {
// Set where I am looking based on my mouse ray (so that other people can see) // Set where I am looking based on my mouse ray (so that other people can see)
glm::vec3 lookAtSpot; glm::vec3 lookAtSpot;
glm::vec3 lookAtRayOrigin = mouseRayOrigin, lookAtRayDirection = mouseRayDirection;
updateFaceshift();
updateFaceshift(deltaTime, mouseRayOrigin, mouseRayDirection, lookAtRayOrigin, lookAtRayDirection);
updateLookatTargetAvatar(mouseRayOrigin, mouseRayDirection, lookAtSpot); updateLookatTargetAvatar(mouseRayOrigin, mouseRayDirection, lookAtSpot);
updateMyAvatarLookAtPosition(lookAtSpot, lookAtRayOrigin, lookAtRayDirection); updateMyAvatarLookAtPosition(lookAtSpot, mouseRayOrigin, mouseRayDirection);
// Find the voxel we are hovering over, and respond if clicked // Find the voxel we are hovering over, and respond if clicked
float distance; float distance;

View file

@ -226,8 +226,7 @@ private:
// Various helper functions called during update() // Various helper functions called during update()
void updateMouseRay(float deltaTime, glm::vec3& mouseRayOrigin, glm::vec3& mouseRayDirection); void updateMouseRay(float deltaTime, glm::vec3& mouseRayOrigin, glm::vec3& mouseRayDirection);
void updateFaceshift(float deltaTime, glm::vec3& mouseRayOrigin, glm::vec3& mouseRayDirection, void updateFaceshift();
glm::vec3& lookAtRayOrigin, glm::vec3& lookAtRayDirection);
void updateMyAvatarLookAtPosition(glm::vec3& lookAtSpot, glm::vec3& lookAtRayOrigin, glm::vec3& lookAtRayDirection); void updateMyAvatarLookAtPosition(glm::vec3& lookAtSpot, glm::vec3& lookAtRayOrigin, glm::vec3& lookAtRayDirection);
void updateHoverVoxels(float deltaTime, glm::vec3& mouseRayOrigin, glm::vec3& mouseRayDirection, void updateHoverVoxels(float deltaTime, glm::vec3& mouseRayOrigin, glm::vec3& mouseRayDirection,
float& distance, BoxFace& face); float& distance, BoxFace& face);

View file

@ -41,6 +41,7 @@ Faceshift::Faceshift() :
_jawOpenIndex(21), _jawOpenIndex(21),
_longTermAverageEyePitch(0.0f), _longTermAverageEyePitch(0.0f),
_longTermAverageEyeYaw(0.0f), _longTermAverageEyeYaw(0.0f),
_longTermAverageInitialized(false),
_estimatedEyePitch(0.0f), _estimatedEyePitch(0.0f),
_estimatedEyeYaw(0.0f) _estimatedEyeYaw(0.0f)
{ {
@ -62,25 +63,23 @@ void Faceshift::update() {
if (!isActive()) { if (!isActive()) {
return; return;
} }
float averageEyePitch = (_eyeGazeLeftPitch + _eyeGazeRightPitch) / 2.0f; // get the euler angles relative to the window
float averageEyeYaw = (_eyeGazeLeftYaw + _eyeGazeRightYaw) / 2.0f; glm::vec3 eulers = safeEulerAngles(_headRotation * glm::quat(glm::radians(glm::vec3(
(_eyeGazeLeftPitch + _eyeGazeRightPitch) / 2.0f, (_eyeGazeLeftYaw + _eyeGazeRightYaw) / 2.0f, 0.0f))));
// get the gaze relative to the window // compute and subtract the long term average
glm::vec3 eyeEulers = safeEulerAngles(_headRotation * glm::quat(glm::radians(glm::vec3( const float LONG_TERM_AVERAGE_SMOOTHING = 0.9999f;
averageEyePitch, averageEyeYaw, 0.0f)))); if (!_longTermAverageInitialized) {
_longTermAverageEyePitch = eulers.x;
// smooth relative to the window _longTermAverageEyeYaw = eulers.y;
const float LONG_TERM_AVERAGE_SMOOTHING = 0.999f; _longTermAverageInitialized = true;
_longTermAverageEyePitch = glm::mix(eyeEulers.x, _longTermAverageEyePitch, LONG_TERM_AVERAGE_SMOOTHING);
_longTermAverageEyeYaw = glm::mix(eyeEulers.y, _longTermAverageEyeYaw, LONG_TERM_AVERAGE_SMOOTHING); } else {
_longTermAverageEyePitch = glm::mix(eulers.x, _longTermAverageEyePitch, LONG_TERM_AVERAGE_SMOOTHING);
// back to head-relative _longTermAverageEyeYaw = glm::mix(eulers.y, _longTermAverageEyeYaw, LONG_TERM_AVERAGE_SMOOTHING);
float windowEyePitch = eyeEulers.x - _longTermAverageEyePitch; }
float windowEyeYaw = eyeEulers.y - _longTermAverageEyeYaw; _estimatedEyePitch = eulers.x - _longTermAverageEyePitch;
glm::vec3 relativeEyeEulers = safeEulerAngles(glm::inverse(_headRotation) * glm::quat(glm::radians(glm::vec3( _estimatedEyeYaw = eulers.y - _longTermAverageEyeYaw;
windowEyePitch, windowEyeYaw, 0.0f))));
_estimatedEyePitch = relativeEyeEulers.x;
_estimatedEyeYaw = relativeEyeEulers.y;
} }
void Faceshift::reset() { void Faceshift::reset() {
@ -89,6 +88,7 @@ void Faceshift::reset() {
fsBinaryStream::encode_message(message, fsMsgCalibrateNeutral()); fsBinaryStream::encode_message(message, fsMsgCalibrateNeutral());
send(message); send(message);
} }
_longTermAverageInitialized = false;
} }
void Faceshift::setTCPEnabled(bool enabled) { void Faceshift::setTCPEnabled(bool enabled) {

View file

@ -120,6 +120,7 @@ private:
float _longTermAverageEyePitch; float _longTermAverageEyePitch;
float _longTermAverageEyeYaw; float _longTermAverageEyeYaw;
bool _longTermAverageInitialized;
float _estimatedEyePitch; float _estimatedEyePitch;
float _estimatedEyeYaw; float _estimatedEyeYaw;