From 2a3d06f6de95f60788f8eb7c1ea5a765639bbb4e Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Wed, 24 Apr 2013 17:45:26 -0700 Subject: [PATCH 1/4] Fixed warning in starfield code --- interface/src/starfield/renderer/Renderer.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/interface/src/starfield/renderer/Renderer.h b/interface/src/starfield/renderer/Renderer.h index 8ef9bb3270..9d363a6262 100644 --- a/interface/src/starfield/renderer/Renderer.h +++ b/interface/src/starfield/renderer/Renderer.h @@ -161,10 +161,6 @@ namespace starfield { #if STARFIELD_HEMISPHERE_ONLY altitude = std::max(0.0f, altitude); #endif - unsigned tileIndex = - _objTiling.getTileIndex(azimuth, altitude); - -// printLog("Stars.cpp: starting on tile #%d\n", tileIndex); #if STARFIELD_DEBUG_CULLING mat4 matrix_debug = glm::translate(glm::frustum(-hw, hw, -hh, hh, nearClip, 10.0f), From ba551758701d4aeb6437fadbe242d67e49789d07 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Thu, 25 Apr 2013 09:50:35 -0700 Subject: [PATCH 2/4] Gravity is ON near origin, off in space, and a gravity field can be created with getGravity() --- interface/src/Avatar.cpp | 17 ++++++++++++++++- interface/src/Avatar.h | 3 +++ libraries/avatars/src/AvatarData.cpp | 6 ++---- libraries/avatars/src/AvatarData.h | 2 +- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 9f9d1febba..05ea1399f1 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -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); + } +} + diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index 32d31184a8..e23821306b 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -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; diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index fd20e099c0..155edab504 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -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) { diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index cb2171cbe5..52d4c4c355 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -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); From b9fb8880731da83192765e9e11b2ceb49cc38a4f Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Thu, 25 Apr 2013 10:02:14 -0700 Subject: [PATCH 3/4] Small speed/cleanup to thrust setting --- interface/src/Avatar.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 05ea1399f1..82d9f3334f 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -397,28 +397,22 @@ void Avatar::simulate(float deltaTime) { _thrust = glm::vec3( 0.0, 0.0, 0.0 ); if (_driveKeys[FWD]) { - glm::vec3 front( _orientation.getFront().x, _orientation.getFront().y, _orientation.getFront().z ); - _thrust += front * THRUST_MAG; + _thrust += _orientation.getFront() * THRUST_MAG; } if (_driveKeys[BACK]) { - glm::vec3 front( _orientation.getFront().x, _orientation.getFront().y, _orientation.getFront().z ); - _thrust -= front * THRUST_MAG; + _thrust -= _orientation.getFront() * THRUST_MAG; } if (_driveKeys[RIGHT]) { - glm::vec3 right( _orientation.getRight().x, _orientation.getRight().y, _orientation.getRight().z ); - _thrust += right * THRUST_MAG; + _thrust += _orientation.getRight() * THRUST_MAG; } if (_driveKeys[LEFT]) { - glm::vec3 right( _orientation.getRight().x, _orientation.getRight().y, _orientation.getRight().z ); - _thrust -= right * THRUST_MAG; + _thrust -= _orientation.getRight() * THRUST_MAG; } if (_driveKeys[UP]) { - glm::vec3 up( _orientation.getUp().x, _orientation.getUp().y, _orientation.getUp().z ); - _thrust += up * THRUST_MAG; + _thrust += _orientation.getUp() * THRUST_MAG; } if (_driveKeys[DOWN]) { - glm::vec3 up( _orientation.getUp().x, _orientation.getUp().y, _orientation.getUp().z ); - _thrust -= up * THRUST_MAG; + _thrust -= _orientation.getUp() * THRUST_MAG; } if (_driveKeys[ROT_RIGHT]) { _bodyYawDelta -= YAW_MAG * deltaTime; From 9e62728c3388ada26adaa7c740eb66999f653a74 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Thu, 25 Apr 2013 10:18:30 -0700 Subject: [PATCH 4/4] Changed velocity to be dvec3 --- interface/src/Avatar.cpp | 4 ++-- interface/src/Avatar.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 82d9f3334f..b19f1f3212 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -442,10 +442,10 @@ void Avatar::simulate(float deltaTime) { _bodyYawDelta *= (1.0 - TEST_YAW_DECAY * deltaTime); // add thrust to velocity - _velocity += glm::dvec3(_thrust * deltaTime); + _velocity += _thrust * deltaTime; // update position by velocity - _position += (glm::vec3)_velocity * deltaTime; + _position += _velocity * deltaTime; // decay velocity _velocity *= ( 1.0 - LIN_VEL_DECAY * deltaTime ); diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index e23821306b..52d5073932 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -236,7 +236,7 @@ class Avatar : public AvatarData { AvatarBone _bone[ NUM_AVATAR_BONES ]; AvatarMode _mode; AvatarHandHolding _handHolding; - glm::dvec3 _velocity; + glm::vec3 _velocity; glm::vec3 _thrust; float _maxArmLength; Orientation _orientation;