mirror of
https://github.com/overte-org/overte.git
synced 2025-08-16 09:12:26 +02:00
Revisited where smoothing was done (to a much lower-level); still needs testing.
This commit is contained in:
parent
a94f4ca182
commit
b00cd66a2a
4 changed files with 86 additions and 93 deletions
|
@ -85,14 +85,6 @@ Avatar::Avatar(QThread* thread, RigPointer rig) :
|
|||
_lastOrientation(),
|
||||
_worldUpDirection(DEFAULT_UP_DIRECTION),
|
||||
_moving(false),
|
||||
_smoothPositionTime(SMOOTH_TIME_POSITION),
|
||||
_smoothPositionTimer(std::numeric_limits<float>::max()),
|
||||
_smoothOrientationTime(SMOOTH_TIME_ORIENTATION),
|
||||
_smoothOrientationTimer(std::numeric_limits<float>::max()),
|
||||
_smoothPositionInitial(),
|
||||
_smoothPositionTarget(),
|
||||
_smoothOrientationInitial(),
|
||||
_smoothOrientationTarget(),
|
||||
_initialized(false),
|
||||
_voiceSphereID(GeometryCache::UNKNOWN_ID)
|
||||
{
|
||||
|
@ -346,38 +338,6 @@ void Avatar::simulate(float deltaTime, bool inView) {
|
|||
_simulationInViewRate.increment();
|
||||
}
|
||||
|
||||
if (!isMyAvatar()) {
|
||||
if (_smoothPositionTimer < _smoothPositionTime) {
|
||||
// Smooth the remote avatar movement.
|
||||
_smoothPositionTimer += deltaTime;
|
||||
if (_smoothPositionTimer < _smoothPositionTime) {
|
||||
AvatarData::setPosition(
|
||||
lerp(_smoothPositionInitial,
|
||||
_smoothPositionTarget,
|
||||
easeInOutQuad(glm::clamp(_smoothPositionTimer / _smoothPositionTime, 0.0f, 1.0f)))
|
||||
);
|
||||
updateAttitude();
|
||||
}
|
||||
} else if (AvatarData::getPosition() != _smoothPositionTarget) {
|
||||
setPosition(AvatarData::getPosition());
|
||||
}
|
||||
|
||||
if (_smoothOrientationTimer < _smoothOrientationTime) {
|
||||
// Smooth the remote avatar movement.
|
||||
_smoothOrientationTimer += deltaTime;
|
||||
if (_smoothOrientationTimer < _smoothOrientationTime) {
|
||||
AvatarData::setOrientation(
|
||||
slerp(_smoothOrientationInitial,
|
||||
_smoothOrientationTarget,
|
||||
easeInOutQuad(glm::clamp(_smoothOrientationTimer / _smoothOrientationTime, 0.0f, 1.0f)))
|
||||
);
|
||||
updateAttitude();
|
||||
}
|
||||
} else if (AvatarData::getOrientation() != _smoothOrientationTarget) {
|
||||
setOrientation(AvatarData::getOrientation());
|
||||
}
|
||||
}
|
||||
|
||||
PerformanceTimer perfTimer("simulate");
|
||||
{
|
||||
PROFILE_RANGE(simulation, "updateJoints");
|
||||
|
@ -1382,31 +1342,15 @@ glm::quat Avatar::getUncachedRightPalmRotation() const {
|
|||
}
|
||||
|
||||
void Avatar::setPosition(const glm::vec3& position) {
|
||||
if (isMyAvatar()) {
|
||||
// This is the local avatar, no need to handle any position smoothing.
|
||||
AvatarData::setPosition(position);
|
||||
updateAttitude();
|
||||
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 = AvatarData::getPosition();
|
||||
_smoothPositionTarget = position;
|
||||
_smoothPositionTimer = 0.0f;
|
||||
// This is the local avatar, no need to handle any position smoothing.
|
||||
AvatarData::setPosition(position);
|
||||
updateAttitude();
|
||||
}
|
||||
|
||||
void Avatar::setOrientation(const glm::quat& orientation) {
|
||||
if (isMyAvatar()) {
|
||||
// This is the local avatar, no need to handle any position smoothing.
|
||||
AvatarData::setOrientation(orientation);
|
||||
updateAttitude();
|
||||
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.
|
||||
_smoothOrientationInitial = AvatarData::getOrientation();
|
||||
_smoothOrientationTarget = orientation;
|
||||
_smoothOrientationTimer = 0.0f;
|
||||
// This is the local avatar, no need to handle any position smoothing.
|
||||
AvatarData::setOrientation(orientation);
|
||||
updateAttitude();
|
||||
}
|
||||
|
||||
void Avatar::updatePalms() {
|
||||
|
|
|
@ -228,16 +228,6 @@ public:
|
|||
|
||||
bool hasNewJointData() const { return _hasNewJointData; }
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public slots:
|
||||
|
||||
// FIXME - these should be migrated to use Pose data instead
|
||||
|
@ -252,9 +242,6 @@ public slots:
|
|||
protected:
|
||||
friend class AvatarManager;
|
||||
|
||||
const float SMOOTH_TIME_POSITION = 0.125f;
|
||||
const float SMOOTH_TIME_ORIENTATION = 0.15f;
|
||||
|
||||
virtual const QString& getSessionDisplayNameForTransport() const override { return _empty; } // Save a tiny bit of bandwidth. Mixer won't look at what we send.
|
||||
QString _empty{};
|
||||
virtual void maybeUpdateSessionDisplayNameFromTransport(const QString& sessionDisplayName) override { _sessionDisplayName = sessionDisplayName; } // don't use no-op setter!
|
||||
|
@ -324,16 +311,6 @@ protected:
|
|||
RateCounter<> _skeletonModelSimulationRate;
|
||||
RateCounter<> _jointDataSimulationRate;
|
||||
|
||||
// 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;
|
||||
|
||||
private:
|
||||
class AvatarEntityDataHash {
|
||||
public:
|
||||
|
|
|
@ -18,8 +18,16 @@
|
|||
QString const ModelOverlay::TYPE = "model";
|
||||
|
||||
ModelOverlay::ModelOverlay()
|
||||
: _model(std::make_shared<Model>(std::make_shared<Rig>(), nullptr, this)),
|
||||
_modelTextures(QVariantMap())
|
||||
: _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->init();
|
||||
_isLoaded = false;
|
||||
|
@ -40,6 +48,35 @@ ModelOverlay::ModelOverlay(const ModelOverlay* modelOverlay) :
|
|||
}
|
||||
|
||||
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) {
|
||||
_updateModel = false;
|
||||
_model->setSnapModelToCenter(true);
|
||||
|
@ -173,8 +210,18 @@ ModelOverlay* ModelOverlay::createClone() const {
|
|||
void ModelOverlay::locationChanged(bool tellPhysics) {
|
||||
Base3DOverlay::locationChanged(tellPhysics);
|
||||
|
||||
if (_model && _model->isActive()) {
|
||||
_model->setRotation(getRotation());
|
||||
_model->setTranslation(getPosition());
|
||||
}
|
||||
}
|
||||
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,7 +39,32 @@ 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) 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;
|
||||
|
||||
private:
|
||||
|
||||
|
|
Loading…
Reference in a new issue