Move changes to Head and remove leftover code

This commit is contained in:
luiscuenca 2019-10-23 14:23:29 -07:00
parent a4fcb2c39e
commit bb0849d3a0
No known key found for this signature in database
GPG key ID: 2387ECD129A6961D
7 changed files with 47 additions and 53 deletions

View file

@ -2191,20 +2191,15 @@ void MyAvatar::computeMyLookAtTarget(const AvatarHash& hash) {
foreach (const AvatarSharedPointer& avatarData, hash) {
std::shared_ptr<Avatar> avatar = std::static_pointer_cast<Avatar>(avatarData);
if (!avatar->isMyAvatar() && avatar->isInitialized()) {
if (_forceTargetAvatarID.isNull() || avatar->getID() != _forceTargetAvatarID) {
glm::vec3 otherForward = avatar->getHeadJointFrontVector();
glm::vec3 otherPosition = avatar->getHead()->getEyePosition();
const float TIME_WITHOUT_TALKING_THRESHOLD = 1.0f;
bool otherIsTalking = avatar->getHead()->getTimeWithoutTalking() <= TIME_WITHOUT_TALKING_THRESHOLD;
bool lookingAtOtherAlready = _lookAtTargetAvatar.lock().get() == avatar.get();
float cost = lookAtCostFunction(myForward, myPosition, otherForward, otherPosition, otherIsTalking, lookingAtOtherAlready);
if (cost < bestCost) {
bestCost = cost;
bestAvatar = avatar;
}
} else {
glm::vec3 otherForward = avatar->getHeadJointFrontVector();
glm::vec3 otherPosition = avatar->getHead()->getEyePosition();
const float TIME_WITHOUT_TALKING_THRESHOLD = 1.0f;
bool otherIsTalking = avatar->getHead()->getTimeWithoutTalking() <= TIME_WITHOUT_TALKING_THRESHOLD;
bool lookingAtOtherAlready = _lookAtTargetAvatar.lock().get() == avatar.get();
float cost = lookAtCostFunction(myForward, myPosition, otherForward, otherPosition, otherIsTalking, lookingAtOtherAlready);
if (cost < bestCost) {
bestCost = cost;
bestAvatar = avatar;
break;
}
}
}
@ -6652,7 +6647,7 @@ void MyAvatar::updateEyesLookAtPosition(FaceTracker* faceTracker, Camera& myCame
} else if (_scriptControlsEyesLookAt) {
if (_scriptEyesControlTimer < MAX_LOOK_AT_TIME_SCRIPT_CONTROL) {
_scriptEyesControlTimer += deltaTime;
lookAtSpot = _eyesLookAtTarget;
lookAtSpot = _eyesLookAtTarget.get();
} else {
_scriptControlsEyesLookAt = false;
}
@ -6740,7 +6735,7 @@ void MyAvatar::updateEyesLookAtPosition(FaceTracker* faceTracker, Camera& myCame
}
}
}
_eyesLookAtTarget = lookAtSpot;
_eyesLookAtTarget.set(lookAtSpot);
getHead()->setLookAtPosition(lookAtSpot);
}
@ -6829,7 +6824,7 @@ void MyAvatar::setEyesLookAt(const glm::vec3& lookAtTarget) {
Q_ARG(const glm::vec3&, lookAtTarget));
return;
}
_eyesLookAtTarget = lookAtTarget;
_eyesLookAtTarget.set(lookAtTarget);
_scriptEyesControlTimer = 0.0f;
_scriptControlsEyesLookAt = true;
}

View file

