Gravity is ON near origin, off in space, and a gravity field can be created with getGravity()

This commit is contained in:
Philip Rosedale 2013-04-25 09:50:35 -07:00
parent fd329cd1bb
commit ba55175870
4 changed files with 22 additions and 6 deletions

View file

@ -378,7 +378,7 @@ void Avatar::simulate(float deltaTime) {
if ( AVATAR_GRAVITY ) {
if ( _position.y > _bone[ AVATAR_BONE_RIGHT_FOOT ].radius * 2.0 ) {
_velocity += glm::dvec3( 0.0, -1.0, 0.0 ) * ( 6.0 * deltaTime );
_velocity += glm::dvec3(getGravity(getPosition())) * ( 6.0 * deltaTime );
}
else {
if ( _position.y < _bone[ AVATAR_BONE_RIGHT_FOOT ].radius ) {
@ -1267,3 +1267,18 @@ void Avatar::processTransmitterData(unsigned char* packetData, int numBytes) {
}
// 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 (glm::length(pos) < 5.f) {
// If near the origin sphere, 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);
}
}

View file

@ -218,6 +218,9 @@ class Avatar : public AvatarData {
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);
private:
AvatarHead _head;
bool _isMine;

View file

@ -171,10 +171,8 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) {
return sourceBuffer - startPosition;
}
glm::vec3 AvatarData::getPosition() {
return glm::vec3(_position.x,
_position.y,
_position.z);
const glm::vec3& AvatarData::getPosition() const {
return _position;
}
void AvatarData::setPosition(glm::vec3 position) {

View file

@ -20,7 +20,7 @@ public:
AvatarData* clone() const;
glm::vec3 getPosition();
const glm::vec3& getPosition() const;
void setPosition(glm::vec3 position);
void setHandPosition(glm::vec3 handPosition);