mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 14:37:46 +02:00
commit
69734f41fc
3 changed files with 115 additions and 100 deletions
|
@ -21,7 +21,9 @@
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
const bool BALLS_ON = false;
|
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 DECAY = 0.1;
|
||||||
const float THRUST_MAG = 1200.0;
|
const float THRUST_MAG = 1200.0;
|
||||||
const float YAW_MAG = 500.0;
|
const float YAW_MAG = 500.0;
|
||||||
|
@ -145,6 +147,7 @@ Avatar::Avatar(bool isMine) {
|
||||||
_interactingOther = NULL;
|
_interactingOther = NULL;
|
||||||
_handHoldingPosition = glm::vec3(0.0f, 0.0f, 0.0f);
|
_handHoldingPosition = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||||
_distanceToNearestAvatar = std::numeric_limits<float>::max();
|
_distanceToNearestAvatar = std::numeric_limits<float>::max();
|
||||||
|
_gravity = glm::vec3(0.0f, -1.0f, 0.0f); // default
|
||||||
|
|
||||||
initializeSkeleton();
|
initializeSkeleton();
|
||||||
|
|
||||||
|
@ -336,13 +339,13 @@ void Avatar::simulate(float deltaTime) {
|
||||||
updateHandMovementAndTouching(deltaTime);
|
updateHandMovementAndTouching(deltaTime);
|
||||||
|
|
||||||
|
|
||||||
// apply gravity and collision wiht the ground/floor
|
// apply gravity and collision with the ground/floor
|
||||||
if (AVATAR_GRAVITY) {
|
if (USING_AVATAR_GRAVITY) {
|
||||||
if (_position.y > _pelvisStandingHeight + 0.01f) {
|
if (_position.y > _pelvisStandingHeight + 0.01f) {
|
||||||
_velocity += glm::dvec3(getGravity(getPosition())) * (6.0 * deltaTime );
|
_velocity += _gravity * (GRAVITY_SCALE * deltaTime);
|
||||||
} else if (_position.y < _pelvisStandingHeight) {
|
} else if (_position.y < _pelvisStandingHeight) {
|
||||||
_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) {
|
if (glm::length(vectorBetweenBoundingSpheres) < _height * ONE_HALF + otherAvatar->_height * ONE_HALF) {
|
||||||
|
|
||||||
float bodyMomentum = 1.0f;
|
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
|
// loop through the joints of each avatar to check for every possible collision
|
||||||
for (int b=1; b<NUM_AVATAR_JOINTS; b++) {
|
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) {
|
void Avatar::render(bool lookingInMirror) {
|
||||||
|
|
||||||
// render a simple round on the ground projected down from the avatar's position
|
// 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";
|
const char AVATAR_DATA_FILENAME[] = "avatar.ifd";
|
||||||
|
|
|
@ -93,6 +93,7 @@ public:
|
||||||
float getLastMeasuredHeadYaw() const {return _head.yawRate;}
|
float getLastMeasuredHeadYaw() const {return _head.yawRate;}
|
||||||
float getBodyYaw() {return _bodyYaw;};
|
float getBodyYaw() {return _bodyYaw;};
|
||||||
void addBodyYaw(float y) {_bodyYaw += y;};
|
void addBodyYaw(float y) {_bodyYaw += y;};
|
||||||
|
void setGravity(glm::vec3 gravity);
|
||||||
|
|
||||||
bool getIsNearInteractingOther();
|
bool getIsNearInteractingOther();
|
||||||
|
|
||||||
|
@ -143,9 +144,6 @@ public:
|
||||||
void processTransmitterData(unsigned char * packetData, int numBytes);
|
void processTransmitterData(unsigned char * packetData, int numBytes);
|
||||||
float getTransmitterHz() { return _transmitterHz; };
|
float getTransmitterHz() { return _transmitterHz; };
|
||||||
|
|
||||||
// Find out what the local gravity vector is at this location
|
|
||||||
glm::vec3 getGravity(glm::vec3 pos);
|
|
||||||
|
|
||||||
void writeAvatarDataToFile();
|
void writeAvatarDataToFile();
|
||||||
void readAvatarDataFromFile();
|
void readAvatarDataFromFile();
|
||||||
|
|
||||||
|
@ -251,6 +249,7 @@ private:
|
||||||
bool _displayingHead; // should be false if in first-person view
|
bool _displayingHead; // should be false if in first-person view
|
||||||
bool _returnHeadToCenter;
|
bool _returnHeadToCenter;
|
||||||
float _distanceToNearestAvatar; // How close is the nearest avatar?
|
float _distanceToNearestAvatar; // How close is the nearest avatar?
|
||||||
|
glm::vec3 _gravity;
|
||||||
|
|
||||||
// private methods...
|
// private methods...
|
||||||
void initializeSkeleton();
|
void initializeSkeleton();
|
||||||
|
|
|
@ -90,6 +90,8 @@ using namespace std;
|
||||||
void reshape(int width, int height); // will be defined below
|
void reshape(int width, int height); // will be defined below
|
||||||
void loadViewFrustum(ViewFrustum& viewFrustum); // 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;
|
QApplication* app;
|
||||||
|
|
||||||
bool enableNetworkThread = true;
|
bool enableNetworkThread = true;
|
||||||
|
@ -1703,6 +1705,7 @@ void idle(void) {
|
||||||
}
|
}
|
||||||
agentList->unlock();
|
agentList->unlock();
|
||||||
|
|
||||||
|
myAvatar.setGravity(getGravity(myAvatar.getPosition()));
|
||||||
myAvatar.simulate(deltaTime);
|
myAvatar.simulate(deltaTime);
|
||||||
|
|
||||||
glutPostRedisplay();
|
glutPostRedisplay();
|
||||||
|
@ -1765,6 +1768,30 @@ void reshape(int width, int height) {
|
||||||
glLoadIdentity();
|
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) {
|
void mouseFunc(int button, int state, int x, int y) {
|
||||||
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN ) {
|
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN ) {
|
||||||
if (state == GLUT_DOWN && !menu.mouseClick(x, y)) {
|
if (state == GLUT_DOWN && !menu.mouseClick(x, y)) {
|
||||||
|
|
Loading…
Reference in a new issue