From 2d8c15e0cb73e8fdee3b991bc01a5eb289ea74a3 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Tue, 7 May 2013 18:32:56 -0700 Subject: [PATCH 1/4] cleaned up some spacing issues in Orientarion class --- libraries/avatars/src/Orientation.cpp | 46 +++++++++++++-------------- libraries/avatars/src/Orientation.h | 34 ++++++++++---------- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/libraries/avatars/src/Orientation.cpp b/libraries/avatars/src/Orientation.cpp index fddb64d700..ac47dd3f6e 100755 --- a/libraries/avatars/src/Orientation.cpp +++ b/libraries/avatars/src/Orientation.cpp @@ -20,25 +20,25 @@ Orientation::Orientation() { void Orientation::setToIdentity() { quat = glm::quat(); - right = glm::vec3( IDENTITY_RIGHT ); - up = glm::vec3( IDENTITY_UP ); - front = glm::vec3( IDENTITY_FRONT ); + right = glm::vec3(IDENTITY_RIGHT); + up = glm::vec3(IDENTITY_UP ); + front = glm::vec3(IDENTITY_FRONT); } -void Orientation::set( Orientation o ) { +void Orientation::set(Orientation o) { - quat = o.quat; - right = o.right; - up = o.up; - front = o.front; + quat = o.quat; + right = o.right; + up = o.up; + front = o.front; } -void Orientation::yaw( float angle ) { +void Orientation::yaw(float angle) { float radian = angle * PI_OVER_180; - if ( USING_QUATERNIONS ) { - rotateAndGenerateDirections( glm::quat( glm::vec3( 0.0f, -radian, 0.0f )) ); + if (USING_QUATERNIONS) { + rotateAndGenerateDirections(glm::quat(glm::vec3(0.0f, -radian, 0.0f))); } else { float s = sin(radian); float c = cos(radian); @@ -53,12 +53,12 @@ void Orientation::yaw( float angle ) { } } -void Orientation::pitch( float angle ) { +void Orientation::pitch(float angle) { float radian = angle * PI_OVER_180; - if ( USING_QUATERNIONS ) { - rotateAndGenerateDirections( glm::quat( glm::vec3( radian, 0.0f, 0.0f ) ) ); + if (USING_QUATERNIONS) { + rotateAndGenerateDirections(glm::quat(glm::vec3(radian, 0.0f, 0.0f))); } else { float s = sin(radian); float c = cos(radian); @@ -73,12 +73,12 @@ void Orientation::pitch( float angle ) { } } -void Orientation::roll( float angle ) { +void Orientation::roll(float angle) { float radian = angle * PI_OVER_180; - if ( USING_QUATERNIONS ) { - rotateAndGenerateDirections( glm::quat( glm::vec3( 0.0f, 0.0f, radian )) ); + if (USING_QUATERNIONS) { + rotateAndGenerateDirections(glm::quat(glm::vec3(0.0f, 0.0f, radian))); } else { float s = sin(radian); float c = cos(radian); @@ -93,13 +93,13 @@ void Orientation::roll( float angle ) { } } -void Orientation::rotate( float p, float y, float r ) { +void Orientation::rotate(float p, float y, float r) { pitch(p); yaw (y); roll (r); } -void Orientation::rotate( glm::vec3 eulerAngles ) { +void Orientation::rotate(glm::vec3 eulerAngles) { //this needs to be optimized! pitch(eulerAngles.x); @@ -112,13 +112,13 @@ void Orientation::rotate( glm::quat rotation ) { } -void Orientation::rotateAndGenerateDirections( glm::quat rotation ) { +void Orientation::rotateAndGenerateDirections(glm::quat rotation) { quat = quat * rotation; glm::mat4 rotationMatrix = glm::mat4_cast(quat); - right = glm::vec3( glm::vec4( IDENTITY_RIGHT, 0.0f ) * rotationMatrix ); - up = glm::vec3( glm::vec4( IDENTITY_UP, 0.0f ) * rotationMatrix ); - front = glm::vec3( glm::vec4( IDENTITY_FRONT, 0.0f ) * rotationMatrix ); + right = glm::vec3(glm::vec4(IDENTITY_RIGHT, 0.0f) * rotationMatrix); + up = glm::vec3(glm::vec4(IDENTITY_UP, 0.0f) * rotationMatrix); + front = glm::vec3(glm::vec4(IDENTITY_FRONT, 0.0f) * rotationMatrix); } diff --git a/libraries/avatars/src/Orientation.h b/libraries/avatars/src/Orientation.h index 50b400b935..4bf487be02 100755 --- a/libraries/avatars/src/Orientation.h +++ b/libraries/avatars/src/Orientation.h @@ -12,33 +12,33 @@ #include // this is where the coordinate system is represented -const glm::vec3 IDENTITY_RIGHT = glm::vec3( -1.0f, 0.0f, 0.0f ); -const glm::vec3 IDENTITY_UP = glm::vec3( 0.0f, 1.0f, 0.0f ); -const glm::vec3 IDENTITY_FRONT = glm::vec3( 0.0f, 0.0f, 1.0f ); +const glm::vec3 IDENTITY_RIGHT = glm::vec3(-1.0f, 0.0f, 0.0f); +const glm::vec3 IDENTITY_UP = glm::vec3( 0.0f, 1.0f, 0.0f); +const glm::vec3 IDENTITY_FRONT = glm::vec3( 0.0f, 0.0f, 1.0f); class Orientation { public: Orientation(); - void set( Orientation ); + void set(Orientation); void setToIdentity(); - void pitch( float p ); - void yaw ( float y ); - void roll ( float r ); + void pitch(float p); + void yaw (float y); + void roll (float r); - void rotate( float pitch, float yaw, float roll ); - void rotate( glm::vec3 EulerAngles ); - void rotate( glm::quat quaternion ); + void rotate(float pitch, float yaw, float roll); + void rotate(glm::vec3 EulerAngles); + void rotate(glm::quat quaternion); - const glm::vec3 & getRight() const { return right; } - const glm::vec3 & getUp () const { return up; } - const glm::vec3 & getFront() const { return front; } + const glm::vec3 & getRight() const {return right;} + const glm::vec3 & getUp () const {return up; } + const glm::vec3 & getFront() const {return front;} - const glm::vec3 & getIdentityRight() const { return IDENTITY_RIGHT; } - const glm::vec3 & getIdentityUp () const { return IDENTITY_UP; } - const glm::vec3 & getIdentityFront() const { return IDENTITY_FRONT; } + const glm::vec3 & getIdentityRight() const {return IDENTITY_RIGHT;} + const glm::vec3 & getIdentityUp () const {return IDENTITY_UP;} + const glm::vec3 & getIdentityFront() const {return IDENTITY_FRONT;} private: @@ -47,7 +47,7 @@ private: glm::vec3 up; glm::vec3 front; - void rotateAndGenerateDirections( glm::quat rotation ); + void rotateAndGenerateDirections(glm::quat rotation); }; #endif From 9e60c8a36e48a5c21b5cf8b363830c68a5c90004 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Wed, 8 May 2013 08:59:29 -0700 Subject: [PATCH 2/4] increased GRAVITY_SCALE to 10.0; tidied-up avatar code; moved Orientation class to shared folder --- interface/src/Avatar.cpp | 104 +++++------------- interface/src/Avatar.h | 11 +- .../{avatars => shared}/src/Orientation.cpp | 6 +- .../{avatars => shared}/src/Orientation.h | 0 4 files changed, 38 insertions(+), 83 deletions(-) rename libraries/{avatars => shared}/src/Orientation.cpp (97%) rename libraries/{avatars => shared}/src/Orientation.h (100%) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index a54ee12ba7..c47e84640d 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -22,7 +22,7 @@ using namespace std; const bool BALLS_ON = false; const bool USING_AVATAR_GRAVITY = true; -const float GRAVITY_SCALE = 6.0f; +const float GRAVITY_SCALE = 10.0f; const float BOUNCE = 0.3f; const float DECAY = 0.1; const float THRUST_MAG = 1200.0; @@ -36,13 +36,18 @@ const float MY_HAND_HOLDING_PULL = 0.2; const float YOUR_HAND_HOLDING_PULL = 1.0; const float BODY_SPRING_DEFAULT_TIGHTNESS = 1500.0f; const float BODY_SPRING_FORCE = 300.0f; - const float BODY_SPRING_DECAY = 16.0f; const float COLLISION_RADIUS_SCALAR = 1.8; const float COLLISION_BALL_FORCE = 1.0; const float COLLISION_BODY_FORCE = 6.0; const float COLLISION_BALL_FRICTION = 60.0; const float COLLISION_BODY_FRICTION = 0.5; +const float HEAD_ROTATION_SCALE = 0.70; +const float HEAD_ROLL_SCALE = 0.40; +const float HEAD_MAX_PITCH = 45; +const float HEAD_MIN_PITCH = -45; +const float HEAD_MAX_YAW = 85; +const float HEAD_MIN_YAW = -85; float skinColor [] = {1.0, 0.84, 0.66}; float lightBlue [] = {0.7, 0.8, 1.0}; @@ -136,7 +141,6 @@ Avatar::Avatar(bool isMine) { _head.noise = 0; _head.returnSpringScale = 1.0; _movedHandOffset = glm::vec3(0.0f, 0.0f, 0.0f); - _usingBodySprings = true; _renderYaw = 0.0; _renderPitch = 0.0; _sphere = NULL; @@ -186,7 +190,6 @@ Avatar::Avatar(const Avatar &otherAvatar) { _TEST_bigSphereRadius = otherAvatar._TEST_bigSphereRadius; _TEST_bigSpherePosition = otherAvatar._TEST_bigSpherePosition; _movedHandOffset = otherAvatar._movedHandOffset; - _usingBodySprings = otherAvatar._usingBodySprings; _orientation.set(otherAvatar._orientation); @@ -276,20 +279,14 @@ void Avatar::UpdateGyros(float frametime, SerialInterface* serialInterface, glm: } // Update avatar head position based on measured gyro rates - const float HEAD_ROTATION_SCALE = 0.70; - const float HEAD_ROLL_SCALE = 0.40; - const float MAX_PITCH = 45; - const float MIN_PITCH = -45; - const float MAX_YAW = 85; - const float MIN_YAW = -85; - if ((_headPitch < MAX_PITCH) && (_headPitch > MIN_PITCH)) { + if ((_headPitch < HEAD_MAX_PITCH) && (_headPitch > HEAD_MIN_PITCH)) { addHeadPitch(measured_pitch_rate * -HEAD_ROTATION_SCALE * frametime); } addHeadRoll(measured_roll_rate * HEAD_ROLL_SCALE * frametime); - if ((_headYaw < MAX_YAW) && (_headYaw > MIN_YAW)) { + if ((_headYaw < HEAD_MAX_YAW) && (_headYaw > HEAD_MIN_YAW)) { addHeadYaw(_head.yawRate * HEAD_ROTATION_SCALE * frametime); } } @@ -299,7 +296,7 @@ float Avatar::getAbsoluteHeadYaw() const { } void Avatar::addLean(float x, float z) { - // Add Body lean as impulse + //Add lean as impulse _head.leanSideways += x; _head.leanForward += z; } @@ -641,12 +638,14 @@ void Avatar::updateCollisionWithSphere(glm::vec3 position, float radius, float d } } + /* if (jointCollision) { if (!_usingBodySprings) { _usingBodySprings = true; initializeBodySprings(); } } + */ } } @@ -747,18 +746,15 @@ void Avatar::setDisplayingHead(bool displayingHead) { _displayingHead = displayingHead; } - static TextRenderer* textRenderer() { static TextRenderer* renderer = new TextRenderer(SANS_FONT_FAMILY, 24); return renderer; } - void Avatar::setGravity(glm::vec3 gravity) { _gravity = gravity; } - void Avatar::render(bool lookingInMirror, glm::vec3 cameraPosition) { // render a simple round on the ground projected down from the avatar's position @@ -858,16 +854,9 @@ void Avatar::renderHead(bool lookingInMirror) { glPushMatrix(); - if (_usingBodySprings) { glTranslatef(_joint[ AVATAR_JOINT_HEAD_BASE ].springyPosition.x, _joint[ AVATAR_JOINT_HEAD_BASE ].springyPosition.y, _joint[ AVATAR_JOINT_HEAD_BASE ].springyPosition.z); - } - else { - glTranslatef(_joint[ AVATAR_JOINT_HEAD_BASE ].position.x, - _joint[ AVATAR_JOINT_HEAD_BASE ].position.y, - _joint[ AVATAR_JOINT_HEAD_BASE ].position.z); - } glScalef ( @@ -1032,7 +1021,7 @@ void Avatar::initializeSkeleton() { for (int b=0; b 0.0f) { + if (length > 0.0f) { // to avoid divide by zero glm::vec3 springDirection = springVector / length; float force = (length - _joint[b].length) * BODY_SPRING_FORCE * deltaTime; @@ -1342,56 +1324,30 @@ void Avatar::renderBody() { if (b != AVATAR_JOINT_HEAD_BASE) { // the head is rendered as a special case in "renderHead" - //render bone orientation + //show direction vectors of the bone orientation //renderOrientationDirections(_joint[b].springyPosition, _joint[b].orientation, _joint[b].radius * 2.0); - if (_usingBodySprings) { - glColor3fv(skinColor); - glPushMatrix(); - glTranslatef(_joint[b].springyPosition.x, _joint[b].springyPosition.y, _joint[b].springyPosition.z); - glutSolidSphere(_joint[b].radius, 20.0f, 20.0f); - glPopMatrix(); - } - else { - glColor3fv(skinColor); - glPushMatrix(); - glTranslatef(_joint[b].position.x, _joint[b].position.y, _joint[b].position.z); - glutSolidSphere(_joint[b].radius, 20.0f, 20.0f); - glPopMatrix(); - } + glColor3fv(skinColor); + glPushMatrix(); + glTranslatef(_joint[b].springyPosition.x, _joint[b].springyPosition.y, _joint[b].springyPosition.z); + glutSolidSphere(_joint[b].radius, 20.0f, 20.0f); + glPopMatrix(); } } // Render lines connecting the joint positions - if (_usingBodySprings) { - glColor3f(0.4f, 0.5f, 0.6f); - glLineWidth(3.0); - - for (int b = 1; b < NUM_AVATAR_JOINTS; b++) { - if (_joint[b].parent != AVATAR_JOINT_NULL) - if (b != AVATAR_JOINT_HEAD_TOP) { - glBegin(GL_LINE_STRIP); - glVertex3fv(&_joint[ _joint[ b ].parent ].springyPosition.x); - glVertex3fv(&_joint[ b ].springyPosition.x); - glEnd(); - } + glColor3f(0.4f, 0.5f, 0.6f); + glLineWidth(3.0); + + for (int b = 1; b < NUM_AVATAR_JOINTS; b++) { + if (_joint[b].parent != AVATAR_JOINT_NULL) + if (b != AVATAR_JOINT_HEAD_TOP) { + glBegin(GL_LINE_STRIP); + glVertex3fv(&_joint[ _joint[ b ].parent ].springyPosition.x); + glVertex3fv(&_joint[ b ].springyPosition.x); + glEnd(); } } - /* - else { - glColor3fv(skinColor); - glLineWidth(3.0); - - for (int b = 1; b < NUM_AVATAR_JOINTS; b++) { - if (_joint[b].parent != AVATAR_JOINT_NULL) { - glBegin(GL_LINE_STRIP); - glVertex3fv(&_joint[ _joint[ b ].parent ].position.x); - glVertex3fv(&_joint[ b ].position.x); - glEnd(); - } - } - } - */ } void Avatar::SetNewHeadTarget(float pitch, float yaw) { diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index 29896556a5..4709764c73 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -142,10 +142,6 @@ public: private: - // Do you want head to try to return to center (depends on interface detected) - void setHeadReturnToCenter(bool r) { _returnHeadToCenter = r; }; - const bool getHeadReturnToCenter() const { return _returnHeadToCenter; }; - struct AvatarJoint { AvatarJointID parent; // which joint is this joint connected to? @@ -213,7 +209,6 @@ private: float _bodyPitchDelta; float _bodyYawDelta; float _bodyRollDelta; - bool _usingBodySprings; glm::vec3 _movedHandOffset; glm::quat _rotation; // the rotation of the avatar body as a whole expressed as a quaternion AvatarJoint _joint[ NUM_AVATAR_JOINTS ]; @@ -240,7 +235,7 @@ private: AvatarTouch _avatarTouch; bool _displayingHead; // should be false if in first-person view bool _returnHeadToCenter; - float _distanceToNearestAvatar; // How close is the nearest avatar? + float _distanceToNearestAvatar; // How close is the nearest avatar? glm::vec3 _gravity; // private methods... @@ -257,6 +252,10 @@ private: void applyCollisionWithOtherAvatar( Avatar * other, float deltaTime ); void setHeadFromGyros(glm::vec3 * eulerAngles, glm::vec3 * angularVelocity, float deltaTime, float smoothingTime); void setHeadSpringScale(float s) { _head.returnSpringScale = s; } + + // Do you want head to try to return to center (depends on interface detected) + void setHeadReturnToCenter(bool r) { _returnHeadToCenter = r; }; + const bool getHeadReturnToCenter() const { return _returnHeadToCenter; }; }; #endif diff --git a/libraries/avatars/src/Orientation.cpp b/libraries/shared/src/Orientation.cpp similarity index 97% rename from libraries/avatars/src/Orientation.cpp rename to libraries/shared/src/Orientation.cpp index ac47dd3f6e..447739c32c 100755 --- a/libraries/avatars/src/Orientation.cpp +++ b/libraries/shared/src/Orientation.cpp @@ -6,10 +6,10 @@ //----------------------------------------------------------- #include "Orientation.h" -#include -#include "avatars_Log.h" +#include "SharedUtil.h" +//#include "avatars_Log.h" -using avatars_lib::printLog; +//using avatars_lib::printLog; static const bool USING_QUATERNIONS = true; diff --git a/libraries/avatars/src/Orientation.h b/libraries/shared/src/Orientation.h similarity index 100% rename from libraries/avatars/src/Orientation.h rename to libraries/shared/src/Orientation.h From e55661bb0f92949347240887ebe70d8174a731ac Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 8 May 2013 11:05:43 -0700 Subject: [PATCH 3/4] temporarily disable add scene in voxel server --- voxel-server/src/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/voxel-server/src/main.cpp b/voxel-server/src/main.cpp index f7d4567711..c229bed425 100644 --- a/voxel-server/src/main.cpp +++ b/voxel-server/src/main.cpp @@ -347,7 +347,9 @@ int main(int argc, const char * argv[]) // 1) we attempted to load a persistant file and it wasn't there // 2) you asked us to add a scene // HOWEVER -- we will NEVER add a scene if you explicitly tell us not to! - bool actuallyAddScene = !noAddScene && (addScene || (::wantVoxelPersist && !persistantFileRead)); + // + // TEMPORARILY DISABLED!!! + bool actuallyAddScene = false; // !noAddScene && (addScene || (::wantVoxelPersist && !persistantFileRead)); if (actuallyAddScene) { addSphereScene(&randomTree); } From 66bf71f8d9715999805f8c2afa8d985f3b621c6a Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 8 May 2013 11:55:00 -0700 Subject: [PATCH 4/4] debug file loading --- voxel-server/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/voxel-server/src/main.cpp b/voxel-server/src/main.cpp index c229bed425..b7de5254e5 100644 --- a/voxel-server/src/main.cpp +++ b/voxel-server/src/main.cpp @@ -304,7 +304,7 @@ int main(int argc, const char * argv[]) printf("loading voxels from file...\n"); persistantFileRead = ::randomTree.readFromFileV2(VOXELS_PERSIST_FILE); ::randomTree.clearDirtyBit(); // the tree is clean since we just loaded it - printf("DONE loading voxels from file...\n"); + printf("DONE loading voxels from file... fileRead=%s\n", persistantFileRead ? "yes" : "no" ); unsigned long nodeCount = ::randomTree.getVoxelCount(); printf("Nodes after loading scene %ld nodes\n", nodeCount); }