Fade looking-at-me eye spheres over half a second

This commit is contained in:
David Rowe 2015-07-21 18:23:50 -07:00
parent 9ac4e2f687
commit bed266dfe9
3 changed files with 24 additions and 13 deletions

View file

@ -464,19 +464,24 @@ void Avatar::render(RenderArgs* renderArgs, const glm::vec3& cameraPosition, boo
// If the avatar is looking at me, indicate that they are
if (getHead()->getIsLookingAtMe() && Menu::getInstance()->isOptionChecked(MenuOption::ShowWhosLookingAtMe)) {
const glm::vec3 LOOKING_AT_ME_COLOR = { 1.0f, 1.0f, 1.0f };
float alpha = 1.0f;
float radius = 0.035f;
Transform transform;
glm::vec3 position = getHead()->getLeftEyePosition();
transform.setTranslation(position);
batch.setModelTransform(transform);
DependencyManager::get<DeferredLightingEffect>()->renderSolidSphere(batch, radius, 15, 15,
glm::vec4(LOOKING_AT_ME_COLOR, alpha));
position = getHead()->getRightEyePosition();
transform.setTranslation(position);
batch.setModelTransform(transform);
DependencyManager::get<DeferredLightingEffect>()->renderSolidSphere(batch, radius, 15, 15,
glm::vec4(LOOKING_AT_ME_COLOR, alpha));
const float LOOKING_AT_ME_DURATION = 0.5f; // seconds
quint64 now = usecTimestampNow();
float alpha = 1.0f - ((float)(usecTimestampNow() - getHead()->getIsLookingAtMeStarted()))
/ (LOOKING_AT_ME_DURATION * (float)USECS_PER_SECOND);
if (alpha > 0.0f) {
float radius = 0.035f;
Transform transform;
glm::vec3 position = getHead()->getLeftEyePosition();
transform.setTranslation(position);
batch.setModelTransform(transform);
DependencyManager::get<DeferredLightingEffect>()->renderSolidSphere(batch, radius, 15, 15,
glm::vec4(LOOKING_AT_ME_COLOR, alpha));
position = getHead()->getRightEyePosition();
transform.setTranslation(position);
batch.setModelTransform(transform);
DependencyManager::get<DeferredLightingEffect>()->renderSolidSphere(batch, radius, 15, 15,
glm::vec4(LOOKING_AT_ME_COLOR, alpha));
}
}
// quick check before falling into the code below:

View file

@ -55,6 +55,7 @@ Head::Head(Avatar* owningAvatar) :
_deltaLeanForward(0.0f),
_isCameraMoving(false),
_isLookingAtMe(false),
_isLookingAtMeStarted(0),
_faceModel(this),
_leftEyeLookAtID(DependencyManager::get<GeometryCache>()->allocateID()),
_rightEyeLookAtID(DependencyManager::get<GeometryCache>()->allocateID())
@ -323,6 +324,9 @@ glm::vec3 Head::getCorrectedLookAtPosition() {
}
void Head::setCorrectedLookAtPosition(glm::vec3 correctedLookAtPosition) {
if (!_isLookingAtMe) {
_isLookingAtMeStarted = usecTimestampNow();
}
_isLookingAtMe = true;
_correctedLookAtPosition = correctedLookAtPosition;
}

View file

@ -53,6 +53,7 @@ public:
glm::vec3 getCorrectedLookAtPosition();
void clearCorrectedLookAtPosition() { _isLookingAtMe = false; }
bool getIsLookingAtMe() { return _isLookingAtMe; }
quint64 getIsLookingAtMeStarted() { return _isLookingAtMeStarted; }
float getScale() const { return _scale; }
glm::vec3 getPosition() const { return _position; }
@ -139,6 +140,7 @@ private:
bool _isCameraMoving;
bool _isLookingAtMe;
quint64 _isLookingAtMeStarted;
FaceModel _faceModel;
glm::vec3 _correctedLookAtPosition;