mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 06:18:52 +02:00
fix for underdamped avatar rotation momentum
This commit is contained in:
parent
fecb0e3675
commit
b26f4b0c8d
1 changed files with 26 additions and 14 deletions
|
@ -54,7 +54,7 @@
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
const glm::vec3 DEFAULT_UP_DIRECTION(0.0f, 1.0f, 0.0f);
|
const glm::vec3 DEFAULT_UP_DIRECTION(0.0f, 1.0f, 0.0f);
|
||||||
const float YAW_SPEED = 500.0f; // degrees/sec
|
const float YAW_SPEED = 150.0f; // degrees/sec
|
||||||
const float PITCH_SPEED = 100.0f; // degrees/sec
|
const float PITCH_SPEED = 100.0f; // degrees/sec
|
||||||
const float DEFAULT_REAL_WORLD_FIELD_OF_VIEW_DEGREES = 30.0f;
|
const float DEFAULT_REAL_WORLD_FIELD_OF_VIEW_DEGREES = 30.0f;
|
||||||
|
|
||||||
|
@ -1290,22 +1290,34 @@ bool MyAvatar::shouldRenderHead(const RenderArgs* renderArgs) const {
|
||||||
|
|
||||||
void MyAvatar::updateOrientation(float deltaTime) {
|
void MyAvatar::updateOrientation(float deltaTime) {
|
||||||
// Smoothly rotate body with arrow keys
|
// Smoothly rotate body with arrow keys
|
||||||
_bodyYawDelta -= _driveKeys[ROT_RIGHT] * YAW_SPEED * deltaTime;
|
float driveLeft = _driveKeys[ROT_LEFT] - _driveKeys[ROT_RIGHT];
|
||||||
_bodyYawDelta += _driveKeys[ROT_LEFT] * YAW_SPEED * deltaTime;
|
float targetSpeed = (_driveKeys[ROT_LEFT] - _driveKeys[ROT_RIGHT]) * YAW_SPEED;
|
||||||
getHead()->setBasePitch(getHead()->getBasePitch() + (_driveKeys[ROT_UP] - _driveKeys[ROT_DOWN]) * PITCH_SPEED * deltaTime);
|
if (targetSpeed != 0.0f) {
|
||||||
|
const float ROTATION_RAMP_TIMESCALE = 0.1f;
|
||||||
|
float blend = deltaTime / ROTATION_RAMP_TIMESCALE;
|
||||||
|
if (blend > 1.0f) {
|
||||||
|
blend = 1.0f;
|
||||||
|
}
|
||||||
|
_bodyYawDelta = (1.0f - blend) * _bodyYawDelta + blend * targetSpeed;
|
||||||
|
} else if (_bodyYawDelta != 0.0f) {
|
||||||
|
// attenuate body rotation speed
|
||||||
|
const float ROTATION_DECAY_TIMESCALE = 0.05f;
|
||||||
|
float attenuation = 1.0f - deltaTime / ROTATION_DECAY_TIMESCALE;
|
||||||
|
if (attenuation < 0.0f) {
|
||||||
|
attenuation = 0.0f;
|
||||||
|
}
|
||||||
|
_bodyYawDelta *= attenuation;
|
||||||
|
|
||||||
|
float MINIMUM_ROTATION_RATE = 2.0f;
|
||||||
|
if (fabsf(_bodyYawDelta) < MINIMUM_ROTATION_RATE) {
|
||||||
|
_bodyYawDelta = 0.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getHead()->setBasePitch(getHead()->getBasePitch() + (_driveKeys[ROT_UP] - _driveKeys[ROT_DOWN]) * PITCH_SPEED * deltaTime);
|
||||||
// update body orientation by movement inputs
|
// update body orientation by movement inputs
|
||||||
setOrientation(getOrientation() *
|
setOrientation(getOrientation() *
|
||||||
glm::quat(glm::radians(glm::vec3(0.0f, _bodyYawDelta, 0.0f) * deltaTime)));
|
glm::quat(glm::radians(glm::vec3(0.0f, _bodyYawDelta * deltaTime, 0.0f))));
|
||||||
|
|
||||||
// decay body rotation momentum
|
|
||||||
const float BODY_SPIN_FRICTION = 7.5f;
|
|
||||||
float bodySpinMomentum = 1.0f - BODY_SPIN_FRICTION * deltaTime;
|
|
||||||
if (bodySpinMomentum < 0.0f) { bodySpinMomentum = 0.0f; }
|
|
||||||
_bodyYawDelta *= bodySpinMomentum;
|
|
||||||
|
|
||||||
float MINIMUM_ROTATION_RATE = 2.0f;
|
|
||||||
if (fabs(_bodyYawDelta) < MINIMUM_ROTATION_RATE) { _bodyYawDelta = 0.0f; }
|
|
||||||
|
|
||||||
if (qApp->isHMDMode()) {
|
if (qApp->isHMDMode()) {
|
||||||
// these angles will be in radians
|
// these angles will be in radians
|
||||||
|
|
Loading…
Reference in a new issue