mirror of
https://github.com/lubosz/overte.git
synced 2025-04-16 05:59:50 +02:00
Do not use turningSpeed when setting seatedTurn vars, and iterate acceleration formula
This commit is contained in:
parent
64634f51b1
commit
995f5f92cd
3 changed files with 72 additions and 21 deletions
|
@ -3513,21 +3513,69 @@ void MyAvatar::updateOrientation(float deltaTime) {
|
|||
}
|
||||
setWorldOrientation(glm::slerp(getWorldOrientation(), faceRotation, blend));
|
||||
} else if (isRotatingWhileSeated) {
|
||||
float direction = -getDriveKey(TRANSLATE_X);
|
||||
float seatedTargetSpeed = direction * _yawSpeed * deltaTime;
|
||||
|
||||
float seatedTargetSpeed = -getDriveKey(TRANSLATE_X) * _yawSpeed;
|
||||
|
||||
const float SEATED_ROTATION_RAMP_TIMESCALE = 0.5f;
|
||||
const float SEATED_ROTATION_RAMP_TIMESCALE = 1.0; //used as divisor
|
||||
float blend = deltaTime / SEATED_ROTATION_RAMP_TIMESCALE;
|
||||
if (blend > 1.0f) {
|
||||
blend = 1.0f;
|
||||
}
|
||||
_seatedBodyYawDelta = (1.0f - blend) * _seatedBodyYawDelta + blend * seatedTargetSpeed;
|
||||
|
||||
/////// ease in
|
||||
//_seatedBodyYawDelta = (1.0f - blend) * _seatedBodyYawDelta + blend * seatedTargetSpeed;
|
||||
|
||||
/////// ease out WIP
|
||||
|
||||
if (fabsf(_seatedBodyYawDelta) > 0.0f) {
|
||||
//we are rotating
|
||||
if (fabsf(_seatedBodyYawDelta) >= fabsf(seatedTargetSpeed)) {
|
||||
//we've reached target speed
|
||||
_seatedBodyYawDelta = seatedTargetSpeed;
|
||||
} else {
|
||||
_seatedInterpTime += blend;
|
||||
_seatedBodyYawDelta = _seatedInterpTime * _seatedInterpTime * direction;
|
||||
}
|
||||
} else {
|
||||
//init rotation
|
||||
_seatedInterpTime = blend;
|
||||
_seatedBodyYawDelta = blend * direction;
|
||||
}
|
||||
|
||||
//////// linear
|
||||
//if (_seatedBodyYawDelta < seatedTargetSpeed) {
|
||||
// _seatedBodyYawDelta += blend;
|
||||
//}
|
||||
|
||||
setWorldOrientation(getWorldOrientation() * glm::quat(glm::radians(glm::vec3(0.0f, _seatedBodyYawDelta, 0.0f))));
|
||||
|
||||
qDebug() << "_seatedBodyYawDelta: " << _seatedBodyYawDelta;
|
||||
|
||||
|
||||
//original
|
||||
//float rotatingWhileSeatedYaw = -getDriveKey(TRANSLATE_X) * _yawSpeed * deltaTime;
|
||||
//setWorldOrientation(getWorldOrientation() * glm::quat(glm::radians(glm::vec3(0.0f, rotatingWhileSeatedYaw, 0.0f))));
|
||||
|
||||
//qDebug() << "_seatedBodyYawDelta: " << rotatingWhileSeatedYaw;
|
||||
} else if (_characterController.getSeated() && _seatedBodyYawDelta > 0.0f) {
|
||||
// attenuate body rotation speed
|
||||
const float SEATED_ROTATION_DECAY_TIMESCALE = 0.05f;
|
||||
float attenuation = 1.0f - deltaTime / SEATED_ROTATION_DECAY_TIMESCALE;
|
||||
if (attenuation < 0.0f) {
|
||||
attenuation = 0.0f;
|
||||
}
|
||||
_seatedBodyYawDelta *= attenuation;
|
||||
|
||||
float MINIMUM_ROTATION_RATE = 2.0f;
|
||||
if (fabsf(_seatedBodyYawDelta) < MINIMUM_ROTATION_RATE) {
|
||||
_seatedBodyYawDelta = 0.0f;
|
||||
}
|
||||
|
||||
setWorldOrientation(getWorldOrientation() * glm::quat(glm::radians(glm::vec3(0.0f, _seatedBodyYawDelta, 0.0f))));
|
||||
|
||||
qDebug() << "attenuated _seatedBodyYawDelta: " << _seatedBodyYawDelta;
|
||||
} else {
|
||||
_seatedBodyYawDelta = 0.0f;
|
||||
_seatedInterpTime = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1093,6 +1093,12 @@ void Rig::computeMotionAnimationState(float deltaTime, const glm::vec3& worldPos
|
|||
const float TURN_ENTER_SPEED_THRESHOLD = 0.5f; // rad/sec
|
||||
const float TURN_EXIT_SPEED_THRESHOLD = 0.2f; // rad/sec
|
||||
|
||||
//stategraph vars based on input
|
||||
const float INPUT_DEADZONE_THRESHOLD = 0.05f;
|
||||
const float SLOW_SPEED_THRESHOLD = 1.5f;
|
||||
const float HAS_MOMENTUM_THRESHOLD = 2.2f;
|
||||
const float RESET_MOMENTUM_THRESHOLD = 0.05f;
|
||||
|
||||
if (ccState == CharacterControllerState::Hover) {
|
||||
if (_desiredState != RigRole::Hover) {
|
||||
_desiredStateAge = 0.0f;
|
||||
|
@ -1412,21 +1418,21 @@ void Rig::computeMotionAnimationState(float deltaTime, const glm::vec3& worldPos
|
|||
|
||||
_animVars.set("inAirAlpha", alpha);
|
||||
} else if (_state == RigRole::Seated) {
|
||||
if (turningSpeed > 0.05f) {
|
||||
// seated turning right
|
||||
_animVars.set("isSeatedTurningRight", true);
|
||||
_animVars.set("isSeatedTurningLeft", false);
|
||||
_animVars.set("isSeatedNotTurning", false);
|
||||
} else if (turningSpeed < -0.05f) {
|
||||
// seated turning left
|
||||
_animVars.set("isSeatedTurningRight", false);
|
||||
_animVars.set("isSeatedTurningLeft", true);
|
||||
_animVars.set("isSeatedNotTurning", false);
|
||||
} else {
|
||||
if (fabsf(_previousControllerParameters.inputX) <= INPUT_DEADZONE_THRESHOLD) {
|
||||
// seated not turning
|
||||
_animVars.set("isSeatedTurningRight", false);
|
||||
_animVars.set("isSeatedTurningLeft", false);
|
||||
_animVars.set("isSeatedNotTurning", true);
|
||||
} else if (turningSpeed > 0.1f) {
|
||||
// seated turning right
|
||||
_animVars.set("isSeatedTurningRight", true);
|
||||
_animVars.set("isSeatedTurningLeft", false);
|
||||
_animVars.set("isSeatedNotTurning", false);
|
||||
} else if (turningSpeed < -0.1f) {
|
||||
// seated turning left
|
||||
_animVars.set("isSeatedTurningRight", false);
|
||||
_animVars.set("isSeatedTurningLeft", true);
|
||||
_animVars.set("isSeatedNotTurning", false);
|
||||
}
|
||||
|
||||
_animVars.set("isMovingForward", false);
|
||||
|
@ -1470,11 +1476,7 @@ void Rig::computeMotionAnimationState(float deltaTime, const glm::vec3& worldPos
|
|||
_lastEnableInverseKinematics = _enableInverseKinematics;
|
||||
|
||||
|
||||
//stategraph vars based on input
|
||||
const float INPUT_DEADZONE_THRESHOLD = 0.05f;
|
||||
const float SLOW_SPEED_THRESHOLD = 1.5f;
|
||||
const float HAS_MOMENTUM_THRESHOLD = 2.2f;
|
||||
const float RESET_MOMENTUM_THRESHOLD = 0.05f;
|
||||
|
||||
|
||||
if (fabsf(_previousControllerParameters.inputX) <= INPUT_DEADZONE_THRESHOLD &&
|
||||
fabsf(_previousControllerParameters.inputZ) <= INPUT_DEADZONE_THRESHOLD) {
|
||||
|
|
|
@ -663,6 +663,7 @@ protected:
|
|||
|
||||
float _bodyYawDelta { 0.0f }; // degrees/sec
|
||||
float _seatedBodyYawDelta{ 0.0f }; //degrees/sec
|
||||
float _seatedInterpTime{ 0.0f }; //used to transition rot while seated.
|
||||
|
||||
// These position histories and derivatives are in the world-frame.
|
||||
// The derivatives are the MEASURED results of all external and internal forces
|
||||
|
|
Loading…
Reference in a new issue