Merge pull request #1509 from birarda/master

fix for avatar fade/scale bug
This commit is contained in:
Andrzej Kapolka 2014-01-13 14:02:45 -08:00
commit e721e8b7d4
6 changed files with 41 additions and 39 deletions

View file

@ -2127,9 +2127,12 @@ void Application::updateAvatars(float deltaTime, glm::vec3 mouseRayOrigin, glm::
for (vector<Avatar*>::iterator fade = _avatarFades.begin(); fade != _avatarFades.end(); fade++) { for (vector<Avatar*>::iterator fade = _avatarFades.begin(); fade != _avatarFades.end(); fade++) {
Avatar* avatar = *fade; Avatar* avatar = *fade;
const float SHRINK_RATE = 0.9f; const float SHRINK_RATE = 0.9f;
avatar->setNewScale(avatar->getNewScale() * SHRINK_RATE);
const float MINIMUM_SCALE = 0.001f; avatar->setTargetScale(avatar->getScale() * SHRINK_RATE);
if (avatar->getNewScale() < MINIMUM_SCALE) {
const float MIN_FADE_SCALE = 0.001;
if (avatar->getTargetScale() < MIN_FADE_SCALE) {
delete avatar; delete avatar;
_avatarFades.erase(fade--); _avatarFades.erase(fade--);

View file

@ -891,7 +891,7 @@ void Menu::editPreferences() {
_maxVoxelPacketsPerSecond = maxVoxelsPPS->value(); _maxVoxelPacketsPerSecond = maxVoxelsPPS->value();
applicationInstance->getAvatar()->setLeanScale(leanScale->value()); applicationInstance->getAvatar()->setLeanScale(leanScale->value());
applicationInstance->getAvatar()->setNewScale(avatarScale->value()); applicationInstance->getAvatar()->setClampedTargetScale(avatarScale->value());
_audioJitterBufferSamples = audioJitterBufferSamples->value(); _audioJitterBufferSamples = audioJitterBufferSamples->value();

View file

@ -167,8 +167,8 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
follow(NULL); follow(NULL);
} }
if (_scale != _newScale) { if (_scale != _targetScale) {
setScale(_newScale); setScale(_targetScale);
} }
// copy velocity so we can use it later for acceleration // copy velocity so we can use it later for acceleration
@ -439,30 +439,30 @@ void Avatar::goHome() {
} }
void Avatar::increaseSize() { void Avatar::increaseSize() {
if ((1.f + SCALING_RATIO) * _newScale < MAX_SCALE) { if ((1.f + SCALING_RATIO) * _targetScale < MAX_AVATAR_SCALE) {
_newScale *= (1.f + SCALING_RATIO); _targetScale *= (1.f + SCALING_RATIO);
qDebug("Changed scale to %f\n", _newScale); qDebug("Changed scale to %f\n", _targetScale);
} }
} }
void Avatar::decreaseSize() { void Avatar::decreaseSize() {
if (MIN_SCALE < (1.f - SCALING_RATIO) * _newScale) { if (MIN_AVATAR_SCALE < (1.f - SCALING_RATIO) * _targetScale) {
_newScale *= (1.f - SCALING_RATIO); _targetScale *= (1.f - SCALING_RATIO);
qDebug("Changed scale to %f\n", _newScale); qDebug("Changed scale to %f\n", _targetScale);
} }
} }
void Avatar::resetSize() { void Avatar::resetSize() {
_newScale = 1.0f; _targetScale = 1.0f;
qDebug("Reseted scale to %f\n", _newScale); qDebug("Reseted scale to %f\n", _targetScale);
} }
void Avatar::setScale(const float scale) { void Avatar::setScale(const float scale) {
_scale = scale; _scale = scale;
if (_newScale * (1.f - RESCALING_TOLERANCE) < _scale && if (_targetScale * (1.f - RESCALING_TOLERANCE) < _scale &&
_scale < _newScale * (1.f + RESCALING_TOLERANCE)) { _scale < _targetScale * (1.f + RESCALING_TOLERANCE)) {
_scale = _newScale; _scale = _targetScale;
} }
_skeleton.setScale(_scale); _skeleton.setScale(_scale);

View file

@ -92,12 +92,12 @@ void MyAvatar::simulate(float deltaTime, Transmitter* transmitter) {
} }
// Ajust, scale, position and lookAt position when following an other avatar // Ajust, scale, position and lookAt position when following an other avatar
if (_leadingAvatar && _newScale != _leadingAvatar->getScale()) { if (_leadingAvatar && _targetScale != _leadingAvatar->getScale()) {
_newScale = _leadingAvatar->getScale(); _targetScale = _leadingAvatar->getScale();
} }
if (_scale != _newScale) { if (_scale != _targetScale) {
float scale = (1.f - SMOOTHING_RATIO) * _scale + SMOOTHING_RATIO * _newScale; float scale = (1.f - SMOOTHING_RATIO) * _scale + SMOOTHING_RATIO * _targetScale;
setScale(scale); setScale(scale);
Application::getInstance()->getCamera()->setScale(scale); Application::getInstance()->getCamera()->setScale(scale);
} }
@ -513,7 +513,7 @@ void MyAvatar::saveData(QSettings* settings) {
settings->setValue("pupilDilation", _head.getPupilDilation()); settings->setValue("pupilDilation", _head.getPupilDilation());
settings->setValue("leanScale", _leanScale); settings->setValue("leanScale", _leanScale);
settings->setValue("scale", _newScale); settings->setValue("scale", _targetScale);
settings->endGroup(); settings->endGroup();
} }
@ -536,7 +536,7 @@ void MyAvatar::loadData(QSettings* settings) {
_leanScale = loadSetting(settings, "leanScale", 0.05f); _leanScale = loadSetting(settings, "leanScale", 0.05f);
_newScale = loadSetting(settings, "scale", 1.0f); _targetScale = loadSetting(settings, "scale", 1.0f);
setScale(_scale); setScale(_scale);
Application::getInstance()->getCamera()->setScale(_scale); Application::getInstance()->getCamera()->setScale(_scale);

View file

@ -29,7 +29,7 @@ AvatarData::AvatarData(Node* owningNode) :
_bodyYaw(-90.0), _bodyYaw(-90.0),
_bodyPitch(0.0), _bodyPitch(0.0),
_bodyRoll(0.0), _bodyRoll(0.0),
_newScale(1.0f), _targetScale(1.0f),
_leaderUUID(), _leaderUUID(),
_handState(0), _handState(0),
_keyState(NO_KEY_DOWN), _keyState(NO_KEY_DOWN),
@ -76,7 +76,7 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) {
destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _bodyRoll); destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _bodyRoll);
// Body scale // Body scale
destinationBuffer += packFloatRatioToTwoByte(destinationBuffer, _newScale); destinationBuffer += packFloatRatioToTwoByte(destinationBuffer, _targetScale);
// Follow mode info // Follow mode info
memcpy(destinationBuffer, _leaderUUID.toRfc4122().constData(), NUM_BYTES_RFC4122_UUID); memcpy(destinationBuffer, _leaderUUID.toRfc4122().constData(), NUM_BYTES_RFC4122_UUID);
@ -198,7 +198,7 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) {
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*) sourceBuffer, &_bodyRoll); sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*) sourceBuffer, &_bodyRoll);
// Body scale // Body scale
sourceBuffer += unpackFloatRatioFromTwoByte(sourceBuffer, _newScale); sourceBuffer += unpackFloatRatioFromTwoByte(sourceBuffer, _targetScale);
// Follow mode info // Follow mode info
_leaderUUID = QUuid::fromRfc4122(QByteArray((char*) sourceBuffer, NUM_BYTES_RFC4122_UUID)); _leaderUUID = QUuid::fromRfc4122(QByteArray((char*) sourceBuffer, NUM_BYTES_RFC4122_UUID));
@ -296,12 +296,10 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) {
return sourceBuffer - startPosition; return sourceBuffer - startPosition;
} }
void AvatarData::setNewScale(float newScale) { void AvatarData::setClampedTargetScale(float targetScale) {
if (newScale > MAX_SCALE) {
newScale = MAX_SCALE; targetScale = glm::clamp(targetScale, MIN_AVATAR_SCALE, MAX_AVATAR_SCALE);
} else if (newScale < MIN_SCALE) {
newScale = MIN_SCALE; _targetScale = targetScale;
} qDebug() << "Changed scale to " << _targetScale << "\n";
_newScale = newScale;
qDebug() << "Changed scale to " << _newScale << "\n";
} }

