Merge pull request #2604 from AndrewMeadows/oculus-with-thrust

fix #2567 thrust + oculus doesn't change body rotation
This commit is contained in:
Andrzej Kapolka 2014-04-04 15:19:44 -07:00
commit 10288bce35
3 changed files with 6 additions and 28 deletions

View file

@ -510,7 +510,7 @@ void Application::paintGL() {
_myCamera.setDistance(0.0f);
_myCamera.setTightness(0.0f); // Camera is directly connected to head without smoothing
_myCamera.setTargetPosition(_myAvatar->getHead()->calculateAverageEyePosition());
_myCamera.setTargetRotation(_myAvatar->getHead()->getOrientation());
_myCamera.setTargetRotation(_myAvatar->getHead()->getCameraOrientation());
} else if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON) {
_myCamera.setTightness(0.0f); // In first person, camera follows (untweaked) head exactly without delay

View file

@ -14,6 +14,7 @@
#include "Head.h"
#include "Menu.h"
#include "Util.h"
#include "devices/OculusManager.h"
using namespace std;
@ -198,6 +199,9 @@ glm::quat Head::getFinalOrientation() const {
}
glm::quat Head::getCameraOrientation () const {
if (OculusManager::isConnected()) {
return getOrientation();
}
Avatar* owningAvatar = static_cast<Avatar*>(_owningAvatar);
return owningAvatar->getWorldAlignedOrientation() * glm::quat(glm::radians(glm::vec3(_basePitch, 0.f, 0.0f)));
}

View file

@ -169,9 +169,6 @@ void MyAvatar::simulate(float deltaTime) {
// Collect thrust forces from keyboard and devices
updateThrust(deltaTime);
// copy velocity so we can use it later for acceleration
glm::vec3 oldVelocity = getVelocity();
// calculate speed
_speed = glm::length(_velocity);
@ -231,29 +228,6 @@ void MyAvatar::simulate(float deltaTime) {
// update the euler angles
setOrientation(orientation);
// Compute instantaneous acceleration
float forwardAcceleration = glm::length(glm::dot(getBodyFrontDirection(), getVelocity() - oldVelocity)) / deltaTime;
const float OCULUS_ACCELERATION_PULL_THRESHOLD = 1.0f;
const int OCULUS_YAW_OFFSET_THRESHOLD = 10;
if (!Application::getInstance()->getFaceshift()->isActive() && OculusManager::isConnected() &&
fabsf(forwardAcceleration) > OCULUS_ACCELERATION_PULL_THRESHOLD &&
fabs(getHead()->getBaseYaw()) > OCULUS_YAW_OFFSET_THRESHOLD) {
// if we're wearing the oculus
// and this acceleration is above the pull threshold
// and the head yaw if off the body by more than OCULUS_YAW_OFFSET_THRESHOLD
// match the body yaw to the oculus yaw
_bodyYaw = getAbsoluteHeadYaw();
// set the head yaw to zero for this draw
getHead()->setBaseYaw(0);
// correct the oculus yaw offset
OculusManager::updateYawOffset();
}
const float WALKING_SPEED_THRESHOLD = 0.2f;
// use speed and angular velocity to determine walking vs. standing
if (_speed + fabs(_bodyYawDelta) > WALKING_SPEED_THRESHOLD) {
@ -308,7 +282,7 @@ void MyAvatar::simulate(float deltaTime) {
head->simulate(deltaTime, true);
// Zero thrust out now that we've added it to velocity in this frame
_thrust = glm::vec3(0, 0, 0);
_thrust = glm::vec3(0.f);
// now that we're done stepping the avatar forward in time, compute new collisions
if (_collisionFlags != 0) {