Glow when moving.

This commit is contained in:
Andrzej Kapolka 2013-08-22 11:23:28 -07:00
parent ff245427fd
commit 7da9556815
5 changed files with 49 additions and 4 deletions

View file

@ -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");

View file

@ -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; }

View file

@ -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;
}
}

View file

@ -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();
}

View file

@ -69,4 +69,12 @@ private:
QStack<float> _intensityStack;
};
/// RAII-style glow handler. Applies glow when in scope.
class Glower {
public:
Glower(float amount = 1.0f);
~Glower();
};
#endif /* defined(__interface__GlowEffect__) */