View file

@ -32,8 +32,8 @@ const int HAND_STATE_START_BIT = 2; // 3rd and 4th bits
const int IS_FACESHIFT_CONNECTED = 4; // 5th bit const int IS_FACESHIFT_CONNECTED = 4; // 5th bit
const int IS_CHAT_CIRCLING_ENABLED = 5; const int IS_CHAT_CIRCLING_ENABLED = 5;
static const float MAX_SCALE = 1000.f; static const float MAX_AVATAR_SCALE = 1000.f;
static const float MIN_SCALE = .005f; static const float MIN_AVATAR_SCALE = .005f;
const float MAX_AUDIO_LOUDNESS = 1000.0; // close enough for mouth animation const float MAX_AUDIO_LOUDNESS = 1000.0; // close enough for mouth animation
@ -82,8 +82,9 @@ public:
void setBodyRoll(float bodyRoll) { _bodyRoll = bodyRoll; } void setBodyRoll(float bodyRoll) { _bodyRoll = bodyRoll; }
// Scale // Scale
float getNewScale() const { return _newScale; } float getTargetScale() const { return _targetScale; }
void setNewScale(float); void setTargetScale(float targetScale) { _targetScale = targetScale; }
void setClampedTargetScale(float targetScale);
// Hand State // Hand State
void setHandState(char s) { _handState = s; } void setHandState(char s) { _handState = s; }
@ -132,7 +133,7 @@ protected:
float _bodyRoll; float _bodyRoll;
// Body scale // Body scale
float _newScale; float _targetScale;
// Following mode infos // Following mode infos
QUuid _leaderUUID; QUuid _leaderUUID;