diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 5f206fb6ed..39ce97c8eb 100755 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -105,7 +105,8 @@ Avatar::Avatar(Node* owningNode) : _initialized(false), _handHoldingPosition(0.0f, 0.0f, 0.0f), _maxArmLength(0.0f), - _pelvisStandingHeight(0.0f) + _pelvisStandingHeight(0.0f), + _moving(false) { // give the pointer to our head to inherited _headData variable from AvatarData _headData = &_head; @@ -695,6 +696,10 @@ float Avatar::getBallRenderAlpha(int ball, bool lookingInMirror) const { } void Avatar::renderBody(bool lookingInMirror, bool renderAvatarBalls) { + + // glow when moving + Glower glower(_moving ? 1.0f : 0.0f); + if (_head.getFace().isFullFrame()) { // Render the full-frame video float alpha = getBallRenderAlpha(BODY_BALL_HEAD_BASE, lookingInMirror); @@ -793,6 +798,14 @@ void Avatar::getBodyBallTransform(AvatarJointID jointID, glm::vec3& position, gl rotation = _bodyBall[jointID].rotation; } +int Avatar::parseData(unsigned char* sourceBuffer, int numBytes) { + // change in position implies movement + glm::vec3 oldPosition = _position; + AvatarData::parseData(sourceBuffer, numBytes); + const float MOVE_DISTANCE_THRESHOLD = 0.001f; + _moving = glm::distance(oldPosition, _position) > MOVE_DISTANCE_THRESHOLD; +} + void Avatar::saveData(QSettings* set) { set->beginGroup("Avatar"); diff --git a/interface/src/avatar/Avatar.h b/interface/src/avatar/Avatar.h index eb7a7851d0..4048f15d0f 100755 --- a/interface/src/avatar/Avatar.h +++ b/interface/src/avatar/Avatar.h @@ -164,6 +164,8 @@ public: // Get the position/rotation of a single body ball void getBodyBallTransform(AvatarJointID jointID, glm::vec3& position, glm::quat& rotation) const; + virtual int parseData(unsigned char* sourceBuffer, int numBytes); + static void renderJointConnectingCone(glm::vec3 position1, glm::vec3 position2, float radius1, float radius2); public slots: @@ -219,6 +221,8 @@ protected: float _stringLength; AvatarVoxelSystem _voxels; + bool _moving; ///< set when position is changing + // protected methods... glm::vec3 getBodyRightDirection() const { return getOrientation() * IDENTITY_RIGHT; } glm::vec3 getBodyUpDirection() const { return getOrientation() * IDENTITY_UP; } diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 00898da333..175b38378d 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -318,6 +318,10 @@ void MyAvatar::simulate(float deltaTime, Transmitter* transmitter, float gyroCam _mode = AVATAR_MODE_INTERACTING; } + // update moving flag based on speed + const float MOVING_SPEED_THRESHOLD = 0.01f; + _moving = _speed > MOVING_SPEED_THRESHOLD; + // update position by velocity, and subtract the change added earlier for gravity _position += _velocity * deltaTime; @@ -511,7 +515,13 @@ void MyAvatar::renderBody(bool lookingInMirror, bool renderAvatarBalls) { if (Application::getInstance()->getCamera()->getMode() == CAMERA_MODE_FIRST_PERSON) { // Dont display body - } else if (_head.getFace().isFullFrame()) { + return; + } + + // glow when moving + Glower glower(_moving ? 1.0f : 0.0f); + + if (_head.getFace().isFullFrame()) { // Render the full-frame video float alpha = getBallRenderAlpha(BODY_BALL_HEAD_BASE, lookingInMirror); if (alpha > 0.0f) { @@ -1032,4 +1042,4 @@ void MyAvatar::setOrientation(const glm::quat& orientation) { void MyAvatar::setNewScale(const float scale) { _newScale = scale; -} \ No newline at end of file +} diff --git a/interface/src/renderer/GlowEffect.cpp b/interface/src/renderer/GlowEffect.cpp index 782bda2a06..24936b85d3 100644 --- a/interface/src/renderer/GlowEffect.cpp +++ b/interface/src/renderer/GlowEffect.cpp @@ -73,10 +73,11 @@ void GlowEffect::begin(float intensity) { // store the current intensity and add the new amount _intensityStack.push(_intensity); glBlendColor(0.0f, 0.0f, 0.0f, _intensity += intensity); - _isEmpty = false; + _isEmpty &= (_intensity == 0.0f); } void GlowEffect::end() { + // restore the saved intensity glBlendColor(0.0f, 0.0f, 0.0f, _intensity = _intensityStack.pop()); } @@ -270,3 +271,12 @@ void GlowEffect::cycleRenderMode() { break; } } + +Glower::Glower(float amount) { + Application::getInstance()->getGlowEffect()->begin(amount); +} + +Glower::~Glower() { + Application::getInstance()->getGlowEffect()->end(); +} + diff --git a/interface/src/renderer/GlowEffect.h b/interface/src/renderer/GlowEffect.h index 81acd0c108..37765d18ba 100644 --- a/interface/src/renderer/GlowEffect.h +++ b/interface/src/renderer/GlowEffect.h @@ -69,4 +69,12 @@ private: QStack _intensityStack; }; +/// RAII-style glow handler. Applies glow when in scope. +class Glower { +public: + + Glower(float amount = 1.0f); + ~Glower(); +}; + #endif /* defined(__interface__GlowEffect__) */