mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-04-10 10:34:56 +02:00
linear acceleration experiment
This commit is contained in:
parent
b8e85aedc7
commit
11e1c4e6fe
1 changed files with 38 additions and 23 deletions
|
@ -3514,42 +3514,56 @@ 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 = direction * _yawSpeed; //deg/sec
|
||||
float seatedTargetSpeed = direction * _yawSpeed * deltaTime; //deg/renderframe
|
||||
|
||||
const float SEATED_ROTATION_RAMP_TIMESCALE = 0.25; //used as divisor
|
||||
float blend = deltaTime / SEATED_ROTATION_RAMP_TIMESCALE;
|
||||
//if (_seatedBodyYawDelta / seatedTargetSpeed < 0.0f) {
|
||||
// //reverse direction, start acceleration timer again
|
||||
// _seatedInterpTime = 0.0f;
|
||||
//}
|
||||
|
||||
const float SEATED_ROTATION_RAMP_TIMESCALE = 2.5;
|
||||
float blend = deltaTime * SEATED_ROTATION_RAMP_TIMESCALE;
|
||||
if (blend > 1.0f) {
|
||||
blend = 1.0f;
|
||||
}
|
||||
|
||||
/////// ease in
|
||||
//_seatedBodyYawDelta = (1.0f - blend) * _seatedBodyYawDelta + blend * seatedTargetSpeed;
|
||||
|
||||
/////// ease out
|
||||
|
||||
//init, accelerate or clamp rotation at target speed
|
||||
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;
|
||||
//_seatedInterpTime += blend;
|
||||
//_seatedBodyYawDelta = _seatedInterpTime * _seatedInterpTime * direction / blend;
|
||||
_seatedBodyYawDelta += blend * direction;
|
||||
}
|
||||
} else {
|
||||
//init rotation
|
||||
_seatedInterpTime = blend;
|
||||
_seatedBodyYawDelta = blend * direction;
|
||||
}
|
||||
|
||||
|
||||
float totalSeatedBodyYaw = _seatedBodyYawDelta * deltaTime;
|
||||
//setWorldOrientation(getWorldOrientation() * glm::quat(glm::radians(glm::vec3(0.0f, totalSeatedBodyYaw, 0.0f))));
|
||||
setWorldOrientation(getWorldOrientation() * glm::quat(glm::radians(glm::vec3(0.0f, _seatedBodyYawDelta, 0.0f))));
|
||||
|
||||
} else if (_seatedBodyYawDelta != 0.0f) {
|
||||
//qDebug() << "start _seatedBodyYawDelta: " << _seatedBodyYawDelta;
|
||||
// decelerate
|
||||
const float ROTATION_DECAY_TIMESCALE = 0.25f;
|
||||
float attenuation = 1.0f - deltaTime / ROTATION_DECAY_TIMESCALE;
|
||||
if (attenuation < 0.0f) {
|
||||
attenuation = 0.0f;
|
||||
}
|
||||
_seatedBodyYawDelta *= attenuation;
|
||||
|
||||
//original
|
||||
//float rotatingWhileSeatedYaw = -getDriveKey(TRANSLATE_X) * _yawSpeed * deltaTime;
|
||||
//setWorldOrientation(getWorldOrientation() * glm::quat(glm::radians(glm::vec3(0.0f, rotatingWhileSeatedYaw, 0.0f))));
|
||||
float MINIMUM_ROTATION_RATE = 2.0f;
|
||||
if (fabsf(_seatedBodyYawDelta) < MINIMUM_ROTATION_RATE * deltaTime) {
|
||||
_seatedBodyYawDelta = 0.0f;
|
||||
}
|
||||
|
||||
//float totalSeatedBodyYaw = _seatedBodyYawDelta * deltaTime;
|
||||
//setWorldOrientation(getWorldOrientation() * glm::quat(glm::radians(glm::vec3(0.0f, totalSeatedBodyYaw, 0.0f))));
|
||||
setWorldOrientation(getWorldOrientation() * glm::quat(glm::radians(glm::vec3(0.0f, _seatedBodyYawDelta, 0.0f))));
|
||||
} else {
|
||||
_seatedBodyYawDelta = 0.0f;
|
||||
_seatedInterpTime = 0.0f;
|
||||
|
@ -3611,20 +3625,20 @@ void MyAvatar::updateOrientation(float deltaTime) {
|
|||
|
||||
const float DEFAULT_REORIENT_ANGLE = 65.0f;
|
||||
const float FIRST_PERSON_REORIENT_ANGLE = 95.0f;
|
||||
const float TRIGGER_REORIENT_ANGLE = 45.0f;
|
||||
const float TRIGGER_REORIENT_ANGLE = 135.0f;
|
||||
const float FIRST_PERSON_TRIGGER_REORIENT_ANGLE = 65.0f;
|
||||
glm::vec3 ajustedYawVector = cameraYawVector;
|
||||
float limitAngle = 0.0f;
|
||||
float triggerAngle = -glm::sin(glm::radians(TRIGGER_REORIENT_ANGLE));
|
||||
float triggerAngle = glm::sin(glm::radians(90.0f - TRIGGER_REORIENT_ANGLE));
|
||||
float limitAngle = triggerAngle;
|
||||
if (mode == CAMERA_MODE_FIRST_PERSON_LOOK_AT) {
|
||||
limitAngle = glm::sin(glm::radians(90.0f - FIRST_PERSON_TRIGGER_REORIENT_ANGLE));
|
||||
triggerAngle = limitAngle;
|
||||
}
|
||||
float reorientAngle = mode == CAMERA_MODE_FIRST_PERSON_LOOK_AT ? FIRST_PERSON_REORIENT_ANGLE : DEFAULT_REORIENT_ANGLE;
|
||||
if (frontBackDot < 0.0f) {
|
||||
ajustedYawVector = (leftRightDot < 0.0f ? -avatarVectorRight : avatarVectorRight);
|
||||
}
|
||||
if (frontBackDot < limitAngle) {
|
||||
if (frontBackDot < 0.0f) {
|
||||
ajustedYawVector = (leftRightDot < 0.0f ? -avatarVectorRight : avatarVectorRight);
|
||||
}
|
||||
if (!isRotatingWhileSeated) {
|
||||
if (frontBackDot < triggerAngle) {
|
||||
_shouldTurnToFaceCamera = true;
|
||||
|
@ -3632,6 +3646,7 @@ void MyAvatar::updateOrientation(float deltaTime) {
|
|||
}
|
||||
} else {
|
||||
setWorldOrientation(previousOrientation);
|
||||
_seatedBodyYawDelta = 0.0f;
|
||||
}
|
||||
} else if (frontBackDot > glm::sin(glm::radians(reorientAngle))) {
|
||||
_shouldTurnToFaceCamera = false;
|
||||
|
|
Loading…
Reference in a new issue