Working on reorientation.

This commit is contained in:
Andrzej Kapolka 2013-05-22 12:49:25 -07:00
parent 0e7c0e08eb
commit 30958e3ce6

View file

@ -6,6 +6,7 @@
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
#include <glm/glm.hpp>
#include <glm/gtx/quaternion.hpp>
#include <vector>
#include <lodepng.h>
#include <SharedUtil.h>
@ -324,7 +325,22 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
_bodyRoll *= tiltDecay;
//the following will be used to make the avatar upright no matter what gravity is
//float f = angleBetween(_orientation.getUp(), _gravity);
float gravityLength = glm::length(_gravity);
if (gravityLength > 0.0f) {
glm::vec3 targetUp = _gravity / -gravityLength;
const glm::vec3& currentUp = _orientation.getUp();
float angle = glm::degrees(acosf(glm::dot(currentUp, targetUp)));
if (angle > 0.0f) {
glm::vec3 axis;
if (angle > 180.0f - EPSILON) { // 180 degree rotation; must use another axis
axis = _orientation.getRight();
} else {
axis = glm::normalize(glm::cross(currentUp, targetUp));
}
_orientation.rotate(glm::angleAxis(angle, axis));
}
}
// update position by velocity
_position += _velocity * deltaTime;