mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-18 04:44:16 +02:00
only need one animateScaleChanges() implementation
This commit is contained in:
parent
7baee8c391
commit
0e1e5db7eb
3 changed files with 8 additions and 24 deletions
|
@ -150,14 +150,17 @@ float Avatar::getLODDistance() const {
|
|||
void Avatar::animateScaleChanges(float deltaTime) {
|
||||
float currentScale = getUniformScale();
|
||||
if (currentScale != _targetScale) {
|
||||
// use exponential decay toward _targetScale
|
||||
const float SCALE_ANIMATION_TIMESCALE = 0.5f;
|
||||
float scaleVelocity = (_targetScale - currentScale) / SCALE_ANIMATION_TIMESCALE;
|
||||
float animatedScale = currentScale + deltaTime * scaleVelocity;
|
||||
const float MIN_SCALE_SPEED = 0.3f;
|
||||
if (fabsf(scaleVelocity) < MIN_SCALE_SPEED) {
|
||||
// close enough
|
||||
float blendFactor = glm::clamp(deltaTime / SCALE_ANIMATION_TIMESCALE, 0.0f, 1.0f);
|
||||
float animatedScale = (1.0f - blendFactor) * currentScale + blendFactor * _targetScale;
|
||||
|
||||
// snap to the end when we get close enough
|
||||
const float MIN_RELATIVE_SCALE_ERROR = 0.03f;
|
||||
if (fabsf(_targetScale - currentScale) / _targetScale < 0.03f) {
|
||||
animatedScale = _targetScale;
|
||||
}
|
||||
|
||||
setScale(glm::vec3(animatedScale)); // avatar scale is uniform
|
||||
rebuildCollisionShape();
|
||||
}
|
||||
|
|
|
@ -284,22 +284,6 @@ void MyAvatar::update(float deltaTime) {
|
|||
extern QByteArray avatarStateToFrame(const AvatarData* _avatar);
|
||||
extern void avatarStateFromFrame(const QByteArray& frameData, AvatarData* _avatar);
|
||||
|
||||
void MyAvatar::animateScaleChanges(float deltaTime) {
|
||||
// HACK: override Avatar::animateScaleChanges() until MyAvatar has a MotionState
|
||||
float currentScale = getUniformScale();
|
||||
if (currentScale != _targetScale) {
|
||||
const float SCALE_ANIMATION_TIMESCALE = 1.0f;
|
||||
float blendFactor = deltaTime / SCALE_ANIMATION_TIMESCALE;
|
||||
float animatedScale = (1.0f - blendFactor) * currentScale + blendFactor * _targetScale;
|
||||
const float CLOSE_ENOUGH = 0.05f;
|
||||
if (fabsf(animatedScale - _targetScale) / _targetScale < CLOSE_ENOUGH) {
|
||||
animatedScale = _targetScale;
|
||||
}
|
||||
setScale(glm::vec3(animatedScale));
|
||||
rebuildCollisionShape();
|
||||
}
|
||||
}
|
||||
|
||||
void MyAvatar::simulate(float deltaTime) {
|
||||
PerformanceTimer perfTimer("simulate");
|
||||
|
||||
|
|
|
@ -263,9 +263,6 @@ public slots:
|
|||
glm::vec3 getPositionForAudio();
|
||||
glm::quat getOrientationForAudio();
|
||||
|
||||
protected:
|
||||
void animateScaleChanges(float deltaTime);
|
||||
|
||||
signals:
|
||||
void audioListenerModeChanged();
|
||||
void transformChanged();
|
||||
|
|
Loading…
Reference in a new issue