mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-23 17:34:54 +02:00
Relax head/lean when not tracking
This commit is contained in:
parent
e37ef226fc
commit
fdf9fdd877
6 changed files with 48 additions and 23 deletions
|
@ -1158,15 +1158,8 @@ void MyAvatar::updateOrientation(float deltaTime) {
|
||||||
pitch *= DEGREES_PER_RADIAN;
|
pitch *= DEGREES_PER_RADIAN;
|
||||||
roll *= DEGREES_PER_RADIAN;
|
roll *= DEGREES_PER_RADIAN;
|
||||||
|
|
||||||
// Record the angular velocity
|
|
||||||
Head* head = getHead();
|
|
||||||
if (deltaTime > 0.0f) {
|
|
||||||
glm::vec3 angularVelocity(pitch - head->getBasePitch(), yaw - head->getBaseYaw(), roll - head->getBaseRoll());
|
|
||||||
angularVelocity *= 1.0f / deltaTime;
|
|
||||||
head->setAngularVelocity(angularVelocity);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Invert yaw and roll when in mirror mode
|
//Invert yaw and roll when in mirror mode
|
||||||
|
Head* head = getHead();
|
||||||
if (Application::getInstance()->getCamera()->getMode() == CAMERA_MODE_MIRROR) {
|
if (Application::getInstance()->getCamera()->getMode() == CAMERA_MODE_MIRROR) {
|
||||||
head->setBaseYaw(-yaw);
|
head->setBaseYaw(-yaw);
|
||||||
head->setBasePitch(pitch);
|
head->setBasePitch(pitch);
|
||||||
|
|
|
@ -14,3 +14,33 @@
|
||||||
inline float FaceTracker::getBlendshapeCoefficient(int index) const {
|
inline float FaceTracker::getBlendshapeCoefficient(int index) const {
|
||||||
return isValidBlendshapeIndex(index) ? _blendshapeCoefficients[index] : 0.0f;
|
return isValidBlendshapeIndex(index) ? _blendshapeCoefficients[index] : 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float FaceTracker::getFadeCoefficient() const {
|
||||||
|
// TODO: apply exponential relaxation
|
||||||
|
return _relaxationStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
const glm::vec3 FaceTracker::getHeadTranslation() const {
|
||||||
|
return glm::mix(glm::vec3(0.0f), _headTranslation, getFadeCoefficient());
|
||||||
|
}
|
||||||
|
|
||||||
|
const glm::quat FaceTracker::getHeadRotation() const {
|
||||||
|
return glm::mix(glm::quat(), _headRotation, getFadeCoefficient());
|
||||||
|
}
|
||||||
|
|
||||||
|
void FaceTracker::update(float deltaTime) {
|
||||||
|
static const float RELAXATION_TIME = 0.4; // sec
|
||||||
|
|
||||||
|
if (isTracking()) {
|
||||||
|
if (_relaxationStatus == 1.0f) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_relaxationStatus += deltaTime / RELAXATION_TIME;
|
||||||
|
} else {
|
||||||
|
if (_relaxationStatus == 0.0f) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_relaxationStatus -= deltaTime / RELAXATION_TIME;
|
||||||
|
}
|
||||||
|
_relaxationStatus = glm::clamp(_relaxationStatus, 0.0f, 1.0f);
|
||||||
|
}
|
|
@ -27,11 +27,13 @@ public:
|
||||||
virtual bool isTracking() const { return false; }
|
virtual bool isTracking() const { return false; }
|
||||||
|
|
||||||
virtual void init() {}
|
virtual void init() {}
|
||||||
virtual void update(float deltaTime) {}
|
virtual void update(float deltaTime);
|
||||||
virtual void reset() {}
|
virtual void reset() {}
|
||||||
|
|
||||||
const glm::vec3& getHeadTranslation() const { return _headTranslation; }
|
float getFadeCoefficient() const;
|
||||||
const glm::quat& getHeadRotation() const { return _headRotation; }
|
|
||||||
|
const glm::vec3 getHeadTranslation() const;
|
||||||
|
const glm::quat getHeadRotation() const;
|
||||||
|
|
||||||
float getEstimatedEyePitch() const { return _estimatedEyePitch; }
|
float getEstimatedEyePitch() const { return _estimatedEyePitch; }
|
||||||
float getEstimatedEyeYaw() const { return _estimatedEyeYaw; }
|
float getEstimatedEyeYaw() const { return _estimatedEyeYaw; }
|
||||||
|
@ -42,15 +44,13 @@ public:
|
||||||
float getBlendshapeCoefficient(int index) const;
|
float getBlendshapeCoefficient(int index) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|
||||||
glm::vec3 _headTranslation = glm::vec3(0.0f);
|
glm::vec3 _headTranslation = glm::vec3(0.0f);
|
||||||
glm::quat _headRotation = glm::quat();
|
glm::quat _headRotation = glm::quat();
|
||||||
float _estimatedEyePitch = 0.0f;
|
float _estimatedEyePitch = 0.0f;
|
||||||
float _estimatedEyeYaw = 0.0f;
|
float _estimatedEyeYaw = 0.0f;
|
||||||
QVector<float> _blendshapeCoefficients;
|
QVector<float> _blendshapeCoefficients;
|
||||||
|
|
||||||
float _fadeCoefficient = 0.0f;
|
float _relaxationStatus = 0.0f; // Between 0.0f and 1.0f
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_FaceTracker_h
|
#endif // hifi_FaceTracker_h
|
||||||
|
|
|
@ -54,6 +54,8 @@ void Faceshift::update(float deltaTime) {
|
||||||
if (!isActive()) {
|
if (!isActive()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
FaceTracker::update(deltaTime);
|
||||||
|
|
||||||
// get the euler angles relative to the window
|
// get the euler angles relative to the window
|
||||||
glm::vec3 eulers = glm::degrees(safeEulerAngles(_headRotation * glm::quat(glm::radians(glm::vec3(
|
glm::vec3 eulers = glm::degrees(safeEulerAngles(_headRotation * glm::quat(glm::radians(glm::vec3(
|
||||||
(_eyeGazeLeftPitch + _eyeGazeRightPitch) / 2.0f, (_eyeGazeLeftYaw + _eyeGazeRightYaw) / 2.0f, 0.0f)))));
|
(_eyeGazeLeftPitch + _eyeGazeRightPitch) / 2.0f, (_eyeGazeLeftYaw + _eyeGazeRightYaw) / 2.0f, 0.0f)))));
|
||||||
|
|
|
@ -41,7 +41,6 @@ const glm::vec3 DEFAULT_HEAD_ORIGIN(0.0f, 0.0f, 0.7f);
|
||||||
|
|
||||||
Visage::Visage() :
|
Visage::Visage() :
|
||||||
_enabled(false),
|
_enabled(false),
|
||||||
_active(false),
|
|
||||||
_headOrigin(DEFAULT_HEAD_ORIGIN) {
|
_headOrigin(DEFAULT_HEAD_ORIGIN) {
|
||||||
|
|
||||||
#ifdef HAVE_VISAGE
|
#ifdef HAVE_VISAGE
|
||||||
|
@ -119,19 +118,20 @@ static const QMultiHash<QByteArray, QPair<int, float> >& getActionUnitNameMap()
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const float TRANSLATION_SCALE = 20.0f;
|
|
||||||
|
|
||||||
|
#ifdef HAVE_VISAGE
|
||||||
|
const float TRANSLATION_SCALE = 20.0f;
|
||||||
void Visage::init() {
|
void Visage::init() {
|
||||||
connect(DependencyManager::get<Faceshift>().data(), SIGNAL(connectionStateChanged()), SLOT(updateEnabled()));
|
connect(DependencyManager::get<Faceshift>().data(), SIGNAL(connectionStateChanged()), SLOT(updateEnabled()));
|
||||||
updateEnabled();
|
updateEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Visage::update(float deltaTime) {
|
void Visage::update(float deltaTime) {
|
||||||
#ifdef HAVE_VISAGE
|
if (!isActive()) {
|
||||||
_active = (_tracker->getTrackingData(_data) == TRACK_STAT_OK);
|
|
||||||
if (!_active) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
FaceTracker::update(deltaTime);
|
||||||
|
|
||||||
_headRotation = glm::quat(glm::vec3(-_data->faceRotation[0], -_data->faceRotation[1], _data->faceRotation[2]));
|
_headRotation = glm::quat(glm::vec3(-_data->faceRotation[0], -_data->faceRotation[1], _data->faceRotation[2]));
|
||||||
_headTranslation = (glm::vec3(_data->faceTranslation[0], _data->faceTranslation[1], _data->faceTranslation[2]) -
|
_headTranslation = (glm::vec3(_data->faceTranslation[0], _data->faceTranslation[1], _data->faceTranslation[2]) -
|
||||||
_headOrigin) * TRANSLATION_SCALE;
|
_headOrigin) * TRANSLATION_SCALE;
|
||||||
|
@ -163,12 +163,12 @@ void Visage::update(float deltaTime) {
|
||||||
}
|
}
|
||||||
_blendshapeCoefficients[leftEyeBlinkIndex] = 1.0f - _data->eyeClosure[1];
|
_blendshapeCoefficients[leftEyeBlinkIndex] = 1.0f - _data->eyeClosure[1];
|
||||||
_blendshapeCoefficients[rightEyeBlinkIndex] = 1.0f - _data->eyeClosure[0];
|
_blendshapeCoefficients[rightEyeBlinkIndex] = 1.0f - _data->eyeClosure[0];
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Visage::reset() {
|
void Visage::reset() {
|
||||||
_headOrigin += _headTranslation / TRANSLATION_SCALE;
|
_headOrigin += _headTranslation / TRANSLATION_SCALE;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void Visage::updateEnabled() {
|
void Visage::updateEnabled() {
|
||||||
setEnabled(Menu::getInstance()->isOptionChecked(MenuOption::Visage) &&
|
setEnabled(Menu::getInstance()->isOptionChecked(MenuOption::Visage) &&
|
||||||
|
|
|
@ -31,15 +31,16 @@ class Visage : public FaceTracker, public Dependency {
|
||||||
SINGLETON_DEPENDENCY
|
SINGLETON_DEPENDENCY
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
#ifdef HAVE_VISAGE
|
||||||
virtual void init();
|
virtual void init();
|
||||||
virtual void update(float deltaTime);
|
virtual void update(float deltaTime);
|
||||||
virtual void reset();
|
virtual void reset();
|
||||||
|
|
||||||
virtual bool isActive() const { return _active; }
|
virtual bool isActive() const { return _tracker->getTrackingData(_data) == TRACK_STAT_OK; }
|
||||||
virtual bool isTracking() const { return isActive(); }
|
virtual bool isTracking() const { return isActive(); }
|
||||||
|
#endif
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
void updateEnabled();
|
void updateEnabled();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -55,7 +56,6 @@ private:
|
||||||
void setEnabled(bool enabled);
|
void setEnabled(bool enabled);
|
||||||
|
|
||||||
bool _enabled;
|
bool _enabled;
|
||||||
bool _active;
|
|
||||||
|
|
||||||
glm::vec3 _headOrigin;
|
glm::vec3 _headOrigin;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue