Merge remote-tracking branch 'upstream/master' into domain-rfd

This commit is contained in:
Stephen Birarda 2013-05-06 13:18:34 -07:00
commit 6d91e4721e
4 changed files with 120 additions and 100 deletions

View file

@ -21,7 +21,9 @@
using namespace std;
const bool BALLS_ON = false;
const bool AVATAR_GRAVITY = true;
const bool USING_AVATAR_GRAVITY = true;
const float GRAVITY_SCALE = 6.0f;
const float BOUNCE = 0.3f;
const float DECAY = 0.1;
const float THRUST_MAG = 1200.0;
const float YAW_MAG = 500.0;
@ -145,6 +147,7 @@ Avatar::Avatar(bool isMine) {
_interactingOther = NULL;
_handHoldingPosition = glm::vec3(0.0f, 0.0f, 0.0f);
_distanceToNearestAvatar = std::numeric_limits<float>::max();
_gravity = glm::vec3(0.0f, -1.0f, 0.0f); // default
initializeSkeleton();
@ -336,13 +339,13 @@ void Avatar::simulate(float deltaTime) {
updateHandMovementAndTouching(deltaTime);
// apply gravity and collision wiht the ground/floor
if (AVATAR_GRAVITY) {
// apply gravity and collision with the ground/floor
if (USING_AVATAR_GRAVITY) {
if (_position.y > _pelvisStandingHeight + 0.01f) {
_velocity += glm::dvec3(getGravity(getPosition())) * (6.0 * deltaTime );
_velocity += _gravity * (GRAVITY_SCALE * deltaTime);
} else if (_position.y < _pelvisStandingHeight) {
_position.y = _pelvisStandingHeight;
_velocity.y = 0.0;
_velocity.y = -_velocity.y * BOUNCE;
}
}
@ -695,7 +698,7 @@ void Avatar::updateCollisionWithOtherAvatar( Avatar * otherAvatar, float deltaTi
if (glm::length(vectorBetweenBoundingSpheres) < _height * ONE_HALF + otherAvatar->_height * ONE_HALF) {
float bodyMomentum = 1.0f;
glm::vec3 bodyPushForce = glm::vec3( 0.0, 0.0, 0.0 );
glm::vec3 bodyPushForce = glm::vec3(0.0f, 0.0f, 0.0f);
// loop through the joints of each avatar to check for every possible collision
for (int b=1; b<NUM_AVATAR_JOINTS; b++) {
@ -760,6 +763,11 @@ static TextRenderer* textRenderer() {
}
void Avatar::setGravity(glm::vec3 gravity) {
_gravity = gravity;
}
void Avatar::render(bool lookingInMirror) {
// render a simple round on the ground projected down from the avatar's position
@ -1523,25 +1531,6 @@ void Avatar::setHeadFromGyros(glm::vec3* eulerAngles, glm::vec3* angularVelocity
}
}
// Find and return the gravity vector at my location
glm::vec3 Avatar::getGravity(glm::vec3 pos) {
//
// For now, we'll test this with a simple global lookup, but soon we will add getting this
// from the domain/voxelserver (or something similar)
//
if ((pos.x > 0.f) &&
(pos.x < 10.f) &&
(pos.z > 0.f) &&
(pos.z < 10.f) &&
(pos.y > 0.f) &&
(pos.y < 3.f)) {
// If above ground plane, turn gravity on
return glm::vec3(0.f, -1.f, 0.f);
} else {
// If flying in space, turn gravity OFF
return glm::vec3(0.f, 0.f, 0.f);
}
}
const char AVATAR_DATA_FILENAME[] = "avatar.ifd";

View file

@ -93,6 +93,7 @@ public:
float getLastMeasuredHeadYaw() const {return _head.yawRate;}
float getBodyYaw() {return _bodyYaw;};
void addBodyYaw(float y) {_bodyYaw += y;};
void setGravity(glm::vec3 gravity);
bool getIsNearInteractingOther();
@ -143,9 +144,6 @@ public:
void processTransmitterData(unsigned char * packetData, int numBytes);
float getTransmitterHz() { return _transmitterHz; };
// Find out what the local gravity vector is at this location
glm::vec3 getGravity(glm::vec3 pos);
void writeAvatarDataToFile();
void readAvatarDataFromFile();
@ -251,6 +249,7 @@ private:
bool _displayingHead; // should be false if in first-person view
bool _returnHeadToCenter;
float _distanceToNearestAvatar; // How close is the nearest avatar?
glm::vec3 _gravity;
// private methods...
void initializeSkeleton();

View file

@ -34,6 +34,11 @@ const int GRAVITY_SAMPLES = 200; // Use the first samples to
const bool USING_INVENSENSE_MPU9150 = 1;
SerialInterface::SerialInterface() :
active(false),
_failedOpenAttempts(0) {
}
void SerialInterface::pair() {
#ifdef __APPLE__

View file

@ -90,6 +90,8 @@ using namespace std;
void reshape(int width, int height); // will be defined below
void loadViewFrustum(ViewFrustum& viewFrustum); // will be defined below
glm::vec3 getGravity(glm::vec3 pos); //get the local gravity vector at this location in the universe
QApplication* app;
bool enableNetworkThread = true;
@ -1703,6 +1705,7 @@ void idle(void) {
}
agentList->unlock();
myAvatar.setGravity(getGravity(myAvatar.getPosition()));
myAvatar.simulate(deltaTime);
glutPostRedisplay();
@ -1765,6 +1768,30 @@ void reshape(int width, int height) {
glLoadIdentity();
}
//Find and return the gravity vector at this location
glm::vec3 getGravity(glm::vec3 pos) {
//
// For now, we'll test this with a simple global lookup, but soon we will add getting this
// from the domain/voxelserver (or something similar)
//
if ((pos.x > 0.f) &&
(pos.x < 10.f) &&
(pos.z > 0.f) &&
(pos.z < 10.f) &&
(pos.y > 0.f) &&
(pos.y < 3.f)) {
// If above ground plane, turn gravity on
return glm::vec3(0.f, -1.f, 0.f);
} else {
// If flying in space, turn gravity OFF
return glm::vec3(0.f, 0.f, 0.f);
}
}
void mouseFunc(int button, int state, int x, int y) {
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN ) {
if (state == GLUT_DOWN && !menu.mouseClick(x, y)) {