mirror of
https://github.com/overte-org/overte.git
synced 2025-04-23 06:53:46 +02:00
Working on reorientation.
This commit is contained in:
parent
0e7c0e08eb
commit
30958e3ce6
1 changed files with 17 additions and 1 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue