This commit is contained in:
Andrzej Kapolka 2013-04-25 15:41:57 -07:00
commit d5da35e91a
5 changed files with 31 additions and 25 deletions

View file

@ -380,7 +380,7 @@ void Avatar::simulate(float deltaTime) {
if ( AVATAR_GRAVITY ) { if ( AVATAR_GRAVITY ) {
if ( _position.y > _bone[ AVATAR_BONE_RIGHT_FOOT ].radius * 2.0 ) { 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 { else {
if ( _position.y < _bone[ AVATAR_BONE_RIGHT_FOOT ].radius ) { if ( _position.y < _bone[ AVATAR_BONE_RIGHT_FOOT ].radius ) {
@ -399,28 +399,22 @@ void Avatar::simulate(float deltaTime) {
_thrust = glm::vec3( 0.0, 0.0, 0.0 ); _thrust = glm::vec3( 0.0, 0.0, 0.0 );
if (_driveKeys[FWD]) { if (_driveKeys[FWD]) {
glm::vec3 front( _orientation.getFront().x, _orientation.getFront().y, _orientation.getFront().z ); _thrust += _orientation.getFront() * THRUST_MAG;
_thrust += front * THRUST_MAG;
} }
if (_driveKeys[BACK]) { if (_driveKeys[BACK]) {
glm::vec3 front( _orientation.getFront().x, _orientation.getFront().y, _orientation.getFront().z ); _thrust -= _orientation.getFront() * THRUST_MAG;
_thrust -= front * THRUST_MAG;
} }
if (_driveKeys[RIGHT]) { if (_driveKeys[RIGHT]) {
glm::vec3 right( _orientation.getRight().x, _orientation.getRight().y, _orientation.getRight().z ); _thrust += _orientation.getRight() * THRUST_MAG;
_thrust += right * THRUST_MAG;
} }
if (_driveKeys[LEFT]) { if (_driveKeys[LEFT]) {
glm::vec3 right( _orientation.getRight().x, _orientation.getRight().y, _orientation.getRight().z ); _thrust -= _orientation.getRight() * THRUST_MAG;
_thrust -= right * THRUST_MAG;
} }
if (_driveKeys[UP]) { if (_driveKeys[UP]) {
glm::vec3 up( _orientation.getUp().x, _orientation.getUp().y, _orientation.getUp().z ); _thrust += _orientation.getUp() * THRUST_MAG;
_thrust += up * THRUST_MAG;
} }
if (_driveKeys[DOWN]) { if (_driveKeys[DOWN]) {
glm::vec3 up( _orientation.getUp().x, _orientation.getUp().y, _orientation.getUp().z ); _thrust -= _orientation.getUp() * THRUST_MAG;
_thrust -= up * THRUST_MAG;
} }
if (_driveKeys[ROT_RIGHT]) { if (_driveKeys[ROT_RIGHT]) {
_bodyYawDelta -= YAW_MAG * deltaTime; _bodyYawDelta -= YAW_MAG * deltaTime;
@ -450,10 +444,10 @@ void Avatar::simulate(float deltaTime) {
_bodyYawDelta *= (1.0 - TEST_YAW_DECAY * deltaTime); _bodyYawDelta *= (1.0 - TEST_YAW_DECAY * deltaTime);
// add thrust to velocity // add thrust to velocity
_velocity += glm::dvec3(_thrust * deltaTime); _velocity += _thrust * deltaTime;
// update position by velocity // update position by velocity
_position += (glm::vec3)_velocity * deltaTime; _position += _velocity * deltaTime;
// decay velocity // decay velocity
_velocity *= ( 1.0 - LIN_VEL_DECAY * deltaTime ); _velocity *= ( 1.0 - LIN_VEL_DECAY * deltaTime );
@ -1293,3 +1287,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); 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);
private: private:
AvatarHead _head; AvatarHead _head;
bool _isMine; bool _isMine;
@ -233,7 +236,7 @@ class Avatar : public AvatarData {
AvatarBone _bone[ NUM_AVATAR_BONES ]; AvatarBone _bone[ NUM_AVATAR_BONES ];
AvatarMode _mode; AvatarMode _mode;
AvatarHandHolding _handHolding; AvatarHandHolding _handHolding;
glm::dvec3 _velocity; glm::vec3 _velocity;
glm::vec3 _thrust; glm::vec3 _thrust;
float _maxArmLength; float _maxArmLength;
Orientation _orientation; Orientation _orientation;

View file

@ -161,10 +161,6 @@ namespace starfield {
#if STARFIELD_HEMISPHERE_ONLY #if STARFIELD_HEMISPHERE_ONLY
altitude = std::max(0.0f, altitude); altitude = std::max(0.0f, altitude);
#endif #endif
unsigned tileIndex =
_objTiling.getTileIndex(azimuth, altitude);
// printLog("Stars.cpp: starting on tile #%d\n", tileIndex);
#if STARFIELD_DEBUG_CULLING #if STARFIELD_DEBUG_CULLING
mat4 matrix_debug = glm::translate(glm::frustum(-hw, hw, -hh, hh, nearClip, 10.0f), mat4 matrix_debug = glm::translate(glm::frustum(-hw, hw, -hh, hh, nearClip, 10.0f),

View file

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

View file

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