From 85ad5601d722f257747964c4198c352c341328a5 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Fri, 3 May 2013 15:22:01 -0700 Subject: [PATCH 01/21] added avatar shadow --- interface/src/Avatar.cpp | 33 ++++++++++++++++++++++++-------- interface/src/AvatarRenderer.cpp | 6 +----- interface/src/Util.cpp | 28 +++++++++++++++++++++++++++ interface/src/Util.h | 2 ++ interface/src/main.cpp | 4 ++-- 5 files changed, 58 insertions(+), 15 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 7a4468d608..a80fea7dc9 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -34,21 +34,21 @@ const float MY_HAND_HOLDING_PULL = 0.2; const float YOUR_HAND_HOLDING_PULL = 1.0; const float BODY_SPRING_FORCE = 6.0f; const float BODY_SPRING_DECAY = 16.0f; -const float BODY_SPRING_DEFAULT_TIGHTNESS = 10.0f; +const float BODY_SPRING_DEFAULT_TIGHTNESS = 20.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; -float skinColor[] = {1.0, 0.84, 0.66}; -float lightBlue[] = { 0.7, 0.8, 1.0 }; -float browColor[] = {210.0/255.0, 105.0/255.0, 30.0/255.0}; +float skinColor [] = {1.0, 0.84, 0.66}; +float lightBlue [] = { 0.7, 0.8, 1.0 }; +float browColor [] = {210.0/255.0, 105.0/255.0, 30.0/255.0}; float mouthColor[] = {1, 0, 0}; -float BrowRollAngle[5] = {0, 15, 30, -30, -15}; +float BrowRollAngle [5] = {0, 15, 30, -30, -15}; float BrowPitchAngle[3] = {-70, -60, -50}; -float eyeColor[3] = {1,1,1}; +float eyeColor [3] = {1,1,1}; float MouthWidthChoices[3] = {0.5, 0.77, 0.3}; @@ -91,7 +91,7 @@ Avatar::Avatar(bool isMine) { _pelvisStandingHeight = 0.0f; _displayingHead = true; _TEST_bigSphereRadius = 0.4f; - _TEST_bigSpherePosition = glm::vec3( 0.0f, _TEST_bigSphereRadius, 2.0f ); + _TEST_bigSpherePosition = glm::vec3( 5.0f, _TEST_bigSphereRadius, 5.0f ); for (int i = 0; i < MAX_DRIVE_KEYS; i++) _driveKeys[i] = false; @@ -759,9 +759,25 @@ static TextRenderer* textRenderer() { return renderer; } + +struct TriangleArray +{ + float v0x,v0y,v0z; // x,y,z coordinate of vertex 0 + float r0,g0,b0,a0; // r,g,b color of vertex 0 + + float v1x,v1y,v1z; // x,y,z coordinate of vertex 1 + float r1,g1,b1,a1; // r,g,b color of vertex 1 + + float v2x,v2y,v2z; // x,y,z coordinate of vertex 2 + float r2,g2,b2,a2; // r,g,b color of vertex 2 +}; + + void Avatar::render(bool lookingInMirror) { - + // render a simple round on the ground projected down from the avatar's position + renderDiskShadow( _position, glm::vec3( 0.0f, 1.0f, 0.0f ), 0.1f, 0.2f ); + /* // show avatar position glColor4f( 0.5f, 0.5f, 0.5f, 0.6 ); @@ -1539,3 +1555,4 @@ glm::vec3 Avatar::getGravity(glm::vec3 pos) { return glm::vec3(0.f, 0.f, 0.f); } } + diff --git a/interface/src/AvatarRenderer.cpp b/interface/src/AvatarRenderer.cpp index b533b69e22..b1ed54d083 100644 --- a/interface/src/AvatarRenderer.cpp +++ b/interface/src/AvatarRenderer.cpp @@ -11,13 +11,11 @@ #include "AvatarRenderer.h" #include "InterfaceConfig.h" - AvatarRenderer::AvatarRenderer() { } // this method renders the avatar void AvatarRenderer::render(Avatar *avatar, bool lookingInMirror) { - /* // show avatar position glColor4f( 0.5f, 0.5f, 0.5f, 0.6 ); @@ -27,6 +25,4 @@ void AvatarRenderer::render(Avatar *avatar, bool lookingInMirror) { glutSolidSphere( 1, 10, 10 ); glPopMatrix(); */ -} - - \ No newline at end of file +} \ No newline at end of file diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 138ae7aef4..50a9e8099f 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -239,6 +239,34 @@ void drawGroundPlaneGrid(float size) } + +void renderDiskShadow(glm::vec3 position, glm::vec3 upDirection, float radius, float darkness) { + + glColor4f( 0.0f, 0.0f, 0.0f, darkness ); + + int num = 20; + float y = 0.01f; + float x2 = 0.0f; + float z2 = radius; + float x1; + float z1; + + for (int i=1; igetLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) { Avatar *avatar = (Avatar *)agent->getLinkedData(); avatar->render(0); - //avatarRenderer.render(avatar, 0); // this will replace the above call + avatarRenderer.render(avatar, 0); // this will replace the above call } } agentList->unlock(); @@ -731,7 +731,7 @@ void displaySide(Camera& whichCamera) { //Render my own avatar myAvatar.render(::lookingInMirror); - //avatarRenderer.render(&myAvatar, lookingInMirror); // this will replace the above call + avatarRenderer.render(&myAvatar, lookingInMirror); // this will replace the above call glPopMatrix(); } From cb8e68f300cfca0e777f3096347c65fe2f3b8c7b Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Fri, 3 May 2013 16:11:35 -0700 Subject: [PATCH 02/21] fixed a physics bug in avatar body spring (forgot to use deltaTime) - and adjusted various physics constants accordingly. --- interface/src/Avatar.cpp | 26 ++++++++++++++++---------- interface/src/Util.cpp | 8 +++++--- interface/src/main.cpp | 2 +- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index a80fea7dc9..24dae3c35d 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -32,9 +32,14 @@ const float BODY_ROLL_WHILE_TURNING = 0.1; const float LIN_VEL_DECAY = 5.0; const float MY_HAND_HOLDING_PULL = 0.2; const float YOUR_HAND_HOLDING_PULL = 1.0; -const float BODY_SPRING_FORCE = 6.0f; + +//const float BODY_SPRING_DEFAULT_TIGHTNESS = 20.0f; +//const float BODY_SPRING_FORCE = 6.0f; + +const float BODY_SPRING_DEFAULT_TIGHTNESS = 1500.0f; +const float BODY_SPRING_FORCE = 300.0f; + const float BODY_SPRING_DECAY = 16.0f; -const float BODY_SPRING_DEFAULT_TIGHTNESS = 20.0f; const float COLLISION_RADIUS_SCALAR = 1.8; const float COLLISION_BALL_FORCE = 1.0; const float COLLISION_BODY_FORCE = 6.0; @@ -336,10 +341,6 @@ void Avatar::simulate(float deltaTime) { //update the movement of the hand and process handshaking with other avatars... updateHandMovementAndTouching(deltaTime); - // test for avatar collision response with the big sphere - if (usingBigSphereCollisionTest) { - updateCollisionWithSphere( _TEST_bigSpherePosition, _TEST_bigSphereRadius, deltaTime ); - } // apply gravity and collision wiht the ground/floor if ( AVATAR_GRAVITY ) { @@ -354,6 +355,11 @@ void Avatar::simulate(float deltaTime) { // update body springs updateBodySprings( deltaTime ); + // test for avatar collision response with the big sphere + if (usingBigSphereCollisionTest) { + updateCollisionWithSphere( _TEST_bigSpherePosition, _TEST_bigSphereRadius, deltaTime ); + } + // driving the avatar around should only apply if this is my avatar (as opposed to an avatar being driven remotely) if ( _isMine ) { @@ -670,9 +676,9 @@ void Avatar::updateCollisionWithSphere( glm::vec3 position, float radius, float float penetration = 1.0 - (distanceToBigSphereCenter / combinedRadius); glm::vec3 collisionForce = vectorFromJointToBigSphereCenter * penetration; - _joint[b].springyVelocity += collisionForce * 30.0f * deltaTime; - _velocity += collisionForce * 100.0f * deltaTime; - _joint[b].springyPosition = position + directionVector * combinedRadius; + _joint[b].springyVelocity += collisionForce * 0.0f * deltaTime; + _velocity += collisionForce * 40.0f * deltaTime; + _joint[b].springyPosition = position + directionVector * combinedRadius; } } } @@ -1292,7 +1298,7 @@ void Avatar::updateBodySprings( float deltaTime ) { _joint[b].springyVelocity = glm::vec3( 0.0f, 0.0f, 0.0f ); } - _joint[b].springyPosition += _joint[b].springyVelocity; + _joint[b].springyPosition += _joint[b].springyVelocity * deltaTime; } } diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 50a9e8099f..436a52e7d3 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -245,12 +245,14 @@ void renderDiskShadow(glm::vec3 position, glm::vec3 upDirection, float radius, f glColor4f( 0.0f, 0.0f, 0.0f, darkness ); int num = 20; - float y = 0.01f; + float y = 0.001f; float x2 = 0.0f; float z2 = radius; float x1; float z1; + glBegin(GL_TRIANGLES); + for (int i=1; i Date: Fri, 3 May 2013 16:58:52 -0700 Subject: [PATCH 03/21] added avatar data file stuff that got lost during a merge or something --- interface/src/Avatar.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 24dae3c35d..815c10fb62 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -1562,3 +1562,24 @@ glm::vec3 Avatar::getGravity(glm::vec3 pos) { } } + +const char AVATAR_DATA_FILENAME[] = "avatar.ifd"; + +void Avatar::writeAvatarDataToFile() { + // write the avatar position and yaw to a local file + FILE* avatarFile = fopen(AVATAR_DATA_FILENAME, "w"); + + if (avatarFile) { + fprintf(avatarFile, "%f,%f,%f %f", _position.x, _position.y, _position.z, _bodyYaw); + fclose(avatarFile); + } +} + +void Avatar::readAvatarDataFromFile() { + FILE* avatarFile = fopen(AVATAR_DATA_FILENAME, "r"); + + if (avatarFile) { + fscanf(avatarFile, "%f,%f,%f %f", &_position.x, &_position.y, &_position.z, &_bodyYaw); + } +} + From f8cbe34e070faea0c0860877d44d8a01020b09a4 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Fri, 3 May 2013 17:27:57 -0700 Subject: [PATCH 04/21] Added basic ray intersection testing to VoxelTree. --- libraries/voxels/src/AABox.cpp | 49 ++++++++++++++++++++++++++++++ libraries/voxels/src/AABox.h | 5 ++- libraries/voxels/src/VoxelTree.cpp | 34 +++++++++++++++++++++ libraries/voxels/src/VoxelTree.h | 2 ++ 4 files changed, 89 insertions(+), 1 deletion(-) diff --git a/libraries/voxels/src/AABox.cpp b/libraries/voxels/src/AABox.cpp index 0187bae853..d79c36882c 100755 --- a/libraries/voxels/src/AABox.cpp +++ b/libraries/voxels/src/AABox.cpp @@ -8,6 +8,8 @@ // Simple axis aligned box class. // +#include "SharedUtil.h" + #include "AABox.h" @@ -66,3 +68,50 @@ glm::vec3 AABox::getVertexN(const glm::vec3 &normal) const { return(res); } + +// determines whether a value is within the extents +static bool isWithin(float value, float corner, float size) { + return value >= corner && value <= corner + size; +} + +bool AABox::contains(const glm::vec3& point) const { + return isWithin(point.x, _corner.x, _size.x) && + isWithin(point.y, _corner.y, _size.y) && + isWithin(point.z, _corner.z, _size.z); +} + +// finds the intersection between the closer plane in one direction +static bool findIntersection(float origin, float direction, float corner, float size, float* t) { + if (direction > EPSILON) { + *t = (corner - origin) / direction; + return true; + + } else if (direction < -EPSILON) { + *t = (corner + size - origin) / direction; + return true; + } + return false; +} + +bool AABox::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float* t) const { + // handle the trivial case where the box contains the origin + if (contains(origin)) { + *t = 0; + return true; + } + // check each direction + float nt; + if (findIntersection(origin.x, direction.x, _corner.x, _size.x, &nt) && + isWithin(origin.y + nt*direction.y, _corner.y, _size.y) && + isWithin(origin.z + nt*direction.z, _corner.z, _size.z) || + findIntersection(origin.y, direction.y, _corner.y, _size.y, &nt) && + isWithin(origin.x + nt*direction.x, _corner.x, _size.x) && + isWithin(origin.z + nt*direction.z, _corner.z, _size.z) || + findIntersection(origin.z, direction.z, _corner.z, _size.z, &nt) && + isWithin(origin.y + nt*direction.y, _corner.y, _size.y) && + isWithin(origin.x + nt*direction.x, _corner.x, _size.x)) { + *t = nt; + return true; + } + return false; +} diff --git a/libraries/voxels/src/AABox.h b/libraries/voxels/src/AABox.h index 0a69b8608d..0dae354860 100755 --- a/libraries/voxels/src/AABox.h +++ b/libraries/voxels/src/AABox.h @@ -35,10 +35,13 @@ public: const glm::vec3& getCorner() const { return _corner; }; const glm::vec3& getSize() const { return _size; }; + bool contains(const glm::vec3& point) const; + bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float* t) const; + private: glm::vec3 _corner; glm::vec3 _size; }; -#endif \ No newline at end of file +#endif diff --git a/libraries/voxels/src/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index 21118c929e..a13675f00d 100644 --- a/libraries/voxels/src/VoxelTree.cpp +++ b/libraries/voxels/src/VoxelTree.cpp @@ -546,7 +546,41 @@ int VoxelTree::searchForColoredNodes(int maxSearchLevel, VoxelNode* node, const return levelReached; } +// combines the ray cast arguments into a single object +class RayArgs { +public: + glm::vec3 origin; + glm::vec3 direction; + VoxelNode** node; + float* t; + bool found; +}; +bool findRayOperation(VoxelNode* node, void* extraData) { + RayArgs* args = static_cast(extraData); + AABox box; + node->getAABox(box); + float t; + if (!box.findRayIntersection(args->origin, args->direction, &t)) { + return false; + } + if (!node->isLeaf()) { + return true; // recurse on children + } + if (!args->found || t < *(args->t)) { + *(args->node) = node; + *(args->t) = t; + args->found = true; + } + return false; +} + +bool VoxelTree::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, VoxelNode** node, float* t) +{ + RayArgs args = { origin, direction, node, t }; + recurseTreeWithOperation(findRayOperation, &args); + return args.found; +} int VoxelTree::searchForColoredNodesRecursion(int maxSearchLevel, int& currentSearchLevel, VoxelNode* node, const ViewFrustum& viewFrustum, VoxelNodeBag& bag) { diff --git a/libraries/voxels/src/VoxelTree.h b/libraries/voxels/src/VoxelTree.h index 309766bcd2..e0346ebdb5 100644 --- a/libraries/voxels/src/VoxelTree.h +++ b/libraries/voxels/src/VoxelTree.h @@ -61,6 +61,8 @@ public: bool isDirty() const { return _isDirty; }; void clearDirtyBit() { _isDirty = false; }; unsigned long int getNodesChangedFromBitstream() const { return _nodesChangedFromBitstream; }; + + bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, VoxelNode** node, float* t); private: int encodeTreeBitstreamRecursion(int maxEncodeLevel, int& currentEncodeLevel, From ff4e21e50490c0ef947db7b7c5d24b3a78f47efb Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Fri, 3 May 2013 20:12:46 -0700 Subject: [PATCH 05/21] Remaining pick bits. --- libraries/voxels/src/AABox.cpp | 6 +++--- libraries/voxels/src/ViewFrustum.cpp | 4 ++++ libraries/voxels/src/ViewFrustum.h | 1 + libraries/voxels/src/VoxelTree.cpp | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/libraries/voxels/src/AABox.cpp b/libraries/voxels/src/AABox.cpp index d79c36882c..1d85b3181a 100755 --- a/libraries/voxels/src/AABox.cpp +++ b/libraries/voxels/src/AABox.cpp @@ -101,13 +101,13 @@ bool AABox::findRayIntersection(const glm::vec3& origin, const glm::vec3& direct } // check each direction float nt; - if (findIntersection(origin.x, direction.x, _corner.x, _size.x, &nt) && + if (findIntersection(origin.x, direction.x, _corner.x, _size.x, &nt) && nt >= 0 && isWithin(origin.y + nt*direction.y, _corner.y, _size.y) && isWithin(origin.z + nt*direction.z, _corner.z, _size.z) || - findIntersection(origin.y, direction.y, _corner.y, _size.y, &nt) && + findIntersection(origin.y, direction.y, _corner.y, _size.y, &nt) && nt >= 0 && isWithin(origin.x + nt*direction.x, _corner.x, _size.x) && isWithin(origin.z + nt*direction.z, _corner.z, _size.z) || - findIntersection(origin.z, direction.z, _corner.z, _size.z, &nt) && + findIntersection(origin.z, direction.z, _corner.z, _size.z, &nt) && nt >= 0 && isWithin(origin.y + nt*direction.y, _corner.y, _size.y) && isWithin(origin.x + nt*direction.x, _corner.x, _size.x)) { *t = nt; diff --git a/libraries/voxels/src/ViewFrustum.cpp b/libraries/voxels/src/ViewFrustum.cpp index 8bdb2d97cb..4f725ff1b4 100644 --- a/libraries/voxels/src/ViewFrustum.cpp +++ b/libraries/voxels/src/ViewFrustum.cpp @@ -225,3 +225,7 @@ int ViewFrustum::boxInFrustum(const AABox& box) const { return(result); } +void ViewFrustum::computePickRay(float x, float y, glm::vec3* origin, glm::vec3* direction) const { + *origin = _nearTopLeft + x*(_nearTopRight - _nearTopLeft) + y*(_nearBottomLeft - _nearTopLeft); + *direction = glm::normalize(*origin - _position); +} diff --git a/libraries/voxels/src/ViewFrustum.h b/libraries/voxels/src/ViewFrustum.h index d05bb9e1cf..feb1ecc8c6 100644 --- a/libraries/voxels/src/ViewFrustum.h +++ b/libraries/voxels/src/ViewFrustum.h @@ -98,6 +98,7 @@ public: int sphereInFrustum(const glm::vec3& center, float radius) const; int boxInFrustum(const AABox& box) const; + void computePickRay(float x, float y, glm::vec3* origin, glm::vec3* direction) const; }; diff --git a/libraries/voxels/src/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index a13675f00d..263c2f016e 100644 --- a/libraries/voxels/src/VoxelTree.cpp +++ b/libraries/voxels/src/VoxelTree.cpp @@ -577,7 +577,7 @@ bool findRayOperation(VoxelNode* node, void* extraData) { bool VoxelTree::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, VoxelNode** node, float* t) { - RayArgs args = { origin, direction, node, t }; + RayArgs args = { origin / (float)TREE_SCALE, direction, node, t }; recurseTreeWithOperation(findRayOperation, &args); return args.found; } From 34565a4956c640f0edab7e6dd3f3eed9b6df271f Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Sat, 4 May 2013 07:56:30 -0700 Subject: [PATCH 06/21] Pointers to references for in/out parameters, renamed line parameter to more descriptive "distance." --- libraries/voxels/src/AABox.cpp | 36 +++++++++++++++--------------- libraries/voxels/src/AABox.h | 2 +- libraries/voxels/src/VoxelTree.cpp | 18 +++++++-------- libraries/voxels/src/VoxelTree.h | 2 +- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/libraries/voxels/src/AABox.cpp b/libraries/voxels/src/AABox.cpp index 1d85b3181a..3c28401c66 100755 --- a/libraries/voxels/src/AABox.cpp +++ b/libraries/voxels/src/AABox.cpp @@ -80,37 +80,37 @@ bool AABox::contains(const glm::vec3& point) const { isWithin(point.z, _corner.z, _size.z); } -// finds the intersection between the closer plane in one direction -static bool findIntersection(float origin, float direction, float corner, float size, float* t) { +// finds the intersection between a ray and the facing plane on one axis +static bool findIntersection(float origin, float direction, float corner, float size, float& distance) { if (direction > EPSILON) { - *t = (corner - origin) / direction; + distance = (corner - origin) / direction; return true; } else if (direction < -EPSILON) { - *t = (corner + size - origin) / direction; + distance = (corner + size - origin) / direction; return true; } return false; } -bool AABox::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float* t) const { +bool AABox::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance) const { // handle the trivial case where the box contains the origin if (contains(origin)) { - *t = 0; + distance = 0; return true; } - // check each direction - float nt; - if (findIntersection(origin.x, direction.x, _corner.x, _size.x, &nt) && nt >= 0 && - isWithin(origin.y + nt*direction.y, _corner.y, _size.y) && - isWithin(origin.z + nt*direction.z, _corner.z, _size.z) || - findIntersection(origin.y, direction.y, _corner.y, _size.y, &nt) && nt >= 0 && - isWithin(origin.x + nt*direction.x, _corner.x, _size.x) && - isWithin(origin.z + nt*direction.z, _corner.z, _size.z) || - findIntersection(origin.z, direction.z, _corner.z, _size.z, &nt) && nt >= 0 && - isWithin(origin.y + nt*direction.y, _corner.y, _size.y) && - isWithin(origin.x + nt*direction.x, _corner.x, _size.x)) { - *t = nt; + // check each axis + float axisDistance; + if (findIntersection(origin.x, direction.x, _corner.x, _size.x, axisDistance) && axisDistance >= 0 && + isWithin(origin.y + axisDistance*direction.y, _corner.y, _size.y) && + isWithin(origin.z + axisDistance*direction.z, _corner.z, _size.z) || + findIntersection(origin.y, direction.y, _corner.y, _size.y, axisDistance) && axisDistance >= 0 && + isWithin(origin.x + axisDistance*direction.x, _corner.x, _size.x) && + isWithin(origin.z + axisDistance*direction.z, _corner.z, _size.z) || + findIntersection(origin.z, direction.z, _corner.z, _size.z, axisDistance) && axisDistance >= 0 && + isWithin(origin.y + axisDistance*direction.y, _corner.y, _size.y) && + isWithin(origin.x + axisDistance*direction.x, _corner.x, _size.x)) { + distance = axisDistance; return true; } return false; diff --git a/libraries/voxels/src/AABox.h b/libraries/voxels/src/AABox.h index 0dae354860..0184355de2 100755 --- a/libraries/voxels/src/AABox.h +++ b/libraries/voxels/src/AABox.h @@ -36,7 +36,7 @@ public: const glm::vec3& getSize() const { return _size; }; bool contains(const glm::vec3& point) const; - bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float* t) const; + bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance) const; private: glm::vec3 _corner; diff --git a/libraries/voxels/src/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index 263c2f016e..23027de420 100644 --- a/libraries/voxels/src/VoxelTree.cpp +++ b/libraries/voxels/src/VoxelTree.cpp @@ -551,8 +551,8 @@ class RayArgs { public: glm::vec3 origin; glm::vec3 direction; - VoxelNode** node; - float* t; + VoxelNode*& node; + float& distance; bool found; }; @@ -560,24 +560,24 @@ bool findRayOperation(VoxelNode* node, void* extraData) { RayArgs* args = static_cast(extraData); AABox box; node->getAABox(box); - float t; - if (!box.findRayIntersection(args->origin, args->direction, &t)) { + float distance; + if (!box.findRayIntersection(args->origin, args->direction, distance)) { return false; } if (!node->isLeaf()) { return true; // recurse on children } - if (!args->found || t < *(args->t)) { - *(args->node) = node; - *(args->t) = t; + if (!args->found || distance < args->distance) { + args->node = node; + args->distance = distance; args->found = true; } return false; } -bool VoxelTree::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, VoxelNode** node, float* t) +bool VoxelTree::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, VoxelNode*& node, float& distance) { - RayArgs args = { origin / (float)TREE_SCALE, direction, node, t }; + RayArgs args = { origin / (float)TREE_SCALE, direction, node, distance }; recurseTreeWithOperation(findRayOperation, &args); return args.found; } diff --git a/libraries/voxels/src/VoxelTree.h b/libraries/voxels/src/VoxelTree.h index e0346ebdb5..221a04138b 100644 --- a/libraries/voxels/src/VoxelTree.h +++ b/libraries/voxels/src/VoxelTree.h @@ -62,7 +62,7 @@ public: void clearDirtyBit() { _isDirty = false; }; unsigned long int getNodesChangedFromBitstream() const { return _nodesChangedFromBitstream; }; - bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, VoxelNode** node, float* t); + bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, VoxelNode*& node, float& distance); private: int encodeTreeBitstreamRecursion(int maxEncodeLevel, int& currentEncodeLevel, From aff465b17bef372f877275aa82561fb4ac0df841 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Sat, 4 May 2013 07:59:45 -0700 Subject: [PATCH 07/21] Missed a spot with the conversion from pointers to references. --- libraries/voxels/src/ViewFrustum.cpp | 6 +++--- libraries/voxels/src/ViewFrustum.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/voxels/src/ViewFrustum.cpp b/libraries/voxels/src/ViewFrustum.cpp index 4f725ff1b4..999c1c3efd 100644 --- a/libraries/voxels/src/ViewFrustum.cpp +++ b/libraries/voxels/src/ViewFrustum.cpp @@ -225,7 +225,7 @@ int ViewFrustum::boxInFrustum(const AABox& box) const { return(result); } -void ViewFrustum::computePickRay(float x, float y, glm::vec3* origin, glm::vec3* direction) const { - *origin = _nearTopLeft + x*(_nearTopRight - _nearTopLeft) + y*(_nearBottomLeft - _nearTopLeft); - *direction = glm::normalize(*origin - _position); +void ViewFrustum::computePickRay(float x, float y, glm::vec3& origin, glm::vec3& direction) const { + origin = _nearTopLeft + x*(_nearTopRight - _nearTopLeft) + y*(_nearBottomLeft - _nearTopLeft); + direction = glm::normalize(origin - _position); } diff --git a/libraries/voxels/src/ViewFrustum.h b/libraries/voxels/src/ViewFrustum.h index feb1ecc8c6..291697f2b9 100644 --- a/libraries/voxels/src/ViewFrustum.h +++ b/libraries/voxels/src/ViewFrustum.h @@ -98,7 +98,7 @@ public: int sphereInFrustum(const glm::vec3& center, float radius) const; int boxInFrustum(const AABox& box) const; - void computePickRay(float x, float y, glm::vec3* origin, glm::vec3* direction) const; + void computePickRay(float x, float y, glm::vec3& origin, glm::vec3& direction) const; }; From 5c7fd0fe7dcbeb47eeab8e136a67400c93b15ce3 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Mon, 6 May 2013 11:29:18 -0700 Subject: [PATCH 08/21] a few small formatting and glitch fixes --- interface/src/Avatar.cpp | 49 +++++++++++++++------------------------- interface/src/main.cpp | 6 ----- 2 files changed, 18 insertions(+), 37 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 815c10fb62..62f330eff6 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -47,7 +47,7 @@ const float COLLISION_BALL_FRICTION = 60.0; const float COLLISION_BODY_FRICTION = 0.5; float skinColor [] = {1.0, 0.84, 0.66}; -float lightBlue [] = { 0.7, 0.8, 1.0 }; +float lightBlue [] = {0.7, 0.8, 1.0}; float browColor [] = {210.0/255.0, 105.0/255.0, 30.0/255.0}; float mouthColor[] = {1, 0, 0}; @@ -75,9 +75,9 @@ Avatar::Avatar(bool isMine) { _orientation.setToIdentity(); - _velocity = glm::vec3( 0.0, 0.0, 0.0 ); - _thrust = glm::vec3( 0.0, 0.0, 0.0 ); - _rotation = glm::quat( 0.0f, 0.0f, 0.0f, 0.0f ); + _velocity = glm::vec3(0.0f, 0.0f, 0.0f); + _thrust = glm::vec3(0.0f, 0.0f, 0.0f); + _rotation = glm::quat(0.0f, 0.0f, 0.0f, 0.0f); _bodyYaw = -90.0; _bodyPitch = 0.0; _bodyRoll = 0.0; @@ -91,12 +91,12 @@ Avatar::Avatar(bool isMine) { _transmitterHz = 0.0; _transmitterPackets = 0; _transmitterIsFirstData = true; - _transmitterInitialReading = glm::vec3( 0.f, 0.f, 0.f ); + _transmitterInitialReading = glm::vec3(0.f, 0.f, 0.f); _speed = 0.0; _pelvisStandingHeight = 0.0f; _displayingHead = true; _TEST_bigSphereRadius = 0.4f; - _TEST_bigSpherePosition = glm::vec3( 5.0f, _TEST_bigSphereRadius, 5.0f ); + _TEST_bigSpherePosition = glm::vec3(5.0f, _TEST_bigSphereRadius, 5.0f); for (int i = 0; i < MAX_DRIVE_KEYS; i++) _driveKeys[i] = false; @@ -137,13 +137,13 @@ Avatar::Avatar(bool isMine) { _head.browAudioLift = 0.0; _head.noise = 0; _head.returnSpringScale = 1.0; - _movedHandOffset = glm::vec3( 0.0, 0.0, 0.0 ); + _movedHandOffset = glm::vec3(0.0f, 0.0f, 0.0f); _usingBodySprings = true; _renderYaw = 0.0; _renderPitch = 0.0; _sphere = NULL; _interactingOther = NULL; - _handHoldingPosition = glm::vec3( 0.0, 0.0, 0.0 ); + _handHoldingPosition = glm::vec3(0.0f, 0.0f, 0.0f); _distanceToNearestAvatar = std::numeric_limits::max(); initializeSkeleton(); @@ -188,7 +188,7 @@ Avatar::Avatar(const Avatar &otherAvatar) { _movedHandOffset = otherAvatar._movedHandOffset; _usingBodySprings = otherAvatar._usingBodySprings; - _orientation.set( otherAvatar._orientation ); + _orientation.set(otherAvatar._orientation); _sphere = NULL; @@ -319,7 +319,7 @@ void Avatar::setLeanSideways(float dist){ _head.leanSideways = dist; } -void Avatar::setMousePressed( bool d ) { +void Avatar::setMousePressed(bool d) { _mousePressed = d; } @@ -343,27 +343,27 @@ void Avatar::simulate(float deltaTime) { // apply gravity and collision wiht the ground/floor - if ( AVATAR_GRAVITY ) { - if ( _position.y > _pelvisStandingHeight + 0.01 ) { - _velocity += glm::dvec3(getGravity(getPosition())) * ( 6.0 * deltaTime ); - } else if ( _position.y < _pelvisStandingHeight ) { + if (AVATAR_GRAVITY) { + if ( _position.y > _pelvisStandingHeight + 0.01f) { + _velocity += glm::dvec3(getGravity(getPosition())) * (6.0 * deltaTime ); + } else if (_position.y < _pelvisStandingHeight) { _position.y = _pelvisStandingHeight; _velocity.y = 0.0; } } // update body springs - updateBodySprings( deltaTime ); + updateBodySprings(deltaTime); // test for avatar collision response with the big sphere if (usingBigSphereCollisionTest) { - updateCollisionWithSphere( _TEST_bigSpherePosition, _TEST_bigSphereRadius, deltaTime ); + updateCollisionWithSphere(_TEST_bigSpherePosition, _TEST_bigSphereRadius, deltaTime); } // driving the avatar around should only apply if this is my avatar (as opposed to an avatar being driven remotely) - if ( _isMine ) { + if (_isMine) { - _thrust = glm::vec3( 0.0, 0.0, 0.0 ); + _thrust = glm::vec3(0.0f, 0.0f, 0.0f); if (_driveKeys[FWD ]) {_thrust += THRUST_MAG * deltaTime * _orientation.getFront();} if (_driveKeys[BACK ]) {_thrust -= THRUST_MAG * deltaTime * _orientation.getFront();} @@ -766,19 +766,6 @@ static TextRenderer* textRenderer() { } -struct TriangleArray -{ - float v0x,v0y,v0z; // x,y,z coordinate of vertex 0 - float r0,g0,b0,a0; // r,g,b color of vertex 0 - - float v1x,v1y,v1z; // x,y,z coordinate of vertex 1 - float r1,g1,b1,a1; // r,g,b color of vertex 1 - - float v2x,v2y,v2z; // x,y,z coordinate of vertex 2 - float r2,g2,b2,a2; // r,g,b color of vertex 2 -}; - - void Avatar::render(bool lookingInMirror) { // render a simple round on the ground projected down from the avatar's position diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 91fd33fb66..d41d4ce9c4 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -69,7 +69,6 @@ #include "Camera.h" #include "Avatar.h" -#include "AvatarRenderer.h" #include "Texture.h" #include #include @@ -120,9 +119,6 @@ Avatar myAvatar(true); // The rendered avatar of oneself Camera myCamera; // My view onto the world (sometimes on myself :) Camera viewFrustumOffsetCamera; // The camera we use to sometimes show the view frustum from an offset mode - -AvatarRenderer avatarRenderer; - // Starfield information char starFile[] = "https://s3-us-west-1.amazonaws.com/highfidelity/stars.txt"; char starCacheFile[] = "cachedStars.txt"; @@ -720,7 +716,6 @@ void displaySide(Camera& whichCamera) { if (agent->getLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) { Avatar *avatar = (Avatar *)agent->getLinkedData(); avatar->render(0); - avatarRenderer.render(avatar, 0); // this will replace the above call } } agentList->unlock(); @@ -733,7 +728,6 @@ void displaySide(Camera& whichCamera) { //Render my own avatar myAvatar.render(::lookingInMirror); - avatarRenderer.render(&myAvatar, lookingInMirror); // this will replace the above call glPopMatrix(); } From fcf37352d407fdae1e07a3e005cf6a2455b059e2 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Mon, 6 May 2013 11:32:04 -0700 Subject: [PATCH 09/21] thingy --- CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9af86e2891..9fe77c7f74 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,5 +10,4 @@ add_subdirectory(interface) add_subdirectory(injector) add_subdirectory(pairing-server) add_subdirectory(space-server) -add_subdirectory(voxel-server) -add_subdirectory(voxel-edit) \ No newline at end of file +add_subdirectory(voxel-edit)add_subdirectory(voxel-server) \ No newline at end of file From 7c04244f534a238f5a5145068f10ba9dc018e80c Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 6 May 2013 12:01:39 -0700 Subject: [PATCH 10/21] add missing newline to root CMakeLists --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9fe77c7f74..14692ef3f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,4 +10,5 @@ add_subdirectory(interface) add_subdirectory(injector) add_subdirectory(pairing-server) add_subdirectory(space-server) -add_subdirectory(voxel-edit)add_subdirectory(voxel-server) \ No newline at end of file +add_subdirectory(voxel-edit) +add_subdirectory(voxel-server) \ No newline at end of file From 2a1bbcc1683a2b11f71ba10b004d424d5ef378d3 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Mon, 6 May 2013 12:35:52 -0700 Subject: [PATCH 11/21] improved avatar gravity code and moved source of gravity vector to main.cpp --- interface/src/Avatar.cpp | 181 ++++++++++++++++++--------------------- interface/src/Avatar.h | 7 +- interface/src/main.cpp | 27 ++++++ 3 files changed, 115 insertions(+), 100 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 3e4a8430e7..a1a93fbfe3 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -21,7 +21,9 @@ using namespace std; 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 THRUST_MAG = 1200.0; const float YAW_MAG = 500.0; @@ -145,6 +147,7 @@ Avatar::Avatar(bool isMine) { _interactingOther = NULL; _handHoldingPosition = glm::vec3(0.0f, 0.0f, 0.0f); _distanceToNearestAvatar = std::numeric_limits::max(); + _gravity = glm::vec3(0.0f, -1.0f, 0.0f); // default initializeSkeleton(); @@ -336,13 +339,13 @@ void Avatar::simulate(float deltaTime) { updateHandMovementAndTouching(deltaTime); - // apply gravity and collision wiht the ground/floor - if (AVATAR_GRAVITY) { - if ( _position.y > _pelvisStandingHeight + 0.01f) { - _velocity += glm::dvec3(getGravity(getPosition())) * (6.0 * deltaTime ); + // apply gravity and collision with the ground/floor + if (USING_AVATAR_GRAVITY) { + if (_position.y > _pelvisStandingHeight + 0.01f) { + _velocity += _gravity * (GRAVITY_SCALE * deltaTime); } else if (_position.y < _pelvisStandingHeight) { _position.y = _pelvisStandingHeight; - _velocity.y = 0.0; + _velocity.y = -_velocity.y * BOUNCE; } } @@ -387,16 +390,16 @@ void Avatar::simulate(float deltaTime) { _velocity += _thrust * deltaTime; // calculate speed - _speed = glm::length( _velocity ); + _speed = glm::length(_velocity); //pitch and roll the body as a function of forward speed and turning delta - float forwardComponentOfVelocity = glm::dot( _orientation.getFront(), _velocity ); + float forwardComponentOfVelocity = glm::dot(_orientation.getFront(), _velocity); _bodyPitch += BODY_PITCH_WHILE_WALKING * deltaTime * forwardComponentOfVelocity; _bodyRoll += BODY_ROLL_WHILE_TURNING * deltaTime * _speed * _bodyYawDelta; // these forces keep the body upright... float tiltDecay = 1.0 - BODY_UPRIGHT_FORCE * deltaTime; - if ( tiltDecay < 0.0f ) { tiltDecay = 0.0f; } + if (tiltDecay < 0.0f) {tiltDecay = 0.0f;} _bodyPitch *= tiltDecay; _bodyRoll *= tiltDecay; @@ -404,7 +407,7 @@ void Avatar::simulate(float deltaTime) { _position += _velocity * deltaTime; // decay velocity - _velocity *= ( 1.0 - LIN_VEL_DECAY * deltaTime ); + _velocity *= (1.0 - LIN_VEL_DECAY * deltaTime); // If someone is near, damp velocity as a function of closeness const float AVATAR_BRAKING_RANGE = 1.2f; @@ -419,7 +422,7 @@ void Avatar::simulate(float deltaTime) { updateHead(deltaTime); // use speed and angular velocity to determine walking vs. standing - if ( _speed + fabs( _bodyYawDelta ) > 0.2 ) { + if (_speed + fabs(_bodyYawDelta) > 0.2) { _mode = AVATAR_MODE_WALKING; } else { _mode = AVATAR_MODE_INTERACTING; @@ -449,7 +452,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { // if the avatar being simulated is mine, then loop through // all the other avatars for potential interactions... - if ( _isMine ) + if (_isMine) { // Reset detector for nearest avatar _distanceToNearestAvatar = std::numeric_limits::max(); @@ -463,24 +466,24 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { updateCollisionWithOtherAvatar(otherAvatar, deltaTime ); // test other avatar hand position for proximity - glm::vec3 v( _joint[ AVATAR_JOINT_RIGHT_SHOULDER ].position ); - v -= otherAvatar->getJointPosition( AVATAR_JOINT_RIGHT_SHOULDER ); + glm::vec3 v(_joint[ AVATAR_JOINT_RIGHT_SHOULDER ].position); + v -= otherAvatar->getJointPosition(AVATAR_JOINT_RIGHT_SHOULDER); - float distance = glm::length( v ); - if (distance < _distanceToNearestAvatar) { _distanceToNearestAvatar = distance; } + float distance = glm::length(v); + if (distance < _distanceToNearestAvatar) {_distanceToNearestAvatar = distance;} if (distance < _maxArmLength + _maxArmLength) { _interactingOther = otherAvatar; - if ( ! _avatarTouch.getAbleToReachOtherAvatar() ) { + if (! _avatarTouch.getAbleToReachOtherAvatar()) { //initialize _handHolding _handHoldingPosition = _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position; _avatarTouch.setAbleToReachOtherAvatar(true); } - glm::vec3 vectorBetweenHands( _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position ); - vectorBetweenHands -= otherAvatar->getJointPosition( AVATAR_JOINT_RIGHT_FINGERTIPS ); + glm::vec3 vectorBetweenHands(_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position); + vectorBetweenHands -= otherAvatar->getJointPosition(AVATAR_JOINT_RIGHT_FINGERTIPS); float distanceBetweenHands = glm::length(vectorBetweenHands); if (distanceBetweenHands < HANDS_CLOSE_ENOUGH_TO_GRASP) { @@ -488,7 +491,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { } // if I am holding hands with another avatar, a force is applied - if (( _handState == 1 ) || ( _interactingOther->_handState == 1 )) { + if ((_handState == 1) || (_interactingOther->_handState == 1)) { // if the hands are close enough to grasp... if (distanceBetweenHands < HANDS_CLOSE_ENOUGH_TO_GRASP) @@ -502,7 +505,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position = _handHoldingPosition; // apply a force to the avatar body - if ( glm::length(vectorToOtherHand) > _maxArmLength * 0.9 ) { + if (glm::length(vectorToOtherHand) > _maxArmLength * 0.9) { _velocity += vectorToOtherHand; } } @@ -514,18 +517,18 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { // Set the vector we send for hand position to other people to be our right hand setHandPosition(_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position); - }//if ( _isMine ) + }//if (_isMine) //constrain right arm length and re-adjust elbow position as it bends - updateArmIKAndConstraints( deltaTime ); + updateArmIKAndConstraints(deltaTime); // set hand positions for _avatarTouch.setMyHandPosition AFTER calling updateArmIKAndConstraints - if ( _interactingOther ) { + if (_interactingOther) { if (_isMine) { - _avatarTouch.setMyHandPosition ( _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position ); - _avatarTouch.setYourHandPosition( _interactingOther->_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position ); - _avatarTouch.setMyHandState ( _handState ); - _avatarTouch.setYourHandState ( _interactingOther->_handState ); + _avatarTouch.setMyHandPosition (_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position); + _avatarTouch.setYourHandPosition(_interactingOther->_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position); + _avatarTouch.setMyHandState (_handState); + _avatarTouch.setYourHandState (_interactingOther->_handState); _avatarTouch.simulate(deltaTime); } } @@ -539,7 +542,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { void Avatar::updateHead(float deltaTime) { //apply the head lean values to the springy position... - if ( fabs( _head.leanSideways + _head.leanForward ) > 0.0f ) { + if (fabs( _head.leanSideways + _head.leanForward ) > 0.0f) { glm::vec3 headLean = _orientation.getRight() * _head.leanSideways + _orientation.getFront() * _head.leanForward; @@ -650,19 +653,19 @@ float Avatar::getHeight() { } -void Avatar::updateCollisionWithSphere( glm::vec3 position, float radius, float deltaTime ) { +void Avatar::updateCollisionWithSphere(glm::vec3 position, float radius, float deltaTime) { float myBodyApproximateBoundingRadius = 1.0f; glm::vec3 vectorFromMyBodyToBigSphere(_position - position); bool jointCollision = false; float distanceToBigSphere = glm::length(vectorFromMyBodyToBigSphere); - if ( distanceToBigSphere < myBodyApproximateBoundingRadius + radius ) { + if (distanceToBigSphere < myBodyApproximateBoundingRadius + radius) { for (int b = 0; b < NUM_AVATAR_JOINTS; b++) { glm::vec3 vectorFromJointToBigSphereCenter(_joint[b].springyPosition - position); float distanceToBigSphereCenter = glm::length(vectorFromJointToBigSphereCenter); float combinedRadius = _joint[b].radius + radius; - if ( distanceToBigSphereCenter < combinedRadius ) { + if (distanceToBigSphereCenter < combinedRadius) { jointCollision = true; if (distanceToBigSphereCenter > 0.0) { glm::vec3 directionVector = vectorFromJointToBigSphereCenter / distanceToBigSphereCenter; @@ -677,7 +680,7 @@ void Avatar::updateCollisionWithSphere( glm::vec3 position, float radius, float } } - if ( jointCollision ) { + if (jointCollision) { if (!_usingBodySprings) { _usingBodySprings = true; initializeBodySprings(); @@ -688,37 +691,37 @@ void Avatar::updateCollisionWithSphere( glm::vec3 position, float radius, float //detect collisions with other avatars and respond -void Avatar::updateCollisionWithOtherAvatar( Avatar * otherAvatar, float deltaTime ) { +void Avatar::updateCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime) { // check if the bounding spheres of the two avatars are colliding glm::vec3 vectorBetweenBoundingSpheres(_position - otherAvatar->_position); - 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; - 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 for (int b=1; b_joint[o].isCollidable ) { + if (otherAvatar->_joint[o].isCollidable) { glm::vec3 vectorBetweenJoints(_joint[b].springyPosition - otherAvatar->_joint[o].springyPosition); float distanceBetweenJoints = glm::length(vectorBetweenJoints); - if ( distanceBetweenJoints > 0.0 ) { // to avoid divide by zero + if (distanceBetweenJoints > 0.0 ) { // to avoid divide by zero float combinedRadius = _joint[b].radius + otherAvatar->_joint[o].radius; // check for collision - if ( distanceBetweenJoints < combinedRadius * COLLISION_RADIUS_SCALAR) { + if (distanceBetweenJoints < combinedRadius * COLLISION_RADIUS_SCALAR) { glm::vec3 directionVector = vectorBetweenJoints / distanceBetweenJoints; // push balls away from each other and apply friction glm::vec3 ballPushForce = directionVector * COLLISION_BALL_FORCE * deltaTime; float ballMomentum = 1.0 - COLLISION_BALL_FRICTION * deltaTime; - if ( ballMomentum < 0.0 ) { ballMomentum = 0.0;} + if (ballMomentum < 0.0 ) { ballMomentum = 0.0;} _joint[b].springyVelocity += ballPushForce; otherAvatar->_joint[o].springyVelocity -= ballPushForce; @@ -729,7 +732,7 @@ void Avatar::updateCollisionWithOtherAvatar( Avatar * otherAvatar, float deltaTi // accumulate forces and frictions to apply to the velocities of avatar bodies bodyPushForce += directionVector * COLLISION_BODY_FORCE * deltaTime; bodyMomentum -= COLLISION_BODY_FRICTION * deltaTime; - if ( bodyMomentum < 0.0 ) { bodyMomentum = 0.0;} + if (bodyMomentum < 0.0 ) { bodyMomentum = 0.0;} }// check for collision } // to avoid divide by zero @@ -749,7 +752,7 @@ void Avatar::updateCollisionWithOtherAvatar( Avatar * otherAvatar, float deltaTi } //method -void Avatar::setDisplayingHead( bool displayingHead ) { +void Avatar::setDisplayingHead(bool displayingHead ) { _displayingHead = displayingHead; } @@ -760,28 +763,33 @@ static TextRenderer* textRenderer() { } +void Avatar::setGravity(glm::vec3 gravity) { + _gravity = gravity; +} + + void Avatar::render(bool lookingInMirror) { // render a simple round on the ground projected down from the avatar's position - renderDiskShadow( _position, glm::vec3( 0.0f, 1.0f, 0.0f ), 0.1f, 0.2f ); + renderDiskShadow(_position, glm::vec3(0.0f, 1.0f, 0.0f ), 0.1f, 0.2f ); /* // show avatar position - glColor4f( 0.5f, 0.5f, 0.5f, 0.6 ); + glColor4f(0.5f, 0.5f, 0.5f, 0.6 ); glPushMatrix(); glTranslatef(_position.x, _position.y, _position.z); - glScalef( 0.03, 0.03, 0.03 ); - glutSolidSphere( 1, 10, 10 ); + glScalef(0.03, 0.03, 0.03 ); + glutSolidSphere(1, 10, 10 ); glPopMatrix(); */ - if ( usingBigSphereCollisionTest ) { + if (usingBigSphereCollisionTest ) { // show TEST big sphere - glColor4f( 0.5f, 0.6f, 0.8f, 0.7 ); + glColor4f(0.5f, 0.6f, 0.8f, 0.7 ); glPushMatrix(); glTranslatef(_TEST_bigSpherePosition.x, _TEST_bigSpherePosition.y, _TEST_bigSpherePosition.z); - glScalef( _TEST_bigSphereRadius, _TEST_bigSphereRadius, _TEST_bigSphereRadius ); - glutSolidSphere( 1, 20, 20 ); + glScalef(_TEST_bigSphereRadius, _TEST_bigSphereRadius, _TEST_bigSphereRadius ); + glutSolidSphere(1, 20, 20 ); glPopMatrix(); } @@ -794,7 +802,7 @@ void Avatar::render(bool lookingInMirror) { } // if this is my avatar, then render my interactions with the other avatar - if ( _isMine ) { + if (_isMine ) { _avatarTouch.render(); } @@ -855,7 +863,7 @@ void Avatar::renderHead(bool lookingInMirror) { glEnable(GL_RESCALE_NORMAL); // show head orientation - //renderOrientationDirections( _joint[ AVATAR_JOINT_HEAD_BASE ].springyPosition, _joint[ AVATAR_JOINT_HEAD_BASE ].orientation, 0.2f ); + //renderOrientationDirections(_joint[ AVATAR_JOINT_HEAD_BASE ].springyPosition, _joint[ AVATAR_JOINT_HEAD_BASE ].orientation, 0.2f ); glPushMatrix(); @@ -871,7 +879,7 @@ void Avatar::renderHead(bool lookingInMirror) { } glScalef - ( + ( _joint[ AVATAR_JOINT_HEAD_BASE ].radius, _joint[ AVATAR_JOINT_HEAD_BASE ].radius, _joint[ AVATAR_JOINT_HEAD_BASE ].radius @@ -883,15 +891,15 @@ void Avatar::renderHead(bool lookingInMirror) { //glRotatef(_bodyPitch + _headPitch, 1, 0, 0); //glRotatef(_bodyRoll - _headRoll, 0, 0, 1); // don't let body pitch and roll affect the head.. - glRotatef( _headPitch, 1, 0, 0); - glRotatef( -_headRoll, 0, 0, 1); + glRotatef( _headPitch, 1, 0, 0); + glRotatef(-_headRoll, 0, 0, 1); } else { glRotatef(_bodyYaw + _headYaw, 0, 1, 0); //glRotatef(_bodyPitch + _headPitch, 1, 0, 0); //glRotatef(_bodyRoll + _headRoll, 0, 0, 1); // don't let body pitch and roll affect the head.. - glRotatef( _headPitch, 1, 0, 0); - glRotatef( _headRoll, 0, 0, 1); + glRotatef(_headPitch, 1, 0, 0); + glRotatef(_headRoll, 0, 0, 1); } //glScalef(2.0, 2.0, 2.0); @@ -1020,7 +1028,7 @@ void Avatar::renderHead(bool lookingInMirror) { glPopMatrix(); } -void Avatar::setHandMovementValues( glm::vec3 handOffset ) { +void Avatar::setHandMovementValues(glm::vec3 handOffset ) { _movedHandOffset = handOffset; } @@ -1033,11 +1041,11 @@ void Avatar::initializeSkeleton() { for (int b=0; b 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"; diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index d2570d1976..6fb8ee01ee 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -84,7 +84,7 @@ public: void reset(); void UpdateGyros(float frametime, SerialInterface * serialInterface, glm::vec3 * gravity); - void setNoise (float mag) { _head.noise = mag; } + void setNoise (float mag) {_head.noise = mag;} void setScale(float s) {_head.scale = s; }; void setRenderYaw(float y) {_renderYaw = y;} void setRenderPitch(float p) {_renderPitch = p;} @@ -93,6 +93,7 @@ public: float getLastMeasuredHeadYaw() const {return _head.yawRate;} float getBodyYaw() {return _bodyYaw;}; void addBodyYaw(float y) {_bodyYaw += y;}; + void setGravity(glm::vec3 gravity); bool getIsNearInteractingOther(); @@ -143,9 +144,6 @@ public: 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); - void writeAvatarDataToFile(); void readAvatarDataFromFile(); @@ -251,6 +249,7 @@ private: bool _displayingHead; // should be false if in first-person view bool _returnHeadToCenter; float _distanceToNearestAvatar; // How close is the nearest avatar? + glm::vec3 _gravity; // private methods... void initializeSkeleton(); diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 13654da2d0..8916fcd319 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -90,6 +90,8 @@ using namespace std; void reshape(int width, int height); // 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; bool enableNetworkThread = true; @@ -1703,6 +1705,7 @@ void idle(void) { } agentList->unlock(); + myAvatar.setGravity(getGravity(myAvatar.getPosition())); myAvatar.simulate(deltaTime); glutPostRedisplay(); @@ -1765,6 +1768,30 @@ void reshape(int width, int height) { 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) { if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN ) { if (state == GLUT_DOWN && !menu.mouseClick(x, y)) { From beca9cac8d80318f604784b4f7f7141a868efc69 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 6 May 2013 12:40:52 -0700 Subject: [PATCH 12/21] update timestamp variables in Agent, use new packet headers for DS --- domain-server/src/main.cpp | 42 +++++++++++++--------------- libraries/shared/src/Agent.cpp | 28 ++++--------------- libraries/shared/src/Agent.h | 12 ++++---- libraries/shared/src/AgentList.cpp | 30 ++++++++++---------- libraries/shared/src/PacketHeaders.h | 3 ++ 5 files changed, 51 insertions(+), 64 deletions(-) diff --git a/domain-server/src/main.cpp b/domain-server/src/main.cpp index 8c862fa934..3510ca02c0 100644 --- a/domain-server/src/main.cpp +++ b/domain-server/src/main.cpp @@ -45,8 +45,6 @@ unsigned char packetData[MAX_PACKET_SIZE]; const int LOGOFF_CHECK_INTERVAL = 5000; -#define DEBUG_TO_SELF 0 - int lastActiveCount = 0; unsigned char* addAgentToBroadcastPacket(unsigned char* currentPosition, Agent* agentToAdd) { @@ -81,13 +79,13 @@ int main(int argc, const char * argv[]) setvbuf(stdout, NULL, _IOLBF, 0); ssize_t receivedBytes = 0; - char agentType; + char agentType = '\0'; - unsigned char *broadcastPacket = new unsigned char[MAX_PACKET_SIZE]; - *broadcastPacket = PACKET_HEADER_DOMAIN; + unsigned char broadcastPacket[MAX_PACKET_SIZE]; + broadcastPacket[0] = PACKET_HEADER_DOMAIN; - unsigned char *currentBufferPos; - unsigned char *startPointer; + unsigned char* currentBufferPos; + unsigned char* startPointer; int packetBytesWithoutLeadingChar; sockaddr_in agentPublicAddress, agentLocalAddress; @@ -101,8 +99,8 @@ int main(int argc, const char * argv[]) if (agentList->getAgentSocket().receive((sockaddr *)&agentPublicAddress, packetData, &receivedBytes)) { std::map newestSoloAgents; - agentType = packetData[0]; - unpackSocket(&packetData[1], (sockaddr *)&agentLocalAddress); + agentType = packetData[1]; + unpackSocket(&packetData[2], (sockaddr *)&agentLocalAddress); // check the agent public address // if it matches our local address we're on the same box @@ -115,21 +113,21 @@ int main(int argc, const char * argv[]) } } - if (agentList->addOrUpdateAgent((sockaddr *)&agentPublicAddress, - (sockaddr *)&agentLocalAddress, + if (agentList->addOrUpdateAgent((sockaddr*) &agentPublicAddress, + (sockaddr*) &agentLocalAddress, agentType, agentList->getLastAgentId())) { - agentList->increaseAgentId(); - + } else if (packetData[0] == PACKET_HEADER_DOMAIN_RFD) { + // if this is a previous agent, and they are re-reporting for duty + // then we need to update the first receive time } currentBufferPos = broadcastPacket + 1; startPointer = currentBufferPos; for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { - if (DEBUG_TO_SELF || - !agent->matches((sockaddr *)&agentPublicAddress, (sockaddr *)&agentLocalAddress, agentType)) { + if (!agent->matches((sockaddr*) &agentPublicAddress, (sockaddr*) &agentLocalAddress, agentType)) { if (memchr(SOLO_AGENT_TYPES, agent->getType(), sizeof(SOLO_AGENT_TYPES)) == NULL) { // this is an agent of which there can be multiple, just add them to the packet // don't send avatar agents to other avatars, that will come from avatar mixer @@ -140,26 +138,26 @@ int main(int argc, const char * argv[]) } else { // solo agent, we need to only send newest if (newestSoloAgents[agent->getType()] == NULL || - newestSoloAgents[agent->getType()]->getFirstRecvTimeUsecs() < agent->getFirstRecvTimeUsecs()) { + newestSoloAgents[agent->getType()]->getWakeMicrostamp() < agent->getWakeMicrostamp()) { // we have to set the newer solo agent to add it to the broadcast later newestSoloAgents[agent->getType()] = &(*agent); } } } else { // this is the agent, just update last receive to now - agent->setLastRecvTimeUsecs(usecTimestampNow()); + agent->setLastHeardMicrostamp(usecTimestampNow()); } } - for (std::map::iterator agentIterator = newestSoloAgents.begin(); - agentIterator != newestSoloAgents.end(); - agentIterator++) { + for (std::map::iterator soloAgent = newestSoloAgents.begin(); + soloAgent != newestSoloAgents.end(); + soloAgent++) { // this is the newest alive solo agent, add them to the packet - currentBufferPos = addAgentToBroadcastPacket(currentBufferPos, agentIterator->second); + currentBufferPos = addAgentToBroadcastPacket(currentBufferPos, soloAgent->second); } if ((packetBytesWithoutLeadingChar = (currentBufferPos - startPointer))) { - agentList->getAgentSocket().send((sockaddr *)&agentPublicAddress, + agentList->getAgentSocket().send((sockaddr*) &agentPublicAddress, broadcastPacket, packetBytesWithoutLeadingChar + 1); } diff --git a/libraries/shared/src/Agent.cpp b/libraries/shared/src/Agent.cpp index cd694ccf78..125063e9ec 100644 --- a/libraries/shared/src/Agent.cpp +++ b/libraries/shared/src/Agent.cpp @@ -52,8 +52,8 @@ Agent::Agent(sockaddr *agentPublicSocket, sockaddr *agentLocalSocket, char agent type = agentType; agentId = thisAgentId; - firstRecvTimeUsecs = usecTimestampNow(); - lastRecvTimeUsecs = usecTimestampNow(); + _wakeMicrostamp = usecTimestampNow(); + _lastHeardMicrostamp = usecTimestampNow(); activeSocket = NULL; linkedData = NULL; @@ -87,8 +87,8 @@ Agent::Agent(const Agent &otherAgent) { activeSocket = NULL; } - firstRecvTimeUsecs = otherAgent.firstRecvTimeUsecs; - lastRecvTimeUsecs = otherAgent.lastRecvTimeUsecs; + _wakeMicrostamp = otherAgent._wakeMicrostamp; + _lastHeardMicrostamp = otherAgent._lastHeardMicrostamp; type = otherAgent.type; if (otherAgent.linkedData != NULL) { @@ -120,8 +120,8 @@ void Agent::swap(Agent &first, Agent &second) { swap(first.type, second.type); swap(first.linkedData, second.linkedData); swap(first.agentId, second.agentId); - swap(first.firstRecvTimeUsecs, second.firstRecvTimeUsecs); - swap(first.lastRecvTimeUsecs, second.lastRecvTimeUsecs); + swap(first._wakeMicrostamp, second._wakeMicrostamp); + swap(first._lastHeardMicrostamp, second._lastHeardMicrostamp); swap(first._bytesReceivedMovingAverage, second._bytesReceivedMovingAverage); } @@ -178,22 +178,6 @@ void Agent::setAgentId(uint16_t thisAgentId) { agentId = thisAgentId; } -double Agent::getFirstRecvTimeUsecs() { - return firstRecvTimeUsecs; -} - -void Agent::setFirstRecvTimeUsecs(double newTimeUsecs) { - firstRecvTimeUsecs = newTimeUsecs; -} - -double Agent::getLastRecvTimeUsecs() { - return lastRecvTimeUsecs; -} - -void Agent::setLastRecvTimeUsecs(double newTimeUsecs) { - lastRecvTimeUsecs = newTimeUsecs; -} - sockaddr* Agent::getPublicSocket() { return publicSocket; } diff --git a/libraries/shared/src/Agent.h b/libraries/shared/src/Agent.h index 1b8fadfdd8..b611770593 100644 --- a/libraries/shared/src/Agent.h +++ b/libraries/shared/src/Agent.h @@ -38,11 +38,11 @@ public: uint16_t getAgentId(); void setAgentId(uint16_t thisAgentId); - double getFirstRecvTimeUsecs(); - void setFirstRecvTimeUsecs(double newTimeUsecs); + double getWakeMicrostamp() const { return _wakeMicrostamp; } + void setWakeMicrostamp(double wakeMicrostamp) { _wakeMicrostamp = wakeMicrostamp; } - double getLastRecvTimeUsecs(); - void setLastRecvTimeUsecs(double newTimeUsecs); + double getLastHeardMicrostamp() const { return _lastHeardMicrostamp; } + void setLastHeardMicrostamp(double lastHeardMicrostamp) { _lastHeardMicrostamp = lastHeardMicrostamp; } sockaddr* getPublicSocket(); void setPublicSocket(sockaddr *newSocket); @@ -70,8 +70,8 @@ private: sockaddr *publicSocket, *localSocket, *activeSocket; char type; uint16_t agentId; - double firstRecvTimeUsecs; - double lastRecvTimeUsecs; + double _wakeMicrostamp; + double _lastHeardMicrostamp; SimpleMovingAverage* _bytesReceivedMovingAverage; AgentData* linkedData; bool _isAlive; diff --git a/libraries/shared/src/AgentList.cpp b/libraries/shared/src/AgentList.cpp index ce312d5eb2..cc9b7b06ed 100644 --- a/libraries/shared/src/AgentList.cpp +++ b/libraries/shared/src/AgentList.cpp @@ -114,7 +114,7 @@ void AgentList::processBulkAgentData(sockaddr *senderAddress, unsigned char *pac Agent* bulkSendAgent = agentWithAddress(senderAddress); if (bulkSendAgent) { - bulkSendAgent->setLastRecvTimeUsecs(usecTimestampNow()); + bulkSendAgent->setLastHeardMicrostamp(usecTimestampNow()); bulkSendAgent->recordBytesReceived(numTotalBytes); } @@ -161,7 +161,7 @@ int AgentList::updateAgentWithData(sockaddr *senderAddress, unsigned char *packe } int AgentList::updateAgentWithData(Agent *agent, unsigned char *packetData, int dataBytes) { - agent->setLastRecvTimeUsecs(usecTimestampNow()); + agent->setLastHeardMicrostamp(usecTimestampNow()); if (agent->getActiveSocket() != NULL) { agent->recordBytesReceived(dataBytes); @@ -273,7 +273,7 @@ bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket, if (agent->getType() == AGENT_TYPE_AUDIO_MIXER || agent->getType() == AGENT_TYPE_VOXEL) { // until the Audio class also uses our agentList, we need to update // the lastRecvTimeUsecs for the audio mixer so it doesn't get killed and re-added continously - agent->setLastRecvTimeUsecs(usecTimestampNow()); + agent->setLastHeardMicrostamp(usecTimestampNow()); } // we had this agent already, do nothing for now @@ -383,7 +383,7 @@ void *removeSilentAgents(void *args) { for(AgentList::iterator agent = agentList->begin(); agent != agentList->end(); ++agent) { - if ((checkTimeUSecs - agent->getLastRecvTimeUsecs()) > AGENT_SILENCE_THRESHOLD_USECS + if ((checkTimeUSecs - agent->getLastHeardMicrostamp()) > AGENT_SILENCE_THRESHOLD_USECS && agent->getType() != AGENT_TYPE_VOXEL) { printLog("Killing agent - "); @@ -418,13 +418,6 @@ void *checkInWithDomainServer(void *args) { const int DOMAIN_SERVER_CHECK_IN_USECS = 1 * 1000000; - AgentList* parentAgentList = (AgentList*) args; - - timeval lastSend; - unsigned char output[7]; - - in_addr_t localAddress = getLocalAddress(); - // Lookup the IP address of the domain server if we need to if (atoi(DOMAIN_IP) == 0) { struct hostent* pHostInfo; @@ -439,14 +432,23 @@ void *checkInWithDomainServer(void *args) { } } else printLog("Using static domainserver IP: %s\n", DOMAIN_IP); + AgentList* parentAgentList = (AgentList*) args; + + timeval lastSend; + in_addr_t localAddress = getLocalAddress(); + unsigned char packet[8]; + + packet[0] = PACKET_HEADER_DOMAIN_RFD; + packet[1] = parentAgentList->getOwnerType(); while (!domainServerCheckinStopFlag) { gettimeofday(&lastSend, NULL); - output[0] = parentAgentList->getOwnerType(); - packSocket(output + 1, localAddress, htons(parentAgentList->getSocketListenPort())); + packSocket(packet + 2, localAddress, htons(parentAgentList->getSocketListenPort())); - parentAgentList->getAgentSocket().send(DOMAIN_IP, DOMAINSERVER_PORT, output, 7); + parentAgentList->getAgentSocket().send(DOMAIN_IP, DOMAINSERVER_PORT, packet, sizeof(packet)); + + packet[0] = PACKET_HEADER_DOMAIN_LIST_REQUEST; double usecToSleep = DOMAIN_SERVER_CHECK_IN_USECS - (usecTimestampNow() - usecTimestamp(&lastSend)); diff --git a/libraries/shared/src/PacketHeaders.h b/libraries/shared/src/PacketHeaders.h index ed2e5d5638..1ceb3fcc5a 100644 --- a/libraries/shared/src/PacketHeaders.h +++ b/libraries/shared/src/PacketHeaders.h @@ -1,3 +1,4 @@ + // // PacketHeaders.h // hifi @@ -23,5 +24,7 @@ const char PACKET_HEADER_ERASE_VOXEL = 'E'; const char PACKET_HEADER_VOXEL_DATA = 'V'; const char PACKET_HEADER_BULK_AVATAR_DATA = 'X'; const char PACKET_HEADER_TRANSMITTER_DATA = 't'; +const char PACKET_HEADER_DOMAIN_LIST_REQUEST = 'L'; +const char PACKET_HEADER_DOMAIN_RFD = 'C'; #endif From 9e5f446ba28c58216074c85111a53c7fa2700ed7 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 6 May 2013 12:51:43 -0700 Subject: [PATCH 13/21] update wake microstamp when receiving an RFD from an agent already in list --- domain-server/src/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/domain-server/src/main.cpp b/domain-server/src/main.cpp index 3510ca02c0..b7e43f48bb 100644 --- a/domain-server/src/main.cpp +++ b/domain-server/src/main.cpp @@ -121,9 +121,11 @@ int main(int argc, const char * argv[]) } else if (packetData[0] == PACKET_HEADER_DOMAIN_RFD) { // if this is a previous agent, and they are re-reporting for duty // then we need to update the first receive time + Agent *refreshedAgent = agentList->agentWithAddress((sockaddr*) &agentLocalAddress); + refreshedAgent->setWakeMicrostamp(usecTimestampNow()); } - currentBufferPos = broadcastPacket + 1; + currentBufferPos = broadcastPacket + 2; startPointer = currentBufferPos; for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { From f3a9dcf7776104a982aa2a2c2376b312f8b00681 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 6 May 2013 13:08:45 -0700 Subject: [PATCH 14/21] if we fail to open SerialInterface twice then don't keep trying --- interface/src/SerialInterface.cpp | 40 +++++++++++++++++++------------ interface/src/SerialInterface.h | 5 ++-- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/interface/src/SerialInterface.cpp b/interface/src/SerialInterface.cpp index 5878ab672e..2efe487304 100644 --- a/interface/src/SerialInterface.cpp +++ b/interface/src/SerialInterface.cpp @@ -34,6 +34,11 @@ const int GRAVITY_SAMPLES = 200; // Use the first samples to const bool USING_INVENSENSE_MPU9150 = 1; +SerialInterface::SerialInterface() : + active(false), + _failedOpenAttempts(0) { +} + void SerialInterface::pair() { #ifdef __APPLE__ @@ -43,25 +48,29 @@ void SerialInterface::pair() { int matchStatus; regex_t regex; - // for now this only works on OS X, where the usb serial shows up as /dev/tty.usb* - if((devDir = opendir("/dev"))) { - while((entry = readdir(devDir))) { - regcomp(®ex, "tty\\.usb", REG_EXTENDED|REG_NOSUB); - matchStatus = regexec(®ex, entry->d_name, (size_t) 0, NULL, 0); - if (matchStatus == 0) { - char *serialPortname = new char[100]; - sprintf(serialPortname, "/dev/%s", entry->d_name); - - initializePort(serialPortname, 115200); - - delete [] serialPortname; + if (_failedOpenAttempts < 2) { + // if we've already failed to open the detected interface twice then don't try again + + // for now this only works on OS X, where the usb serial shows up as /dev/tty.usb* + if((devDir = opendir("/dev"))) { + while((entry = readdir(devDir))) { + regcomp(®ex, "tty\\.usb", REG_EXTENDED|REG_NOSUB); + matchStatus = regexec(®ex, entry->d_name, (size_t) 0, NULL, 0); + if (matchStatus == 0) { + char *serialPortname = new char[100]; + sprintf(serialPortname, "/dev/%s", entry->d_name); + + initializePort(serialPortname, 115200); + + delete [] serialPortname; + } + regfree(®ex); } - regfree(®ex); + closedir(devDir); } - closedir(devDir); } -#endif +#endif } // connect to the serial port @@ -73,6 +82,7 @@ int SerialInterface::initializePort(char* portname, int baud) { if (serialFd == -1) { printLog("Failed.\n"); + _failedOpenAttempts++; return -1; // Failed to open port } struct termios options; diff --git a/interface/src/SerialInterface.h b/interface/src/SerialInterface.h index 9558a1601f..917c968c3f 100644 --- a/interface/src/SerialInterface.h +++ b/interface/src/SerialInterface.h @@ -36,7 +36,7 @@ extern const bool USING_INVENSENSE_MPU9150; class SerialInterface { public: - SerialInterface() { active = false; }; + SerialInterface(); void pair(); void readData(); @@ -56,7 +56,7 @@ public: glm::vec3 getGravity() {return gravity;}; private: - int initializePort(char * portname, int baud); + int initializePort(char* portname, int baud); void resetSerial(); int lastMeasured[NUM_CHANNELS]; float trailingAverage[NUM_CHANNELS]; @@ -68,6 +68,7 @@ private: int _lastYaw; int _lastPitch; int _lastRoll; + int _failedOpenAttempts; }; #endif From 0b810fa4c257f4ac4ce350cf9c4edfc47f10f016 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 6 May 2013 13:08:45 -0700 Subject: [PATCH 15/21] if we fail to open SerialInterface twice then don't keep trying --- interface/src/SerialInterface.cpp | 40 +++++++++++++++++++------------ interface/src/SerialInterface.h | 5 ++-- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/interface/src/SerialInterface.cpp b/interface/src/SerialInterface.cpp index 5878ab672e..2efe487304 100644 --- a/interface/src/SerialInterface.cpp +++ b/interface/src/SerialInterface.cpp @@ -34,6 +34,11 @@ const int GRAVITY_SAMPLES = 200; // Use the first samples to const bool USING_INVENSENSE_MPU9150 = 1; +SerialInterface::SerialInterface() : + active(false), + _failedOpenAttempts(0) { +} + void SerialInterface::pair() { #ifdef __APPLE__ @@ -43,25 +48,29 @@ void SerialInterface::pair() { int matchStatus; regex_t regex; - // for now this only works on OS X, where the usb serial shows up as /dev/tty.usb* - if((devDir = opendir("/dev"))) { - while((entry = readdir(devDir))) { - regcomp(®ex, "tty\\.usb", REG_EXTENDED|REG_NOSUB); - matchStatus = regexec(®ex, entry->d_name, (size_t) 0, NULL, 0); - if (matchStatus == 0) { - char *serialPortname = new char[100]; - sprintf(serialPortname, "/dev/%s", entry->d_name); - - initializePort(serialPortname, 115200); - - delete [] serialPortname; + if (_failedOpenAttempts < 2) { + // if we've already failed to open the detected interface twice then don't try again + + // for now this only works on OS X, where the usb serial shows up as /dev/tty.usb* + if((devDir = opendir("/dev"))) { + while((entry = readdir(devDir))) { + regcomp(®ex, "tty\\.usb", REG_EXTENDED|REG_NOSUB); + matchStatus = regexec(®ex, entry->d_name, (size_t) 0, NULL, 0); + if (matchStatus == 0) { + char *serialPortname = new char[100]; + sprintf(serialPortname, "/dev/%s", entry->d_name); + + initializePort(serialPortname, 115200); + + delete [] serialPortname; + } + regfree(®ex); } - regfree(®ex); + closedir(devDir); } - closedir(devDir); } -#endif +#endif } // connect to the serial port @@ -73,6 +82,7 @@ int SerialInterface::initializePort(char* portname, int baud) { if (serialFd == -1) { printLog("Failed.\n"); + _failedOpenAttempts++; return -1; // Failed to open port } struct termios options; diff --git a/interface/src/SerialInterface.h b/interface/src/SerialInterface.h index 9558a1601f..917c968c3f 100644 --- a/interface/src/SerialInterface.h +++ b/interface/src/SerialInterface.h @@ -36,7 +36,7 @@ extern const bool USING_INVENSENSE_MPU9150; class SerialInterface { public: - SerialInterface() { active = false; }; + SerialInterface(); void pair(); void readData(); @@ -56,7 +56,7 @@ public: glm::vec3 getGravity() {return gravity;}; private: - int initializePort(char * portname, int baud); + int initializePort(char* portname, int baud); void resetSerial(); int lastMeasured[NUM_CHANNELS]; float trailingAverage[NUM_CHANNELS]; @@ -68,6 +68,7 @@ private: int _lastYaw; int _lastPitch; int _lastRoll; + int _failedOpenAttempts; }; #endif From 499899c6e03b697b3ed1cdc39ec1f4477bb38420 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 6 May 2013 13:11:40 -0700 Subject: [PATCH 16/21] if there are no active agents in list begin() iterator should be end() --- libraries/shared/src/AgentList.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/shared/src/AgentList.cpp b/libraries/shared/src/AgentList.cpp index cc9b7b06ed..51a14d8cb1 100644 --- a/libraries/shared/src/AgentList.cpp +++ b/libraries/shared/src/AgentList.cpp @@ -64,8 +64,7 @@ AgentList::AgentList(char newOwnerType, unsigned int newSocketListenPort) : agentSocket(newSocketListenPort), ownerType(newOwnerType), socketListenPort(newSocketListenPort), - lastAgentId(0) -{ + lastAgentId(0) { pthread_mutex_init(&mutex, 0); } @@ -483,7 +482,8 @@ AgentList::iterator AgentList::begin() const { } } - return AgentListIterator(this, 0); + // there's no alive agent to start from - return the end + return end(); } AgentList::iterator AgentList::end() const { From e8babd6d1eb66591a68f627add4231114109aa64 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 6 May 2013 13:14:28 -0700 Subject: [PATCH 17/21] type star squish in domain server --- domain-server/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/domain-server/src/main.cpp b/domain-server/src/main.cpp index b7e43f48bb..722a0f2075 100644 --- a/domain-server/src/main.cpp +++ b/domain-server/src/main.cpp @@ -100,7 +100,7 @@ int main(int argc, const char * argv[]) std::map newestSoloAgents; agentType = packetData[1]; - unpackSocket(&packetData[2], (sockaddr *)&agentLocalAddress); + unpackSocket(&packetData[2], (sockaddr*) &agentLocalAddress); // check the agent public address // if it matches our local address we're on the same box From 2a240f6474c35888f51d710f49f6cc48bb4d8abc Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 6 May 2013 13:14:58 -0700 Subject: [PATCH 18/21] type star squish in domain server --- domain-server/src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/domain-server/src/main.cpp b/domain-server/src/main.cpp index 722a0f2075..2ded57b9ae 100644 --- a/domain-server/src/main.cpp +++ b/domain-server/src/main.cpp @@ -100,7 +100,7 @@ int main(int argc, const char * argv[]) std::map newestSoloAgents; agentType = packetData[1]; - unpackSocket(&packetData[2], (sockaddr*) &agentLocalAddress); + unpackSocket(&packetData[2], (sockaddr*) g&agentLocalAddress); // check the agent public address // if it matches our local address we're on the same box @@ -121,7 +121,7 @@ int main(int argc, const char * argv[]) } else if (packetData[0] == PACKET_HEADER_DOMAIN_RFD) { // if this is a previous agent, and they are re-reporting for duty // then we need to update the first receive time - Agent *refreshedAgent = agentList->agentWithAddress((sockaddr*) &agentLocalAddress); + Agent* refreshedAgent = agentList->agentWithAddress((sockaddr*) &agentLocalAddress); refreshedAgent->setWakeMicrostamp(usecTimestampNow()); } From ee4c55afe7e453e4e0f422fb4442d0cebdf0e332 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 6 May 2013 13:18:06 -0700 Subject: [PATCH 19/21] move SerialInterface constructor to header file --- interface/src/SerialInterface.cpp | 5 ----- interface/src/SerialInterface.h | 3 ++- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/interface/src/SerialInterface.cpp b/interface/src/SerialInterface.cpp index 2efe487304..3e906552b3 100644 --- a/interface/src/SerialInterface.cpp +++ b/interface/src/SerialInterface.cpp @@ -34,11 +34,6 @@ const int GRAVITY_SAMPLES = 200; // Use the first samples to const bool USING_INVENSENSE_MPU9150 = 1; -SerialInterface::SerialInterface() : - active(false), - _failedOpenAttempts(0) { -} - void SerialInterface::pair() { #ifdef __APPLE__ diff --git a/interface/src/SerialInterface.h b/interface/src/SerialInterface.h index 917c968c3f..7677562c53 100644 --- a/interface/src/SerialInterface.h +++ b/interface/src/SerialInterface.h @@ -36,7 +36,8 @@ extern const bool USING_INVENSENSE_MPU9150; class SerialInterface { public: - SerialInterface(); + SerialInterface() : active(false), + _failedOpenAttempts(0) {} void pair(); void readData(); From 49042046de08fddd4639223e34ff7225f6a6b21e Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 6 May 2013 13:20:13 -0700 Subject: [PATCH 20/21] remove duplicated constructor after merge --- interface/src/SerialInterface.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/interface/src/SerialInterface.cpp b/interface/src/SerialInterface.cpp index 2efe487304..3e906552b3 100644 --- a/interface/src/SerialInterface.cpp +++ b/interface/src/SerialInterface.cpp @@ -34,11 +34,6 @@ const int GRAVITY_SAMPLES = 200; // Use the first samples to const bool USING_INVENSENSE_MPU9150 = 1; -SerialInterface::SerialInterface() : - active(false), - _failedOpenAttempts(0) { -} - void SerialInterface::pair() { #ifdef __APPLE__ From 969bf7645a7c6b71884257079ef39009e0a970ee Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 6 May 2013 13:30:10 -0700 Subject: [PATCH 21/21] remove an accidentally added g --- domain-server/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/domain-server/src/main.cpp b/domain-server/src/main.cpp index 2ded57b9ae..705bc317b2 100644 --- a/domain-server/src/main.cpp +++ b/domain-server/src/main.cpp @@ -100,7 +100,7 @@ int main(int argc, const char * argv[]) std::map newestSoloAgents; agentType = packetData[1]; - unpackSocket(&packetData[2], (sockaddr*) g&agentLocalAddress); + unpackSocket(&packetData[2], (sockaddr*) &agentLocalAddress); // check the agent public address // if it matches our local address we're on the same box