diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index b369edb812..772908abe5 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1389,21 +1389,22 @@ void Application::setRenderThirdPerson(bool thirdPerson) { } void Application::increaseAvatarSize() { - if (5.0f < _myAvatar.getScale() + 0.05f) { - return; + if ((1.f + SCALING_RATIO) * _myAvatar.getNewScale() < MAX_SCALE) { + _myAvatar.setNewScale((1.f + SCALING_RATIO) * _myAvatar.getNewScale()); + qDebug("Changed scale to %f\n", _myAvatar.getNewScale()); } - - _myAvatar.setScale(_myAvatar.getScale() + 0.05f); - _myCamera.setScale(_myAvatar.getScale() + 0.05f); } void Application::decreaseAvatarSize() { - if (_myAvatar.getScale() - 0.05f < 0.15f) { - return; + if (MIN_SCALE < (1.f - SCALING_RATIO) * _myAvatar.getNewScale()) { + _myAvatar.setNewScale((1.f - SCALING_RATIO) * _myAvatar.getNewScale()); + qDebug("Changed scale to %f\n", _myAvatar.getNewScale()); } +} - _myAvatar.setScale(_myAvatar.getScale() - 0.05f); - _myCamera.setScale(_myAvatar.getScale() - 0.05f); +void Application::resetAvatarSize() { + _myAvatar.setNewScale(1.f); + qDebug("Reseted scale to %f\n", _myAvatar.getNewScale()); } void Application::setFrustumOffset(bool frustumOffset) { @@ -1981,6 +1982,7 @@ void Application::initMenu() { "Third Person", this, SLOT(setRenderThirdPerson(bool))))->setCheckable(true); renderMenu->addAction("Increase Avatar Size", this, SLOT(increaseAvatarSize()), Qt::Key_Plus); renderMenu->addAction("Decrease Avatar Size", this, SLOT(decreaseAvatarSize()), Qt::Key_Minus); + renderMenu->addAction("Reset Avatar Size", this, SLOT(resetAvatarSize())); QMenu* toolsMenu = menuBar->addMenu("Tools"); @@ -2967,6 +2969,7 @@ void Application::displaySide(Camera& whichCamera) { if (_renderGroundPlaneOn->isChecked()) { // draw grass plane with fog glEnable(GL_FOG); + glEnable(GL_NORMALIZE); const float FOG_COLOR[] = { 1.0f, 1.0f, 1.0f, 1.0f }; glFogfv(GL_FOG_COLOR, FOG_COLOR); glFogi(GL_FOG_MODE, GL_EXP2); @@ -2981,6 +2984,7 @@ void Application::displaySide(Camera& whichCamera) { _geometryCache.renderSquare(GRASS_DIVISIONS, GRASS_DIVISIONS); glPopMatrix(); glDisable(GL_FOG); + glDisable(GL_NORMALIZE); renderGroundPlaneGrid(EDGE_SIZE_GROUND_PLANE, _audio.getCollisionSoundMagnitude()); } diff --git a/interface/src/Application.h b/interface/src/Application.h index 36d90c9b19..cb851c1dfc 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -134,6 +134,7 @@ private slots: void setRenderThirdPerson(bool thirdPerson); void increaseAvatarSize(); void decreaseAvatarSize(); + void resetAvatarSize(); void renderThrustAtVoxel(const glm::vec3& thrust); void renderLineToTouchedVoxel(); diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index a9db96e65c..3fdb401751 100644 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -105,6 +105,12 @@ void Camera::updateFollowMode(float deltaTime) { } } +float Camera::getFarClip() const { + return (_scale * _farClip < std::numeric_limits::max()) + ? _scale * _farClip + : std::numeric_limits::max() - 1; +} + void Camera::setModeShiftRate ( float rate ) { _modeShiftRate = rate; @@ -188,7 +194,7 @@ void Camera::initialize() { } // call to find out if the view frustum needs to be reshaped -bool Camera::getFrustumNeedsReshape() { +bool Camera::getFrustumNeedsReshape() const { return _frustumNeedsReshape; } diff --git a/interface/src/Camera.h b/interface/src/Camera.h index d83a36ee16..de4553b6dc 100644 --- a/interface/src/Camera.h +++ b/interface/src/Camera.h @@ -48,20 +48,20 @@ public: void setEyeOffsetOrientation( const glm::quat& o ); void setScale ( const float s ); - const glm::vec3& getTargetPosition () { return _targetPosition; } - const glm::vec3& getPosition () { return _position; } - const glm::quat& getTargetRotation () { return _targetRotation; } - const glm::quat& getRotation () { return _rotation; } - CameraMode getMode () { return _mode; } - float getFieldOfView () { return _fieldOfView; } - float getAspectRatio () { return _aspectRatio; } - float getNearClip () { return _scale * _nearClip; } - float getFarClip () { return _scale * _farClip; } - const glm::vec3& getEyeOffsetPosition () { return _eyeOffsetPosition; } - const glm::quat& getEyeOffsetOrientation () { return _eyeOffsetOrientation; } - float getScale () { return _scale; } + const glm::vec3& getTargetPosition () const { return _targetPosition; } + const glm::vec3& getPosition () const { return _position; } + const glm::quat& getTargetRotation () const { return _targetRotation; } + const glm::quat& getRotation () const { return _rotation; } + CameraMode getMode () const { return _mode; } + float getFieldOfView () const { return _fieldOfView; } + float getAspectRatio () const { return _aspectRatio; } + float getNearClip () const { return _scale * _nearClip; } + float getFarClip () const; + const glm::vec3& getEyeOffsetPosition () const { return _eyeOffsetPosition; } + const glm::quat& getEyeOffsetOrientation () const { return _eyeOffsetOrientation; } + float getScale () const { return _scale; } - bool getFrustumNeedsReshape(); // call to find out if the view frustum needs to be reshaped + bool getFrustumNeedsReshape() const; // call to find out if the view frustum needs to be reshaped void setFrustumWasReshaped(); // call this after reshaping the view frustum. private: diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 346d5ff7d5..26192ffe5a 100755 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -505,11 +505,6 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) { glm::quat orientation = getOrientation(); glm::vec3 front = orientation * IDENTITY_FRONT; glm::vec3 right = orientation * IDENTITY_RIGHT; - - // - if (!isMyAvatar() && _scale != _newScale) { - setScale(_newScale); - } // Update movement timers if (isMyAvatar()) { @@ -523,18 +518,30 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) { _elapsedTimeMoving += deltaTime; } } + + if (_leadingAvatar && !_leadingAvatar->getOwningNode()->isAlive()) { + follow(NULL); + } + + // Ajust, scale, thrust and lookAt position when following an other avatar + if (isMyAvatar() && _leadingAvatar && _newScale != _leadingAvatar->getScale()) { + _newScale = _leadingAvatar->getScale(); + } + + if (isMyAvatar() && _scale != _newScale) { + float scale = (1.f - SMOOTHING_RATIO) * _scale + SMOOTHING_RATIO * _newScale; + setScale(scale); + Application::getInstance()->getCamera()->setScale(scale); + } + + if (!isMyAvatar() && _scale != _newScale) { + setScale(_newScale); + } // Collect thrust forces from keyboard and devices if (isMyAvatar()) { updateThrust(deltaTime, transmitter); } - - // Ajust, scale, thrust and lookAt position when following an other avatar - if (isMyAvatar() && _leadingAvatar && _scale != _leadingAvatar->getScale()) { - float scale = 0.95f * _scale + 0.05f * _leadingAvatar->getScale(); - setScale(scale); - Application::getInstance()->getCamera()->setScale(scale); - } // copy velocity so we can use it later for acceleration glm::vec3 oldVelocity = getVelocity(); @@ -1446,7 +1453,7 @@ void Avatar::loadData(QSettings* settings) { _leanScale = loadSetting(settings, "leanScale", 0.5f); - _scale = loadSetting(settings, "scale", 1.0f); + _newScale = loadSetting(settings, "scale", 1.0f); setScale(_scale); Application::getInstance()->getCamera()->setScale(_scale); @@ -1472,7 +1479,7 @@ void Avatar::saveData(QSettings* set) { set->setValue("voxelURL", _voxels.getVoxelURL()); set->setValue("leanScale", _leanScale); - set->setValue("scale", _scale); + set->setValue("scale", _newScale); set->endGroup(); } @@ -1525,9 +1532,17 @@ void Avatar::renderJointConnectingCone(glm::vec3 position1, glm::vec3 position2, glEnd(); } +void Avatar::setNewScale(const float scale) { + _newScale = scale; +} + void Avatar::setScale(const float scale) { _scale = scale; - _newScale = _scale; + + if (_newScale * (1.f - RESCALING_TOLERANCE) < _scale && + _scale < _newScale * (1.f + RESCALING_TOLERANCE)) { + _scale = _newScale; + } _skeleton.setScale(_scale); diff --git a/interface/src/avatar/Avatar.h b/interface/src/avatar/Avatar.h index e9df1c125d..b490429ec9 100755 --- a/interface/src/avatar/Avatar.h +++ b/interface/src/avatar/Avatar.h @@ -26,6 +26,13 @@ #include "Transmitter.h" #include "world.h" + +static const float MAX_SCALE = 5.f; +static const float MIN_SCALE = .5f; +static const float SCALING_RATIO = .05f; +static const float SMOOTHING_RATIO = .05f; // 0 < ratio < 1 +static const float RESCALING_TOLERANCE = .02f; + const float BODY_BALL_RADIUS_PELVIS = 0.07; const float BODY_BALL_RADIUS_TORSO = 0.065; const float BODY_BALL_RADIUS_CHEST = 0.08; @@ -134,7 +141,7 @@ public: void setGravity (glm::vec3 gravity); void setMouseRay (const glm::vec3 &origin, const glm::vec3 &direction); void setOrientation (const glm::quat& orientation); - void setScale (const float scale); + void setNewScale (const float scale); //getters bool isInitialized () const { return _initialized;} @@ -149,6 +156,7 @@ public: glm::vec3 getBodyUpDirection () const { return getOrientation() * IDENTITY_UP; } glm::vec3 getBodyFrontDirection () const { return getOrientation() * IDENTITY_FRONT; } float getScale () const { return _scale;} + float getNewScale () const { return _newScale;} const glm::vec3& getVelocity () const { return _velocity;} float getSpeed () const { return _speed;} float getHeight () const { return _height;} @@ -281,6 +289,7 @@ private: void updateCollisionSound(const glm::vec3& penetration, float deltaTime, float frequency); void applyCollisionWithOtherAvatar( Avatar * other, float deltaTime ); void checkForMouseRayTouching(); + void setScale (const float scale); }; #endif diff --git a/libraries/avatars/src/HandData.cpp b/libraries/avatars/src/HandData.cpp index fb3d437489..644a0764b7 100644 --- a/libraries/avatars/src/HandData.cpp +++ b/libraries/avatars/src/HandData.cpp @@ -105,6 +105,9 @@ int HandData::encodeRemoteData(unsigned char* destinationBuffer) { size_t checkLength = destinationBuffer - startPosition; *destinationBuffer++ = (unsigned char)checkLength; + // just a double-check, while tracing a crash. +// decodeRemoteData(destinationBuffer - (destinationBuffer - startPosition)); + return destinationBuffer - startPosition; } @@ -157,8 +160,9 @@ int HandData::decodeRemoteData(unsigned char* sourceBuffer) { } setRaveGloveActive((gloveFlags & GLOVE_FLAG_RAVE) != 0); - setRaveGloveMode(effectsMode); - +// This is disabled for crash tracing. +// setRaveGloveMode(effectsMode); + // One byte for error checking safety. unsigned char requiredLength = (unsigned char)(sourceBuffer - startPosition); unsigned char checkLength = *sourceBuffer++; diff --git a/libraries/avatars/src/HandData.h b/libraries/avatars/src/HandData.h index c280a7840f..fd820bccc0 100755 --- a/libraries/avatars/src/HandData.h +++ b/libraries/avatars/src/HandData.h @@ -44,6 +44,7 @@ enum RaveGloveEffectsMode class HandData { public: HandData(AvatarData* owningAvatar); + virtual ~HandData() {} // These methods return the positions in Leap-relative space. // To convert to world coordinates, use Hand::leapPositionToWorldPosition.