Compute only when delta is not zero

This commit is contained in:
luiscuenca 2019-09-11 16:25:48 -07:00
parent 8a6cb93a84
commit 793b2917f6
No known key found for this signature in database
GPG key ID: 2387ECD129A6961D

View file

@ -3419,19 +3419,23 @@ void MyAvatar::updateOrientation(float deltaTime) {
_lookAtOffsetYaw = getWorldOrientation();
_lookAtOffsetPitch = Quaternions::IDENTITY;
} else {
// Set look at vector
// Compute new look at vectors
if (totalBodyYaw > 0.0f) {
_lookAtOffsetYaw = _lookAtOffsetYaw * glm::quat(glm::radians(glm::vec3(0.0f, totalBodyYaw, 0.0f)));
}
float pitchIncrement = getDriveKey(PITCH) * _pitchSpeed * deltaTime
+ getDriveKey(DELTA_PITCH) * _pitchSpeed / PITCH_SPEED_DEFAULT;
_lookAtOffsetYaw = _lookAtOffsetYaw * glm::quat(glm::radians(glm::vec3(0.0f, totalBodyYaw, 0.0f)));
glm::quat _previousLookAtOffsetPitch = _lookAtOffsetPitch;
_lookAtOffsetPitch = _lookAtOffsetPitch * glm::quat(glm::radians(glm::vec3(pitchIncrement, 0.0f, 0.0f)));
// Limit the camera horizontal pitch
float MAX_LOOK_AT_PITCH_DEGREES = 80.0f;
float pitchFromHorizont = glm::degrees(angleBetween(getLookAtOffset() * Vectors::FRONT, _lookAtOffsetYaw * Vectors::FRONT));
if (pitchFromHorizont > MAX_LOOK_AT_PITCH_DEGREES || pitchFromHorizont < -MAX_LOOK_AT_PITCH_DEGREES) {
_lookAtOffsetPitch = _previousLookAtOffsetPitch;
if (pitchIncrement > 0.0f) {
glm::quat _previousLookAtOffsetPitch = _lookAtOffsetPitch;
_lookAtOffsetPitch = _lookAtOffsetPitch * glm::quat(glm::radians(glm::vec3(pitchIncrement, 0.0f, 0.0f)));
// Limit the camera horizontal pitch
float MAX_LOOK_AT_PITCH_DEGREES = 80.0f;
float pitchFromHorizont = glm::degrees(angleBetween(getLookAtOffset() * Vectors::FRONT, _lookAtOffsetYaw * Vectors::FRONT));
if (pitchFromHorizont > MAX_LOOK_AT_PITCH_DEGREES || pitchFromHorizont < -MAX_LOOK_AT_PITCH_DEGREES) {
_lookAtOffsetPitch = _previousLookAtOffsetPitch;
}
}
// Blend the avatar orientation with the camera look at if moving forward.
if (faceForward) {
const float FACE_FORWARD_BLEND = 0.25f;