mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 09:48:44 +02:00
change some code to look at head-controller position rather than hmd position
This commit is contained in:
parent
499897e271
commit
bdbc6ddcc1
6 changed files with 39 additions and 39 deletions
|
@ -3953,6 +3953,7 @@ void Application::updateMyAvatarLookAtPosition() {
|
||||||
lookAtPosition.x = -lookAtPosition.x;
|
lookAtPosition.x = -lookAtPosition.x;
|
||||||
}
|
}
|
||||||
if (isHMD) {
|
if (isHMD) {
|
||||||
|
// TODO -- this code is probably wrong, getHeadPose() returns something in sensor frame, not avatar
|
||||||
glm::mat4 headPose = getActiveDisplayPlugin()->getHeadPose();
|
glm::mat4 headPose = getActiveDisplayPlugin()->getHeadPose();
|
||||||
glm::quat hmdRotation = glm::quat_cast(headPose);
|
glm::quat hmdRotation = glm::quat_cast(headPose);
|
||||||
lookAtSpot = _myCamera.getPosition() + myAvatar->getOrientation() * (hmdRotation * lookAtPosition);
|
lookAtSpot = _myCamera.getPosition() + myAvatar->getOrientation() * (hmdRotation * lookAtPosition);
|
||||||
|
@ -3995,7 +3996,8 @@ void Application::updateMyAvatarLookAtPosition() {
|
||||||
} else {
|
} else {
|
||||||
// I am not looking at anyone else, so just look forward
|
// I am not looking at anyone else, so just look forward
|
||||||
if (isHMD) {
|
if (isHMD) {
|
||||||
glm::mat4 worldHMDMat = myAvatar->getSensorToWorldMatrix() * myAvatar->getHMDSensorMatrix();
|
glm::mat4 worldHMDMat = myAvatar->getSensorToWorldMatrix() *
|
||||||
|
(glm::mat4)myAvatar->getHeadControllerPoseInSensorFrame();
|
||||||
lookAtSpot = transformPoint(worldHMDMat, glm::vec3(0.0f, 0.0f, -TREE_SCALE));
|
lookAtSpot = transformPoint(worldHMDMat, glm::vec3(0.0f, 0.0f, -TREE_SCALE));
|
||||||
} else {
|
} else {
|
||||||
lookAtSpot = myAvatar->getHead()->getEyePosition() +
|
lookAtSpot = myAvatar->getHead()->getEyePosition() +
|
||||||
|
|
|
@ -401,7 +401,7 @@ void MyAvatar::update(float deltaTime) {
|
||||||
// update moving average of HMD facing in xz plane.
|
// update moving average of HMD facing in xz plane.
|
||||||
const float HMD_FACING_TIMESCALE = 4.0f; // very slow average
|
const float HMD_FACING_TIMESCALE = 4.0f; // very slow average
|
||||||
float tau = deltaTime / HMD_FACING_TIMESCALE;
|
float tau = deltaTime / HMD_FACING_TIMESCALE;
|
||||||
_hmdSensorFacingMovingAverage = lerp(_hmdSensorFacingMovingAverage, _hmdSensorFacing, tau);
|
_headControllerFacingMovingAverage = lerp(_headControllerFacingMovingAverage, _headControllerFacing, tau);
|
||||||
|
|
||||||
if (_smoothOrientationTimer < SMOOTH_TIME_ORIENTATION) {
|
if (_smoothOrientationTimer < SMOOTH_TIME_ORIENTATION) {
|
||||||
_rotationChanged = usecTimestampNow();
|
_rotationChanged = usecTimestampNow();
|
||||||
|
@ -409,16 +409,18 @@ void MyAvatar::update(float deltaTime) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_DRAW_HMD_MOVING_AVERAGE
|
#ifdef DEBUG_DRAW_HMD_MOVING_AVERAGE
|
||||||
glm::vec3 p = transformPoint(getSensorToWorldMatrix(), _hmdSensorPosition + glm::vec3(_hmdSensorFacingMovingAverage.x, 0.0f, _hmdSensorFacingMovingAverage.y));
|
glm::vec3 p = transformPoint(getSensorToWorldMatrix(), getHeadControllerPoseInAvatarFrame() +
|
||||||
|
glm::vec3(_headControllerFacingMovingAverage.x, 0.0f, _headControllerFacingMovingAverage.y));
|
||||||
DebugDraw::getInstance().addMarker("facing-avg", getOrientation(), p, glm::vec4(1.0f));
|
DebugDraw::getInstance().addMarker("facing-avg", getOrientation(), p, glm::vec4(1.0f));
|
||||||
p = transformPoint(getSensorToWorldMatrix(), _hmdSensorPosition + glm::vec3(_hmdSensorFacing.x, 0.0f, _hmdSensorFacing.y));
|
p = transformPoint(getSensorToWorldMatrix(), getHMDSensorPosition() +
|
||||||
|
glm::vec3(_headControllerFacing.x, 0.0f, _headControllerFacing.y));
|
||||||
DebugDraw::getInstance().addMarker("facing", getOrientation(), p, glm::vec4(1.0f));
|
DebugDraw::getInstance().addMarker("facing", getOrientation(), p, glm::vec4(1.0f));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (_goToPending) {
|
if (_goToPending) {
|
||||||
setPosition(_goToPosition);
|
setPosition(_goToPosition);
|
||||||
setOrientation(_goToOrientation);
|
setOrientation(_goToOrientation);
|
||||||
_hmdSensorFacingMovingAverage = _hmdSensorFacing; // reset moving average
|
_headControllerFacingMovingAverage = _headControllerFacing; // reset moving average
|
||||||
_goToPending = false;
|
_goToPending = false;
|
||||||
// updateFromHMDSensorMatrix (called from paintGL) expects that the sensorToWorldMatrix is updated for any position changes
|
// updateFromHMDSensorMatrix (called from paintGL) expects that the sensorToWorldMatrix is updated for any position changes
|
||||||
// that happen between render and Application::update (which calls updateSensorToWorldMatrix to do so).
|
// that happen between render and Application::update (which calls updateSensorToWorldMatrix to do so).
|
||||||
|
@ -625,7 +627,7 @@ void MyAvatar::updateFromHMDSensorMatrix(const glm::mat4& hmdSensorMatrix) {
|
||||||
_hmdSensorMatrix = hmdSensorMatrix;
|
_hmdSensorMatrix = hmdSensorMatrix;
|
||||||
auto newHmdSensorPosition = extractTranslation(hmdSensorMatrix);
|
auto newHmdSensorPosition = extractTranslation(hmdSensorMatrix);
|
||||||
|
|
||||||
if (newHmdSensorPosition != _hmdSensorPosition &&
|
if (newHmdSensorPosition != getHMDSensorPosition() &&
|
||||||
glm::length(newHmdSensorPosition) > MAX_HMD_ORIGIN_DISTANCE) {
|
glm::length(newHmdSensorPosition) > MAX_HMD_ORIGIN_DISTANCE) {
|
||||||
qWarning() << "Invalid HMD sensor position " << newHmdSensorPosition;
|
qWarning() << "Invalid HMD sensor position " << newHmdSensorPosition;
|
||||||
// Ignore unreasonable HMD sensor data
|
// Ignore unreasonable HMD sensor data
|
||||||
|
@ -633,7 +635,7 @@ void MyAvatar::updateFromHMDSensorMatrix(const glm::mat4& hmdSensorMatrix) {
|
||||||
}
|
}
|
||||||
_hmdSensorPosition = newHmdSensorPosition;
|
_hmdSensorPosition = newHmdSensorPosition;
|
||||||
_hmdSensorOrientation = glm::quat_cast(hmdSensorMatrix);
|
_hmdSensorOrientation = glm::quat_cast(hmdSensorMatrix);
|
||||||
_hmdSensorFacing = getFacingDir2D(_hmdSensorOrientation);
|
_headControllerFacing = getFacingDir2D(_headControllerPoseInSensorFrameCache.get().rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyAvatar::updateJointFromController(controller::Action poseKey, ThreadSafeValueCache<glm::mat4>& matrixCache) {
|
void MyAvatar::updateJointFromController(controller::Action poseKey, ThreadSafeValueCache<glm::mat4>& matrixCache) {
|
||||||
|
@ -671,7 +673,7 @@ void MyAvatar::updateSensorToWorldMatrix() {
|
||||||
|
|
||||||
// Update avatar head rotation with sensor data
|
// Update avatar head rotation with sensor data
|
||||||
void MyAvatar::updateFromTrackers(float deltaTime) {
|
void MyAvatar::updateFromTrackers(float deltaTime) {
|
||||||
glm::vec3 estimatedPosition, estimatedRotation;
|
glm::vec3 estimatedRotation;
|
||||||
|
|
||||||
bool inHmd = qApp->isHMDMode();
|
bool inHmd = qApp->isHMDMode();
|
||||||
bool playing = DependencyManager::get<recording::Deck>()->isPlaying();
|
bool playing = DependencyManager::get<recording::Deck>()->isPlaying();
|
||||||
|
@ -682,11 +684,7 @@ void MyAvatar::updateFromTrackers(float deltaTime) {
|
||||||
FaceTracker* tracker = qApp->getActiveFaceTracker();
|
FaceTracker* tracker = qApp->getActiveFaceTracker();
|
||||||
bool inFacetracker = tracker && !FaceTracker::isMuted();
|
bool inFacetracker = tracker && !FaceTracker::isMuted();
|
||||||
|
|
||||||
if (inHmd) {
|
if (inFacetracker) {
|
||||||
estimatedPosition = extractTranslation(getHMDSensorMatrix());
|
|
||||||
estimatedPosition.x *= -1.0f;
|
|
||||||
} else if (inFacetracker) {
|
|
||||||
estimatedPosition = tracker->getHeadTranslation();
|
|
||||||
estimatedRotation = glm::degrees(safeEulerAngles(tracker->getHeadRotation()));
|
estimatedRotation = glm::degrees(safeEulerAngles(tracker->getHeadRotation()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1884,20 +1882,14 @@ void MyAvatar::updateOrientation(float deltaTime) {
|
||||||
|
|
||||||
getHead()->setBasePitch(getHead()->getBasePitch() + getDriveKey(PITCH) * _pitchSpeed * deltaTime);
|
getHead()->setBasePitch(getHead()->getBasePitch() + getDriveKey(PITCH) * _pitchSpeed * deltaTime);
|
||||||
|
|
||||||
if (qApp->isHMDMode()) {
|
glm::quat localOrientation = getHeadControllerPoseInAvatarFrame();
|
||||||
glm::quat orientation = glm::quat_cast(getSensorToWorldMatrix()) * getHMDSensorOrientation();
|
// these angles will be in radians
|
||||||
glm::quat bodyOrientation = getWorldBodyOrientation();
|
// ... so they need to be converted to degrees before we do math...
|
||||||
glm::quat localOrientation = glm::inverse(bodyOrientation) * orientation;
|
glm::vec3 euler = glm::eulerAngles(localOrientation) * DEGREES_PER_RADIAN;
|
||||||
|
Head* head = getHead();
|
||||||
// these angles will be in radians
|
head->setBaseYaw(YAW(euler));
|
||||||
// ... so they need to be converted to degrees before we do math...
|
head->setBasePitch(PITCH(euler));
|
||||||
glm::vec3 euler = glm::eulerAngles(localOrientation) * DEGREES_PER_RADIAN;
|
head->setBaseRoll(ROLL(euler));
|
||||||
|
|
||||||
Head* head = getHead();
|
|
||||||
head->setBaseYaw(YAW(euler));
|
|
||||||
head->setBasePitch(PITCH(euler));
|
|
||||||
head->setBaseRoll(ROLL(euler));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyAvatar::updateActionMotor(float deltaTime) {
|
void MyAvatar::updateActionMotor(float deltaTime) {
|
||||||
|
@ -2332,8 +2324,8 @@ glm::quat MyAvatar::getWorldBodyOrientation() const {
|
||||||
glm::mat4 MyAvatar::deriveBodyFromHMDSensor() const {
|
glm::mat4 MyAvatar::deriveBodyFromHMDSensor() const {
|
||||||
|
|
||||||
// HMD is in sensor space.
|
// HMD is in sensor space.
|
||||||
const glm::vec3 hmdPosition = getHMDSensorPosition();
|
const glm::vec3 hmdPosition = getHeadControllerPoseInSensorFrame();
|
||||||
const glm::quat hmdOrientation = getHMDSensorOrientation();
|
const glm::quat hmdOrientation = getHeadControllerPoseInSensorFrame();
|
||||||
const glm::quat hmdOrientationYawOnly = cancelOutRollAndPitch(hmdOrientation);
|
const glm::quat hmdOrientationYawOnly = cancelOutRollAndPitch(hmdOrientation);
|
||||||
|
|
||||||
const Rig& rig = _skeletonModel->getRig();
|
const Rig& rig = _skeletonModel->getRig();
|
||||||
|
@ -2478,7 +2470,7 @@ bool MyAvatar::FollowHelper::shouldActivateRotation(const MyAvatar& myAvatar, co
|
||||||
} else {
|
} else {
|
||||||
const float FOLLOW_ROTATION_THRESHOLD = cosf(PI / 6.0f); // 30 degrees
|
const float FOLLOW_ROTATION_THRESHOLD = cosf(PI / 6.0f); // 30 degrees
|
||||||
glm::vec2 bodyFacing = getFacingDir2D(currentBodyMatrix);
|
glm::vec2 bodyFacing = getFacingDir2D(currentBodyMatrix);
|
||||||
return glm::dot(myAvatar.getHMDSensorFacingMovingAverage(), bodyFacing) < FOLLOW_ROTATION_THRESHOLD;
|
return glm::dot(myAvatar.getHeadControllerFacingMovingAverage(), bodyFacing) < FOLLOW_ROTATION_THRESHOLD;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2625,9 +2617,10 @@ glm::mat4 MyAvatar::computeCameraRelativeHandControllerMatrix(const glm::mat4& c
|
||||||
cameraWorldMatrix *= createMatFromScaleQuatAndPos(vec3(-1.0f, 1.0f, 1.0f), glm::quat(), glm::vec3());
|
cameraWorldMatrix *= createMatFromScaleQuatAndPos(vec3(-1.0f, 1.0f, 1.0f), glm::quat(), glm::vec3());
|
||||||
}
|
}
|
||||||
|
|
||||||
// compute a NEW sensorToWorldMatrix for the camera. The equation is cameraWorldMatrix = cameraSensorToWorldMatrix * _hmdSensorMatrix.
|
// compute a NEW sensorToWorldMatrix for the camera.
|
||||||
|
// The equation is cameraWorldMatrix = cameraSensorToWorldMatrix * _hmdSensorMatrix.
|
||||||
// here we solve for the unknown cameraSensorToWorldMatrix.
|
// here we solve for the unknown cameraSensorToWorldMatrix.
|
||||||
glm::mat4 cameraSensorToWorldMatrix = cameraWorldMatrix * glm::inverse(_hmdSensorMatrix);
|
glm::mat4 cameraSensorToWorldMatrix = cameraWorldMatrix * glm::inverse(getHMDSensorMatrix());
|
||||||
|
|
||||||
// Using the new cameraSensorToWorldMatrix, compute where the controller is in world space.
|
// Using the new cameraSensorToWorldMatrix, compute where the controller is in world space.
|
||||||
glm::mat4 controllerWorldMatrix = cameraSensorToWorldMatrix * controllerSensorMatrix;
|
glm::mat4 controllerWorldMatrix = cameraSensorToWorldMatrix * controllerSensorMatrix;
|
||||||
|
|
|
@ -185,7 +185,6 @@ public:
|
||||||
const glm::mat4& getHMDSensorMatrix() const { return _hmdSensorMatrix; }
|
const glm::mat4& getHMDSensorMatrix() const { return _hmdSensorMatrix; }
|
||||||
const glm::vec3& getHMDSensorPosition() const { return _hmdSensorPosition; }
|
const glm::vec3& getHMDSensorPosition() const { return _hmdSensorPosition; }
|
||||||
const glm::quat& getHMDSensorOrientation() const { return _hmdSensorOrientation; }
|
const glm::quat& getHMDSensorOrientation() const { return _hmdSensorOrientation; }
|
||||||
const glm::vec2& getHMDSensorFacingMovingAverage() const { return _hmdSensorFacingMovingAverage; }
|
|
||||||
|
|
||||||
Q_INVOKABLE void setOrientationVar(const QVariant& newOrientationVar);
|
Q_INVOKABLE void setOrientationVar(const QVariant& newOrientationVar);
|
||||||
Q_INVOKABLE QVariant getOrientationVar() const;
|
Q_INVOKABLE QVariant getOrientationVar() const;
|
||||||
|
@ -470,6 +469,8 @@ public:
|
||||||
controller::Pose getHeadControllerPoseInSensorFrame() const;
|
controller::Pose getHeadControllerPoseInSensorFrame() const;
|
||||||
controller::Pose getHeadControllerPoseInWorldFrame() const;
|
controller::Pose getHeadControllerPoseInWorldFrame() const;
|
||||||
controller::Pose getHeadControllerPoseInAvatarFrame() const;
|
controller::Pose getHeadControllerPoseInAvatarFrame() const;
|
||||||
|
const glm::vec2& getHeadControllerFacingMovingAverage() const { return _headControllerFacingMovingAverage; }
|
||||||
|
|
||||||
|
|
||||||
bool hasDriveInput() const;
|
bool hasDriveInput() const;
|
||||||
|
|
||||||
|
@ -664,13 +665,13 @@ private:
|
||||||
// working copies -- see AvatarData for thread-safe _sensorToWorldMatrixCache, used for outward facing access
|
// working copies -- see AvatarData for thread-safe _sensorToWorldMatrixCache, used for outward facing access
|
||||||
glm::mat4 _sensorToWorldMatrix { glm::mat4() };
|
glm::mat4 _sensorToWorldMatrix { glm::mat4() };
|
||||||
|
|
||||||
// cache of the current HMD sensor position and orientation
|
// cache of the current HMD sensor position and orientation in sensor space.
|
||||||
// in sensor space.
|
|
||||||
glm::mat4 _hmdSensorMatrix;
|
glm::mat4 _hmdSensorMatrix;
|
||||||
glm::quat _hmdSensorOrientation;
|
glm::quat _hmdSensorOrientation;
|
||||||
glm::vec3 _hmdSensorPosition;
|
glm::vec3 _hmdSensorPosition;
|
||||||
glm::vec2 _hmdSensorFacing; // facing vector in xz plane
|
// cache head controller pose in sensor space
|
||||||
glm::vec2 _hmdSensorFacingMovingAverage { 0, 0 }; // facing vector in xz plane
|
glm::vec2 _headControllerFacing; // facing vector in xz plane
|
||||||
|
glm::vec2 _headControllerFacingMovingAverage { 0, 0 }; // facing vector in xz plane
|
||||||
|
|
||||||
// cache of the current body position and orientation of the avatar's body,
|
// cache of the current body position and orientation of the avatar's body,
|
||||||
// in sensor space.
|
// in sensor space.
|
||||||
|
|
|
@ -59,7 +59,7 @@ void MySkeletonModel::updateRig(float deltaTime, glm::mat4 parentTransform) {
|
||||||
} else {
|
} else {
|
||||||
if (qApp->isHMDMode()) {
|
if (qApp->isHMDMode()) {
|
||||||
// get HMD position from sensor space into world space, and back into rig space
|
// get HMD position from sensor space into world space, and back into rig space
|
||||||
glm::mat4 worldHMDMat = myAvatar->getSensorToWorldMatrix() * myAvatar->getHMDSensorMatrix();
|
glm::mat4 worldHMDMat = myAvatar->getHeadControllerPoseInWorldFrame();
|
||||||
glm::mat4 rigToWorld = createMatFromQuatAndPos(getRotation(), getTranslation());
|
glm::mat4 rigToWorld = createMatFromQuatAndPos(getRotation(), getTranslation());
|
||||||
glm::mat4 worldToRig = glm::inverse(rigToWorld);
|
glm::mat4 worldToRig = glm::inverse(rigToWorld);
|
||||||
glm::mat4 rigHMDMat = worldToRig * worldHMDMat;
|
glm::mat4 rigHMDMat = worldToRig * worldHMDMat;
|
||||||
|
|
|
@ -118,7 +118,7 @@ bool HMDScriptingInterface::getHUDLookAtPosition3D(glm::vec3& result) const {
|
||||||
|
|
||||||
glm::mat4 HMDScriptingInterface::getWorldHMDMatrix() const {
|
glm::mat4 HMDScriptingInterface::getWorldHMDMatrix() const {
|
||||||
auto myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
auto myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
||||||
return myAvatar->getSensorToWorldMatrix() * myAvatar->getHMDSensorMatrix();
|
return myAvatar->getSensorToWorldMatrix() * (glm::mat4)myAvatar->getHeadControllerPoseInSensorFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 HMDScriptingInterface::getPosition() const {
|
glm::vec3 HMDScriptingInterface::getPosition() const {
|
||||||
|
|
|
@ -43,6 +43,10 @@ namespace controller {
|
||||||
Pose transform(const glm::mat4& mat) const;
|
Pose transform(const glm::mat4& mat) const;
|
||||||
Pose postTransform(const glm::mat4& mat) const;
|
Pose postTransform(const glm::mat4& mat) const;
|
||||||
|
|
||||||
|
operator glm::mat4() const { return createMatFromQuatAndPos(rotation, translation); }
|
||||||
|
operator glm::quat() const { return rotation; }
|
||||||
|
operator glm::vec3() const { return translation; }
|
||||||
|
|
||||||
static QScriptValue toScriptValue(QScriptEngine* engine, const Pose& event);
|
static QScriptValue toScriptValue(QScriptEngine* engine, const Pose& event);
|
||||||
static void fromScriptValue(const QScriptValue& object, Pose& event);
|
static void fromScriptValue(const QScriptValue& object, Pose& event);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue