Merge pull request #336 from PhilipRosedale/master

View shifts back to straight ahead on movement
This commit is contained in:
ZappoMan 2013-05-16 21:25:04 -07:00
commit 501a68a2de

View file

@ -18,6 +18,7 @@
#include <AgentList.h>
#include <AgentTypes.h>
#include <PacketHeaders.h>
#include <OculusManager.h>
using namespace std;
@ -29,8 +30,6 @@ const float THRUST_MAG = 1200.0;
const float YAW_MAG = 500.0;
const float BODY_SPIN_FRICTION = 5.0;
const float BODY_UPRIGHT_FORCE = 10.0;
const float BODY_PITCH_WHILE_WALKING = 40.0;
const float BODY_ROLL_WHILE_TURNING = 0.1;
const float VELOCITY_DECAY = 5.0;
const float MY_HAND_HOLDING_PULL = 0.2;
const float YOUR_HAND_HOLDING_PULL = 1.0;
@ -50,7 +49,6 @@ const float HEAD_MAX_YAW = 85;
const float HEAD_MIN_YAW = -85;
const float AVATAR_BRAKING_RANGE = 1.6f;
const float AVATAR_BRAKING_STRENGTH = 30.0f;
//const float MAX_JOINT_TOUCH_DOT = 0.995f;
const float JOINT_TOUCH_RANGE = 0.0005f;
float skinColor [] = {1.0, 0.84, 0.66};
@ -188,15 +186,6 @@ Avatar::Avatar(const Avatar &otherAvatar) {
initializeSkeleton();
/*
if (iris_texture.size() == 0) {
switchToResourcesParentIfRequired();
unsigned error = lodepng::decode(iris_texture, iris_texture_width, iris_texture_height, iris_texture_file);
if (error != 0) {
printLog("error %u: %s\n", error, lodepng_error_text(error));
}
}
*/
}
Avatar::~Avatar() {
@ -332,7 +321,10 @@ void Avatar::updateFromMouse(int mouseX, int mouseY, int screenWidth, int scree
void Avatar::simulate(float deltaTime) {
//figure out if the mouse cursor is over any body spheres...
// copy velocity so we can use it later for acceleration
glm::vec3 oldVelocity = getVelocity();
// figure out if the mouse cursor is over any body spheres...
checkForMouseRayTouching();
// update balls
@ -403,10 +395,12 @@ void Avatar::simulate(float deltaTime) {
// add thrust to velocity
_velocity += _thrust * deltaTime;
// calculate speed
// calculate speed
_speed = glm::length(_velocity);
//pitch and roll the body as a function of forward speed and turning delta
const float BODY_PITCH_WHILE_WALKING = 20.0;
const float BODY_ROLL_WHILE_TURNING = 0.2;
float forwardComponentOfVelocity = glm::dot(_orientation.getFront(), _velocity);
_bodyPitch += BODY_PITCH_WHILE_WALKING * deltaTime * forwardComponentOfVelocity;
_bodyRoll += BODY_ROLL_WHILE_TURNING * deltaTime * _speed * _bodyYawDelta;
@ -442,10 +436,15 @@ void Avatar::simulate(float deltaTime) {
}
}
// Compute instantaneous acceleration
float acceleration = glm::distance(getVelocity(), oldVelocity) / deltaTime;
const float ACCELERATION_PITCH_DECAY = 0.4f;
// Decay HeadPitch as a function of acceleration, so that you look straight ahead when
// you start moving, but don't do this with an HMD like the Oculus.
if (!OculusManager::isConnected()) {
setHeadPitch(getHeadPitch() * (1.f - acceleration * ACCELERATION_PITCH_DECAY * deltaTime));
}
// Get head position data from network for other people
if (!_isMine) {
_head.leanSideways = getHeadLeanSideways();