mirror of
https://github.com/lubosz/overte.git
synced 2025-04-19 16:44:04 +02:00
Iteration on the snap-turn smoothing based on feedback from Andrew. Also additional cleanup.
This commit is contained in:
parent
6317857e3d
commit
8f34ec4c7f
9 changed files with 32 additions and 122 deletions
|
@ -1361,13 +1361,11 @@ glm::quat Avatar::getUncachedRightPalmRotation() const {
|
|||
}
|
||||
|
||||
void Avatar::setPosition(const glm::vec3& position) {
|
||||
// This is the local avatar, no need to handle any position smoothing.
|
||||
AvatarData::setPosition(position);
|
||||
updateAttitude();
|
||||
}
|
||||
|
||||
void Avatar::setOrientation(const glm::quat& orientation) {
|
||||
// This is the local avatar, no need to handle any position smoothing.
|
||||
AvatarData::setOrientation(orientation);
|
||||
updateAttitude();
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@ namespace render {
|
|||
}
|
||||
|
||||
static const float SCALING_RATIO = .05f;
|
||||
static const float SMOOTHING_RATIO = .05f; // 0 < ratio < 1
|
||||
|
||||
extern const float CHAT_MESSAGE_SCALE;
|
||||
extern const float CHAT_MESSAGE_HEIGHT;
|
||||
|
|
|
@ -117,6 +117,10 @@ MyAvatar::MyAvatar(QThread* thread, RigPointer rig) :
|
|||
_realWorldFieldOfView("realWorldFieldOfView",
|
||||
DEFAULT_REAL_WORLD_FIELD_OF_VIEW_DEGREES),
|
||||
_useAdvancedMovementControls("advancedMovementForHandControllersIsChecked", false),
|
||||
_smoothOrientationTime(SMOOTH_TIME_ORIENTATION),
|
||||
_smoothOrientationTimer(std::numeric_limits<float>::max()),
|
||||
_smoothOrientationInitial(),
|
||||
_smoothOrientationTarget(),
|
||||
_hmdSensorMatrix(),
|
||||
_hmdSensorOrientation(),
|
||||
_hmdSensorPosition(),
|
||||
|
@ -388,7 +392,7 @@ void MyAvatar::update(float deltaTime) {
|
|||
_hmdSensorFacingMovingAverage = lerp(_hmdSensorFacingMovingAverage, _hmdSensorFacing, tau);
|
||||
|
||||
if (_smoothOrientationTimer < _smoothOrientationTime) {
|
||||
rotationForceChange();
|
||||
_rotationChanged = true;
|
||||
_smoothOrientationTimer = min(_smoothOrientationTimer + deltaTime, _smoothOrientationTime);
|
||||
}
|
||||
|
||||
|
|
|
@ -577,6 +577,17 @@ private:
|
|||
|
||||
void setVisibleInSceneIfReady(Model* model, const render::ScenePointer& scene, bool visiblity);
|
||||
|
||||
// Basic ease-in-ease-out function for smoothing values.
|
||||
static inline float easeInOutQuad(float lerpValue) {
|
||||
assert(!((lerpValue < 0.0f) || (lerpValue > 1.0f)));
|
||||
|
||||
if (lerpValue < 0.5f) {
|
||||
return (2.0f * lerpValue * lerpValue);
|
||||
}
|
||||
|
||||
return (lerpValue*(4.0f - 2.0f * lerpValue) - 1.0f);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
virtual void updatePalms() override {}
|
||||
|
@ -626,6 +637,15 @@ private:
|
|||
Setting::Handle<float> _realWorldFieldOfView;
|
||||
Setting::Handle<bool> _useAdvancedMovementControls;
|
||||
|
||||
// Smoothing.
|
||||
const float SMOOTH_TIME_ORIENTATION = 0.15f;
|
||||
|
||||
// Smoothing data for blending from one position/orientation to another on remote agents.
|
||||
float _smoothOrientationTime;
|
||||
float _smoothOrientationTimer;
|
||||
glm::quat _smoothOrientationInitial;
|
||||
glm::quat _smoothOrientationTarget;
|
||||
|
||||
// private methods
|
||||
void updateOrientation(float deltaTime);
|
||||
void updateActionMotor(float deltaTime);
|
||||
|
|
|
@ -18,16 +18,8 @@
|
|||
QString const ModelOverlay::TYPE = "model";
|
||||
|
||||
ModelOverlay::ModelOverlay()
|
||||
: _smoothPositionTime(SMOOTH_TIME_POSITION),
|
||||
_smoothPositionTimer(std::numeric_limits<float>::max()),
|
||||
_smoothOrientationTime(SMOOTH_TIME_ORIENTATION),
|
||||
_smoothOrientationTimer(std::numeric_limits<float>::max()),
|
||||
_smoothPositionInitial(),
|
||||
_smoothPositionTarget(),
|
||||
_smoothOrientationInitial(),
|
||||
_smoothOrientationTarget(),
|
||||
_model(std::make_shared<Model>(std::make_shared<Rig>(), nullptr, this)),
|
||||
_modelTextures(QVariantMap())
|
||||
: _model(std::make_shared<Model>(std::make_shared<Rig>(), nullptr, this)),
|
||||
_modelTextures(QVariantMap())
|
||||
{
|
||||
_model->init();
|
||||
_isLoaded = false;
|
||||
|
@ -51,30 +43,6 @@ void ModelOverlay::update(float deltatime) {
|
|||
if (_model && _model->isActive()) {
|
||||
_model->setRotation(getRotation());
|
||||
_model->setTranslation(getPosition());
|
||||
|
||||
if (_smoothPositionTimer < _smoothPositionTime) {
|
||||
// Smooth the remote avatar movement.
|
||||
_smoothPositionTimer+= deltatime;
|
||||
if (_smoothPositionTimer < _smoothPositionTime) {
|
||||
_model->setTranslation(
|
||||
lerp(_smoothPositionInitial,
|
||||
_smoothPositionTarget,
|
||||
easeInOutQuad(glm::clamp(_smoothPositionTimer / _smoothPositionTime, 0.0f, 1.0f)))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (_smoothOrientationTimer < _smoothOrientationTime) {
|
||||
// Smooth the remote avatar movement.
|
||||
_smoothOrientationTimer+= deltatime;
|
||||
if (_smoothOrientationTimer < _smoothOrientationTime) {
|
||||
_model->setRotation(
|
||||
slerp(_smoothOrientationInitial,
|
||||
_smoothOrientationTarget,
|
||||
easeInOutQuad(glm::clamp(_smoothOrientationTimer / _smoothOrientationTime, 0.0f, 1.0f)))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_updateModel) {
|
||||
|
@ -306,23 +274,4 @@ bool ModelOverlay::findRayIntersectionExtraInfo(const glm::vec3& origin, const g
|
|||
|
||||
ModelOverlay* ModelOverlay::createClone() const {
|
||||
return new ModelOverlay(this);
|
||||
}
|
||||
|
||||
void ModelOverlay::locationChanged(bool tellPhysics) {
|
||||
Base3DOverlay::locationChanged(tellPhysics);
|
||||
|
||||
if (!_model || !_model->isActive()) {
|
||||
// If it's not active, don't care about it.
|
||||
return;
|
||||
}
|
||||
|
||||
// Whether or not there is an existing smoothing going on, just reset the smoothing timer and set the starting position as the avatar's current position, then smooth to the new position.
|
||||
_smoothPositionInitial = _model->getTranslation();
|
||||
_smoothPositionTarget = getPosition();
|
||||
_smoothPositionTimer = 0.0f;
|
||||
|
||||
// Whether or not there is an existing smoothing going on, just reset the smoothing timer and set the starting position as the avatar's current position, then smooth to the new position.
|
||||
_smoothOrientationInitial = _model->getRotation();
|
||||
_smoothOrientationTarget = getRotation();
|
||||
_smoothOrientationTimer = 0.0f;
|
||||
}
|
|
@ -39,33 +39,6 @@ public:
|
|||
virtual bool addToScene(Overlay::Pointer overlay, const render::ScenePointer& scene, render::Transaction& transaction) override;
|
||||
virtual void removeFromScene(Overlay::Pointer overlay, const render::ScenePointer& scene, render::Transaction& transaction) override;
|
||||
|
||||
void locationChanged(bool tellPhysics = true) override;
|
||||
|
||||
// Basic ease-in-ease-out function for smoothing values.
|
||||
inline float easeInOutQuad(float lerpValue) {
|
||||
assert(!((lerpValue < 0.0f) || (lerpValue > 1.0f)));
|
||||
|
||||
if (lerpValue < 0.5f) {
|
||||
return (2.0f * lerpValue * lerpValue);
|
||||
}
|
||||
|
||||
return (lerpValue*(4.0f - 2.0f * lerpValue) - 1.0f);
|
||||
}
|
||||
|
||||
protected:
|
||||
const float SMOOTH_TIME_POSITION = 0.125f;
|
||||
const float SMOOTH_TIME_ORIENTATION = 0.15f;
|
||||
|
||||
// Smoothing data for blending from one position/orientation to another on remote agents.
|
||||
float _smoothPositionTime;
|
||||
float _smoothPositionTimer;
|
||||
float _smoothOrientationTime;
|
||||
float _smoothOrientationTimer;
|
||||
glm::vec3 _smoothPositionInitial;
|
||||
glm::vec3 _smoothPositionTarget;
|
||||
glm::quat _smoothOrientationInitial;
|
||||
glm::quat _smoothOrientationTarget;
|
||||
|
||||
protected:
|
||||
// helper to extract metadata from our Model's rigged joints
|
||||
template <typename itemType> using mapFunction = std::function<itemType(int jointIndex)>;
|
||||
|
|
|
@ -67,11 +67,7 @@ AvatarData::AvatarData() :
|
|||
_displayNameAlpha(1.0f),
|
||||
_errorLogExpiry(0),
|
||||
_owningAvatarMixer(),
|
||||
_targetVelocity(0.0f),
|
||||
_smoothOrientationTime(SMOOTH_TIME_ORIENTATION),
|
||||
_smoothOrientationTimer(std::numeric_limits<float>::max()),
|
||||
_smoothOrientationInitial(),
|
||||
_smoothOrientationTarget()
|
||||
_targetVelocity(0.0f)
|
||||
{
|
||||
setBodyPitch(0.0f);
|
||||
setBodyYaw(-90.0f);
|
||||
|
@ -1495,15 +1491,8 @@ void AvatarData::parseAvatarIdentityPacket(const QByteArray& data, Identity& ide
|
|||
|
||||
}
|
||||
|
||||
glm::quat AvatarData::getLocalOrientation() const {
|
||||
if (!isMyAvatar() || (_smoothOrientationTimer > _smoothOrientationTime)) {
|
||||
return (SpatiallyNestable::getLocalOrientation());
|
||||
}
|
||||
|
||||
// Smooth the remote avatar movement.
|
||||
float t = _smoothOrientationTimer / _smoothOrientationTime;
|
||||
float l = easeInOutQuad(glm::clamp(t, 0.0f, 1.0f));
|
||||
return (slerp(_smoothOrientationInitial, _smoothOrientationTarget, l));
|
||||
glm::quat AvatarData::getOrientationOutbound() const {
|
||||
return (getLocalOrientation());
|
||||
}
|
||||
|
||||
static const QUrl emptyURL("");
|
||||
|
|
|
@ -602,8 +602,8 @@ public:
|
|||
return _lastSentJointData;
|
||||
}
|
||||
|
||||
// Overload the local orientation function for this.
|
||||
virtual glm::quat getLocalOrientation() const override;
|
||||
// A method intended to be overriden by MyAvatar for polling orientation for network transmission.
|
||||
virtual glm::quat getOrientationOutbound() const;
|
||||
|
||||
static const float OUT_OF_VIEW_PENALTY;
|
||||
|
||||
|
@ -621,17 +621,6 @@ public:
|
|||
static float _avatarSortCoefficientCenter;
|
||||
static float _avatarSortCoefficientAge;
|
||||
|
||||
// Basic ease-in-ease-out function for smoothing values.
|
||||
static inline float easeInOutQuad(float lerpValue) {
|
||||
assert(!((lerpValue < 0.0f) || (lerpValue > 1.0f)));
|
||||
|
||||
if (lerpValue < 0.5f) {
|
||||
return (2.0f * lerpValue * lerpValue);
|
||||
}
|
||||
|
||||
return (lerpValue*(4.0f - 2.0f * lerpValue) - 1.0f);
|
||||
}
|
||||
|
||||
bool getIdentityDataChanged() const { return _identityDataChanged; } // has the identity data changed since the last time sendIdentityPacket() was called
|
||||
void markIdentityDataChanged() {
|
||||
_identityDataChanged = true;
|
||||
|
@ -795,15 +784,6 @@ protected:
|
|||
quint64 _audioLoudnessChanged { 0 };
|
||||
float _audioAverageLoudness { 0.0f };
|
||||
|
||||
// Smoothing.
|
||||
const float SMOOTH_TIME_ORIENTATION = 0.15f;
|
||||
|
||||
// Smoothing data for blending from one position/orientation to another on remote agents.
|
||||
float _smoothOrientationTime;
|
||||
float _smoothOrientationTimer;
|
||||
glm::quat _smoothOrientationInitial;
|
||||
glm::quat _smoothOrientationTarget;
|
||||
|
||||
bool _identityDataChanged { false };
|
||||
quint64 _identityUpdatedAt { 0 };
|
||||
|
||||
|
|
|
@ -183,8 +183,6 @@ public:
|
|||
bool tranlationChangedSince(quint64 time) const { return _translationChanged > time; }
|
||||
bool rotationChangedSince(quint64 time) const { return _rotationChanged > time; }
|
||||
|
||||
inline void rotationForceChange() { _rotationChanged = usecTimestampNow(); }
|
||||
|
||||
protected:
|
||||
const NestableType _nestableType; // EntityItem or an AvatarData
|
||||
QUuid _id;
|
||||
|
|
Loading…
Reference in a new issue