From 2a3d06f6de95f60788f8eb7c1ea5a765639bbb4e Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Wed, 24 Apr 2013 17:45:26 -0700 Subject: [PATCH 01/36] 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 02/36] 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 03/36] 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 04/36] 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; From 68b3f54f5c823c53e7d052e0189ca4b91a7ded4e Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Thu, 25 Apr 2013 10:44:01 -0700 Subject: [PATCH 05/36] tiny change --- interface/src/Avatar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 9f9d1febba..0ed3baf4fe 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -297,7 +297,7 @@ void Avatar::simulate(float deltaTime) { } _interactingOtherIsNearby = false; - + // if the avatar being simulated is mine, then loop through // all the other avatars for potential interactions... if ( _isMine ) From 9a4d27c0b5d139a8aeb549e5437e5bfff39ffe93 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Thu, 25 Apr 2013 12:19:23 -0700 Subject: [PATCH 06/36] cleaned up some camera code and added some functionality for first-person view --- interface/src/Avatar.cpp | 4 +-- interface/src/Camera.cpp | 53 ++++++++++++++++---------------------- interface/src/Camera.h | 55 ++++++++++++++++++++-------------------- interface/src/main.cpp | 45 +++++++++++++++++--------------- 4 files changed, 76 insertions(+), 81 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 0ed3baf4fe..c77efd28b9 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -316,8 +316,8 @@ void Avatar::simulate(float deltaTime) { updateAvatarCollisionDetectionAndResponse ( otherAvatar->getBonePosition( AVATAR_BONE_PELVIS_SPINE ), - 0.2, - 0.2, + 0.1, + 0.1, otherAvatar->getBodyUpDirection(), deltaTime ); diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index 1333196b02..b251e1f5a5 100644 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -12,14 +12,15 @@ Camera::Camera() { _mode = CAMERA_MODE_THIRD_PERSON; - _tightness = DEFAULT_CAMERA_TIGHTNESS; - _fieldOfView = 60.0; // default - _nearClip = 0.08; // default - _farClip = 50.0; // default + _tightness = 10.0; // default + _fieldOfView = 60.0; // default + _nearClip = 0.08; // default + _farClip = 50.0; // default _yaw = 0.0; _pitch = 0.0; _roll = 0.0; - _up = 0.0; + _upShift = 0.0; + _rightShift = 0.0; _distance = 0.0; _idealYaw = 0.0; _targetPosition = glm::vec3( 0.0, 0.0, 0.0 ); @@ -28,46 +29,36 @@ Camera::Camera() { _orientation.setToIdentity(); } +void Camera::update( float deltaTime ) { - -void Camera::update( float deltaTime ) -{ - //---------------------------------------- // derive t from tightness - //---------------------------------------- - float t = _tightness * deltaTime; - - if ( t > 1.0 ){ + float t = _tightness * deltaTime; + if ( t > 1.0 ) { t = 1.0; } - //---------------------------------------- // update _yaw (before position!) - //---------------------------------------- _yaw += ( _idealYaw - _yaw ) * t; + + // generate the ortho-normals for the orientation based on the Euler angles + _orientation.setToIdentity(); + _orientation.yaw ( _yaw ); + _orientation.pitch( _pitch ); + _orientation.roll ( _roll ); + float radian = ( _yaw / 180.0 ) * PIE; - //---------------------------------------- // update _position - //---------------------------------------- - //these need to be checked to make sure they correspond to the coordinate system. + //these need to be checked to make sure they correspond to the correct coordinate system. double x = _distance * -sin( radian ); double z = _distance * cos( radian ); - double y = _up; + double y = _upShift; - _idealPosition = _targetPosition + glm::vec3( x, y, z ); + _idealPosition = _targetPosition + glm::vec3( x, y, z ); + //_idealPosition += _orientation.getRight() * _rightShift; + //_idealPosition += _orientation.getUp () * _upShift; + // pull position towards ideal position _position += ( _idealPosition - _position ) * t; - - //------------------------------------------------------------------------------ - // generate the ortho-normals for the orientation based on the Euler angles - //------------------------------------------------------------------------------ - _orientation.setToIdentity(); - - _orientation.yaw ( _yaw ); - _orientation.pitch ( _pitch ); - _orientation.roll ( _roll ); - - //printLog( "orientation.front = %f, %f, %f\n", _orientation.front.x, _orientation.front.y, _orientation.front.z ); } diff --git a/interface/src/Camera.h b/interface/src/Camera.h index 354a5d8d16..befb5d0826 100644 --- a/interface/src/Camera.h +++ b/interface/src/Camera.h @@ -20,8 +20,6 @@ enum CameraMode NUM_CAMERA_MODES }; -static const float DEFAULT_CAMERA_TIGHTNESS = 10.0f; - class Camera { public: @@ -29,31 +27,33 @@ public: void update( float deltaTime ); - void setMode ( CameraMode m ) { _mode = m; } - void setYaw ( float y ) { _idealYaw = y; } - void setPitch ( float p ) { _pitch = p; } - void setRoll ( float r ) { _roll = r; } - void setUp ( float u ) { _up = u; } - void setDistance ( float d ) { _distance = d; } - void setTargetPosition ( glm::vec3 t ) { _targetPosition = t; }; - void setPosition ( glm::vec3 p ) { _position = p; }; - void setOrientation ( Orientation o ) { _orientation.set(o); } - void setTightness ( float t ) { _tightness = t; } - void setFieldOfView ( float f ) { _fieldOfView = f; } - void setAspectRatio ( float a ) { _aspectRatio = a; } - void setNearClip ( float n ) { _nearClip = n; } - void setFarClip ( float f ) { _farClip = f; } + void setMode ( CameraMode m ) { _mode = m; } + void setYaw ( float y ) { _yaw = y; } + void setPitch ( float p ) { _pitch = p; } + void setRoll ( float r ) { _roll = r; } + void setUpShift ( float u ) { _upShift = u; } + void setRightShift ( float r ) { _rightShift = r; } + void setDistance ( float d ) { _distance = d; } + void setTargetPosition( glm::vec3 t ) { _targetPosition = t; } + void setTargetYaw ( float y ) { _idealYaw = y; } + void setPosition ( glm::vec3 p ) { _position = p; } + void setOrientation ( Orientation o ) { _orientation.set(o); } + void setTightness ( float t ) { _tightness = t; } + void setFieldOfView ( float f ) { _fieldOfView = f; } + void setAspectRatio ( float a ) { _aspectRatio = a; } + void setNearClip ( float n ) { _nearClip = n; } + void setFarClip ( float f ) { _farClip = f; } - float getYaw () { return _yaw; } - float getPitch () { return _pitch; } - float getRoll () { return _roll; } - glm::vec3 getPosition () { return _position; } - Orientation getOrientation () { return _orientation; } - CameraMode getMode () { return _mode; } - float getFieldOfView () { return _fieldOfView; } - float getAspectRatio () { return _aspectRatio; } - float getNearClip () { return _nearClip; } - float getFarClip () { return _farClip; } + float getYaw () { return _yaw; } + float getPitch () { return _pitch; } + float getRoll () { return _roll; } + glm::vec3 getPosition () { return _position; } + Orientation getOrientation() { return _orientation; } + CameraMode getMode () { return _mode; } + float getFieldOfView() { return _fieldOfView; } + float getAspectRatio() { return _aspectRatio; } + float getNearClip () { return _nearClip; } + float getFarClip () { return _farClip; } private: @@ -68,7 +68,8 @@ private: float _yaw; float _pitch; float _roll; - float _up; + float _upShift; + float _rightShift; float _idealYaw; float _distance; float _tightness; diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 497bbfd946..255b541c30 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -800,33 +800,38 @@ void display(void) glMaterialfv(GL_FRONT, GL_SPECULAR, specular_color); glMateriali(GL_FRONT, GL_SHININESS, 96); - //-------------------------------------------------------- // camera settings - //-------------------------------------------------------- if ( ::lookingInMirror ) { - //----------------------------------------------- // set the camera to looking at my own face - //----------------------------------------------- myCamera.setTargetPosition ( myAvatar.getHeadPosition() ); - myCamera.setYaw ( - myAvatar.getBodyYaw() ); + myCamera.setTargetYaw ( - myAvatar.getBodyYaw() ); myCamera.setPitch ( 0.0 ); myCamera.setRoll ( 0.0 ); - myCamera.setUp ( 0.0 ); + myCamera.setUpShift ( 0.0 ); myCamera.setDistance ( 0.2 ); myCamera.setTightness ( 100.0f ); myCamera.update ( 1.f/FPS ); } else { - //---------------------------------------------------- - // set the camera to third-person view behind my av - //---------------------------------------------------- - myCamera.setTargetPosition ( myAvatar.getPosition() ); - myCamera.setYaw ( 180.0 - myAvatar.getBodyYaw() ); - myCamera.setPitch ( 0.0 ); // temporarily, this must be 0.0 or else bad juju - myCamera.setRoll ( 0.0 ); - myCamera.setUp ( 0.45 ); - myCamera.setDistance ( 1.0 ); - myCamera.setTightness ( 8.0f ); - myCamera.update ( 1.f/FPS); + + //this is in the prototyping stages..keep firstPerson false for now. + bool firstPerson = false; + + if ( firstPerson ) { + myCamera.setPitch (15.0f ); // temporarily, this must be 0.0 or else bad juju + myCamera.setUpShift (0.0f ); + myCamera.setDistance (0.0f ); + myCamera.setTightness (100.0f); + } else { + myCamera.setPitch (0.0f ); // temporarily, this must be 0.0 or else bad juju + myCamera.setUpShift (-0.1f); + myCamera.setDistance (1.0f ); + myCamera.setTightness (8.0f ); + } + + myCamera.setTargetPosition( myAvatar.getHeadPosition() ); + myCamera.setTargetYaw ( 180.0 - myAvatar.getBodyYaw() ); + myCamera.setRoll ( 0.0 ); + myCamera.update ( 1.f/FPS); } // Note: whichCamera is used to pick between the normal camera myCamera for our @@ -843,10 +848,10 @@ void display(void) if (::viewFrustumFromOffset && ::frustumOn) { // set the camera to third-person view but offset so we can see the frustum - viewFrustumOffsetCamera.setYaw ( 180.0 - myAvatar.getBodyYaw() + ::viewFrustumOffsetYaw ); + viewFrustumOffsetCamera.setTargetYaw( 180.0 - myAvatar.getBodyYaw() + ::viewFrustumOffsetYaw ); viewFrustumOffsetCamera.setPitch ( ::viewFrustumOffsetPitch ); viewFrustumOffsetCamera.setRoll ( ::viewFrustumOffsetRoll ); - viewFrustumOffsetCamera.setUp ( ::viewFrustumOffsetUp ); + viewFrustumOffsetCamera.setUpShift ( ::viewFrustumOffsetUp ); viewFrustumOffsetCamera.setDistance ( ::viewFrustumOffsetDistance ); viewFrustumOffsetCamera.update(1.f/FPS); whichCamera = viewFrustumOffsetCamera; @@ -864,10 +869,8 @@ void display(void) if (::starsOn) { // should be the first rendering pass - w/o depth buffer / lighting - // finally render the starfield stars.render(whichCamera.getFieldOfView(), aspectRatio, whichCamera.getNearClip()); - } glEnable(GL_LIGHTING); From 836d286b75dabf039a2e25e403cc09212708ca0c Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 25 Apr 2013 13:11:13 -0700 Subject: [PATCH 07/36] initial transition from vector to multi-dimensional array in AgentList --- interface/src/Head.cpp | 13 +- interface/src/main.cpp | 25 ++- libraries/shared/src/Agent.cpp | 27 ++-- libraries/shared/src/Agent.h | 11 +- libraries/shared/src/AgentList.cpp | 235 ++++++++++++++++++----------- libraries/shared/src/AgentList.h | 44 +++++- voxel-server/src/main.cpp | 16 -- 7 files changed, 226 insertions(+), 145 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index f6683b6a9a..ac44e3e530 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -301,20 +301,19 @@ void Head::simulate(float deltaTime) { // if the avatar being simulated is mine, then loop through // all the other avatars to get information about them... //------------------------------------------------------------- - if ( _isMine ) - { + if ( _isMine ) { _nearOtherAvatar = false; float closestDistance = 10000.0f; - AgentList * agentList = AgentList::getInstance(); + AgentList* agentList = AgentList::getInstance(); //_numOtherAvatars = 0; - for(std::vector::iterator agent = agentList->getAgents().begin(); - agent != agentList->getAgents().end(); + for(AgentListIterator agent = agentList->begin(); + agent != agentList->end(); agent++) { - if (( agent->getLinkedData() != NULL && ( agent->getType() == AGENT_TYPE_AVATAR ) )) { - Head *otherAvatar = (Head *)agent->getLinkedData(); + if ((*agent).getLinkedData() != NULL && (*agent).getType() == AGENT_TYPE_AVATAR) { + Head *otherAvatar = (Head *)(*agent).getLinkedData(); // if ( _numOtherAvatars < MAX_OTHER_AVATARS ) { diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 41ffdc1e92..0ede2ed23b 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -907,11 +907,11 @@ void display(void) // Render avatars of other agents AgentList *agentList = AgentList::getInstance(); - for(std::vector::iterator agent = agentList->getAgents().begin(); - agent != agentList->getAgents().end(); + for(AgentListIterator agent = agentList->begin(); + agent != agentList->end(); agent++) { - if (agent->getLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) { - Head *avatar = (Head *)agent->getLinkedData(); + if ((*agent).getLinkedData() != NULL && (*agent).getType() == AGENT_TYPE_AVATAR) { + Head *avatar = (Head *)(*agent).getLinkedData(); avatar->render(0); } } @@ -980,12 +980,13 @@ void display(void) glPointSize(1.0f); char agents[100]; - int totalAgents = AgentList::getInstance()->getAgents().size(); + AgentList *agentList = AgentList::getInstance(); int totalAvatars = 0, totalServers = 0; - for (int i = 0; i < totalAgents; i++) { - (AgentList::getInstance()->getAgents()[i].getType() == AGENT_TYPE_AVATAR) - ? totalAvatars++ : totalServers++; + + for (AgentListIterator agent = agentList->begin(); agent != agentList->end(); agent++) { + (*agent).getType() == AGENT_TYPE_AVATAR ? totalAvatars++ : totalServers++; } + sprintf(agents, "Servers: %d, Avatars: %d\n", totalServers, totalAvatars); drawtext(WIDTH-150,20, 0.10, 0, 1.0, 0, agents, 1, 0, 0); @@ -1489,11 +1490,9 @@ void idle(void) { //loop through all the other avatars and simulate them... AgentList * agentList = AgentList::getInstance(); - for(std::vector::iterator agent = agentList->getAgents().begin(); agent != agentList->getAgents().end(); agent++) - { - if (agent->getLinkedData() != NULL) - { - Head *avatar = (Head *)agent->getLinkedData(); + for(AgentListIterator agent = agentList->begin(); agent != agentList->end(); agent++) { + if ((*agent).getLinkedData() != NULL) { + Head *avatar = (Head *)(*agent).getLinkedData(); avatar->simulate(deltaTime); } } diff --git a/libraries/shared/src/Agent.cpp b/libraries/shared/src/Agent.cpp index 3a92e6c05e..cd694ccf78 100644 --- a/libraries/shared/src/Agent.cpp +++ b/libraries/shared/src/Agent.cpp @@ -22,7 +22,19 @@ using shared_lib::printLog; -Agent::Agent(sockaddr *agentPublicSocket, sockaddr *agentLocalSocket, char agentType, uint16_t thisAgentId) { +int unpackAgentId(unsigned char *packedData, uint16_t *agentId) { + memcpy(agentId, packedData, sizeof(uint16_t)); + return sizeof(uint16_t); +} + +int packAgentId(unsigned char *packStore, uint16_t agentId) { + memcpy(packStore, &agentId, sizeof(uint16_t)); + return sizeof(uint16_t); +} + +Agent::Agent(sockaddr *agentPublicSocket, sockaddr *agentLocalSocket, char agentType, uint16_t thisAgentId) : + _isAlive(true) +{ if (agentPublicSocket != NULL) { publicSocket = new sockaddr; memcpy(publicSocket, agentPublicSocket, sizeof(sockaddr)); @@ -46,12 +58,11 @@ Agent::Agent(sockaddr *agentPublicSocket, sockaddr *agentLocalSocket, char agent activeSocket = NULL; linkedData = NULL; _bytesReceivedMovingAverage = NULL; - - deleteMutex = new pthread_mutex_t; - pthread_mutex_init(deleteMutex, NULL); } Agent::Agent(const Agent &otherAgent) { + _isAlive = otherAgent._isAlive; + if (otherAgent.publicSocket != NULL) { publicSocket = new sockaddr; memcpy(publicSocket, otherAgent.publicSocket, sizeof(sockaddr)); @@ -92,9 +103,6 @@ Agent::Agent(const Agent &otherAgent) { } else { _bytesReceivedMovingAverage = NULL; } - - deleteMutex = new pthread_mutex_t; - pthread_mutex_init(deleteMutex, NULL); } Agent& Agent::operator=(Agent otherAgent) { @@ -105,6 +113,7 @@ Agent& Agent::operator=(Agent otherAgent) { void Agent::swap(Agent &first, Agent &second) { using std::swap; + swap(first._isAlive, second._isAlive); swap(first.publicSocket, second.publicSocket); swap(first.localSocket, second.localSocket); swap(first.activeSocket, second.activeSocket); @@ -114,13 +123,9 @@ void Agent::swap(Agent &first, Agent &second) { swap(first.firstRecvTimeUsecs, second.firstRecvTimeUsecs); swap(first.lastRecvTimeUsecs, second.lastRecvTimeUsecs); swap(first._bytesReceivedMovingAverage, second._bytesReceivedMovingAverage); - swap(first.deleteMutex, second.deleteMutex); } Agent::~Agent() { - // the deleteMutex isn't destroyed here - // that's handled by the agent list silent agent removal thread - delete publicSocket; delete localSocket; delete linkedData; diff --git a/libraries/shared/src/Agent.h b/libraries/shared/src/Agent.h index b1d2347c21..1b8fadfdd8 100644 --- a/libraries/shared/src/Agent.h +++ b/libraries/shared/src/Agent.h @@ -31,8 +31,6 @@ public: bool matches(sockaddr *otherPublicSocket, sockaddr *otherLocalSocket, char otherAgentType); - pthread_mutex_t *deleteMutex; - char getType() const; const char* getTypeName() const; void setType(char newType); @@ -58,6 +56,9 @@ public: AgentData* getLinkedData(); void setLinkedData(AgentData *newData); + bool isAlive() const { return _isAlive; }; + void setAlive(bool isAlive) { _isAlive = isAlive; }; + void recordBytesReceived(int bytesReceived); float getAverageKilobitsPerSecond(); float getAveragePacketsPerSecond(); @@ -73,9 +74,11 @@ private: double lastRecvTimeUsecs; SimpleMovingAverage* _bytesReceivedMovingAverage; AgentData* linkedData; - + bool _isAlive; }; -std::ostream& operator<<(std::ostream& os, const Agent* agent); + +int unpackAgentId(unsigned char *packedData, uint16_t *agentId); +int packAgentId(unsigned char *packStore, uint16_t agentId); #endif /* defined(__hifi__Agent__) */ diff --git a/libraries/shared/src/AgentList.cpp b/libraries/shared/src/AgentList.cpp index 15c4abdd85..809ee2af03 100644 --- a/libraries/shared/src/AgentList.cpp +++ b/libraries/shared/src/AgentList.cpp @@ -59,11 +59,15 @@ AgentList* AgentList::getInstance() { return _sharedInstance; } +AgentList::AgentList(char newOwnerType, unsigned int newSocketListenPort) : + _agentBuckets(), + _numAgents(0), + agentSocket(newSocketListenPort), + ownerType(newOwnerType), + socketListenPort(newSocketListenPort), + lastAgentId(0) +{ -AgentList::AgentList(char newOwnerType, unsigned int newSocketListenPort) : agentSocket(newSocketListenPort) { - ownerType = newOwnerType; - socketListenPort = newSocketListenPort; - lastAgentId = 0; } AgentList::~AgentList() { @@ -73,10 +77,6 @@ AgentList::~AgentList() { stopPingUnknownAgentsThread(); } -std::vector& AgentList::getAgents() { - return agents; -} - UDPSocket& AgentList::getAgentSocket() { return agentSocket; } @@ -108,10 +108,9 @@ void AgentList::processAgentData(sockaddr *senderAddress, unsigned char *packetD void AgentList::processBulkAgentData(sockaddr *senderAddress, unsigned char *packetData, int numTotalBytes) { // find the avatar mixer in our agent list and update the lastRecvTime from it - int bulkSendAgentIndex = indexOfMatchingAgent(senderAddress); + Agent* bulkSendAgent = agentWithAddress(senderAddress); - if (bulkSendAgentIndex >= 0) { - Agent *bulkSendAgent = &agents[bulkSendAgentIndex]; + if (bulkSendAgent) { bulkSendAgent->setLastRecvTimeUsecs(usecTimestampNow()); bulkSendAgent->recordBytesReceived(numTotalBytes); } @@ -128,17 +127,18 @@ void AgentList::processBulkAgentData(sockaddr *senderAddress, unsigned char *pac currentPosition += unpackAgentId(currentPosition, &agentID); memcpy(packetHolder + 1, currentPosition, numTotalBytes - (currentPosition - startPosition)); - int matchingAgentIndex = indexOfMatchingAgent(agentID); + Agent* matchingAgent = agentWithID(agentID); - if (matchingAgentIndex < 0) { + if (!matchingAgent) { // we're missing this agent, we need to add it to the list addOrUpdateAgent(NULL, NULL, AGENT_TYPE_AVATAR, agentID); - // theoretically if we can lock the vector we could assume this is size - 1 - matchingAgentIndex = indexOfMatchingAgent(agentID); + // TODO: this is a really stupid way to do this + // Add a reverse iterator and go from the end of the list + matchingAgent = agentWithID(agentID); } - currentPosition += updateAgentWithData(&agents[matchingAgentIndex], + currentPosition += updateAgentWithData(matchingAgent, packetHolder, numTotalBytes - (currentPosition - startPosition)); } @@ -146,10 +146,10 @@ void AgentList::processBulkAgentData(sockaddr *senderAddress, unsigned char *pac int AgentList::updateAgentWithData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes) { // find the agent by the sockaddr - int agentIndex = indexOfMatchingAgent(senderAddress); + Agent* matchingAgent = agentWithAddress(senderAddress); - if (agentIndex != -1) { - return updateAgentWithData(&agents[agentIndex], packetData, dataBytes); + if (matchingAgent) { + return updateAgentWithData(matchingAgent, packetData, dataBytes); } else { return 0; } @@ -171,24 +171,24 @@ int AgentList::updateAgentWithData(Agent *agent, unsigned char *packetData, int return agent->getLinkedData()->parseData(packetData, dataBytes); } -int AgentList::indexOfMatchingAgent(sockaddr *senderAddress) { - for(std::vector::iterator agent = agents.begin(); agent != agents.end(); agent++) { - if (agent->getActiveSocket() != NULL && socketMatch(agent->getActiveSocket(), senderAddress)) { - return agent - agents.begin(); +Agent* AgentList::agentWithAddress(sockaddr *senderAddress) { + for(AgentListIterator agent = begin(); agent != end(); agent++) { + if ((*agent).getActiveSocket() != NULL && socketMatch((*agent).getActiveSocket(), senderAddress)) { + return &*agent; } } - return -1; + return NULL; } -int AgentList::indexOfMatchingAgent(uint16_t agentID) { - for(std::vector::iterator agent = agents.begin(); agent != agents.end(); agent++) { - if (agent->getAgentId() == agentID) { - return agent - agents.begin(); +Agent* AgentList::agentWithID(uint16_t agentID) { + for(AgentListIterator agent = begin(); agent != end(); agent++) { + if ((*agent).getAgentId() == agentID) { + return &*agent; } } - return -1; + return NULL; } uint16_t AgentList::getLastAgentId() { @@ -227,53 +227,46 @@ int AgentList::updateList(unsigned char *packetData, size_t dataBytes) { } bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket, char agentType, uint16_t agentId) { - std::vector::iterator agent; + AgentListIterator agent = end(); if (publicSocket != NULL) { - for (agent = agents.begin(); agent != agents.end(); agent++) { - if (agent->matches(publicSocket, localSocket, agentType)) { + for (agent = begin(); agent != end(); agent++) { + if ((*agent).matches(publicSocket, localSocket, agentType)) { // we already have this agent, stop checking break; } } - } else { - agent = agents.end(); - } + } - if (agent == agents.end()) { + if (agent == end()) { // we didn't have this agent, so add them - Agent newAgent = Agent(publicSocket, localSocket, agentType, agentId); + Agent *newAgent = new Agent(publicSocket, localSocket, agentType, agentId); if (socketMatch(publicSocket, localSocket)) { // likely debugging scenario with two agents on local network // set the agent active right away - newAgent.activatePublicSocket(); + newAgent->activatePublicSocket(); } - if (newAgent.getType() == AGENT_TYPE_AUDIO_MIXER && audioMixerSocketUpdate != NULL) { + if (newAgent->getType() == AGENT_TYPE_AUDIO_MIXER && audioMixerSocketUpdate != NULL) { // this is an audio mixer // for now that means we need to tell the audio class // to use the local socket information the domain server gave us sockaddr_in *publicSocketIn = (sockaddr_in *)publicSocket; audioMixerSocketUpdate(publicSocketIn->sin_addr.s_addr, publicSocketIn->sin_port); - } else if (newAgent.getType() == AGENT_TYPE_VOXEL) { - newAgent.activatePublicSocket(); + } else if (newAgent->getType() == AGENT_TYPE_VOXEL) { + newAgent->activatePublicSocket(); } - printLog("Added agent - "); - Agent::printLog(newAgent); - - pthread_mutex_lock(&vectorChangeMutex); - agents.push_back(newAgent); - pthread_mutex_unlock(&vectorChangeMutex); + addAgentToList(newAgent); return true; } else { - if (agent->getType() == AGENT_TYPE_AUDIO_MIXER || agent->getType() == AGENT_TYPE_VOXEL) { + 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).setLastRecvTimeUsecs(usecTimestampNow()); } // we had this agent already, do nothing for now @@ -281,25 +274,41 @@ bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket, } } +void AgentList::addAgentToList(Agent* newAgent) { + // find the correct array to add this agent to + int bucketIndex = _numAgents / AGENTS_PER_BUCKET; + + if (!_agentBuckets[bucketIndex]) { + _agentBuckets[bucketIndex] = new Agent*[AGENTS_PER_BUCKET](); + } + + _agentBuckets[bucketIndex][_numAgents % AGENTS_PER_BUCKET] = newAgent; + + ++_numAgents; + + printLog("Added agent - "); + Agent::printLog(*newAgent); +} + void AgentList::broadcastToAgents(unsigned char *broadcastData, size_t dataBytes, const char* agentTypes, int numAgentTypes) { - for(std::vector::iterator agent = agents.begin(); agent != agents.end(); agent++) { + for(AgentListIterator agent = begin(); agent != end(); agent++) { // only send to the AgentTypes we are asked to send to. - if (agent->getActiveSocket() != NULL && memchr(agentTypes, agent->getType(), numAgentTypes)) { + if ((*agent).getActiveSocket() != NULL && memchr(agentTypes, (*agent).getType(), numAgentTypes)) { // we know which socket is good for this agent, send there - agentSocket.send(agent->getActiveSocket(), broadcastData, dataBytes); + agentSocket.send((*agent).getActiveSocket(), broadcastData, dataBytes); } } } void AgentList::handlePingReply(sockaddr *agentAddress) { - for(std::vector::iterator agent = agents.begin(); agent != agents.end(); agent++) { + for(AgentListIterator agent = begin(); agent != end(); agent++) { // check both the public and local addresses for each agent to see if we find a match // prioritize the private address so that we prune erroneous local matches - if (socketMatch(agent->getPublicSocket(), agentAddress)) { - agent->activatePublicSocket(); + if (socketMatch((*agent).getPublicSocket(), agentAddress)) { + (*agent).activatePublicSocket(); break; - } else if (socketMatch(agent->getLocalSocket(), agentAddress)) { - agent->activateLocalSocket(); + } else if (socketMatch((*agent).getLocalSocket(), agentAddress)) { + (*agent).activateLocalSocket(); break; } } @@ -307,8 +316,8 @@ void AgentList::handlePingReply(sockaddr *agentAddress) { Agent* AgentList::soloAgentOfType(char agentType) { if (memchr(SOLO_AGENT_TYPES, agentType, sizeof(SOLO_AGENT_TYPES)) != NULL) { - for(std::vector::iterator agent = agents.begin(); agent != agents.end(); agent++) { - if (agent->getType() == agentType) { + for(AgentListIterator agent = begin(); agent != end(); agent++) { + if ((*agent).getType() == agentType) { return &*agent; } } @@ -327,15 +336,15 @@ void *pingUnknownAgents(void *args) { while (!pingUnknownAgentThreadStopFlag) { gettimeofday(&lastSend, NULL); - for(std::vector::iterator agent = agentList->getAgents().begin(); - agent != agentList->getAgents().end(); + for(AgentListIterator agent = agentList->begin(); + agent != agentList->end(); agent++) { - if (agent->getActiveSocket() == NULL - && (agent->getPublicSocket() != NULL && agent->getLocalSocket() != NULL)) { + if ((*agent).getActiveSocket() == NULL + && ((*agent).getPublicSocket() != NULL && (*agent).getLocalSocket() != NULL)) { // ping both of the sockets for the agent so we can figure out // which socket we can use - agentList->getAgentSocket().send(agent->getPublicSocket(), &PACKET_HEADER_PING, 1); - agentList->getAgentSocket().send(agent->getLocalSocket(), &PACKET_HEADER_PING, 1); + agentList->getAgentSocket().send((*agent).getPublicSocket(), &PACKET_HEADER_PING, 1); + agentList->getAgentSocket().send((*agent).getLocalSocket(), &PACKET_HEADER_PING, 1); } } @@ -359,31 +368,21 @@ void AgentList::stopPingUnknownAgentsThread() { } void *removeSilentAgents(void *args) { - std::vector *agents = (std::vector *)args; + AgentList *agentList = (AgentList *)args; double checkTimeUSecs, sleepTime; while (!silentAgentThreadStopFlag) { checkTimeUSecs = usecTimestampNow(); - for(std::vector::iterator agent = agents->begin(); agent != agents->end();) { + for(AgentListIterator agent = agentList->begin(); agent != agentList->end(); agent++) { - pthread_mutex_t* agentDeleteMutex = agent->deleteMutex; - - if ((checkTimeUSecs - agent->getLastRecvTimeUsecs()) > AGENT_SILENCE_THRESHOLD_USECS - && agent->getType() != AGENT_TYPE_VOXEL - && pthread_mutex_trylock(agentDeleteMutex) == 0) { + if ((checkTimeUSecs - (*agent).getLastRecvTimeUsecs()) > AGENT_SILENCE_THRESHOLD_USECS + && (*agent).getType() != AGENT_TYPE_VOXEL) { printLog("Killing agent - "); Agent::printLog(*agent); - // make sure the vector isn't currently adding an agent - pthread_mutex_lock(&vectorChangeMutex); - agent = agents->erase(agent); - pthread_mutex_unlock(&vectorChangeMutex); - - // release the delete mutex and destroy it - pthread_mutex_unlock(agentDeleteMutex); - pthread_mutex_destroy(agentDeleteMutex); + (*agent).setAlive(false); } else { agent++; } @@ -402,7 +401,7 @@ void *removeSilentAgents(void *args) { } void AgentList::startSilentAgentRemovalThread() { - pthread_create(&removeSilentAgentsThread, NULL, removeSilentAgents, (void *)&agents); + pthread_create(&removeSilentAgentsThread, NULL, removeSilentAgents, (void *)this); } void AgentList::stopSilentAgentRemovalThread() { @@ -464,12 +463,74 @@ void AgentList::stopDomainServerCheckInThread() { pthread_join(checkInWithDomainServerThread, NULL); } -int unpackAgentId(unsigned char *packedData, uint16_t *agentId) { - memcpy(agentId, packedData, sizeof(uint16_t)); - return sizeof(uint16_t); +AgentListIterator AgentList::begin() const { + Agent** agentBucket = NULL; + + for (int i = 0; i < _numAgents; i++) { + if (i % AGENTS_PER_BUCKET == 0) { + agentBucket = _agentBuckets[i / AGENTS_PER_BUCKET]; + } + + if (agentBucket[i % AGENTS_PER_BUCKET]->isAlive()) { + return AgentListIterator(this, i); + } + } + + return AgentListIterator(this, 0); } -int packAgentId(unsigned char *packStore, uint16_t agentId) { - memcpy(packStore, &agentId, sizeof(uint16_t)); - return sizeof(uint16_t); +AgentListIterator AgentList::end() const { + Agent** agentBucket = _agentBuckets[(_numAgents - 1) / AGENTS_PER_BUCKET]; + + for (int i = _numAgents - 1; i >= 0; i--) { + if (i % AGENTS_PER_BUCKET == 0) { + agentBucket = _agentBuckets[i / AGENTS_PER_BUCKET]; + } + + if (agentBucket[i % AGENTS_PER_BUCKET]->isAlive()) { + return AgentListIterator(this, i + 1); + } + } + + return AgentListIterator(this, 0); +} + +AgentListIterator::AgentListIterator(const AgentList* agentList, int agentIndex) : +_agentIndex(agentIndex) { + _agentList = agentList; +} + +AgentListIterator& AgentListIterator::operator=(const AgentListIterator& otherValue) { + _agentList = otherValue._agentList; + _agentIndex = otherValue._agentIndex; + return (*this); +} + +bool AgentListIterator::operator==(const AgentListIterator &otherValue) { + return _agentIndex == otherValue._agentIndex; +} + +bool AgentListIterator::operator!=(const AgentListIterator &otherValue) { + return !(*this == otherValue); +} + +Agent& AgentListIterator::operator*() { + Agent** agentBucket = _agentList->_agentBuckets[_agentIndex / AGENTS_PER_BUCKET]; + return *agentBucket[_agentIndex % AGENTS_PER_BUCKET]; +} + +AgentListIterator& AgentListIterator::operator++() { + if (*this != _agentList->end()) { + ++_agentIndex; + } + + return (*this); +} + +AgentListIterator& AgentListIterator::operator++(int) { + if (*this != _agentList->end()) { + ++_agentIndex; + } + + return (*this); } diff --git a/libraries/shared/src/AgentList.h b/libraries/shared/src/AgentList.h index 76d6917168..8ac1e984c3 100644 --- a/libraries/shared/src/AgentList.h +++ b/libraries/shared/src/AgentList.h @@ -9,8 +9,8 @@ #ifndef __hifi__AgentList__ #define __hifi__AgentList__ -#include #include +#include #include "Agent.h" #include "UDPSocket.h" @@ -19,6 +19,9 @@ #include "pthread.h" #endif +const int MAX_NUM_AGENTS = 10000; +const int AGENTS_PER_BUCKET = 100; + const int MAX_PACKET_SIZE = 1500; const unsigned int AGENT_SOCKET_LISTEN_PORT = 40103; const int AGENT_SILENCE_THRESHOLD_USECS = 2 * 1000000; @@ -28,15 +31,21 @@ extern char DOMAIN_HOSTNAME[]; extern char DOMAIN_IP[100]; // IP Address will be re-set by lookup on startup extern const int DOMAINSERVER_PORT; +class AgentListIterator; + class AgentList { public: static AgentList* createInstance(char ownerType, unsigned int socketListenPort = AGENT_SOCKET_LISTEN_PORT); static AgentList* getInstance(); + + AgentListIterator begin() const; + AgentListIterator end() const; void(*linkedDataCreateCallback)(Agent *); void(*audioMixerSocketUpdate)(in_addr_t, in_port_t); - std::vector& getAgents(); + int size() { return _numAgents; } + UDPSocket& getAgentSocket(); uint16_t getLastAgentId(); @@ -44,8 +53,8 @@ public: int updateList(unsigned char *packetData, size_t dataBytes); - int indexOfMatchingAgent(sockaddr *senderAddress); - int indexOfMatchingAgent(uint16_t agentID); + Agent* agentWithAddress(sockaddr *senderAddress); + Agent* agentWithID(uint16_t agentID); bool addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket, char agentType, uint16_t agentId); @@ -67,6 +76,8 @@ public: void stopDomainServerCheckInThread(); void startPingUnknownAgentsThread(); void stopPingUnknownAgentsThread(); + + friend AgentListIterator; private: static AgentList* _sharedInstance; @@ -75,10 +86,13 @@ private: AgentList(AgentList const&); // Don't implement, needed to avoid copies of singleton void operator=(AgentList const&); // Don't implement, needed to avoid copies of singleton + void addAgentToList(Agent* newAgent); + + Agent** _agentBuckets[MAX_NUM_AGENTS / AGENTS_PER_BUCKET]; + int _numAgents; UDPSocket agentSocket; char ownerType; unsigned int socketListenPort; - std::vector agents; uint16_t lastAgentId; pthread_t removeSilentAgentsThread; pthread_t checkInWithDomainServerThread; @@ -87,7 +101,23 @@ private: void handlePingReply(sockaddr *agentAddress); }; -int unpackAgentId(unsigned char *packedData, uint16_t *agentId); -int packAgentId(unsigned char *packStore, uint16_t agentId); +class AgentListIterator : public std::iterator { +public: + AgentListIterator(const AgentList* agentList, int agentIndex); + ~AgentListIterator() {}; + + AgentListIterator& operator=(const AgentListIterator& otherValue); + + bool operator==(const AgentListIterator& otherValue); + bool operator!= (const AgentListIterator& otherValue); + + Agent& operator*(); + + AgentListIterator& operator++(); + AgentListIterator& operator++(int); +private: + const AgentList* _agentList; + int _agentIndex; +}; #endif /* defined(__hifi__AgentList__) */ diff --git a/voxel-server/src/main.cpp b/voxel-server/src/main.cpp index 1d2b961d93..572963b94e 100644 --- a/voxel-server/src/main.cpp +++ b/voxel-server/src/main.cpp @@ -129,17 +129,9 @@ void eraseVoxelTreeAndCleanupAgentVisitData() { Agent *thisAgent = (Agent *)&AgentList::getInstance()->getAgents()[i]; VoxelAgentData *agentData = (VoxelAgentData *)(thisAgent->getLinkedData()); - // lock this agent's delete mutex so that the delete thread doesn't - // kill the agent while we are working with it - pthread_mutex_lock(thisAgent->deleteMutex); - // clean up the agent visit data delete agentData->rootMarkerNode; agentData->rootMarkerNode = new MarkerNode(); - - // unlock the delete mutex so the other thread can - // kill the agent if it has dissapeared - pthread_mutex_unlock(thisAgent->deleteMutex); } } @@ -185,10 +177,6 @@ void *distributeVoxelsToListeners(void *args) { viewFrustum.dump(); } - // lock this agent's delete mutex so that the delete thread doesn't - // kill the agent while we are working with it - pthread_mutex_lock(thisAgent->deleteMutex); - stopOctal = NULL; packetCount = 0; totalBytesSent = 0; @@ -226,10 +214,6 @@ void *distributeVoxelsToListeners(void *args) { delete agentData->rootMarkerNode; agentData->rootMarkerNode = new MarkerNode(); } - - // unlock the delete mutex so the other thread can - // kill the agent if it has dissapeared - pthread_mutex_unlock(thisAgent->deleteMutex); } // dynamically sleep until we need to fire off the next set of voxels From 5a0a1c1cecad19a471a94c1af7193d598f663b50 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Thu, 25 Apr 2013 13:51:20 -0700 Subject: [PATCH 08/36] increased YAW_MAG (faster turning), redesigned the concept of avatar position, and reset Eve's position accordingly. Also added _frustumNeedsReshape in camera in anticipation of fixing problem where setting fov doesn't reshape the frustum. --- eve/src/main.cpp | 5 ++--- interface/src/Avatar.cpp | 44 +++++++++++++++++++++++++++++++--------- interface/src/Avatar.h | 3 ++- interface/src/Camera.cpp | 31 ++++++++++++++-------------- interface/src/Camera.h | 9 ++++---- interface/src/main.cpp | 19 +++++++++-------- 6 files changed, 70 insertions(+), 41 deletions(-) diff --git a/eve/src/main.cpp b/eve/src/main.cpp index 2da001b368..b4e6675ca0 100644 --- a/eve/src/main.cpp +++ b/eve/src/main.cpp @@ -113,9 +113,8 @@ int main(int argc, const char* argv[]) { // move eve away from the origin // pick a random point inside a 10x10 grid - eve.setPosition(glm::vec3(randFloatInRange(-RANDOM_POSITION_MAX_DIMENSION, RANDOM_POSITION_MAX_DIMENSION), - 0, - randFloatInRange(-RANDOM_POSITION_MAX_DIMENSION, RANDOM_POSITION_MAX_DIMENSION))); + eve.setPosition(glm::vec3(randFloatInRange(-RANDOM_POSITION_MAX_DIMENSION, RANDOM_POSITION_MAX_DIMENSION), 0.4, + randFloatInRange(-RANDOM_POSITION_MAX_DIMENSION, RANDOM_POSITION_MAX_DIMENSION))); // face any instance of eve down the z-axis eve.setBodyYaw(0); diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index c77efd28b9..fce2af682e 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -59,8 +59,7 @@ Avatar::Avatar(bool isMine) { //_transmitterTimer = 0; _transmitterHz = 0.0; _transmitterPackets = 0; - - initializeSkeleton(); + _pelvisStandingHeight = 0.0f; _TEST_bigSphereRadius = 0.3f; _TEST_bigSpherePosition = glm::vec3( 0.0f, _TEST_bigSphereRadius, 2.0f ); @@ -117,6 +116,8 @@ Avatar::Avatar(bool isMine) { _handHolding.velocity = glm::vec3( 0.0, 0.0, 0.0 ); _handHolding.force = 10.0f; + initializeSkeleton(); + if (iris_texture.size() == 0) { switchToResourcesParentIfRequired(); unsigned error = lodepng::decode(iris_texture, iris_texture_width, iris_texture_height, iris_texture_file); @@ -127,7 +128,6 @@ Avatar::Avatar(bool isMine) { } - Avatar::Avatar(const Avatar &otherAvatar) { _velocity = otherAvatar._velocity; @@ -156,8 +156,6 @@ Avatar::Avatar(const Avatar &otherAvatar) { _orientation.set( otherAvatar._orientation ); _sphere = NULL; - - initializeSkeleton(); for (int i = 0; i < MAX_DRIVE_KEYS; i++) _driveKeys[i] = otherAvatar._driveKeys[i]; @@ -198,6 +196,9 @@ Avatar::Avatar(const Avatar &otherAvatar) { _head.browAudioLift = otherAvatar._head.browAudioLift; _head.noise = otherAvatar._head.noise; + + initializeSkeleton(); + if (iris_texture.size() == 0) { switchToResourcesParentIfRequired(); unsigned error = lodepng::decode(iris_texture, iris_texture_width, iris_texture_height, iris_texture_file); @@ -315,7 +316,7 @@ void Avatar::simulate(float deltaTime) { // check for collisions with other avatars and respond updateAvatarCollisionDetectionAndResponse ( - otherAvatar->getBonePosition( AVATAR_BONE_PELVIS_SPINE ), + otherAvatar->getPosition(), 0.1, 0.1, otherAvatar->getBodyUpDirection(), @@ -327,7 +328,7 @@ void Avatar::simulate(float deltaTime) { v -= otherAvatar->getBonePosition( AVATAR_BONE_RIGHT_HAND ); float distance = glm::length( v ); - if ( distance < _maxArmLength ) { + if ( distance < _maxArmLength + _maxArmLength ) { //if ( distance < closestDistance ) { // perhaps I don't need this if we want to allow multi-avatar interactions { @@ -376,6 +377,19 @@ void Avatar::simulate(float deltaTime) { ); } + if ( AVATAR_GRAVITY ) { + if ( _position.y > _pelvisStandingHeight + 0.01 ) { + _velocity += glm::dvec3( 0.0, -1.0, 0.0 ) * ( 6.0 * deltaTime ); + } + else { + if ( _position.y < _pelvisStandingHeight ) { + _position.y = _pelvisStandingHeight; + _velocity.y = 0.0; + } + } + } + + /* 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 ); @@ -387,6 +401,8 @@ void Avatar::simulate(float deltaTime) { } } } + */ + // update body springs updateBodySprings( deltaTime ); @@ -612,6 +628,7 @@ void Avatar::updateAvatarCollisionDetectionAndResponse void Avatar::render(bool lookingInMirror) { + /* // show avatar position glColor4f( 0.5f, 0.5f, 0.5f, 0.6 ); glPushMatrix(); @@ -619,6 +636,7 @@ void Avatar::render(bool lookingInMirror) { glScalef( 0.03, 0.03, 0.03 ); glutSolidSphere( 1, 10, 10 ); glPopMatrix(); + */ if ( usingBigSphereCollisionTest ) { @@ -884,7 +902,7 @@ void Avatar::initializeSkeleton() { _bone[ AVATAR_BONE_RIGHT_FOOT ].parent = AVATAR_BONE_RIGHT_SHIN; // specify the default pose position - _bone[ AVATAR_BONE_PELVIS_SPINE ].defaultPosePosition = glm::vec3( 0.0, 0.3, 0.0 ); + _bone[ AVATAR_BONE_PELVIS_SPINE ].defaultPosePosition = glm::vec3( 0.0, 0.0, 0.0 ); _bone[ AVATAR_BONE_MID_SPINE ].defaultPosePosition = glm::vec3( 0.0, 0.1, 0.0 ); _bone[ AVATAR_BONE_CHEST_SPINE ].defaultPosePosition = glm::vec3( 0.0, 0.06, 0.0 ); _bone[ AVATAR_BONE_NECK ].defaultPosePosition = glm::vec3( 0.0, 0.06, 0.0 ); @@ -907,8 +925,7 @@ void Avatar::initializeSkeleton() { _bone[ AVATAR_BONE_RIGHT_THIGH ].defaultPosePosition = glm::vec3( 0.0, -0.15, 0.0 ); _bone[ AVATAR_BONE_RIGHT_SHIN ].defaultPosePosition = glm::vec3( 0.0, -0.15, 0.0 ); _bone[ AVATAR_BONE_RIGHT_FOOT ].defaultPosePosition = glm::vec3( 0.0, 0.0, 0.04 ); - - + _bone[ AVATAR_BONE_PELVIS_SPINE ].radius = 0.05; _bone[ AVATAR_BONE_MID_SPINE ].radius = 0.06; _bone[ AVATAR_BONE_CHEST_SPINE ].radius = 0.03; @@ -935,6 +952,13 @@ void Avatar::initializeSkeleton() { // calculate bone length calculateBoneLengths(); + + _pelvisStandingHeight = + _bone[ AVATAR_BONE_PELVIS_SPINE ].length + + _bone[ AVATAR_BONE_LEFT_THIGH ].length + + _bone[ AVATAR_BONE_LEFT_SHIN ].length + + _bone[ AVATAR_BONE_LEFT_FOOT ].length + + _bone[ AVATAR_BONE_RIGHT_FOOT ].radius; // generate world positions updateSkeleton(); diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index 32d31184a8..be20b10389 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -25,7 +25,7 @@ const bool AVATAR_GRAVITY = true; const float DECAY = 0.1; const float THRUST_MAG = 10.0; -const float YAW_MAG = 300.0; +const float YAW_MAG = 500.0; //JJV - changed from 300.0; const float TEST_YAW_DECAY = 5.0; const float LIN_VEL_DECAY = 5.0; @@ -246,6 +246,7 @@ class Avatar : public AvatarData { int _transmitterPackets; Avatar* _interactingOther; bool _interactingOtherIsNearby; + float _pelvisStandingHeight; // private methods... void initializeSkeleton(); diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index b251e1f5a5..ce3542b217 100644 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -11,21 +11,22 @@ #include "Camera.h" Camera::Camera() { - _mode = CAMERA_MODE_THIRD_PERSON; - _tightness = 10.0; // default - _fieldOfView = 60.0; // default - _nearClip = 0.08; // default - _farClip = 50.0; // default - _yaw = 0.0; - _pitch = 0.0; - _roll = 0.0; - _upShift = 0.0; - _rightShift = 0.0; - _distance = 0.0; - _idealYaw = 0.0; - _targetPosition = glm::vec3( 0.0, 0.0, 0.0 ); - _position = glm::vec3( 0.0, 0.0, 0.0 ); - _idealPosition = glm::vec3( 0.0, 0.0, 0.0 ); + _frustumNeedsReshape = false; + _mode = CAMERA_MODE_THIRD_PERSON; + _tightness = 10.0; // default + _fieldOfView = 60.0; // default + _nearClip = 0.08; // default + _farClip = 50.0; // default + _yaw = 0.0; + _pitch = 0.0; + _roll = 0.0; + _upShift = 0.0; + _rightShift = 0.0; + _distance = 0.0; + _idealYaw = 0.0; + _targetPosition = glm::vec3( 0.0, 0.0, 0.0 ); + _position = glm::vec3( 0.0, 0.0, 0.0 ); + _idealPosition = glm::vec3( 0.0, 0.0, 0.0 ); _orientation.setToIdentity(); } diff --git a/interface/src/Camera.h b/interface/src/Camera.h index befb5d0826..41ee21c7f0 100644 --- a/interface/src/Camera.h +++ b/interface/src/Camera.h @@ -39,10 +39,10 @@ public: void setPosition ( glm::vec3 p ) { _position = p; } void setOrientation ( Orientation o ) { _orientation.set(o); } void setTightness ( float t ) { _tightness = t; } - void setFieldOfView ( float f ) { _fieldOfView = f; } - void setAspectRatio ( float a ) { _aspectRatio = a; } - void setNearClip ( float n ) { _nearClip = n; } - void setFarClip ( float f ) { _farClip = f; } + void setFieldOfView ( float f ) { _fieldOfView = f; _frustumNeedsReshape = true; } + void setAspectRatio ( float a ) { _aspectRatio = a; _frustumNeedsReshape = true; } + void setNearClip ( float n ) { _nearClip = n; _frustumNeedsReshape = true; } + void setFarClip ( float f ) { _farClip = f; _frustumNeedsReshape = true; } float getYaw () { return _yaw; } float getPitch () { return _pitch; } @@ -57,6 +57,7 @@ public: private: + bool _frustumNeedsReshape; CameraMode _mode; glm::vec3 _position; glm::vec3 _idealPosition; diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 255b541c30..e0d014d840 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -810,6 +810,7 @@ void display(void) myCamera.setUpShift ( 0.0 ); myCamera.setDistance ( 0.2 ); myCamera.setTightness ( 100.0f ); + myCamera.setFieldOfView ( 60.0f ); //this doesn't seem to be doing anything? myCamera.update ( 1.f/FPS ); } else { @@ -817,15 +818,17 @@ void display(void) bool firstPerson = false; if ( firstPerson ) { - myCamera.setPitch (15.0f ); // temporarily, this must be 0.0 or else bad juju - myCamera.setUpShift (0.0f ); - myCamera.setDistance (0.0f ); - myCamera.setTightness (100.0f); + myCamera.setPitch (15.0f ); // temporarily, this must be 0.0 or else bad juju + myCamera.setUpShift (0.0f ); + myCamera.setDistance (0.0f ); + myCamera.setTightness (100.0f); + myCamera.setFieldOfView(60.0f ); //this doesn't seem to be doing anything? } else { - myCamera.setPitch (0.0f ); // temporarily, this must be 0.0 or else bad juju - myCamera.setUpShift (-0.1f); - myCamera.setDistance (1.0f ); - myCamera.setTightness (8.0f ); + myCamera.setPitch (0.0f ); // temporarily, this must be 0.0 or else bad juju + myCamera.setUpShift (-0.1f); + myCamera.setDistance (1.0f ); + myCamera.setTightness (8.0f ); + myCamera.setFieldOfView(60.0f); //this doesn't seem to be doing anything? } myCamera.setTargetPosition( myAvatar.getHeadPosition() ); From 7a0ed469b8415b1551acef80835610fc9918d161 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Thu, 25 Apr 2013 14:25:28 -0700 Subject: [PATCH 09/36] added methods to camera class to check for when the view frustum needs to be reshaped (but the calls are not yet being made - need to make sure the right place to use it) --- interface/src/Camera.cpp | 12 ++++++++++++ interface/src/Camera.h | 2 ++ interface/src/main.cpp | 2 -- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index ce3542b217..1a4700216a 100644 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -63,3 +63,15 @@ void Camera::update( float deltaTime ) { _position += ( _idealPosition - _position ) * t; } +// call to find out if the view frustum needs to be reshaped +bool Camera::getFrustumNeedsReshape() { + return _frustumNeedsReshape; +} + +// call this after reshaping the view frustum +void Camera::setFrustumWasReshaped() { + _frustumNeedsReshape = false; +} + + + diff --git a/interface/src/Camera.h b/interface/src/Camera.h index 41ee21c7f0..1826bb2c1f 100644 --- a/interface/src/Camera.h +++ b/interface/src/Camera.h @@ -54,6 +54,8 @@ public: float getAspectRatio() { return _aspectRatio; } float getNearClip () { return _nearClip; } float getFarClip () { return _farClip; } + bool getFrustumNeedsReshape(); // call to find out if the view frustum needs to be reshaped + void setFrustumWasReshaped(); // call this after reshaping the view frustum. private: diff --git a/interface/src/main.cpp b/interface/src/main.cpp index e0d014d840..080db4fe92 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -240,8 +240,6 @@ void updateHandController( int x, int y ) { handController.startX = WIDTH / 2; handController.startY = HEIGHT / 2; handController.envelope = 0.0; -//prototype -//myAvatar.stopHandMovement(); } } } From 2850d74a8428ae319b0ea2d86fee82c5b4ec9cc3 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 25 Apr 2013 14:48:07 -0700 Subject: [PATCH 10/36] add typedefs for stl iterator implementation --- interface/src/Head.cpp | 2 +- interface/src/main.cpp | 6 ++-- libraries/shared/src/AgentList.cpp | 50 +++++++++++++++++------------- libraries/shared/src/AgentList.h | 11 ++++++- 4 files changed, 43 insertions(+), 26 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index ac44e3e530..c4511659df 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -309,7 +309,7 @@ void Head::simulate(float deltaTime) { //_numOtherAvatars = 0; - for(AgentListIterator agent = agentList->begin(); + for(AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { if ((*agent).getLinkedData() != NULL && (*agent).getType() == AGENT_TYPE_AVATAR) { diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 0ede2ed23b..20e6c05491 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -907,7 +907,7 @@ void display(void) // Render avatars of other agents AgentList *agentList = AgentList::getInstance(); - for(AgentListIterator agent = agentList->begin(); + for(AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { if ((*agent).getLinkedData() != NULL && (*agent).getType() == AGENT_TYPE_AVATAR) { @@ -983,7 +983,7 @@ void display(void) AgentList *agentList = AgentList::getInstance(); int totalAvatars = 0, totalServers = 0; - for (AgentListIterator agent = agentList->begin(); agent != agentList->end(); agent++) { + for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { (*agent).getType() == AGENT_TYPE_AVATAR ? totalAvatars++ : totalServers++; } @@ -1490,7 +1490,7 @@ void idle(void) { //loop through all the other avatars and simulate them... AgentList * agentList = AgentList::getInstance(); - for(AgentListIterator agent = agentList->begin(); agent != agentList->end(); agent++) { + for(AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { if ((*agent).getLinkedData() != NULL) { Head *avatar = (Head *)(*agent).getLinkedData(); avatar->simulate(deltaTime); diff --git a/libraries/shared/src/AgentList.cpp b/libraries/shared/src/AgentList.cpp index 809ee2af03..3ba79c4719 100644 --- a/libraries/shared/src/AgentList.cpp +++ b/libraries/shared/src/AgentList.cpp @@ -172,7 +172,7 @@ int AgentList::updateAgentWithData(Agent *agent, unsigned char *packetData, int } Agent* AgentList::agentWithAddress(sockaddr *senderAddress) { - for(AgentListIterator agent = begin(); agent != end(); agent++) { + for(AgentList::iterator agent = begin(); agent != end(); agent++) { if ((*agent).getActiveSocket() != NULL && socketMatch((*agent).getActiveSocket(), senderAddress)) { return &*agent; } @@ -182,7 +182,7 @@ Agent* AgentList::agentWithAddress(sockaddr *senderAddress) { } Agent* AgentList::agentWithID(uint16_t agentID) { - for(AgentListIterator agent = begin(); agent != end(); agent++) { + for(AgentList::iterator agent = begin(); agent != end(); agent++) { if ((*agent).getAgentId() == agentID) { return &*agent; } @@ -227,7 +227,7 @@ int AgentList::updateList(unsigned char *packetData, size_t dataBytes) { } bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket, char agentType, uint16_t agentId) { - AgentListIterator agent = end(); + AgentList::iterator agent = end(); if (publicSocket != NULL) { for (agent = begin(); agent != end(); agent++) { @@ -291,7 +291,7 @@ void AgentList::addAgentToList(Agent* newAgent) { } void AgentList::broadcastToAgents(unsigned char *broadcastData, size_t dataBytes, const char* agentTypes, int numAgentTypes) { - for(AgentListIterator agent = begin(); agent != end(); agent++) { + for(AgentList::iterator agent = begin(); agent != end(); agent++) { // only send to the AgentTypes we are asked to send to. if ((*agent).getActiveSocket() != NULL && memchr(agentTypes, (*agent).getType(), numAgentTypes)) { // we know which socket is good for this agent, send there @@ -301,7 +301,7 @@ void AgentList::broadcastToAgents(unsigned char *broadcastData, size_t dataBytes } void AgentList::handlePingReply(sockaddr *agentAddress) { - for(AgentListIterator agent = begin(); agent != end(); agent++) { + for(AgentList::iterator agent = begin(); agent != end(); agent++) { // check both the public and local addresses for each agent to see if we find a match // prioritize the private address so that we prune erroneous local matches if (socketMatch((*agent).getPublicSocket(), agentAddress)) { @@ -316,7 +316,7 @@ void AgentList::handlePingReply(sockaddr *agentAddress) { Agent* AgentList::soloAgentOfType(char agentType) { if (memchr(SOLO_AGENT_TYPES, agentType, sizeof(SOLO_AGENT_TYPES)) != NULL) { - for(AgentListIterator agent = begin(); agent != end(); agent++) { + for(AgentList::iterator agent = begin(); agent != end(); agent++) { if ((*agent).getType() == agentType) { return &*agent; } @@ -336,7 +336,7 @@ void *pingUnknownAgents(void *args) { while (!pingUnknownAgentThreadStopFlag) { gettimeofday(&lastSend, NULL); - for(AgentListIterator agent = agentList->begin(); + for(AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { if ((*agent).getActiveSocket() == NULL @@ -374,7 +374,7 @@ void *removeSilentAgents(void *args) { while (!silentAgentThreadStopFlag) { checkTimeUSecs = usecTimestampNow(); - for(AgentListIterator agent = agentList->begin(); agent != agentList->end(); agent++) { + for(AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { if ((checkTimeUSecs - (*agent).getLastRecvTimeUsecs()) > AGENT_SILENCE_THRESHOLD_USECS && (*agent).getType() != AGENT_TYPE_VOXEL) { @@ -463,7 +463,7 @@ void AgentList::stopDomainServerCheckInThread() { pthread_join(checkInWithDomainServerThread, NULL); } -AgentListIterator AgentList::begin() const { +AgentList::iterator AgentList::begin() const { Agent** agentBucket = NULL; for (int i = 0; i < _numAgents; i++) { @@ -479,7 +479,7 @@ AgentListIterator AgentList::begin() const { return AgentListIterator(this, 0); } -AgentListIterator AgentList::end() const { +AgentList::iterator AgentList::end() const { Agent** agentBucket = _agentBuckets[(_numAgents - 1) / AGENTS_PER_BUCKET]; for (int i = _numAgents - 1; i >= 0; i--) { @@ -520,17 +520,25 @@ Agent& AgentListIterator::operator*() { } AgentListIterator& AgentListIterator::operator++() { - if (*this != _agentList->end()) { - ++_agentIndex; - } - - return (*this); + skipDeadAndStopIncrement(); + return *this; } -AgentListIterator& AgentListIterator::operator++(int) { - if (*this != _agentList->end()) { - ++_agentIndex; - } - - return (*this); +AgentList::iterator AgentListIterator::operator++(int) { + AgentListIterator newIterator = AgentListIterator(*this); + skipDeadAndStopIncrement(); + return newIterator; +} + +void AgentListIterator::skipDeadAndStopIncrement() { + while (*this != _agentList->end()) { + ++_agentIndex; + + if (*this == _agentList->end()) { + break; + } else if ((*(*this)).isAlive()) { + // skip over the dead agents + break; + } + } } diff --git a/libraries/shared/src/AgentList.h b/libraries/shared/src/AgentList.h index 8ac1e984c3..09d69681e3 100644 --- a/libraries/shared/src/AgentList.h +++ b/libraries/shared/src/AgentList.h @@ -37,6 +37,13 @@ class AgentList { public: static AgentList* createInstance(char ownerType, unsigned int socketListenPort = AGENT_SOCKET_LISTEN_PORT); static AgentList* getInstance(); + + typedef AgentListIterator iterator; + typedef ptrdiff_t difference_type; + typedef size_t size_type; + typedef Agent value_type; + typedef Agent * pointer; + typedef Agent & reference; AgentListIterator begin() const; AgentListIterator end() const; @@ -114,8 +121,10 @@ public: Agent& operator*(); AgentListIterator& operator++(); - AgentListIterator& operator++(int); + AgentListIterator operator++(int); private: + void skipDeadAndStopIncrement(); + const AgentList* _agentList; int _agentIndex; }; From ad530b4eb8cd08d36bfb58f63998cd29d822ab30 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 25 Apr 2013 15:10:08 -0700 Subject: [PATCH 11/36] fix bug based on dynamic end of agentList iterator --- libraries/shared/src/AgentList.cpp | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/libraries/shared/src/AgentList.cpp b/libraries/shared/src/AgentList.cpp index 3ba79c4719..dc46558766 100644 --- a/libraries/shared/src/AgentList.cpp +++ b/libraries/shared/src/AgentList.cpp @@ -37,7 +37,6 @@ const int DOMAINSERVER_PORT = 40102; bool silentAgentThreadStopFlag = false; bool domainServerCheckinStopFlag = false; bool pingUnknownAgentThreadStopFlag = false; -pthread_mutex_t vectorChangeMutex = PTHREAD_MUTEX_INITIALIZER; AgentList* AgentList::_sharedInstance = NULL; @@ -374,7 +373,7 @@ void *removeSilentAgents(void *args) { while (!silentAgentThreadStopFlag) { checkTimeUSecs = usecTimestampNow(); - for(AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { + for(AgentList::iterator agent = agentList->begin(); agent != agentList->end(); ++agent) { if ((checkTimeUSecs - (*agent).getLastRecvTimeUsecs()) > AGENT_SILENCE_THRESHOLD_USECS && (*agent).getType() != AGENT_TYPE_VOXEL) { @@ -383,8 +382,6 @@ void *removeSilentAgents(void *args) { Agent::printLog(*agent); (*agent).setAlive(false); - } else { - agent++; } } @@ -480,30 +477,18 @@ AgentList::iterator AgentList::begin() const { } AgentList::iterator AgentList::end() const { - Agent** agentBucket = _agentBuckets[(_numAgents - 1) / AGENTS_PER_BUCKET]; - - for (int i = _numAgents - 1; i >= 0; i--) { - if (i % AGENTS_PER_BUCKET == 0) { - agentBucket = _agentBuckets[i / AGENTS_PER_BUCKET]; - } - - if (agentBucket[i % AGENTS_PER_BUCKET]->isAlive()) { - return AgentListIterator(this, i + 1); - } - } - - return AgentListIterator(this, 0); + return AgentListIterator(this, _numAgents); } AgentListIterator::AgentListIterator(const AgentList* agentList, int agentIndex) : -_agentIndex(agentIndex) { + _agentIndex(agentIndex) { _agentList = agentList; } AgentListIterator& AgentListIterator::operator=(const AgentListIterator& otherValue) { _agentList = otherValue._agentList; _agentIndex = otherValue._agentIndex; - return (*this); + return *this; } bool AgentListIterator::operator==(const AgentListIterator &otherValue) { @@ -531,10 +516,10 @@ AgentList::iterator AgentListIterator::operator++(int) { } void AgentListIterator::skipDeadAndStopIncrement() { - while (*this != _agentList->end()) { + while (_agentIndex != _agentList->_numAgents) { ++_agentIndex; - if (*this == _agentList->end()) { + if (_agentIndex == _agentList->_numAgents) { break; } else if ((*(*this)).isAlive()) { // skip over the dead agents From f86704fa94114a22c3831b4bf0af3f68868cd0a3 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 25 Apr 2013 15:21:44 -0700 Subject: [PATCH 12/36] update avatar-mixer to use new AgentList iterator --- avatar-mixer/src/main.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/avatar-mixer/src/main.cpp b/avatar-mixer/src/main.cpp index 1d446f40f4..e9fbda89df 100644 --- a/avatar-mixer/src/main.cpp +++ b/avatar-mixer/src/main.cpp @@ -83,11 +83,11 @@ int main(int argc, char* argv[]) agentIndex = 0; // send back a packet with other active agent data to this agent - for (std::vector::iterator avatarAgent = agentList->getAgents().begin(); - avatarAgent != agentList->getAgents().end(); + for (AgentList::iterator avatarAgent = agentList->begin(); + avatarAgent != agentList->end(); avatarAgent++) { - if (avatarAgent->getLinkedData() != NULL - && agentIndex != agentList->indexOfMatchingAgent(agentAddress)) { + if ((*avatarAgent).getLinkedData() != NULL + && !socketMatch(agentAddress, (*avatarAgent).getActiveSocket())) { currentBufferPosition = addAgentToBroadcastPacket(currentBufferPosition, &*avatarAgent); } From ef6593eb893d5cbff0c1d1cdc5172e5c70080ff0 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 25 Apr 2013 15:21:56 -0700 Subject: [PATCH 13/36] update audio-mixer to use new AgentList iterator --- audio-mixer/src/main.cpp | 32 +++++++++++++++----------------- libraries/shared/src/AgentList.h | 2 ++ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index 0d571d1c74..a3e50b4901 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -85,16 +85,16 @@ void *sendBuffer(void *args) while (true) { sentBytes = 0; - for (int i = 0; i < agentList->getAgents().size(); i++) { - AudioRingBuffer *agentBuffer = (AudioRingBuffer *) agentList->getAgents()[i].getLinkedData(); + for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { + AudioRingBuffer *agentBuffer = (AudioRingBuffer *)(*agent).getLinkedData(); if (agentBuffer != NULL && agentBuffer->getEndOfLastWrite() != NULL) { if (!agentBuffer->isStarted() && agentBuffer->diffLastWriteNextOutput() <= BUFFER_LENGTH_SAMPLES_PER_CHANNEL + JITTER_BUFFER_SAMPLES) { - printf("Held back buffer %d.\n", i); + printf("Held back buffer for agent with ID %d.\n", (*agent).getAgentId()); } else if (agentBuffer->diffLastWriteNextOutput() < BUFFER_LENGTH_SAMPLES_PER_CHANNEL) { - printf("Buffer %d starved.\n", i); + printf("Buffer from agent with ID %d starved.\n", (*agent).getAgentId()); agentBuffer->setStarted(false); } else { // good buffer, add this to the mix @@ -104,14 +104,12 @@ void *sendBuffer(void *args) } } - int numAgents = agentList->getAgents().size(); + int numAgents = agentList->size(); float distanceCoeffs[numAgents][numAgents]; memset(distanceCoeffs, 0, sizeof(distanceCoeffs)); - for (int i = 0; i < agentList->getAgents().size(); i++) { - Agent *agent = &agentList->getAgents()[i]; - - AudioRingBuffer *agentRingBuffer = (AudioRingBuffer *) agent->getLinkedData(); + for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { + AudioRingBuffer *agentRingBuffer = (AudioRingBuffer *)(*agent).getLinkedData(); float agentBearing = agentRingBuffer->getBearing(); bool agentWantsLoopback = false; @@ -128,9 +126,9 @@ void *sendBuffer(void *args) int16_t clientMix[BUFFER_LENGTH_SAMPLES_PER_CHANNEL * 2] = {}; - for (int j = 0; j < agentList->getAgents().size(); j++) { - if (i != j || ( i == j && agentWantsLoopback)) { - AudioRingBuffer *otherAgentBuffer = (AudioRingBuffer *)agentList->getAgents()[j].getLinkedData(); + for (AgentList::iterator otherAgent = agentList->begin(); agent != agentList->end(); agent++) { + if (otherAgent != agent || ( otherAgent == agent && agentWantsLoopback)) { + AudioRingBuffer *otherAgentBuffer = (AudioRingBuffer *)(*otherAgent).getLinkedData(); float *agentPosition = agentRingBuffer->getPosition(); float *otherAgentPosition = otherAgentBuffer->getPosition(); @@ -138,8 +136,8 @@ void *sendBuffer(void *args) // calculate the distance to the other agent // use the distance to the other agent to calculate the change in volume for this frame - int lowAgentIndex = std::min(i, j); - int highAgentIndex = std::max(i, j); + int lowAgentIndex = std::min(agent.getAgentIndex(), otherAgent.getAgentIndex()); + int highAgentIndex = std::max(agent.getAgentIndex(), otherAgent.getAgentIndex()); if (distanceCoeffs[lowAgentIndex][highAgentIndex] == 0) { float distanceToAgent = sqrtf(powf(agentPosition[0] - otherAgentPosition[0], 2) + @@ -220,11 +218,11 @@ void *sendBuffer(void *args) } } - agentList->getAgentSocket().send(agent->getPublicSocket(), clientMix, BUFFER_LENGTH_BYTES); + agentList->getAgentSocket().send((*agent).getPublicSocket(), clientMix, BUFFER_LENGTH_BYTES); } - for (int i = 0; i < agentList->getAgents().size(); i++) { - AudioRingBuffer *agentBuffer = (AudioRingBuffer *)agentList->getAgents()[i].getLinkedData(); + for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { + AudioRingBuffer *agentBuffer = (AudioRingBuffer *)(*agent).getLinkedData(); if (agentBuffer->wasAddedToMix()) { agentBuffer->setNextOutput(agentBuffer->getNextOutput() + BUFFER_LENGTH_SAMPLES_PER_CHANNEL); diff --git a/libraries/shared/src/AgentList.h b/libraries/shared/src/AgentList.h index 09d69681e3..c94b69131c 100644 --- a/libraries/shared/src/AgentList.h +++ b/libraries/shared/src/AgentList.h @@ -113,6 +113,8 @@ public: AgentListIterator(const AgentList* agentList, int agentIndex); ~AgentListIterator() {}; + int getAgentIndex() { return _agentIndex; }; + AgentListIterator& operator=(const AgentListIterator& otherValue); bool operator==(const AgentListIterator& otherValue); From 88eca950208999895609f36a483bb74bbf9c20d3 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 25 Apr 2013 15:24:36 -0700 Subject: [PATCH 14/36] fix domain-server to use new AgentList iterator --- domain-server/src/main.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/domain-server/src/main.cpp b/domain-server/src/main.cpp index 52631a3c25..2126d8e561 100644 --- a/domain-server/src/main.cpp +++ b/domain-server/src/main.cpp @@ -49,7 +49,7 @@ const int LOGOFF_CHECK_INTERVAL = 5000; int lastActiveCount = 0; -unsigned char * addAgentToBroadcastPacket(unsigned char *currentPosition, Agent *agentToAdd) { +unsigned char* addAgentToBroadcastPacket(unsigned char* currentPosition, Agent* agentToAdd) { *currentPosition++ = agentToAdd->getType(); currentPosition += packAgentId(currentPosition, agentToAdd->getAgentId()); @@ -127,30 +127,30 @@ int main(int argc, const char * argv[]) currentBufferPos = broadcastPacket + 1; startPointer = currentBufferPos; - for(std::vector::iterator agent = agentList->getAgents().begin(); - agent != agentList->getAgents().end(); + for(AgentList::iterator agent = agentList->begin(); + agent != agentList->end(); agent++) { if (DEBUG_TO_SELF || - !agent->matches((sockaddr *)&agentPublicAddress, (sockaddr *)&agentLocalAddress, agentType)) { - if (memchr(SOLO_AGENT_TYPES, agent->getType(), sizeof(SOLO_AGENT_TYPES)) == NULL) { + !(*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 - if (agentType != AGENT_TYPE_AVATAR || agent->getType() != AGENT_TYPE_AVATAR) { + if (agentType != AGENT_TYPE_AVATAR || (*agent).getType() != AGENT_TYPE_AVATAR) { currentBufferPos = addAgentToBroadcastPacket(currentBufferPos, &(*agent)); } } else { // solo agent, we need to only send newest - if (newestSoloAgents[agent->getType()] == NULL || - newestSoloAgents[agent->getType()]->getFirstRecvTimeUsecs() < agent->getFirstRecvTimeUsecs()) { + if (newestSoloAgents[(*agent).getType()] == NULL || + newestSoloAgents[(*agent).getType()]->getFirstRecvTimeUsecs() < (*agent).getFirstRecvTimeUsecs()) { // we have to set the newer solo agent to add it to the broadcast later - newestSoloAgents[agent->getType()] = &(*agent); + newestSoloAgents[(*agent).getType()] = &(*agent); } } } else { // this is the agent, just update last receive to now - agent->setLastRecvTimeUsecs(usecTimestampNow()); + (*agent).setLastRecvTimeUsecs(usecTimestampNow()); } } From 89da132bf254718367bdacbabbf1f36fe8b908bd Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 25 Apr 2013 15:26:21 -0700 Subject: [PATCH 15/36] update voxel-server to use new AgentList iterator --- voxel-server/src/main.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/voxel-server/src/main.cpp b/voxel-server/src/main.cpp index 572963b94e..91e91d81a7 100644 --- a/voxel-server/src/main.cpp +++ b/voxel-server/src/main.cpp @@ -122,12 +122,12 @@ void eraseVoxelTreeAndCleanupAgentVisitData() { ::randomTree.eraseAllVoxels(); // enumerate the agents clean up their marker nodes - for (int i = 0; i < AgentList::getInstance()->getAgents().size(); i++) { + + for (AgentList::iterator agent = AgentList::getInstance()->begin(); agent != AgentList::getInstance()->end(); agent++) { //printf("eraseVoxelTreeAndCleanupAgentVisitData() agent[%d]\n",i); - Agent *thisAgent = (Agent *)&AgentList::getInstance()->getAgents()[i]; - VoxelAgentData *agentData = (VoxelAgentData *)(thisAgent->getLinkedData()); + VoxelAgentData *agentData = (VoxelAgentData *)(*agent).getLinkedData(); // clean up the agent visit data delete agentData->rootMarkerNode; @@ -154,10 +154,8 @@ void *distributeVoxelsToListeners(void *args) { gettimeofday(&lastSendTime, NULL); // enumerate the agents to send 3 packets to each - for (int i = 0; i < agentList->getAgents().size(); i++) { - - Agent *thisAgent = (Agent *)&agentList->getAgents()[i]; - VoxelAgentData *agentData = (VoxelAgentData *)(thisAgent->getLinkedData()); + for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { + VoxelAgentData *agentData = (VoxelAgentData *)(*agent).getLinkedData(); ViewFrustum viewFrustum; // get position and orientation details from the camera @@ -193,7 +191,7 @@ void *distributeVoxelsToListeners(void *args) { ::viewFrustumCulling, stopOctal); - agentList->getAgentSocket().send(thisAgent->getActiveSocket(), voxelPacket, voxelPacketEnd - voxelPacket); + agentList->getAgentSocket().send((*agent).getActiveSocket(), voxelPacket, voxelPacketEnd - voxelPacket); packetCount++; totalBytesSent += voxelPacketEnd - voxelPacket; From dac660efda7b869e4f874cdc67698d05c4d6efd2 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 25 Apr 2013 15:30:57 -0700 Subject: [PATCH 16/36] resolve conflicts after merge with upstream master --- interface/src/Avatar.cpp | 477 +++++++++++++++++++-------------------- interface/src/main.cpp | 4 +- 2 files changed, 239 insertions(+), 242 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 3c23cf32cd..c5364c0029 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -3,7 +3,7 @@ // interface // // Created by Philip Rosedale on 9/11/12. -// adapted by Jeffrey Ventrella +// adapted by Jeffrey Ventrella // Copyright (c) 2012 Physical, Inc.. All rights reserved. // @@ -47,7 +47,7 @@ Avatar::Avatar(bool isMine) { _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 ); + _rotation = glm::quat( 0.0f, 0.0f, 0.0f, 0.0f ); _bodyYaw = -90.0; _bodyPitch = 0.0; _bodyRoll = 0.0; @@ -59,13 +59,13 @@ Avatar::Avatar(bool isMine) { //_transmitterTimer = 0; _transmitterHz = 0.0; _transmitterPackets = 0; - + initializeSkeleton(); _TEST_bigSphereRadius = 0.3f; _TEST_bigSpherePosition = glm::vec3( 0.0f, _TEST_bigSphereRadius, 2.0f ); - for (int i = 0; i < MAX_DRIVE_KEYS; i++) _driveKeys[i] = false; + for (int i = 0; i < MAX_DRIVE_KEYS; i++) _driveKeys[i] = false; _head.pupilSize = 0.10; _head.interPupilDistance = 0.6; @@ -84,13 +84,13 @@ Avatar::Avatar(bool isMine) { _head.mouthHeight = 0.2; _head.eyeballPitch[0] = 0; _head.eyeballPitch[1] = 0; - _head.eyeballScaleX = 1.2; - _head.eyeballScaleY = 1.5; + _head.eyeballScaleX = 1.2; + _head.eyeballScaleY = 1.5; _head.eyeballScaleZ = 1.0; _head.eyeballYaw[0] = 0; _head.eyeballYaw[1] = 0; _head.pitchTarget = 0; - _head.yawTarget = 0; + _head.yawTarget = 0; _head.noiseEnvelope = 1.0; _head.pupilConverge = 10.0; _head.leanForward = 0.0; @@ -129,7 +129,7 @@ Avatar::Avatar(bool isMine) { Avatar::Avatar(const Avatar &otherAvatar) { - + _velocity = otherAvatar._velocity; _thrust = otherAvatar._thrust; _rotation = otherAvatar._rotation; @@ -152,15 +152,15 @@ Avatar::Avatar(const Avatar &otherAvatar) { _movedHandOffset = otherAvatar._movedHandOffset; _usingBodySprings = otherAvatar._usingBodySprings; _springForce = otherAvatar._springForce; - _springVelocityDecay = otherAvatar._springVelocityDecay; + _springVelocityDecay = otherAvatar._springVelocityDecay; _orientation.set( otherAvatar._orientation ); - + _sphere = NULL; - + initializeSkeleton(); for (int i = 0; i < MAX_DRIVE_KEYS; i++) _driveKeys[i] = otherAvatar._driveKeys[i]; - + _head.pupilSize = otherAvatar._head.pupilSize; _head.interPupilDistance = otherAvatar._head.interPupilDistance; _head.interBrowDistance = otherAvatar._head.interBrowDistance; @@ -223,7 +223,7 @@ void Avatar::reset() { } -//this pertains to moving the head with the glasses +//this pertains to moving the head with the glasses void Avatar::UpdateGyros(float frametime, SerialInterface * serialInterface, glm::vec3 * gravity) // Using serial data, update avatar/render position and angles { @@ -232,14 +232,14 @@ void Avatar::UpdateGyros(float frametime, SerialInterface * serialInterface, glm float measured_pitch_rate = serialInterface->getRelativeValue(HEAD_PITCH_RATE); _head.yawRate = serialInterface->getRelativeValue(HEAD_YAW_RATE); float measured_lateral_accel = serialInterface->getRelativeValue(ACCEL_X) - - ROLL_ACCEL_COUPLING*serialInterface->getRelativeValue(HEAD_ROLL_RATE); + ROLL_ACCEL_COUPLING*serialInterface->getRelativeValue(HEAD_ROLL_RATE); float measured_fwd_accel = serialInterface->getRelativeValue(ACCEL_Z) - - PITCH_ACCEL_COUPLING*serialInterface->getRelativeValue(HEAD_PITCH_RATE); + PITCH_ACCEL_COUPLING*serialInterface->getRelativeValue(HEAD_PITCH_RATE); float measured_roll_rate = serialInterface->getRelativeValue(HEAD_ROLL_RATE); - - //printLog("Pitch Rate: %d ACCEL_Z: %d\n", serialInterface->getRelativeValue(PITCH_RATE), + + //printLog("Pitch Rate: %d ACCEL_Z: %d\n", serialInterface->getRelativeValue(PITCH_RATE), // serialInterface->getRelativeValue(ACCEL_Z)); - //printLog("Pitch Rate: %d ACCEL_X: %d\n", serialInterface->getRelativeValue(PITCH_RATE), + //printLog("Pitch Rate: %d ACCEL_X: %d\n", serialInterface->getRelativeValue(PITCH_RATE), // serialInterface->getRelativeValue(ACCEL_Z)); //printLog("Pitch: %f\n", Pitch); @@ -251,12 +251,12 @@ void Avatar::UpdateGyros(float frametime, SerialInterface * serialInterface, glm const float MIN_PITCH = -45; const float MAX_YAW = 85; const float MIN_YAW = -85; - + if ((_headPitch < MAX_PITCH) && (_headPitch > 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)) addHeadYaw(_head.yawRate * HEAD_ROTATION_SCALE * frametime); @@ -264,7 +264,7 @@ void Avatar::UpdateGyros(float frametime, SerialInterface * serialInterface, glm } void Avatar::addLean(float x, float z) { - // Add Body lean as impulse + // Add Body lean as impulse _head.leanSideways += x; _head.leanForward += z; } @@ -283,72 +283,70 @@ void Avatar::setMousePressed( bool d ) { } void Avatar::simulate(float deltaTime) { - + // update avatar skeleton updateSkeleton(); // reset hand and arm positions according to hand movement updateHandMovement( deltaTime ); - + if ( !_interactingOtherIsNearby ) { //initialize _handHolding _handHolding.position = _bone[ AVATAR_BONE_RIGHT_HAND ].position; _handHolding.velocity = glm::vec3( 0.0, 0.0, 0.0 ); } - + _interactingOtherIsNearby = false; // if the avatar being simulated is mine, then loop through - // all the other avatars to get information about them... - //------------------------------------------------------------- - if ( _isMine ) { - _nearOtherAvatar = false; + // all the other avatars for potential interactions... + if ( _isMine ) + { float closestDistance = 10000.0f; - AgentList* agentList = AgentList::getInstance(); + AgentList * agentList = AgentList::getInstance(); - //_numOtherAvatars = 0; - for(AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { + if ((*agent).getLinkedData() != NULL && (*agent).getType() == AGENT_TYPE_AVATAR) { - Head *otherAvatar = (Head *)(*agent).getLinkedData(); + Avatar *otherAvatar = (Avatar *)(*agent).getLinkedData(); - // check for collisions with other avatars and respond + // check for collisions with other avatars and respond updateAvatarCollisionDetectionAndResponse ( - otherAvatar->getBonePosition( AVATAR_BONE_PELVIS_SPINE ), - 0.2, - 0.2, - otherAvatar->getBodyUpDirection(), - deltaTime - ); + otherAvatar->getBonePosition( AVATAR_BONE_PELVIS_SPINE ), + 0.2, + 0.2, + otherAvatar->getBodyUpDirection(), + deltaTime + ); - // test other avatar hand position for proximity + // test other avatar hand position for proximity glm::vec3 v( _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position ); v -= otherAvatar->getBonePosition( AVATAR_BONE_RIGHT_HAND ); float distance = glm::length( v ); if ( distance < _maxArmLength ) { - + //if ( distance < closestDistance ) { // perhaps I don't need this if we want to allow multi-avatar interactions { closestDistance = distance; _interactingOther = otherAvatar; _interactingOtherIsNearby = true; - // if I am holding hands with another avatar, a force is applied + // if I am holding hands with another avatar, a force is applied if (( _handState == 1 ) || ( _interactingOther->_handState == 1 )) { glm::vec3 vectorToOtherHand = _interactingOther->_handPosition - _handHolding.position; glm::vec3 vectorToMyHand = _bone[ AVATAR_BONE_RIGHT_HAND ].position - _handHolding.position; _handHolding.velocity *= 0.7; - _handHolding.velocity += ( vectorToOtherHand + vectorToMyHand ) * _handHolding.force * deltaTime; + _handHolding.velocity += ( vectorToOtherHand + vectorToMyHand ) * _handHolding.force * deltaTime; _handHolding.position += _handHolding.velocity; - _bone[ AVATAR_BONE_RIGHT_HAND ].position = _handHolding.position; - } + _bone[ AVATAR_BONE_RIGHT_HAND ].position = _handHolding.position; + } } } } @@ -361,22 +359,22 @@ void Avatar::simulate(float deltaTime) { updateArmIKAndConstraints( deltaTime ); - + if (!_interactingOtherIsNearby) { _interactingOther = NULL; } - + if ( usingBigSphereCollisionTest ) { - + // test for avatar collision response (using a big sphere :) updateAvatarCollisionDetectionAndResponse ( - _TEST_bigSpherePosition, - _TEST_bigSphereRadius, - _TEST_bigSphereRadius, - glm::vec3( 0.0, 1.0, 0.0 ), - deltaTime - ); + _TEST_bigSpherePosition, + _TEST_bigSphereRadius, + _TEST_bigSphereRadius, + glm::vec3( 0.0, 1.0, 0.0 ), + deltaTime + ); } if ( AVATAR_GRAVITY ) { @@ -385,20 +383,20 @@ void Avatar::simulate(float deltaTime) { } else { if ( _position.y < _bone[ AVATAR_BONE_RIGHT_FOOT ].radius ) { - _position.y = _bone[ AVATAR_BONE_RIGHT_FOOT ].radius; + _position.y = _bone[ AVATAR_BONE_RIGHT_FOOT ].radius; _velocity.y = 0.0; - } + } } } // update body springs updateBodySprings( deltaTime ); - - // driving the avatar around should only apply if this is my avatar (as opposed to an avatar being driven remotely) + + // driving the avatar around should only apply if this is my avatar (as opposed to an avatar being driven remotely) if ( _isMine ) { - + _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; @@ -423,14 +421,14 @@ void Avatar::simulate(float deltaTime) { glm::vec3 up( _orientation.getUp().x, _orientation.getUp().y, _orientation.getUp().z ); _thrust -= up * THRUST_MAG; } - if (_driveKeys[ROT_RIGHT]) { + if (_driveKeys[ROT_RIGHT]) { _bodyYawDelta -= YAW_MAG * deltaTime; } - if (_driveKeys[ROT_LEFT]) { + if (_driveKeys[ROT_LEFT]) { _bodyYawDelta += YAW_MAG * deltaTime; } } - + float translationalSpeed = glm::length( _velocity ); float rotationalSpeed = fabs( _bodyYawDelta ); if ( translationalSpeed + rotationalSpeed > 0.2 ) @@ -441,21 +439,21 @@ void Avatar::simulate(float deltaTime) { { _mode = AVATAR_MODE_INTERACTING; } - + // update body yaw by body yaw delta if (_isMine) { - _bodyYaw += _bodyYawDelta * deltaTime; + _bodyYaw += _bodyYawDelta * deltaTime; } - + // decay body yaw delta _bodyYawDelta *= (1.0 - TEST_YAW_DECAY * deltaTime); - + // add thrust to velocity _velocity += glm::dvec3(_thrust * deltaTime); - + // update position by velocity _position += (glm::vec3)_velocity * deltaTime; - + // decay velocity _velocity *= ( 1.0 - LIN_VEL_DECAY * deltaTime ); @@ -464,13 +462,13 @@ void Avatar::simulate(float deltaTime) { // if (!_head.noise) { - // Decay back toward center + // Decay back toward center _headPitch *= (1.0f - DECAY * 2 * deltaTime); _headYaw *= (1.0f - DECAY * 2 * deltaTime); _headRoll *= (1.0f - DECAY * 2 * deltaTime); } else { - // Move toward new target + // Move toward new target _headPitch += (_head.pitchTarget - _headPitch) * 10 * deltaTime; // (1.f - DECAY*deltaTime)*Pitch + ; _headYaw += (_head.yawTarget - _headYaw ) * 10 * deltaTime; // (1.f - DECAY*deltaTime); _headRoll *= 1.f - (DECAY * deltaTime); @@ -479,7 +477,7 @@ void Avatar::simulate(float deltaTime) { _head.leanForward *= (1.f - DECAY * 30 * deltaTime); _head.leanSideways *= (1.f - DECAY * 30 * deltaTime); - // Update where the avatar's eyes are + // Update where the avatar's eyes are // // First, decide if we are making eye contact or not if (randFloat() < 0.005) { @@ -497,7 +495,7 @@ void Avatar::simulate(float deltaTime) { const float DEGREES_BETWEEN_VIEWER_EYES = 3; const float DEGREES_TO_VIEWER_MOUTH = 7; - + if (_head.eyeContact) { // Should we pick a new eye contact target? if (randFloat() < 0.01) { @@ -519,7 +517,7 @@ void Avatar::simulate(float deltaTime) { _head.eyeballYaw[0] = _head.eyeballYaw[1] = -_headYaw + eye_target_yaw_adjust; } - + if (_head.noise) { _headPitch += (randFloat() - 0.5) * 0.2 * _head.noiseEnvelope; @@ -531,14 +529,14 @@ void Avatar::simulate(float deltaTime) { if (!_head.eyeContact) { if (randFloat() < 0.01) _head.eyeballPitch[0] = _head.eyeballPitch[1] = (randFloat() - 0.5) * 20; if (randFloat() < 0.01) _head.eyeballYaw[0] = _head.eyeballYaw[1] = (randFloat()- 0.5) * 10; - } - + } + if ((randFloat() < 0.005) && (fabs(_head.pitchTarget - _headPitch) < 1.0) && (fabs(_head.yawTarget - _headYaw) < 1.0)) { SetNewHeadTarget((randFloat()-0.5) * 20.0, (randFloat()-0.5) * 45.0); } - + if (0) { - + // Pick new target _head.pitchTarget = (randFloat() - 0.5) * 45; _head.yawTarget = (randFloat() - 0.5) * 22; @@ -554,10 +552,10 @@ void Avatar::simulate(float deltaTime) { // Update audio trailing average for rendering facial animations const float AUDIO_AVERAGING_SECS = 0.05; _head.averageLoudness = (1.f - deltaTime / AUDIO_AVERAGING_SECS) * _head.averageLoudness + - (deltaTime / AUDIO_AVERAGING_SECS) * _audioLoudness; + (deltaTime / AUDIO_AVERAGING_SECS) * _audioLoudness; } - - + + float Avatar::getGirth() { return COLLISION_BODY_RADIUS; } @@ -565,38 +563,38 @@ float Avatar::getGirth() { float Avatar::getHeight() { return COLLISION_HEIGHT; } - - + + glm::vec3 Avatar::getBodyUpDirection() { return _orientation.getUp(); } - + // This is a workspace for testing avatar body collision detection and response void Avatar::updateAvatarCollisionDetectionAndResponse ( glm::vec3 collisionPosition, float collisionGirth, float collisionHeight, glm::vec3 collisionUpVector, float deltaTime ) { - + float myBodyApproximateBoundingRadius = 1.0f; glm::vec3 vectorFromMyBodyToBigSphere(_position - collisionPosition); bool jointCollision = false; - + float distanceToBigSphere = glm::length(vectorFromMyBodyToBigSphere); if ( distanceToBigSphere < myBodyApproximateBoundingRadius + collisionGirth ) { - for (int b=0; b 0.0) + if (distanceToBigSphereCenter > 0.0) { glm::vec3 directionVector = vectorFromJointToBigSphereCenter / distanceToBigSphereCenter; - float penetration = 1.0 - (distanceToBigSphereCenter / combinedRadius); - glm::vec3 collisionForce = vectorFromJointToBigSphereCenter * penetration; - + float penetration = 1.0 - (distanceToBigSphereCenter / combinedRadius); + glm::vec3 collisionForce = vectorFromJointToBigSphereCenter * penetration; + _bone[b].springyVelocity += collisionForce * 30.0f * deltaTime; _velocity += collisionForce * 100.0f * deltaTime; _bone[b].springyPosition = collisionPosition + directionVector * combinedRadius; @@ -608,43 +606,43 @@ void Avatar::updateAvatarCollisionDetectionAndResponse if (!_usingBodySprings) { _usingBodySprings = true; initializeBodySprings(); - } - } + } + } } } void Avatar::render(bool lookingInMirror) { - + // show avatar position 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 ); + glTranslatef(_position.x, _position.y, _position.z); + glScalef( 0.03, 0.03, 0.03 ); + glutSolidSphere( 1, 10, 10 ); glPopMatrix(); if ( usingBigSphereCollisionTest ) { - - // show TEST big sphere + + // show TEST big sphere 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 ); + glTranslatef(_TEST_bigSpherePosition.x, _TEST_bigSpherePosition.y, _TEST_bigSpherePosition.z); + glScalef( _TEST_bigSphereRadius, _TEST_bigSphereRadius, _TEST_bigSphereRadius ); + glutSolidSphere( 1, 20, 20 ); glPopMatrix(); - } - + } + // render body renderBody(); - + // render head renderHead(lookingInMirror); // if this is my avatar, then render my interactions with the other avatar if ( _isMine ) { - if ( _interactingOtherIsNearby ) { - + if ( _interactingOtherIsNearby ) { + glm::vec3 v1( _bone[ AVATAR_BONE_RIGHT_HAND ].position ); glm::vec3 v2( _interactingOther->_handPosition ); @@ -658,10 +656,10 @@ void Avatar::render(bool lookingInMirror) { } } - + void Avatar::renderHead(bool lookingInMirror) { int side = 0; - + glEnable(GL_DEPTH_TEST); glEnable(GL_RESCALE_NORMAL); @@ -682,7 +680,7 @@ void Avatar::renderHead(bool lookingInMirror) { } glScalef( 0.03, 0.03, 0.03 ); - + if (lookingInMirror) { glRotatef(_bodyYaw - _headYaw, 0, 1, 0); glRotatef(_bodyPitch + _headPitch, 1, 0, 0); @@ -697,22 +695,22 @@ void Avatar::renderHead(bool lookingInMirror) { glColor3fv(skinColor); glutSolidSphere(1, 30, 30); - + // Ears glPushMatrix(); - glTranslatef(1.0, 0, 0); - for(side = 0; side < 2; side++) { - glPushMatrix(); - glScalef(0.3, 0.65, .65); - glutSolidSphere(0.5, 30, 30); - glPopMatrix(); - glTranslatef(-2.0, 0, 0); - } + glTranslatef(1.0, 0, 0); + for(side = 0; side < 2; side++) { + glPushMatrix(); + glScalef(0.3, 0.65, .65); + glutSolidSphere(0.5, 30, 30); + glPopMatrix(); + glTranslatef(-2.0, 0, 0); + } glPopMatrix(); - - - // Update audio attack data for facial animation (eyebrows and mouth) - _head.audioAttack = 0.9 * _head.audioAttack + 0.1 * fabs(_audioLoudness - _head.lastLoudness); + + + // Update audio attack data for facial animation (eyebrows and mouth) + _head.audioAttack = 0.9 * _head.audioAttack + 0.1 * fabs(_audioLoudness - _head.lastLoudness); _head.lastLoudness = _audioLoudness; @@ -721,43 +719,43 @@ void Avatar::renderHead(bool lookingInMirror) { _head.browAudioLift += sqrt(_head.audioAttack) / 1000.0; _head.browAudioLift *= .90; - + // Render Eyebrows glPushMatrix(); - glTranslatef(-_head.interBrowDistance / 2.0,0.4,0.45); - for(side = 0; side < 2; side++) { - glColor3fv(browColor); - glPushMatrix(); - glTranslatef(0, 0.35 + _head.browAudioLift, 0); - glRotatef(_head.eyebrowPitch[side]/2.0, 1, 0, 0); - glRotatef(_head.eyebrowRoll[side]/2.0, 0, 0, 1); - glScalef(browWidth, browThickness, 1); - glutSolidCube(0.5); - glPopMatrix(); - glTranslatef(_head.interBrowDistance, 0, 0); - } + glTranslatef(-_head.interBrowDistance / 2.0,0.4,0.45); + for(side = 0; side < 2; side++) { + glColor3fv(browColor); + glPushMatrix(); + glTranslatef(0, 0.35 + _head.browAudioLift, 0); + glRotatef(_head.eyebrowPitch[side]/2.0, 1, 0, 0); + glRotatef(_head.eyebrowRoll[side]/2.0, 0, 0, 1); + glScalef(browWidth, browThickness, 1); + glutSolidCube(0.5); + glPopMatrix(); + glTranslatef(_head.interBrowDistance, 0, 0); + } glPopMatrix(); // Mouth glPushMatrix(); - glTranslatef(0,-0.35,0.75); - glColor3f(0,0,0); - glRotatef(_head.mouthPitch, 1, 0, 0); - glRotatef(_head.mouthYaw, 0, 0, 1); - glScalef(_head.mouthWidth*(.7 + sqrt(_head.averageLoudness)/60.0), _head.mouthHeight*(1.0 + sqrt(_head.averageLoudness)/30.0), 1); - glutSolidCube(0.5); + glTranslatef(0,-0.35,0.75); + glColor3f(0,0,0); + glRotatef(_head.mouthPitch, 1, 0, 0); + glRotatef(_head.mouthYaw, 0, 0, 1); + glScalef(_head.mouthWidth*(.7 + sqrt(_head.averageLoudness)/60.0), _head.mouthHeight*(1.0 + sqrt(_head.averageLoudness)/30.0), 1); + glutSolidCube(0.5); glPopMatrix(); glTranslatef(0, 1.0, 0); - + glTranslatef(-_head.interPupilDistance/2.0,-0.68,0.7); // Right Eye glRotatef(-10, 1, 0, 0); glColor3fv(eyeColor); - glPushMatrix(); + glPushMatrix(); { glTranslatef(_head.interPupilDistance/10.0, 0, 0.05); glRotatef(20, 0, 0, 1); @@ -775,7 +773,7 @@ void Avatar::renderHead(bool lookingInMirror) { gluQuadricOrientation(_sphere, GLU_OUTSIDE); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, iris_texture_width, iris_texture_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, &iris_texture[0]); } - + glPushMatrix(); { glRotatef(_head.eyeballPitch[1], 1, 0, 0); @@ -788,12 +786,12 @@ void Avatar::renderHead(bool lookingInMirror) { gluSphere(_sphere, _head.pupilSize, 15, 15); glDisable(GL_TEXTURE_2D); } - + glPopMatrix(); // Left Eye glColor3fv(eyeColor); glTranslatef(_head.interPupilDistance, 0, 0); - glPushMatrix(); + glPushMatrix(); { glTranslatef(-_head.interPupilDistance/10.0, 0, .05); glRotatef(-20, 0, 0, 1); @@ -809,20 +807,20 @@ void Avatar::renderHead(bool lookingInMirror) { glTranslatef(0, 0, .35); glRotatef(-75, 1, 0, 0); glScalef(1.0, 0.4, 1.0); - + glEnable(GL_TEXTURE_2D); gluSphere(_sphere, _head.pupilSize, 15, 15); glDisable(GL_TEXTURE_2D); } glPopMatrix(); - - + + glPopMatrix(); - } - -void Avatar::startHandMovement() { +} +void Avatar::startHandMovement() { + if (!_usingBodySprings) { initializeBodySprings(); _usingBodySprings = true; @@ -830,9 +828,9 @@ void Avatar::startHandMovement() { } void Avatar::stopHandMovement() { -//_usingBodySprings = false; + //_usingBodySprings = false; } - + void Avatar::setHandMovementValues( glm::vec3 handOffset ) { _movedHandOffset = handOffset; } @@ -842,7 +840,7 @@ AvatarMode Avatar::getMode() { } void Avatar::initializeSkeleton() { - + for (int b=0; b 0.0f ) { @@ -1023,16 +1021,16 @@ void Avatar::updateBodySprings( float deltaTime ) { } _bone[b].springyVelocity += ( _bone[b].position - _bone[b].springyPosition ) * _bone[b].springBodyTightness * deltaTime; - + float decay = 1.0 - _springVelocityDecay * deltaTime; if ( decay > 0.0 ) { _bone[b].springyVelocity *= decay; } else { - _bone[b].springyVelocity = glm::vec3( 0.0f, 0.0f, 0.0f ); + _bone[b].springyVelocity = glm::vec3( 0.0f, 0.0f, 0.0f ); } - + _bone[b].springyPosition += _bone[b].springyVelocity; } } @@ -1040,32 +1038,32 @@ void Avatar::updateBodySprings( float deltaTime ) { glm::vec3 Avatar::getHeadLookatDirection() { return glm::vec3 ( - _orientation.getFront().x, - _orientation.getFront().y, - _orientation.getFront().z - ); + _orientation.getFront().x, + _orientation.getFront().y, + _orientation.getFront().z + ); } glm::vec3 Avatar::getHeadLookatDirectionUp() { return glm::vec3 ( - _orientation.getUp().x, - _orientation.getUp().y, - _orientation.getUp().z - ); + _orientation.getUp().x, + _orientation.getUp().y, + _orientation.getUp().z + ); } glm::vec3 Avatar::getHeadLookatDirectionRight() { return glm::vec3 ( - _orientation.getRight().x, - _orientation.getRight().y, - _orientation.getRight().z - ); + _orientation.getRight().x, + _orientation.getRight().y, + _orientation.getRight().z + ); } glm::vec3 Avatar::getHeadPosition() { - + if ( _usingBodySprings ) { return _bone[ AVATAR_BONE_HEAD ].springyPosition; } @@ -1082,8 +1080,8 @@ glm::vec3 Avatar::getBonePosition( AvatarBoneID b ) { void Avatar::updateHandMovement( float deltaTime ) { glm::vec3 transformedHandMovement; - - transformedHandMovement + + transformedHandMovement = _orientation.getRight() * _movedHandOffset.x + _orientation.getUp() * -_movedHandOffset.y * 0.5f + _orientation.getFront() * -_movedHandOffset.y; @@ -1097,11 +1095,11 @@ void Avatar::updateHandMovement( float deltaTime ) { void Avatar::updateArmIKAndConstraints( float deltaTime ) { - + // determine the arm vector glm::vec3 armVector = _bone[ AVATAR_BONE_RIGHT_HAND ].position; armVector -= _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; - + // test to see if right hand is being dragged beyond maximum arm length float distance = glm::length( armVector ); @@ -1116,15 +1114,15 @@ void Avatar::updateArmIKAndConstraints( float deltaTime ) { constrainedPosition += armVector; _bone[ AVATAR_BONE_RIGHT_HAND ].position = constrainedPosition; } - - // set elbow position + + // set elbow position glm::vec3 newElbowPosition = _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; newElbowPosition += armVector * ONE_HALF; glm::vec3 perpendicular = glm::cross( _orientation.getFront(), armVector ); newElbowPosition += perpendicular * ( 1.0f - ( _maxArmLength / distance ) ) * ONE_HALF; _bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position = newElbowPosition; - - // set wrist position + + // set wrist position glm::vec3 vv( _bone[ AVATAR_BONE_RIGHT_HAND ].position ); vv -= _bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position; glm::vec3 newWristPosition = _bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position; @@ -1136,35 +1134,35 @@ void Avatar::updateArmIKAndConstraints( float deltaTime ) { void Avatar::renderBody() { - + // Render bone positions as spheres for (int b=0; bANG_VEL_THRESHOLD?gyrX*angVelScale:0, + fabs(gyrZ*angVelScale)>ANG_VEL_THRESHOLD?gyrZ*angVelScale:0, + fabs(-gyrY*angVelScale)>ANG_VEL_THRESHOLD?-gyrY*angVelScale:0); + + // Add linear forces to the hand + //const float LINEAR_VEL_SENSITIVITY = 50.0; + const float LINEAR_VEL_SENSITIVITY = 5.0; + float linVelScale = LINEAR_VEL_SENSITIVITY*(1.0f/getTransmitterHz()); + glm::vec3 linVel(linX*linVelScale, linZ*linVelScale, -linY*linVelScale); + addVelocity(linVel); + */ - addAngularVelocity(fabs(gyrX*angVelScale)>ANG_VEL_THRESHOLD?gyrX*angVelScale:0, - fabs(gyrZ*angVelScale)>ANG_VEL_THRESHOLD?gyrZ*angVelScale:0, - fabs(-gyrY*angVelScale)>ANG_VEL_THRESHOLD?-gyrY*angVelScale:0); - - // Add linear forces to the hand - //const float LINEAR_VEL_SENSITIVITY = 50.0; - const float LINEAR_VEL_SENSITIVITY = 5.0; - float linVelScale = LINEAR_VEL_SENSITIVITY*(1.0f/getTransmitterHz()); - glm::vec3 linVel(linX*linVelScale, linZ*linVelScale, -linY*linVelScale); - addVelocity(linVel); - */ - -} - +} \ No newline at end of file diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 4ae1334262..131ff26c93 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -914,7 +914,7 @@ void display(void) agent != agentList->end(); agent++) { if ((*agent).getLinkedData() != NULL && (*agent).getType() == AGENT_TYPE_AVATAR) { - Head *avatar = (Head *)(*agent).getLinkedData(); + Avatar *avatar = (Avatar *)(*agent).getLinkedData(); avatar->render(0); } } @@ -1500,7 +1500,7 @@ void idle(void) { AgentList * agentList = AgentList::getInstance(); for(AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { if ((*agent).getLinkedData() != NULL) { - Head *avatar = (Head *)(*agent).getLinkedData(); + Avatar *avatar = (Avatar *)(*agent).getLinkedData(); avatar->simulate(deltaTime); } } From 625a9639185bf94fbc756aa0451bb6724d0f6854 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 25 Apr 2013 15:49:25 -0700 Subject: [PATCH 17/36] prefer -> notation to (*TYPE) for AgentList iterator --- audio-mixer/src/main.cpp | 12 ++++----- domain-server/src/main.cpp | 16 +++++------ interface/src/Avatar.cpp | 4 +-- interface/src/main.cpp | 10 +++---- libraries/shared/src/AgentList.cpp | 43 +++++++++++++++++------------- libraries/shared/src/AgentList.h | 1 + voxel-server/src/main.cpp | 6 ++--- 7 files changed, 49 insertions(+), 43 deletions(-) diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index a3e50b4901..7928997a29 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -86,15 +86,15 @@ void *sendBuffer(void *args) sentBytes = 0; for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { - AudioRingBuffer *agentBuffer = (AudioRingBuffer *)(*agent).getLinkedData(); + AudioRingBuffer *agentBuffer = (AudioRingBuffer *)agent->getLinkedData(); if (agentBuffer != NULL && agentBuffer->getEndOfLastWrite() != NULL) { if (!agentBuffer->isStarted() && agentBuffer->diffLastWriteNextOutput() <= BUFFER_LENGTH_SAMPLES_PER_CHANNEL + JITTER_BUFFER_SAMPLES) { - printf("Held back buffer for agent with ID %d.\n", (*agent).getAgentId()); + printf("Held back buffer for agent with ID %d.\n", agent->getAgentId()); } else if (agentBuffer->diffLastWriteNextOutput() < BUFFER_LENGTH_SAMPLES_PER_CHANNEL) { - printf("Buffer from agent with ID %d starved.\n", (*agent).getAgentId()); + printf("Buffer from agent with ID %d starved.\n", agent->getAgentId()); agentBuffer->setStarted(false); } else { // good buffer, add this to the mix @@ -109,7 +109,7 @@ void *sendBuffer(void *args) memset(distanceCoeffs, 0, sizeof(distanceCoeffs)); for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { - AudioRingBuffer *agentRingBuffer = (AudioRingBuffer *)(*agent).getLinkedData(); + AudioRingBuffer *agentRingBuffer = (AudioRingBuffer *)agent->getLinkedData(); float agentBearing = agentRingBuffer->getBearing(); bool agentWantsLoopback = false; @@ -218,11 +218,11 @@ void *sendBuffer(void *args) } } - agentList->getAgentSocket().send((*agent).getPublicSocket(), clientMix, BUFFER_LENGTH_BYTES); + agentList->getAgentSocket().send(agent->getPublicSocket(), clientMix, BUFFER_LENGTH_BYTES); } for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { - AudioRingBuffer *agentBuffer = (AudioRingBuffer *)(*agent).getLinkedData(); + AudioRingBuffer *agentBuffer = (AudioRingBuffer *)agent->getLinkedData(); if (agentBuffer->wasAddedToMix()) { agentBuffer->setNextOutput(agentBuffer->getNextOutput() + BUFFER_LENGTH_SAMPLES_PER_CHANNEL); diff --git a/domain-server/src/main.cpp b/domain-server/src/main.cpp index 2126d8e561..25cecf133b 100644 --- a/domain-server/src/main.cpp +++ b/domain-server/src/main.cpp @@ -132,25 +132,25 @@ int main(int argc, const char * argv[]) agent++) { if (DEBUG_TO_SELF || - !(*agent).matches((sockaddr *)&agentPublicAddress, (sockaddr *)&agentLocalAddress, agentType)) { - if (memchr(SOLO_AGENT_TYPES, (*agent).getType(), sizeof(SOLO_AGENT_TYPES)) == NULL) { + !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 - if (agentType != AGENT_TYPE_AVATAR || (*agent).getType() != AGENT_TYPE_AVATAR) { - currentBufferPos = addAgentToBroadcastPacket(currentBufferPos, &(*agent)); + if (agentType != AGENT_TYPE_AVATAR || agent->getType() != AGENT_TYPE_AVATAR) { + currentBufferPos = addAgentToBroadcastPacket(currentBufferPos, &*agent); } } else { // solo agent, we need to only send newest - if (newestSoloAgents[(*agent).getType()] == NULL || - newestSoloAgents[(*agent).getType()]->getFirstRecvTimeUsecs() < (*agent).getFirstRecvTimeUsecs()) { + if (newestSoloAgents[agent->getType()] == NULL || + newestSoloAgents[agent->getType()]->getFirstRecvTimeUsecs() < agent->getFirstRecvTimeUsecs()) { // we have to set the newer solo agent to add it to the broadcast later - newestSoloAgents[(*agent).getType()] = &(*agent); + newestSoloAgents[agent->getType()] = &*agent; } } } else { // this is the agent, just update last receive to now - (*agent).setLastRecvTimeUsecs(usecTimestampNow()); + agent->setLastRecvTimeUsecs(usecTimestampNow()); } } diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index c5364c0029..ac69891b21 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -310,8 +310,8 @@ void Avatar::simulate(float deltaTime) { agent != agentList->end(); agent++) { - if ((*agent).getLinkedData() != NULL && (*agent).getType() == AGENT_TYPE_AVATAR) { - Avatar *otherAvatar = (Avatar *)(*agent).getLinkedData(); + if (agent->getLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) { + Avatar *otherAvatar = (Avatar *)agent->getLinkedData(); // check for collisions with other avatars and respond updateAvatarCollisionDetectionAndResponse diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 131ff26c93..8fee0ee26a 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -913,8 +913,8 @@ void display(void) for(AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { - if ((*agent).getLinkedData() != NULL && (*agent).getType() == AGENT_TYPE_AVATAR) { - Avatar *avatar = (Avatar *)(*agent).getLinkedData(); + if (agent->getLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) { + Avatar *avatar = (Avatar *)agent->getLinkedData(); avatar->render(0); } } @@ -986,7 +986,7 @@ void display(void) int totalAvatars = 0, totalServers = 0; for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { - (*agent).getType() == AGENT_TYPE_AVATAR ? totalAvatars++ : totalServers++; + agent->getType() == AGENT_TYPE_AVATAR ? totalAvatars++ : totalServers++; } sprintf(agents, "Servers: %d, Avatars: %d\n", totalServers, totalAvatars); @@ -1499,8 +1499,8 @@ void idle(void) { //loop through all the other avatars and simulate them... AgentList * agentList = AgentList::getInstance(); for(AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { - if ((*agent).getLinkedData() != NULL) { - Avatar *avatar = (Avatar *)(*agent).getLinkedData(); + if (agent->getLinkedData() != NULL) { + Avatar *avatar = (Avatar *)agent->getLinkedData(); avatar->simulate(deltaTime); } } diff --git a/libraries/shared/src/AgentList.cpp b/libraries/shared/src/AgentList.cpp index dc46558766..908547e9ba 100644 --- a/libraries/shared/src/AgentList.cpp +++ b/libraries/shared/src/AgentList.cpp @@ -172,7 +172,7 @@ int AgentList::updateAgentWithData(Agent *agent, unsigned char *packetData, int Agent* AgentList::agentWithAddress(sockaddr *senderAddress) { for(AgentList::iterator agent = begin(); agent != end(); agent++) { - if ((*agent).getActiveSocket() != NULL && socketMatch((*agent).getActiveSocket(), senderAddress)) { + if (agent->getActiveSocket() != NULL && socketMatch(agent->getActiveSocket(), senderAddress)) { return &*agent; } } @@ -182,7 +182,7 @@ Agent* AgentList::agentWithAddress(sockaddr *senderAddress) { Agent* AgentList::agentWithID(uint16_t agentID) { for(AgentList::iterator agent = begin(); agent != end(); agent++) { - if ((*agent).getAgentId() == agentID) { + if (agent->getAgentId() == agentID) { return &*agent; } } @@ -230,7 +230,7 @@ bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket, if (publicSocket != NULL) { for (agent = begin(); agent != end(); agent++) { - if ((*agent).matches(publicSocket, localSocket, agentType)) { + if (agent->matches(publicSocket, localSocket, agentType)) { // we already have this agent, stop checking break; } @@ -262,10 +262,10 @@ bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket, return true; } else { - if ((*agent).getType() == AGENT_TYPE_AUDIO_MIXER || (*agent).getType() == AGENT_TYPE_VOXEL) { + 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->setLastRecvTimeUsecs(usecTimestampNow()); } // we had this agent already, do nothing for now @@ -292,9 +292,9 @@ void AgentList::addAgentToList(Agent* newAgent) { void AgentList::broadcastToAgents(unsigned char *broadcastData, size_t dataBytes, const char* agentTypes, int numAgentTypes) { for(AgentList::iterator agent = begin(); agent != end(); agent++) { // only send to the AgentTypes we are asked to send to. - if ((*agent).getActiveSocket() != NULL && memchr(agentTypes, (*agent).getType(), numAgentTypes)) { + if (agent->getActiveSocket() != NULL && memchr(agentTypes, agent->getType(), numAgentTypes)) { // we know which socket is good for this agent, send there - agentSocket.send((*agent).getActiveSocket(), broadcastData, dataBytes); + agentSocket.send(agent->getActiveSocket(), broadcastData, dataBytes); } } } @@ -303,11 +303,11 @@ void AgentList::handlePingReply(sockaddr *agentAddress) { for(AgentList::iterator agent = begin(); agent != end(); agent++) { // check both the public and local addresses for each agent to see if we find a match // prioritize the private address so that we prune erroneous local matches - if (socketMatch((*agent).getPublicSocket(), agentAddress)) { - (*agent).activatePublicSocket(); + if (socketMatch(agent->getPublicSocket(), agentAddress)) { + agent->activatePublicSocket(); break; - } else if (socketMatch((*agent).getLocalSocket(), agentAddress)) { - (*agent).activateLocalSocket(); + } else if (socketMatch(agent->getLocalSocket(), agentAddress)) { + agent->activateLocalSocket(); break; } } @@ -316,7 +316,7 @@ void AgentList::handlePingReply(sockaddr *agentAddress) { Agent* AgentList::soloAgentOfType(char agentType) { if (memchr(SOLO_AGENT_TYPES, agentType, sizeof(SOLO_AGENT_TYPES)) != NULL) { for(AgentList::iterator agent = begin(); agent != end(); agent++) { - if ((*agent).getType() == agentType) { + if (agent->getType() == agentType) { return &*agent; } } @@ -338,12 +338,12 @@ void *pingUnknownAgents(void *args) { for(AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { - if ((*agent).getActiveSocket() == NULL - && ((*agent).getPublicSocket() != NULL && (*agent).getLocalSocket() != NULL)) { + if (agent->getActiveSocket() == NULL + && (agent->getPublicSocket() != NULL && agent->getLocalSocket() != NULL)) { // ping both of the sockets for the agent so we can figure out // which socket we can use - agentList->getAgentSocket().send((*agent).getPublicSocket(), &PACKET_HEADER_PING, 1); - agentList->getAgentSocket().send((*agent).getLocalSocket(), &PACKET_HEADER_PING, 1); + agentList->getAgentSocket().send(agent->getPublicSocket(), &PACKET_HEADER_PING, 1); + agentList->getAgentSocket().send(agent->getLocalSocket(), &PACKET_HEADER_PING, 1); } } @@ -375,13 +375,13 @@ void *removeSilentAgents(void *args) { for(AgentList::iterator agent = agentList->begin(); agent != agentList->end(); ++agent) { - if ((checkTimeUSecs - (*agent).getLastRecvTimeUsecs()) > AGENT_SILENCE_THRESHOLD_USECS - && (*agent).getType() != AGENT_TYPE_VOXEL) { + if ((checkTimeUSecs - agent->getLastRecvTimeUsecs()) > AGENT_SILENCE_THRESHOLD_USECS + && agent->getType() != AGENT_TYPE_VOXEL) { printLog("Killing agent - "); Agent::printLog(*agent); - (*agent).setAlive(false); + agent->setAlive(false); } } @@ -504,6 +504,11 @@ Agent& AgentListIterator::operator*() { return *agentBucket[_agentIndex % AGENTS_PER_BUCKET]; } +Agent* AgentListIterator::operator->() { + Agent** agentBucket = _agentList->_agentBuckets[_agentIndex / AGENTS_PER_BUCKET]; + return agentBucket[_agentIndex % AGENTS_PER_BUCKET]; +} + AgentListIterator& AgentListIterator::operator++() { skipDeadAndStopIncrement(); return *this; diff --git a/libraries/shared/src/AgentList.h b/libraries/shared/src/AgentList.h index c94b69131c..92a80ddc08 100644 --- a/libraries/shared/src/AgentList.h +++ b/libraries/shared/src/AgentList.h @@ -121,6 +121,7 @@ public: bool operator!= (const AgentListIterator& otherValue); Agent& operator*(); + Agent* operator->(); AgentListIterator& operator++(); AgentListIterator operator++(int); diff --git a/voxel-server/src/main.cpp b/voxel-server/src/main.cpp index 91e91d81a7..9be9611048 100644 --- a/voxel-server/src/main.cpp +++ b/voxel-server/src/main.cpp @@ -127,7 +127,7 @@ void eraseVoxelTreeAndCleanupAgentVisitData() { //printf("eraseVoxelTreeAndCleanupAgentVisitData() agent[%d]\n",i); - VoxelAgentData *agentData = (VoxelAgentData *)(*agent).getLinkedData(); + VoxelAgentData *agentData = (VoxelAgentData *)agent->getLinkedData(); // clean up the agent visit data delete agentData->rootMarkerNode; @@ -155,7 +155,7 @@ void *distributeVoxelsToListeners(void *args) { // enumerate the agents to send 3 packets to each for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { - VoxelAgentData *agentData = (VoxelAgentData *)(*agent).getLinkedData(); + VoxelAgentData *agentData = (VoxelAgentData *)agent->getLinkedData(); ViewFrustum viewFrustum; // get position and orientation details from the camera @@ -191,7 +191,7 @@ void *distributeVoxelsToListeners(void *args) { ::viewFrustumCulling, stopOctal); - agentList->getAgentSocket().send((*agent).getActiveSocket(), voxelPacket, voxelPacketEnd - voxelPacket); + agentList->getAgentSocket().send(agent->getActiveSocket(), voxelPacket, voxelPacketEnd - voxelPacket); packetCount++; totalBytesSent += voxelPacketEnd - voxelPacket; From f7e83b208056b388336e3a9230864303cb9d8f7b Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 25 Apr 2013 15:51:10 -0700 Subject: [PATCH 18/36] squish types in audio mixer, use -> notation for other avatars --- audio-mixer/src/main.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index 7928997a29..4e692024c4 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -86,7 +86,7 @@ void *sendBuffer(void *args) sentBytes = 0; for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { - AudioRingBuffer *agentBuffer = (AudioRingBuffer *)agent->getLinkedData(); + AudioRingBuffer* agentBuffer = (AudioRingBuffer*) agent->getLinkedData(); if (agentBuffer != NULL && agentBuffer->getEndOfLastWrite() != NULL) { @@ -109,7 +109,7 @@ void *sendBuffer(void *args) memset(distanceCoeffs, 0, sizeof(distanceCoeffs)); for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { - AudioRingBuffer *agentRingBuffer = (AudioRingBuffer *)agent->getLinkedData(); + AudioRingBuffer* agentRingBuffer = (AudioRingBuffer*) agent->getLinkedData(); float agentBearing = agentRingBuffer->getBearing(); bool agentWantsLoopback = false; @@ -128,7 +128,7 @@ void *sendBuffer(void *args) for (AgentList::iterator otherAgent = agentList->begin(); agent != agentList->end(); agent++) { if (otherAgent != agent || ( otherAgent == agent && agentWantsLoopback)) { - AudioRingBuffer *otherAgentBuffer = (AudioRingBuffer *)(*otherAgent).getLinkedData(); + AudioRingBuffer* otherAgentBuffer = (AudioRingBuffer*) otherAgent->getLinkedData(); float *agentPosition = agentRingBuffer->getPosition(); float *otherAgentPosition = otherAgentBuffer->getPosition(); @@ -222,7 +222,7 @@ void *sendBuffer(void *args) } for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { - AudioRingBuffer *agentBuffer = (AudioRingBuffer *)agent->getLinkedData(); + AudioRingBuffer* agentBuffer = (AudioRingBuffer*) agent->getLinkedData(); if (agentBuffer->wasAddedToMix()) { agentBuffer->setNextOutput(agentBuffer->getNextOutput() + BUFFER_LENGTH_SAMPLES_PER_CHANNEL); From 569fa76dde367a68673d066a8fc21be924e585d2 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 25 Apr 2013 15:52:16 -0700 Subject: [PATCH 19/36] prefer arrow notation in avatar-mixer iterator loop --- avatar-mixer/src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/avatar-mixer/src/main.cpp b/avatar-mixer/src/main.cpp index e9fbda89df..82d75fa0fb 100644 --- a/avatar-mixer/src/main.cpp +++ b/avatar-mixer/src/main.cpp @@ -86,8 +86,8 @@ int main(int argc, char* argv[]) for (AgentList::iterator avatarAgent = agentList->begin(); avatarAgent != agentList->end(); avatarAgent++) { - if ((*avatarAgent).getLinkedData() != NULL - && !socketMatch(agentAddress, (*avatarAgent).getActiveSocket())) { + if (avatarAgent->getLinkedData() != NULL + && !socketMatch(agentAddress, avatarAgent->getActiveSocket())) { currentBufferPosition = addAgentToBroadcastPacket(currentBufferPosition, &*avatarAgent); } From 8deee63f74ef973bb62ca7ab326690a74d81cd19 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 25 Apr 2013 15:56:26 -0700 Subject: [PATCH 20/36] remove line breaks in DS for loop --- domain-server/src/main.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/domain-server/src/main.cpp b/domain-server/src/main.cpp index 25cecf133b..15f11aa0ae 100644 --- a/domain-server/src/main.cpp +++ b/domain-server/src/main.cpp @@ -127,10 +127,7 @@ int main(int argc, const char * argv[]) currentBufferPos = broadcastPacket + 1; startPointer = currentBufferPos; - for(AgentList::iterator agent = agentList->begin(); - agent != agentList->end(); - agent++) { - + for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { if (DEBUG_TO_SELF || !agent->matches((sockaddr *)&agentPublicAddress, (sockaddr *)&agentLocalAddress, agentType)) { if (memchr(SOLO_AGENT_TYPES, agent->getType(), sizeof(SOLO_AGENT_TYPES)) == NULL) { From 114f949a6e2211c9d8521ae245f49949f26621fc Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 25 Apr 2013 15:58:03 -0700 Subject: [PATCH 21/36] spacing cleanup in Avatar class --- interface/src/Avatar.cpp | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index ac69891b21..c51ea678e9 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -304,24 +304,18 @@ void Avatar::simulate(float deltaTime) { { float closestDistance = 10000.0f; - AgentList * agentList = AgentList::getInstance(); + AgentList* agentList = AgentList::getInstance(); - for(AgentList::iterator agent = agentList->begin(); - agent != agentList->end(); - agent++) { - + for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { if (agent->getLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) { Avatar *otherAvatar = (Avatar *)agent->getLinkedData(); // check for collisions with other avatars and respond - updateAvatarCollisionDetectionAndResponse - ( - otherAvatar->getBonePosition( AVATAR_BONE_PELVIS_SPINE ), - 0.2, - 0.2, - otherAvatar->getBodyUpDirection(), - deltaTime - ); + updateAvatarCollisionDetectionAndResponse(otherAvatar->getBonePosition(AVATAR_BONE_PELVIS_SPINE), + 0.2, + 0.2, + otherAvatar->getBodyUpDirection(), + deltaTime); // test other avatar hand position for proximity glm::vec3 v( _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position ); @@ -355,8 +349,7 @@ void Avatar::simulate(float deltaTime) { // Set the vector we send for hand position to other people to be our right hand setHandPosition(_bone[ AVATAR_BONE_RIGHT_HAND ].position); - }//if ( _isMine ) - + } updateArmIKAndConstraints( deltaTime ); From be37237b843ebb645345aeaf8a4e95eca116c6d6 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 25 Apr 2013 15:58:42 -0700 Subject: [PATCH 22/36] fix indent in Avatar class --- interface/src/Avatar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index c51ea678e9..e8450b2aeb 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -545,7 +545,7 @@ void Avatar::simulate(float deltaTime) { // Update audio trailing average for rendering facial animations const float AUDIO_AVERAGING_SECS = 0.05; _head.averageLoudness = (1.f - deltaTime / AUDIO_AVERAGING_SECS) * _head.averageLoudness + - (deltaTime / AUDIO_AVERAGING_SECS) * _audioLoudness; + (deltaTime / AUDIO_AVERAGING_SECS) * _audioLoudness; } From 8370fd2d19c8947ad0cd47b8b8c97c57bc816372 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 25 Apr 2013 16:04:08 -0700 Subject: [PATCH 23/36] spacing fixes in Avatar class --- interface/src/Avatar.cpp | 43 +++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index e8450b2aeb..c79eb2ce2b 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -563,26 +563,26 @@ glm::vec3 Avatar::getBodyUpDirection() { } // This is a workspace for testing avatar body collision detection and response -void Avatar::updateAvatarCollisionDetectionAndResponse -( glm::vec3 collisionPosition, float collisionGirth, float collisionHeight, glm::vec3 collisionUpVector, float deltaTime ) { +void Avatar::updateAvatarCollisionDetectionAndResponse(glm::vec3 collisionPosition, + float collisionGirth, + float collisionHeight, + glm::vec3 collisionUpVector, + float deltaTime) { float myBodyApproximateBoundingRadius = 1.0f; glm::vec3 vectorFromMyBodyToBigSphere(_position - collisionPosition); bool jointCollision = false; float distanceToBigSphere = glm::length(vectorFromMyBodyToBigSphere); - if ( distanceToBigSphere < myBodyApproximateBoundingRadius + collisionGirth ) - { - for (int b=0; b 0.0) - { + if (distanceToBigSphereCenter > 0.0) { glm::vec3 directionVector = vectorFromJointToBigSphereCenter / distanceToBigSphereCenter; float penetration = 1.0 - (distanceToBigSphereCenter / combinedRadius); @@ -935,7 +935,7 @@ void Avatar::initializeSkeleton() { } void Avatar::calculateBoneLengths() { - for (int b=0; b Date: Thu, 25 Apr 2013 16:10:55 -0700 Subject: [PATCH 24/36] bunch of const changes for glm::vec3 in Avatar and Orientation --- interface/src/Avatar.cpp | 43 ++--------------------------- interface/src/Avatar.h | 12 ++++---- interface/src/Util.cpp | 6 ++-- libraries/avatars/src/Orientation.h | 14 +++++----- 4 files changed, 18 insertions(+), 57 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index c79eb2ce2b..68c453e41a 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -557,11 +557,6 @@ float Avatar::getHeight() { return COLLISION_HEIGHT; } - -glm::vec3 Avatar::getBodyUpDirection() { - return _orientation.getUp(); -} - // This is a workspace for testing avatar body collision detection and response void Avatar::updateAvatarCollisionDetectionAndResponse(glm::vec3 collisionPosition, float collisionGirth, @@ -1028,49 +1023,15 @@ void Avatar::updateBodySprings( float deltaTime ) { } } -glm::vec3 Avatar::getHeadLookatDirection() { - return glm::vec3 - ( - _orientation.getFront().x, - _orientation.getFront().y, - _orientation.getFront().z - ); -} - -glm::vec3 Avatar::getHeadLookatDirectionUp() { - return glm::vec3 - ( - _orientation.getUp().x, - _orientation.getUp().y, - _orientation.getUp().z - ); -} - -glm::vec3 Avatar::getHeadLookatDirectionRight() { - return glm::vec3 - ( - _orientation.getRight().x, - _orientation.getRight().y, - _orientation.getRight().z - ); -} - -glm::vec3 Avatar::getHeadPosition() { +const glm::vec3& Avatar::getHeadPosition() const { - if ( _usingBodySprings ) { + if (_usingBodySprings) { return _bone[ AVATAR_BONE_HEAD ].springyPosition; } return _bone[ AVATAR_BONE_HEAD ].position; } - -glm::vec3 Avatar::getBonePosition( AvatarBoneID b ) { - return _bone[b].position; -} - - - void Avatar::updateHandMovement( float deltaTime ) { glm::vec3 transformedHandMovement; diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index 32d31184a8..46aad8ba53 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -178,12 +178,12 @@ class Avatar : public AvatarData { float getBodyYaw() {return _bodyYaw;}; void addBodyYaw(float y) {_bodyYaw += y;}; - glm::vec3 getHeadLookatDirection(); - glm::vec3 getHeadLookatDirectionUp(); - glm::vec3 getHeadLookatDirectionRight(); - glm::vec3 getHeadPosition(); - glm::vec3 getBonePosition( AvatarBoneID b ); - glm::vec3 getBodyUpDirection(); + const glm::vec3& getHeadLookatDirection() const { return _orientation.getFront(); }; + const glm::vec3& getHeadLookatDirectionUp() const { return _orientation.getUp(); }; + const glm::vec3& getHeadLookatDirectionRight() const { return _orientation.getRight(); }; + const glm::vec3& getHeadPosition() const ; + const glm::vec3& getBonePosition(AvatarBoneID b) const { return _bone[b].position; }; + const glm::vec3& getBodyUpDirection() const { return _orientation.getUp(); }; float getGirth(); float getHeight(); diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 17f11cd64c..55b55b12eb 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -278,9 +278,9 @@ void drawGroundPlaneGrid( float size, int resolution ) void renderOrientationDirections( glm::vec3 position, Orientation orientation, float size ) { - glm::vec3 pRight = position + orientation.right * size; - glm::vec3 pUp = position + orientation.up * size; - glm::vec3 pFront = position + orientation.front * size; + glm::vec3 pRight = position + orientation.getRight() * size; + glm::vec3 pUp = position + orientation.getUp() * size; + glm::vec3 pFront = position + orientation.getFront() * size; glColor3f( 1.0f, 0.0f, 0.0f ); glBegin( GL_LINE_STRIP ); diff --git a/libraries/avatars/src/Orientation.h b/libraries/avatars/src/Orientation.h index 06425cf5dc..1b64230812 100755 --- a/libraries/avatars/src/Orientation.h +++ b/libraries/avatars/src/Orientation.h @@ -25,6 +25,10 @@ private: float _pitch; float _roll; + glm::vec3 right; + glm::vec3 up; + glm::vec3 front; + void update(); // actually updates the vectors from yaw, pitch, roll public: @@ -41,13 +45,9 @@ public: void set( Orientation ); void setToIdentity(); - glm::vec3 right; - glm::vec3 up; - glm::vec3 front; - - glm::vec3 getRight() { return right; } - glm::vec3 getUp() { return up; } - glm::vec3 getFront() { return front; } + const glm::vec3& getRight() const { return right; } + const glm::vec3& getUp() const { return up; } + const glm::vec3& getFront() const { return front; } void setRightUpFront( const glm::vec3 &, const glm::vec3 &, const glm::vec3 & ); From 2bda70075356feeee452844ee81e1e6a7a843839 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 25 Apr 2013 16:12:22 -0700 Subject: [PATCH 25/36] put iterator statements on one line in main.cpp --- interface/src/main.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 8fee0ee26a..5785fe8dd8 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -910,9 +910,7 @@ void display(void) // Render avatars of other agents AgentList *agentList = AgentList::getInstance(); - for(AgentList::iterator agent = agentList->begin(); - agent != agentList->end(); - agent++) { + for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { if (agent->getLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) { Avatar *avatar = (Avatar *)agent->getLinkedData(); avatar->render(0); From da6bbacc8e3bbf88573cdea9b96c61321412e668 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 25 Apr 2013 16:12:43 -0700 Subject: [PATCH 26/36] type squish in main.cpp --- interface/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 5785fe8dd8..48f41af7b9 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -909,7 +909,7 @@ void display(void) if (displayField) field.render(); // Render avatars of other agents - AgentList *agentList = AgentList::getInstance(); + AgentList* agentList = AgentList::getInstance(); for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { if (agent->getLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) { Avatar *avatar = (Avatar *)agent->getLinkedData(); From 507f39a052fa6eaf4b47513431057b9057e62465 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 25 Apr 2013 16:14:38 -0700 Subject: [PATCH 27/36] fix readability of agent dereference --- domain-server/src/main.cpp | 4 ++-- libraries/shared/src/AgentList.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/domain-server/src/main.cpp b/domain-server/src/main.cpp index 15f11aa0ae..523a97c25f 100644 --- a/domain-server/src/main.cpp +++ b/domain-server/src/main.cpp @@ -134,7 +134,7 @@ int main(int argc, const char * argv[]) // 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 if (agentType != AGENT_TYPE_AVATAR || agent->getType() != AGENT_TYPE_AVATAR) { - currentBufferPos = addAgentToBroadcastPacket(currentBufferPos, &*agent); + currentBufferPos = addAgentToBroadcastPacket(currentBufferPos, &(*agent)); } } else { @@ -142,7 +142,7 @@ int main(int argc, const char * argv[]) if (newestSoloAgents[agent->getType()] == NULL || newestSoloAgents[agent->getType()]->getFirstRecvTimeUsecs() < agent->getFirstRecvTimeUsecs()) { // we have to set the newer solo agent to add it to the broadcast later - newestSoloAgents[agent->getType()] = &*agent; + newestSoloAgents[agent->getType()] = &(*agent); } } } else { diff --git a/libraries/shared/src/AgentList.cpp b/libraries/shared/src/AgentList.cpp index 908547e9ba..823aaa9e60 100644 --- a/libraries/shared/src/AgentList.cpp +++ b/libraries/shared/src/AgentList.cpp @@ -173,7 +173,7 @@ int AgentList::updateAgentWithData(Agent *agent, unsigned char *packetData, int Agent* AgentList::agentWithAddress(sockaddr *senderAddress) { for(AgentList::iterator agent = begin(); agent != end(); agent++) { if (agent->getActiveSocket() != NULL && socketMatch(agent->getActiveSocket(), senderAddress)) { - return &*agent; + return &(*agent); } } @@ -183,7 +183,7 @@ Agent* AgentList::agentWithAddress(sockaddr *senderAddress) { Agent* AgentList::agentWithID(uint16_t agentID) { for(AgentList::iterator agent = begin(); agent != end(); agent++) { if (agent->getAgentId() == agentID) { - return &*agent; + return &(*agent); } } @@ -317,7 +317,7 @@ Agent* AgentList::soloAgentOfType(char agentType) { if (memchr(SOLO_AGENT_TYPES, agentType, sizeof(SOLO_AGENT_TYPES)) != NULL) { for(AgentList::iterator agent = begin(); agent != end(); agent++) { if (agent->getType() == agentType) { - return &*agent; + return &(*agent); } } } From 7e0dab622498e09548564988fb9d5fee63963245 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 25 Apr 2013 16:18:17 -0700 Subject: [PATCH 28/36] spacing fixes in Avatar class --- interface/src/Avatar.cpp | 25 ++--- interface/src/Avatar.h | 200 +++++++++++++++++++-------------------- 2 files changed, 107 insertions(+), 118 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 68c453e41a..a12aefe8fc 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -357,28 +357,21 @@ void Avatar::simulate(float deltaTime) { _interactingOther = NULL; } - if ( usingBigSphereCollisionTest ) { - + if (usingBigSphereCollisionTest) { // test for avatar collision response (using a big sphere :) - updateAvatarCollisionDetectionAndResponse - ( - _TEST_bigSpherePosition, - _TEST_bigSphereRadius, - _TEST_bigSphereRadius, - glm::vec3( 0.0, 1.0, 0.0 ), - deltaTime - ); + updateAvatarCollisionDetectionAndResponse(_TEST_bigSpherePosition, + _TEST_bigSphereRadius, + _TEST_bigSphereRadius, + glm::vec3( 0.0, 1.0, 0.0 ), + 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 ); - } - else { - if ( _position.y < _bone[ AVATAR_BONE_RIGHT_FOOT ].radius ) { - _position.y = _bone[ AVATAR_BONE_RIGHT_FOOT ].radius; - _velocity.y = 0.0; - } + } else if ( _position.y < _bone[ AVATAR_BONE_RIGHT_FOOT ].radius ) { + _position.y = _bone[ AVATAR_BONE_RIGHT_FOOT ].radius; + _velocity.y = 0.0; } } diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index 46aad8ba53..8b3f79dd89 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -157,112 +157,108 @@ struct AvatarHead class Avatar : public AvatarData { - public: - Avatar(bool isMine); - ~Avatar(); - Avatar(const Avatar &otherAvatar); - Avatar* clone() const; +public: + Avatar(bool isMine); + ~Avatar(); + Avatar(const Avatar &otherAvatar); + Avatar* clone() const; + + void reset(); + void UpdateGyros(float frametime, SerialInterface * serialInterface, glm::vec3 * gravity); + 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;} + float getRenderYaw() {return _renderYaw;} + float getRenderPitch() {return _renderPitch;} + void setLeanForward(float dist); + void setLeanSideways(float dist); + void addLean(float x, float z); + float getLastMeasuredHeadYaw() const {return _head.yawRate;} + float getBodyYaw() {return _bodyYaw;}; + void addBodyYaw(float y) {_bodyYaw += y;}; + + const glm::vec3& getHeadLookatDirection() const { return _orientation.getFront(); }; + const glm::vec3& getHeadLookatDirectionUp() const { return _orientation.getUp(); }; + const glm::vec3& getHeadLookatDirectionRight() const { return _orientation.getRight(); }; + const glm::vec3& getHeadPosition() const ; + const glm::vec3& getBonePosition(AvatarBoneID b) const { return _bone[b].position; }; + const glm::vec3& getBodyUpDirection() const { return _orientation.getUp(); }; + float getGirth(); + float getHeight(); - void reset(); - void UpdateGyros(float frametime, SerialInterface * serialInterface, glm::vec3 * gravity); - 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;} - float getRenderYaw() {return _renderYaw;} - float getRenderPitch() {return _renderPitch;} - void setLeanForward(float dist); - void setLeanSideways(float dist); - void addLean(float x, float z); - float getLastMeasuredHeadYaw() const {return _head.yawRate;} - float getBodyYaw() {return _bodyYaw;}; - void addBodyYaw(float y) {_bodyYaw += y;}; + AvatarMode getMode(); - const glm::vec3& getHeadLookatDirection() const { return _orientation.getFront(); }; - const glm::vec3& getHeadLookatDirectionUp() const { return _orientation.getUp(); }; - const glm::vec3& getHeadLookatDirectionRight() const { return _orientation.getRight(); }; - const glm::vec3& getHeadPosition() const ; - const glm::vec3& getBonePosition(AvatarBoneID b) const { return _bone[b].position; }; - const glm::vec3& getBodyUpDirection() const { return _orientation.getUp(); }; - float getGirth(); - float getHeight(); - - AvatarMode getMode(); - - void setMousePressed( bool pressed ); - void render(bool lookingInMirror); - void renderBody(); - void renderHead(bool lookingInMirror); - void simulate(float); - void startHandMovement(); - void stopHandMovement(); - void setHandMovementValues( glm::vec3 movement ); - void updateHandMovement( float deltaTime ); - void updateArmIKAndConstraints( float deltaTime ); - - float getAverageLoudness() {return _head.averageLoudness;}; - void setAverageLoudness(float al) {_head.averageLoudness = al;}; - - void SetNewHeadTarget(float, float); + void setMousePressed( bool pressed ); + void render(bool lookingInMirror); + void renderBody(); + void renderHead(bool lookingInMirror); + void simulate(float); + void startHandMovement(); + void stopHandMovement(); + void setHandMovementValues( glm::vec3 movement ); + void updateHandMovement( float deltaTime ); + void updateArmIKAndConstraints( float deltaTime ); - // Set what driving keys are being pressed to control thrust levels - void setDriveKeys(int key, bool val) { _driveKeys[key] = val; }; - bool getDriveKeys(int key) { return _driveKeys[key]; }; + float getAverageLoudness() {return _head.averageLoudness;}; + void setAverageLoudness(float al) {_head.averageLoudness = al;}; + + void SetNewHeadTarget(float, float); + + // Set what driving keys are being pressed to control thrust levels + void setDriveKeys(int key, bool val) { _driveKeys[key] = val; }; + bool getDriveKeys(int key) { return _driveKeys[key]; }; + + // Set/Get update the thrust that will move the avatar around + void setThrust(glm::vec3 newThrust) { _thrust = newThrust; }; + void addThrust(glm::vec3 newThrust) { _thrust += newThrust; }; + glm::vec3 getThrust() { return _thrust; }; + + // Related to getting transmitter UDP data used to animate the avatar hand + void processTransmitterData(unsigned char * packetData, int numBytes); + float getTransmitterHz() { return _transmitterHz; }; + +private: + AvatarHead _head; + bool _isMine; + glm::vec3 _TEST_bigSpherePosition; + float _TEST_bigSphereRadius; + bool _mousePressed; + float _bodyYawDelta; + bool _usingBodySprings; + glm::vec3 _movedHandOffset; + float _springVelocityDecay; + float _springForce; + glm::quat _rotation; // the rotation of the avatar body as a whole expressed as a quaternion + AvatarBone _bone[ NUM_AVATAR_BONES ]; + AvatarMode _mode; + AvatarHandHolding _handHolding; + glm::dvec3 _velocity; + glm::vec3 _thrust; + float _maxArmLength; + Orientation _orientation; + int _driveKeys[MAX_DRIVE_KEYS]; + GLUquadric* _sphere; + float _renderYaw; + float _renderPitch; // Pitch from view frustum when this is own head + timeval _transmitterTimer; + float _transmitterHz; + int _transmitterPackets; + Avatar* _interactingOther; + bool _interactingOtherIsNearby; - // Set/Get update the thrust that will move the avatar around - void setThrust(glm::vec3 newThrust) { _thrust = newThrust; }; - void addThrust(glm::vec3 newThrust) { _thrust += newThrust; }; - glm::vec3 getThrust() { return _thrust; }; - - // Related to getting transmitter UDP data used to animate the avatar hand - void processTransmitterData(unsigned char * packetData, int numBytes); - float getTransmitterHz() { return _transmitterHz; }; - - private: - AvatarHead _head; - bool _isMine; - glm::vec3 _TEST_bigSpherePosition; - float _TEST_bigSphereRadius; - bool _mousePressed; - float _bodyYawDelta; - bool _usingBodySprings; - glm::vec3 _movedHandOffset; - float _springVelocityDecay; - float _springForce; - glm::quat _rotation; // the rotation of the avatar body as a whole expressed as a quaternion - AvatarBone _bone[ NUM_AVATAR_BONES ]; - AvatarMode _mode; - AvatarHandHolding _handHolding; - glm::dvec3 _velocity; - glm::vec3 _thrust; - float _maxArmLength; - Orientation _orientation; - int _driveKeys[MAX_DRIVE_KEYS]; - GLUquadric* _sphere; - float _renderYaw; - float _renderPitch; // Pitch from view frustum when this is own head - timeval _transmitterTimer; - float _transmitterHz; - int _transmitterPackets; - Avatar* _interactingOther; - bool _interactingOtherIsNearby; - - // private methods... - void initializeSkeleton(); - void updateSkeleton(); - void initializeBodySprings(); - void updateBodySprings( float deltaTime ); - void calculateBoneLengths(); - void readSensors(); - void renderBoneAsBlock( AvatarBoneID b ); - void updateAvatarCollisionDetectionAndResponse - ( - glm::vec3 collisionPosition, - float collisionGirth, - float collisionHeight, - glm::vec3 collisionUpVector, - float deltaTime - ); + void initializeSkeleton(); + void updateSkeleton(); + void initializeBodySprings(); + void updateBodySprings( float deltaTime ); + void calculateBoneLengths(); + void readSensors(); + void renderBoneAsBlock( AvatarBoneID b ); + void updateAvatarCollisionDetectionAndResponse(glm::vec3 collisionPosition, + float collisionGirth, + float collisionHeight, + glm::vec3 collisionUpVector, + float deltaTime); }; #endif From 81322d01e5ee247df20950d1f402681bbdc767af Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 25 Apr 2013 16:19:33 -0700 Subject: [PATCH 29/36] spacing fixes in AgentList --- libraries/shared/src/AgentList.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/shared/src/AgentList.cpp b/libraries/shared/src/AgentList.cpp index 823aaa9e60..73855d4879 100644 --- a/libraries/shared/src/AgentList.cpp +++ b/libraries/shared/src/AgentList.cpp @@ -239,7 +239,7 @@ bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket, if (agent == end()) { // we didn't have this agent, so add them - Agent *newAgent = new Agent(publicSocket, localSocket, agentType, agentId); + Agent* newAgent = new Agent(publicSocket, localSocket, agentType, agentId); if (socketMatch(publicSocket, localSocket)) { // likely debugging scenario with two agents on local network @@ -367,7 +367,7 @@ void AgentList::stopPingUnknownAgentsThread() { } void *removeSilentAgents(void *args) { - AgentList *agentList = (AgentList *)args; + AgentList* agentList = (AgentList*) args; double checkTimeUSecs, sleepTime; while (!silentAgentThreadStopFlag) { @@ -398,7 +398,7 @@ void *removeSilentAgents(void *args) { } void AgentList::startSilentAgentRemovalThread() { - pthread_create(&removeSilentAgentsThread, NULL, removeSilentAgents, (void *)this); + pthread_create(&removeSilentAgentsThread, NULL, removeSilentAgents, (void*) this); } void AgentList::stopSilentAgentRemovalThread() { @@ -452,7 +452,7 @@ void *checkInWithDomainServer(void *args) { } void AgentList::startDomainServerCheckInThread() { - pthread_create(&checkInWithDomainServerThread, NULL, checkInWithDomainServer, (void *)this); + pthread_create(&checkInWithDomainServerThread, NULL, checkInWithDomainServer, (void*) this); } void AgentList::stopDomainServerCheckInThread() { From edc908b1cd23265671197184223508d3c09315fc Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 25 Apr 2013 16:25:49 -0700 Subject: [PATCH 30/36] AgentList type squishes across project --- audio-mixer/src/main.cpp | 4 ++-- avatar-mixer/src/main.cpp | 2 +- domain-server/src/main.cpp | 2 +- interface/src/main.cpp | 4 ++-- libraries/shared/src/AgentList.cpp | 4 ++-- voxel-server/src/main.cpp | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index 4e692024c4..7ad0f4e8a3 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -78,7 +78,7 @@ void *sendBuffer(void *args) int nextFrame = 0; timeval startTime; - AgentList *agentList = AgentList::getInstance(); + AgentList* agentList = AgentList::getInstance(); gettimeofday(&startTime, NULL); @@ -254,7 +254,7 @@ void attachNewBufferToAgent(Agent *newAgent) { int main(int argc, const char * argv[]) { - AgentList *agentList = AgentList::createInstance(AGENT_TYPE_AUDIO_MIXER, MIXER_LISTEN_PORT); + AgentList* agentList = AgentList::createInstance(AGENT_TYPE_AUDIO_MIXER, MIXER_LISTEN_PORT); setvbuf(stdout, NULL, _IOLBF, 0); ssize_t receivedBytes = 0; diff --git a/avatar-mixer/src/main.cpp b/avatar-mixer/src/main.cpp index 82d75fa0fb..13492639eb 100644 --- a/avatar-mixer/src/main.cpp +++ b/avatar-mixer/src/main.cpp @@ -53,7 +53,7 @@ void attachAvatarDataToAgent(Agent *newAgent) { int main(int argc, char* argv[]) { - AgentList *agentList = AgentList::createInstance(AGENT_TYPE_AVATAR_MIXER, AVATAR_LISTEN_PORT); + AgentList* agentList = AgentList::createInstance(AGENT_TYPE_AVATAR_MIXER, AVATAR_LISTEN_PORT); setvbuf(stdout, NULL, _IOLBF, 0); agentList->linkedDataCreateCallback = attachAvatarDataToAgent; diff --git a/domain-server/src/main.cpp b/domain-server/src/main.cpp index 523a97c25f..8c862fa934 100644 --- a/domain-server/src/main.cpp +++ b/domain-server/src/main.cpp @@ -62,7 +62,7 @@ unsigned char* addAgentToBroadcastPacket(unsigned char* currentPosition, Agent* int main(int argc, const char * argv[]) { - AgentList *agentList = AgentList::createInstance(AGENT_TYPE_DOMAIN, DOMAIN_LISTEN_PORT); + AgentList* agentList = AgentList::createInstance(AGENT_TYPE_DOMAIN, DOMAIN_LISTEN_PORT); // If user asks to run in "local" mode then we do NOT replace the IP // with the EC2 IP. Otherwise, we will replace the IP like we used to // this allows developers to run a local domain without recompiling the diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 48f41af7b9..1d5b9b50dc 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -980,7 +980,7 @@ void display(void) glPointSize(1.0f); char agents[100]; - AgentList *agentList = AgentList::getInstance(); + AgentList* agentList = AgentList::getInstance(); int totalAvatars = 0, totalServers = 0; for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { @@ -1495,7 +1495,7 @@ void idle(void) { updateAvatar(deltaTime); //loop through all the other avatars and simulate them... - AgentList * agentList = AgentList::getInstance(); + AgentList* agentList = AgentList::getInstance(); for(AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { if (agent->getLinkedData() != NULL) { Avatar *avatar = (Avatar *)agent->getLinkedData(); diff --git a/libraries/shared/src/AgentList.cpp b/libraries/shared/src/AgentList.cpp index 73855d4879..2c7d6cf25d 100644 --- a/libraries/shared/src/AgentList.cpp +++ b/libraries/shared/src/AgentList.cpp @@ -327,7 +327,7 @@ Agent* AgentList::soloAgentOfType(char agentType) { void *pingUnknownAgents(void *args) { - AgentList *agentList = (AgentList *)args; + AgentList* agentList = (AgentList*) args; const int PING_INTERVAL_USECS = 1 * 1000000; timeval lastSend; @@ -410,7 +410,7 @@ void *checkInWithDomainServer(void *args) { const int DOMAIN_SERVER_CHECK_IN_USECS = 1 * 1000000; - AgentList *parentAgentList = (AgentList *)args; + AgentList* parentAgentList = (AgentList*) args; timeval lastSend; unsigned char output[7]; diff --git a/voxel-server/src/main.cpp b/voxel-server/src/main.cpp index 9be9611048..a3c018765a 100644 --- a/voxel-server/src/main.cpp +++ b/voxel-server/src/main.cpp @@ -137,7 +137,7 @@ void eraseVoxelTreeAndCleanupAgentVisitData() { void *distributeVoxelsToListeners(void *args) { - AgentList *agentList = AgentList::getInstance(); + AgentList* agentList = AgentList::getInstance(); timeval lastSendTime; unsigned char *stopOctal; @@ -236,7 +236,7 @@ void attachVoxelAgentDataToAgent(Agent *newAgent) { int main(int argc, const char * argv[]) { - AgentList *agentList = AgentList::createInstance(AGENT_TYPE_VOXEL, VOXEL_LISTEN_PORT); + AgentList* agentList = AgentList::createInstance(AGENT_TYPE_VOXEL, VOXEL_LISTEN_PORT); setvbuf(stdout, NULL, _IOLBF, 0); // Handle Local Domain testing with the --local command line From 86e72a90d48302e09d61d2bd4a1169409098d651 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Thu, 25 Apr 2013 16:31:42 -0700 Subject: [PATCH 31/36] working on camera view shifting from first person to third person --- interface/src/Avatar.cpp | 38 +++++++++------ interface/src/Avatar.h | 2 + interface/src/Camera.cpp | 102 ++++++++++++++++++++++++--------------- interface/src/Camera.h | 12 +++-- interface/src/main.cpp | 60 ++++++++++++++++------- 5 files changed, 137 insertions(+), 77 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index fce2af682e..ac3fffd853 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -59,6 +59,7 @@ Avatar::Avatar(bool isMine) { //_transmitterTimer = 0; _transmitterHz = 0.0; _transmitterPackets = 0; + _speed = 0.0; _pelvisStandingHeight = 0.0f; _TEST_bigSphereRadius = 0.3f; @@ -444,18 +445,7 @@ void Avatar::simulate(float deltaTime) { } } - float translationalSpeed = glm::length( _velocity ); - float rotationalSpeed = fabs( _bodyYawDelta ); - if ( translationalSpeed + rotationalSpeed > 0.2 ) - { - _mode = AVATAR_MODE_WALKING; - } - else - { - _mode = AVATAR_MODE_INTERACTING; - } - - // update body yaw by body yaw delta + // update body yaw by body yaw delta if (_isMine) { _bodyYaw += _bodyYawDelta * deltaTime; } @@ -568,6 +558,22 @@ void Avatar::simulate(float deltaTime) { const float AUDIO_AVERAGING_SECS = 0.05; _head.averageLoudness = (1.f - deltaTime / AUDIO_AVERAGING_SECS) * _head.averageLoudness + (deltaTime / AUDIO_AVERAGING_SECS) * _audioLoudness; + + _speed = glm::length( _velocity ); + float rotationalSpeed = fabs( _bodyYawDelta ); + if ( _speed + rotationalSpeed > 0.2 ) + { + _mode = AVATAR_MODE_WALKING; + } + else + { + _mode = AVATAR_MODE_INTERACTING; + } +} + + +float Avatar::getSpeed() { + return _speed; } @@ -1103,11 +1109,11 @@ glm::vec3 Avatar::getBonePosition( AvatarBoneID b ) { void Avatar::updateHandMovement( float deltaTime ) { glm::vec3 transformedHandMovement; - + transformedHandMovement - = _orientation.getRight() * _movedHandOffset.x - + _orientation.getUp() * -_movedHandOffset.y * 0.5f - + _orientation.getFront() * -_movedHandOffset.y; + = _orientation.getRight() * _movedHandOffset.x * 1.6f + + _orientation.getUp() * _movedHandOffset.y * -0.9f + + _orientation.getFront() * _movedHandOffset.y * -1.5f; _bone[ AVATAR_BONE_RIGHT_HAND ].position += transformedHandMovement; diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index be20b10389..94d2563e39 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -184,6 +184,7 @@ class Avatar : public AvatarData { glm::vec3 getHeadPosition(); glm::vec3 getBonePosition( AvatarBoneID b ); glm::vec3 getBodyUpDirection(); + float getSpeed(); float getGirth(); float getHeight(); @@ -235,6 +236,7 @@ class Avatar : public AvatarData { AvatarHandHolding _handHolding; glm::dvec3 _velocity; glm::vec3 _thrust; + float _speed; float _maxArmLength; Orientation _orientation; int _driveKeys[MAX_DRIVE_KEYS]; diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index 1a4700216a..6118a9ead5 100644 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -11,58 +11,80 @@ #include "Camera.h" Camera::Camera() { - _frustumNeedsReshape = false; - _mode = CAMERA_MODE_THIRD_PERSON; - _tightness = 10.0; // default - _fieldOfView = 60.0; // default - _nearClip = 0.08; // default - _farClip = 50.0; // default - _yaw = 0.0; - _pitch = 0.0; - _roll = 0.0; - _upShift = 0.0; - _rightShift = 0.0; - _distance = 0.0; - _idealYaw = 0.0; - _targetPosition = glm::vec3( 0.0, 0.0, 0.0 ); - _position = glm::vec3( 0.0, 0.0, 0.0 ); - _idealPosition = glm::vec3( 0.0, 0.0, 0.0 ); + _frustumNeedsReshape = false; + _mode = CAMERA_MODE_THIRD_PERSON; + _tightness = 10.0; // default + _fieldOfView = 60.0; // default + _nearClip = 0.08; // default + _farClip = 50.0; // default + _modeShift = 0.0; + _yaw = 0.0; + _pitch = 0.0; + _roll = 0.0; + _upShift = 0.0; + _rightShift = 0.0; + _distance = 0.0; + _idealYaw = 0.0; + _targetPosition = glm::vec3( 0.0, 0.0, 0.0 ); + _position = glm::vec3( 0.0, 0.0, 0.0 ); + _idealPosition = glm::vec3( 0.0, 0.0, 0.0 ); _orientation.setToIdentity(); } + void Camera::update( float deltaTime ) { - // derive t from tightness - float t = _tightness * deltaTime; - if ( t > 1.0 ) { - t = 1.0; - } - - // update _yaw (before position!) - _yaw += ( _idealYaw - _yaw ) * t; + // generate the ortho-normals for the orientation based on the Euler angles + _orientation.setToIdentity(); + _orientation.yaw ( _yaw ); + _orientation.pitch( _pitch ); + _orientation.roll ( _roll ); - // generate the ortho-normals for the orientation based on the Euler angles - _orientation.setToIdentity(); - _orientation.yaw ( _yaw ); - _orientation.pitch( _pitch ); - _orientation.roll ( _roll ); - - float radian = ( _yaw / 180.0 ) * PIE; + if ( _mode == CAMERA_MODE_NULL ) { + _modeShift = 0.0; + } else { + // use iterative forces to keep the camera at the desired position and angle + updateFollowMode( deltaTime ); + + if ( _modeShift < 1.0f ) { + _modeShift += MODE_SHIFT_RATE * deltaTime; + if ( _modeShift > 1.0f ) { + _modeShift = 1.0f; + } + } + } +} - // update _position - //these need to be checked to make sure they correspond to the correct coordinate system. - double x = _distance * -sin( radian ); - double z = _distance * cos( radian ); - double y = _upShift; - - _idealPosition = _targetPosition + glm::vec3( x, y, z ); + +// use iterative forces to keep the camera at the desired position and angle +void Camera::updateFollowMode( float deltaTime ) { + // derive t from tightness + float t = _tightness * deltaTime; + if ( t > 1.0 ) { + t = 1.0; + } + + // update _yaw (before position!) + _yaw += ( _idealYaw - _yaw ) * t; + _orientation.yaw ( _yaw ); + + float radian = ( _yaw / 180.0 ) * PIE; + + // update _position + //these need to be checked to make sure they correspond to the correct coordinate system. + double x = _distance * -sin( radian ); + double z = _distance * cos( radian ); + double y = _upShift; + + _idealPosition = _targetPosition + glm::vec3( x, y, z ); //_idealPosition += _orientation.getRight() * _rightShift; //_idealPosition += _orientation.getUp () * _upShift; - + // pull position towards ideal position - _position += ( _idealPosition - _position ) * t; + _position += ( _idealPosition - _position ) * t; } + // call to find out if the view frustum needs to be reshaped bool Camera::getFrustumNeedsReshape() { return _frustumNeedsReshape; diff --git a/interface/src/Camera.h b/interface/src/Camera.h index 1826bb2c1f..51760867c0 100644 --- a/interface/src/Camera.h +++ b/interface/src/Camera.h @@ -14,12 +14,14 @@ enum CameraMode { CAMERA_MODE_NULL = -1, - CAMERA_MODE_FIRST_PERSON, CAMERA_MODE_THIRD_PERSON, + CAMERA_MODE_FIRST_PERSON, CAMERA_MODE_MY_OWN_FACE, NUM_CAMERA_MODES }; +const float MODE_SHIFT_RATE = 2.0f; + class Camera { public: @@ -27,7 +29,7 @@ public: void update( float deltaTime ); - void setMode ( CameraMode m ) { _mode = m; } + void setMode ( CameraMode m ) { _mode = m; _modeShift = 0.0f; } void setYaw ( float y ) { _yaw = y; } void setPitch ( float p ) { _pitch = p; } void setRoll ( float r ) { _roll = r; } @@ -50,6 +52,7 @@ public: glm::vec3 getPosition () { return _position; } Orientation getOrientation() { return _orientation; } CameraMode getMode () { return _mode; } + float getModeShift () { return _modeShift; } float getFieldOfView() { return _fieldOfView; } float getAspectRatio() { return _aspectRatio; } float getNearClip () { return _nearClip; } @@ -59,8 +62,9 @@ public: private: + CameraMode _mode; + float _modeShift; // 0.0 to 1.0 bool _frustumNeedsReshape; - CameraMode _mode; glm::vec3 _position; glm::vec3 _idealPosition; glm::vec3 _targetPosition; @@ -77,6 +81,8 @@ private: float _distance; float _tightness; Orientation _orientation; + + void updateFollowMode( float deltaTime ); }; #endif diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 080db4fe92..fcaff494c1 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -808,32 +808,56 @@ void display(void) myCamera.setUpShift ( 0.0 ); myCamera.setDistance ( 0.2 ); myCamera.setTightness ( 100.0f ); - myCamera.setFieldOfView ( 60.0f ); //this doesn't seem to be doing anything? - myCamera.update ( 1.f/FPS ); } else { - - //this is in the prototyping stages..keep firstPerson false for now. - bool firstPerson = false; - - if ( firstPerson ) { - myCamera.setPitch (15.0f ); // temporarily, this must be 0.0 or else bad juju - myCamera.setUpShift (0.0f ); - myCamera.setDistance (0.0f ); - myCamera.setTightness (100.0f); - myCamera.setFieldOfView(60.0f ); //this doesn't seem to be doing anything? + + float firstPersonPitch = 20.0f; + float firstPersonUpShift = 0.1f; + float firstPersonDistance = 0.0f; + float firstPersonTightness = 100.0f; + + float thirdPersonPitch = 0.0f; + float thirdPersonUpShift = -0.1f; + float thirdPersonDistance = 1.f; + float thirdPersonTightness = 8.0f; + + myCamera.setPitch (thirdPersonPitch ); + myCamera.setUpShift (thirdPersonUpShift ); + myCamera.setDistance (thirdPersonDistance ); + myCamera.setTightness(thirdPersonTightness); + + /* + if ( myAvatar.getSpeed() < 0.02 ) { + if (myCamera.getMode() != CAMERA_MODE_FIRST_PERSON ) { + myCamera.setMode(CAMERA_MODE_FIRST_PERSON); + } + + printf( "myCamera.getModeShift() = %f\n", myCamera.getModeShift()); + + myCamera.setPitch ( thirdPersonPitch + myCamera.getModeShift() * ( firstPersonPitch - thirdPersonPitch )); + myCamera.setUpShift ( thirdPersonUpShift + myCamera.getModeShift() * ( firstPersonUpShift - thirdPersonUpShift )); + myCamera.setDistance ( thirdPersonDistance + myCamera.getModeShift() * ( firstPersonDistance - thirdPersonDistance )); + myCamera.setTightness ( thirdPersonTightness + myCamera.getModeShift() * ( firstPersonTightness - thirdPersonTightness )); } else { - myCamera.setPitch (0.0f ); // temporarily, this must be 0.0 or else bad juju - myCamera.setUpShift (-0.1f); - myCamera.setDistance (1.0f ); - myCamera.setTightness (8.0f ); - myCamera.setFieldOfView(60.0f); //this doesn't seem to be doing anything? + if (myCamera.getMode() != CAMERA_MODE_THIRD_PERSON ) { + myCamera.setMode(CAMERA_MODE_THIRD_PERSON); + } + + printf( "myCamera.getModeShift() = %f\n", myCamera.getModeShift()); + + myCamera.setPitch ( firstPersonPitch + myCamera.getModeShift() * ( thirdPersonPitch - firstPersonPitch )); + myCamera.setUpShift ( firstPersonUpShift + myCamera.getModeShift() * ( thirdPersonUpShift - firstPersonUpShift )); + myCamera.setDistance ( firstPersonDistance + myCamera.getModeShift() * ( thirdPersonDistance - firstPersonDistance )); + myCamera.setTightness ( firstPersonTightness + myCamera.getModeShift() * ( thirdPersonTightness - firstPersonTightness )); } + */ myCamera.setTargetPosition( myAvatar.getHeadPosition() ); myCamera.setTargetYaw ( 180.0 - myAvatar.getBodyYaw() ); myCamera.setRoll ( 0.0 ); - myCamera.update ( 1.f/FPS); } + + // important... + myCamera.update( 1.f/FPS ); // Note: whichCamera is used to pick between the normal camera myCamera for our // main camera, vs, an alternate camera. The alternate camera we support right now From 3df81cc92a9c8ced37fcbc28f1029bdddda4a9f7 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 25 Apr 2013 16:41:35 -0700 Subject: [PATCH 32/36] resolve conflicts on merge with upstream master --- interface/src/Avatar.cpp | 26 ++++++++++++++++++++------ interface/src/Avatar.h | 7 +++++-- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 3c56eeec60..a4ffbec9ed 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -368,7 +368,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 ) { _position.y = _bone[ AVATAR_BONE_RIGHT_FOOT ].radius; _velocity.y = 0.0; @@ -429,11 +429,11 @@ 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 ); @@ -1203,5 +1203,19 @@ void Avatar::processTransmitterData(unsigned char* packetData, int numBytes) { glm::vec3 linVel(linX*linVelScale, linZ*linVelScale, -linY*linVelScale); addVelocity(linVel); */ - } + +// 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); + } +} \ No newline at end of file diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index 8b3f79dd89..c00c7a36a5 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -217,9 +217,12 @@ public: // Related to getting transmitter UDP data used to animate the avatar hand 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; + AvatarHead _head; bool _isMine; glm::vec3 _TEST_bigSpherePosition; float _TEST_bigSphereRadius; @@ -233,7 +236,7 @@ private: AvatarBone _bone[ NUM_AVATAR_BONES ]; AvatarMode _mode; AvatarHandHolding _handHolding; - glm::dvec3 _velocity; + glm::vec3 _velocity; glm::vec3 _thrust; float _maxArmLength; Orientation _orientation; From d2714e9321d4b88fb9a87ac77904af4a165cd418 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 25 Apr 2013 17:04:18 -0700 Subject: [PATCH 33/36] resolve conflicts on merge with upstream master --- interface/src/Avatar.cpp | 80 +++++++++++++--------------------------- interface/src/Avatar.h | 3 ++ interface/src/main.cpp | 8 ++-- 3 files changed, 33 insertions(+), 58 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 3d3f3e9ce4..3450eda231 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -59,8 +59,8 @@ Avatar::Avatar(bool isMine) { //_transmitterTimer = 0; _transmitterHz = 0.0; _transmitterPackets = 0; - - initializeSkeleton(); + _speed = 0.0; + _pelvisStandingHeight = 0.0f; _TEST_bigSphereRadius = 0.3f; _TEST_bigSpherePosition = glm::vec3( 0.0f, _TEST_bigSphereRadius, 2.0f ); @@ -315,9 +315,9 @@ void Avatar::simulate(float deltaTime) { Avatar *otherAvatar = (Avatar *)agent->getLinkedData(); // check for collisions with other avatars and respond - updateAvatarCollisionDetectionAndResponse(otherAvatar->getBonePosition(AVATAR_BONE_PELVIS_SPINE), - 0.2, - 0.2, + updateAvatarCollisionDetectionAndResponse(otherAvatar->getPosition(), + 0.1, + 0.1, otherAvatar->getBodyUpDirection(), deltaTime); @@ -326,8 +326,8 @@ void Avatar::simulate(float deltaTime) { v -= otherAvatar->getBonePosition( AVATAR_BONE_RIGHT_HAND ); float distance = glm::length( v ); - if ( distance < _maxArmLength ) { - + if ( distance < _maxArmLength + _maxArmLength ) { + //if ( distance < closestDistance ) { // perhaps I don't need this if we want to allow multi-avatar interactions { closestDistance = distance; @@ -372,27 +372,12 @@ void Avatar::simulate(float deltaTime) { if ( AVATAR_GRAVITY ) { if ( _position.y > _pelvisStandingHeight + 0.01 ) { - _velocity += glm::dvec3( 0.0, -1.0, 0.0 ) * ( 6.0 * deltaTime ); - } - else { - if ( _position.y < _pelvisStandingHeight ) { - _position.y = _pelvisStandingHeight; - _velocity.y = 0.0; - } - } - } - - /* - if ( AVATAR_GRAVITY ) { - if ( _position.y > _bone[ AVATAR_BONE_RIGHT_FOOT ].radius * 2.0 ) { _velocity += glm::dvec3(getGravity(getPosition())) * ( 6.0 * deltaTime ); - } else if ( _position.y < _bone[ AVATAR_BONE_RIGHT_FOOT ].radius ) { - _position.y = _bone[ AVATAR_BONE_RIGHT_FOOT ].radius; + } else if ( _position.y < _pelvisStandingHeight ) { + _position.y = _pelvisStandingHeight; _velocity.y = 0.0; } } - */ - // update body springs updateBodySprings( deltaTime ); @@ -427,19 +412,8 @@ void Avatar::simulate(float deltaTime) { _bodyYawDelta += YAW_MAG * deltaTime; } } - - float translationalSpeed = glm::length( _velocity ); - float rotationalSpeed = fabs( _bodyYawDelta ); - if ( translationalSpeed + rotationalSpeed > 0.2 ) - { - _mode = AVATAR_MODE_WALKING; - } - else - { - _mode = AVATAR_MODE_INTERACTING; - } - - // update body yaw by body yaw delta + + // update body yaw by body yaw delta if (_isMine) { _bodyYaw += _bodyYawDelta * deltaTime; } @@ -553,23 +527,15 @@ void Avatar::simulate(float deltaTime) { _head.averageLoudness = (1.f - deltaTime / AUDIO_AVERAGING_SECS) * _head.averageLoudness + (deltaTime / AUDIO_AVERAGING_SECS) * _audioLoudness; - _speed = glm::length( _velocity ); + _speed = glm::length( _velocity ); float rotationalSpeed = fabs( _bodyYawDelta ); - if ( _speed + rotationalSpeed > 0.2 ) - { + + if ( _speed + rotationalSpeed > 0.2 ) { _mode = AVATAR_MODE_WALKING; - } - else - { + } else { _mode = AVATAR_MODE_INTERACTING; } } - - -float Avatar::getSpeed() { - return _speed; -} - float Avatar::getGirth() { return COLLISION_BODY_RADIUS; @@ -611,7 +577,7 @@ void Avatar::updateAvatarCollisionDetectionAndResponse(glm::vec3 collisionPositi } } } - + if ( jointCollision ) { if (!_usingBodySprings) { _usingBodySprings = true; @@ -622,7 +588,7 @@ void Avatar::updateAvatarCollisionDetectionAndResponse(glm::vec3 collisionPositi } void Avatar::render(bool lookingInMirror) { - + /* // show avatar position glColor4f( 0.5f, 0.5f, 0.5f, 0.6 ); glPushMatrix(); @@ -908,8 +874,7 @@ void Avatar::initializeSkeleton() { _bone[ AVATAR_BONE_LEFT_HAND ].defaultPosePosition = glm::vec3( 0.0, -0.05, 0.0 ); _bone[ AVATAR_BONE_RIGHT_CHEST ].defaultPosePosition = glm::vec3( 0.05, 0.05, 0.0 ); _bone[ AVATAR_BONE_RIGHT_SHOULDER ].defaultPosePosition = glm::vec3( 0.03, 0.0, 0.0 ); - _bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].defaultPosePosition = glm::vec3( 0.0, -0.1, 0.0 ); - _bone[ AVATAR_BONE_RIGHT_FOREARM ].defaultPosePosition = glm::vec3( 0.0, -0.1, 0.0 ); + _bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].defaultPosePosition = glm::vec3( 0.0, -0.1, 0.0 ); _bone[ AVATAR_BONE_RIGHT_HAND ].defaultPosePosition = glm::vec3( 0.0, -0.05, 0.0 ); _bone[ AVATAR_BONE_LEFT_PELVIS ].defaultPosePosition = glm::vec3( -0.05, 0.0, 0.0 ); _bone[ AVATAR_BONE_LEFT_THIGH ].defaultPosePosition = glm::vec3( 0.0, -0.15, 0.0 ); @@ -948,6 +913,13 @@ void Avatar::initializeSkeleton() { // calculate bone length calculateBoneLengths(); + _pelvisStandingHeight = + _bone[ AVATAR_BONE_PELVIS_SPINE ].length + + _bone[ AVATAR_BONE_LEFT_THIGH ].length + + _bone[ AVATAR_BONE_LEFT_SHIN ].length + + _bone[ AVATAR_BONE_LEFT_FOOT ].length + + _bone[ AVATAR_BONE_RIGHT_FOOT ].radius; + // generate world positions updateSkeleton(); } @@ -1254,4 +1226,4 @@ glm::vec3 Avatar::getGravity(glm::vec3 pos) { // If flying in space, turn gravity OFF return glm::vec3(0.f, 0.f, 0.f); } -} +} \ No newline at end of file diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index 51da7e4d98..f5ebd20747 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -184,6 +184,7 @@ public: const glm::vec3& getHeadPosition() const ; const glm::vec3& getBonePosition(AvatarBoneID b) const { return _bone[b].position; }; const glm::vec3& getBodyUpDirection() const { return _orientation.getUp(); }; + float getSpeed() const { return _speed; }; float getGirth(); float getHeight(); @@ -238,6 +239,7 @@ private: AvatarHandHolding _handHolding; glm::vec3 _velocity; glm::vec3 _thrust; + float _speed; float _maxArmLength; Orientation _orientation; int _driveKeys[MAX_DRIVE_KEYS]; @@ -249,6 +251,7 @@ private: int _transmitterPackets; Avatar* _interactingOther; bool _interactingOtherIsNearby; + float _pelvisStandingHeight; void initializeSkeleton(); void updateSkeleton(); diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 1ffb73e846..ec7c17a58d 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -810,10 +810,10 @@ void display(void) myCamera.setTightness ( 100.0f ); } else { - float firstPersonPitch = 20.0f; - float firstPersonUpShift = 0.1f; - float firstPersonDistance = 0.0f; - float firstPersonTightness = 100.0f; +// float firstPersonPitch = 20.0f; +// float firstPersonUpShift = 0.1f; +// float firstPersonDistance = 0.0f; +// float firstPersonTightness = 100.0f; float thirdPersonPitch = 0.0f; float thirdPersonUpShift = -0.1f; From ccbbf31beb2a10ac0dd5fe2e392f2bb418faa427 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 25 Apr 2013 17:10:09 -0700 Subject: [PATCH 34/36] fix for extraneous typedefs and reference to AgentListIterator as friend --- interface/src/main.cpp | 2 +- libraries/shared/src/AgentList.h | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index ec7c17a58d..4fad6f922b 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -813,7 +813,7 @@ void display(void) // float firstPersonPitch = 20.0f; // float firstPersonUpShift = 0.1f; // float firstPersonDistance = 0.0f; -// float firstPersonTightness = 100.0f; +// float firstPersonT ightness = 100.0f; float thirdPersonPitch = 0.0f; float thirdPersonUpShift = -0.1f; diff --git a/libraries/shared/src/AgentList.h b/libraries/shared/src/AgentList.h index 92a80ddc08..1687fc71c4 100644 --- a/libraries/shared/src/AgentList.h +++ b/libraries/shared/src/AgentList.h @@ -39,11 +39,6 @@ public: static AgentList* getInstance(); typedef AgentListIterator iterator; - typedef ptrdiff_t difference_type; - typedef size_t size_type; - typedef Agent value_type; - typedef Agent * pointer; - typedef Agent & reference; AgentListIterator begin() const; AgentListIterator end() const; @@ -84,7 +79,7 @@ public: void startPingUnknownAgentsThread(); void stopPingUnknownAgentsThread(); - friend AgentListIterator; + friend ::AgentListIterator; private: static AgentList* _sharedInstance; From 69ea567f77657e7281ad72a1222fd6da81ecf66a Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 25 Apr 2013 17:12:11 -0700 Subject: [PATCH 35/36] use class key for AgentListIterator friend in AgentList --- libraries/shared/src/AgentList.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/shared/src/AgentList.h b/libraries/shared/src/AgentList.h index 1687fc71c4..19dee70359 100644 --- a/libraries/shared/src/AgentList.h +++ b/libraries/shared/src/AgentList.h @@ -79,7 +79,7 @@ public: void startPingUnknownAgentsThread(); void stopPingUnknownAgentsThread(); - friend ::AgentListIterator; + friend class AgentListIterator; private: static AgentList* _sharedInstance; From 09256d8c4e59dd094f3f4f31f190c599322c6168 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 25 Apr 2013 17:15:48 -0700 Subject: [PATCH 36/36] put back default for AVATAR_BONE_RIGHT_FOREARM --- interface/src/Avatar.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 3450eda231..521cf4fea0 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -874,7 +874,8 @@ void Avatar::initializeSkeleton() { _bone[ AVATAR_BONE_LEFT_HAND ].defaultPosePosition = glm::vec3( 0.0, -0.05, 0.0 ); _bone[ AVATAR_BONE_RIGHT_CHEST ].defaultPosePosition = glm::vec3( 0.05, 0.05, 0.0 ); _bone[ AVATAR_BONE_RIGHT_SHOULDER ].defaultPosePosition = glm::vec3( 0.03, 0.0, 0.0 ); - _bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].defaultPosePosition = glm::vec3( 0.0, -0.1, 0.0 ); + _bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].defaultPosePosition = glm::vec3( 0.0, -0.1, 0.0 ); + _bone[ AVATAR_BONE_RIGHT_FOREARM ].defaultPosePosition = glm::vec3( 0.0, -0.1, 0.0 ); _bone[ AVATAR_BONE_RIGHT_HAND ].defaultPosePosition = glm::vec3( 0.0, -0.05, 0.0 ); _bone[ AVATAR_BONE_LEFT_PELVIS ].defaultPosePosition = glm::vec3( -0.05, 0.0, 0.0 ); _bone[ AVATAR_BONE_LEFT_THIGH ].defaultPosePosition = glm::vec3( 0.0, -0.15, 0.0 );