@ -1780,7 +1780,7 @@ public:
* @function MyAvatar.getEyesLookAt
* @returns {Vec3} The eyes's look at target in world coordinates.
*/
Q_INVOKABLE glm::vec3 getEyesLookAt() { return _eyesLookAtTarget; }
Q_INVOKABLE glm::vec3 getEyesLookAt() { return _eyesLookAtTarget.get(); }
/**jsdoc
* Aims the pointing directional blending towards the provided target point.
@ -2672,13 +2672,12 @@ private:
AvatarWeakPointer _lookAtTargetAvatar;
glm::vec3 _targetAvatarPosition;
QUuid _forceTargetAvatarID;
bool _shouldRender { true };
float _oculusYawOffset;
eyeContactTarget _eyeContactTarget;
float _eyeContactTargetTimer { 0.0f };
glm::vec3 _eyesLookAtTarget;
ThreadSafeValueCache<glm::vec3> _eyesLookAtTarget { glm::vec3() };
bool _scriptControlsEyesLookAt{ false };
float _scriptEyesControlTimer{ 0.0f };

View file

@ -355,3 +355,24 @@ float Head::getFinalPitch() const {
float Head::getFinalRoll() const {
return glm::clamp(_baseRoll + _deltaRoll, MIN_HEAD_ROLL, MAX_HEAD_ROLL);
}
void Head::setLookAtPosition(const glm::vec3& lookAtPosition) {
if (_isEyeLookAtUpdated && _requestLookAtPosition != lookAtPosition) {
_lookAtPositionChanged = usecTimestampNow();
glm::vec3 oldAvatarLookAtVector = _requestLookAtPosition - _owningAvatar->getWorldPosition();
glm::vec3 newAvatarLookAtVector = lookAtPosition - _owningAvatar->getWorldPosition();
const float MIN_BLINK_ANGLE = 0.35f; // 20 degrees
_forceBlinkToRetarget = angleBetween(oldAvatarLookAtVector, newAvatarLookAtVector) > MIN_BLINK_ANGLE;
if (_forceBlinkToRetarget) {
_isEyeLookAtUpdated = false;
} else {
_lookAtPosition = lookAtPosition;
}
}
_requestLookAtPosition = lookAtPosition;
}
void Head::updateEyeLookAt() {
_lookAtPosition = _requestLookAtPosition;
_isEyeLookAtUpdated = true;
}

View file

@ -79,6 +79,9 @@ public:
float getTimeWithoutTalking() const { return _timeWithoutTalking; }
virtual void setLookAtPosition(const glm::vec3& lookAtPosition) override;
void updateEyeLookAt();
protected:
// disallow copies of the Head, copy of owning Avatar is disallowed too
Head(const Head&);
@ -123,6 +126,10 @@ protected:
int _leftEyeLookAtID;
int _rightEyeLookAtID;
glm::vec3 _requestLookAtPosition;
bool _forceBlinkToRetarget { false };
bool _isEyeLookAtUpdated { false };
// private methods
void calculateMouthShapes(float timeRatio);
void applyEyelidOffset(glm::quat headOrientation);

View file

@ -1480,7 +1480,6 @@ public:
void setIsNewAvatar(bool isNewAvatar) { _isNewAvatar = isNewAvatar; }
bool getIsNewAvatar() { return _isNewAvatar; }
void setIsClientAvatar(bool isClientAvatar) { _isClientAvatar = isClientAvatar; }
bool getIsClientAvatar() const { return _isClientAvatar; }
void setSkeletonData(const std::vector<AvatarSkeletonTrait::UnpackedJointData>& skeletonData);
std::vector<AvatarSkeletonTrait::UnpackedJointData> getSkeletonData() const;
void sendSkeletonData() const;

View file

@ -234,30 +234,3 @@ void HeadData::setFaceTrackerConnected(bool value) {
_isFaceTrackerConnected = value;
}
void HeadData::setLookAtPosition(const glm::vec3& lookAtPosition) {
if (_owningAvatar->getIsClientAvatar() || _owningAvatar->isMyAvatar()) {
if (_isEyeLookAtUpdated && _requestLookAtPosition != lookAtPosition) {
_lookAtPositionChanged = usecTimestampNow();
glm::vec3 oldAvatarLookAtVector = _requestLookAtPosition - _owningAvatar->getWorldPosition();
glm::vec3 newAvatarLookAtVector = lookAtPosition - _owningAvatar->getWorldPosition();
const float MIN_BLINK_ANGLE = 0.35f; // 20 degrees
_forceBlinkToRetarget = angleBetween(oldAvatarLookAtVector, newAvatarLookAtVector) > MIN_BLINK_ANGLE;
if (_forceBlinkToRetarget) {
_isEyeLookAtUpdated = false;
} else {
_lookAtPosition = lookAtPosition;
}
}
_requestLookAtPosition = lookAtPosition;
} else {
if (_lookAtPosition != lookAtPosition) {
_lookAtPositionChanged = usecTimestampNow();
}
_lookAtPosition = lookAtPosition;
}
}
void HeadData::updateEyeLookAt() {
_lookAtPosition = _requestLookAtPosition;
_isEyeLookAtUpdated = true;
}

View file

@ -64,7 +64,12 @@ public:
void setBlendshapeCoefficients(const QVector<float>& blendshapeCoefficients) { _blendshapeCoefficients = blendshapeCoefficients; }
const glm::vec3& getLookAtPosition() const { return _lookAtPosition; }
void setLookAtPosition(const glm::vec3& lookAtPosition);
virtual void setLookAtPosition(const glm::vec3& lookAtPosition) {
if (_lookAtPosition != lookAtPosition) {
_lookAtPositionChanged = usecTimestampNow();
}
_lookAtPosition = lookAtPosition;
}
bool lookAtPositionChangedSince(quint64 time) { return _lookAtPositionChanged >= time; }
bool getHasProceduralEyeFaceMovement() const;
@ -79,8 +84,6 @@ public:
void setFaceTrackerConnected(bool value);
bool getFaceTrackerConnected() const { return _isFaceTrackerConnected; }
void updateEyeLookAt();
friend class AvatarData;
QJsonObject toJson() const;
@ -92,7 +95,6 @@ protected:
float _basePitch;
float _baseRoll;
glm::vec3 _requestLookAtPosition;
glm::vec3 _lookAtPosition;
quint64 _lookAtPositionChanged { 0 };
@ -113,8 +115,6 @@ protected:
QVector<float> _summedBlendshapeCoefficients;
QMap<QString, int> _blendshapeLookupMap;
AvatarData* _owningAvatar;
bool _forceBlinkToRetarget { false };
bool _isEyeLookAtUpdated { false };
private:
// privatize copy ctor and assignment operator so copies of this object cannot be made