From 6273594f51f44e59f91e82ce2a7adb53acbaad90 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Mon, 6 May 2013 12:56:31 -0700 Subject: [PATCH 01/41] made a call to initializeBodySprings at the end of initializeSkeleton --- interface/src/Avatar.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index a1a93fbfe3..f7cf543f14 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -381,7 +381,7 @@ void Avatar::simulate(float deltaTime) { // decay body rotation momentum float bodySpinMomentum = 1.0 - BODY_SPIN_FRICTION * deltaTime; - if ( bodySpinMomentum < 0.0f ) { bodySpinMomentum = 0.0f; } + if (bodySpinMomentum < 0.0f) { bodySpinMomentum = 0.0f; } _bodyPitchDelta *= bodySpinMomentum; _bodyYawDelta *= bodySpinMomentum; _bodyRollDelta *= bodySpinMomentum; @@ -1193,6 +1193,9 @@ void Avatar::initializeSkeleton() { // generate world positions updateSkeleton(); + + //set spring positions to be in the skeleton bone positions + initializeBodySprings(); } void Avatar::calculateBoneLengths() { From 40771e4c4778547738dd72fd25706c38e61c3870 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Mon, 6 May 2013 14:18:14 -0700 Subject: [PATCH 02/41] thingy --- interface/src/Avatar.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index f7cf543f14..fdf8e326ce 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -446,6 +446,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { _handState = _mousePressed; } + /* //reset these for the next go-round _avatarTouch.setAbleToReachOtherAvatar (false); _avatarTouch.setHandsCloseEnoughToGrasp(false); @@ -516,12 +517,14 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { // Set the vector we send for hand position to other people to be our right hand setHandPosition(_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position); - }//if (_isMine) + */ + //constrain right arm length and re-adjust elbow position as it bends updateArmIKAndConstraints(deltaTime); - + + /* // set hand positions for _avatarTouch.setMyHandPosition AFTER calling updateArmIKAndConstraints if (_interactingOther) { if (_isMine) { @@ -536,9 +539,15 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { if (!_avatarTouch.getAbleToReachOtherAvatar() ) { _interactingOther = NULL; } + + */ } + + + + void Avatar::updateHead(float deltaTime) { //apply the head lean values to the springy position... From 114dfeacf66707e73ef416fe975b2a69e34fa5e8 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Mon, 6 May 2013 14:22:01 -0700 Subject: [PATCH 03/41] thingy --- interface/src/Avatar.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index fdf8e326ce..f41fe344b1 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -515,8 +515,6 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { } } - // Set the vector we send for hand position to other people to be our right hand - setHandPosition(_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position); }//if (_isMine) */ @@ -524,6 +522,11 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { //constrain right arm length and re-adjust elbow position as it bends updateArmIKAndConstraints(deltaTime); + if (_isMine) { + // Set the vector we send for hand position to other people to be our right hand + setHandPosition(_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position); + } + /* // set hand positions for _avatarTouch.setMyHandPosition AFTER calling updateArmIKAndConstraints if (_interactingOther) { From c1ac3eb320dba8f5664993e546b8429b9b1ac9cb Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Mon, 6 May 2013 15:14:13 -0700 Subject: [PATCH 04/41] improving the code for detecting collisions, hand movement and handholding --- interface/src/Avatar.cpp | 229 +++++++++++++++++---------------------- interface/src/Avatar.h | 5 +- 2 files changed, 101 insertions(+), 133 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index f41fe344b1..c103d93e37 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -144,7 +144,7 @@ Avatar::Avatar(bool isMine) { _renderYaw = 0.0; _renderPitch = 0.0; _sphere = NULL; - _interactingOther = NULL; + //_interactingOther = NULL; _handHoldingPosition = glm::vec3(0.0f, 0.0f, 0.0f); _distanceToNearestAvatar = std::numeric_limits::max(); _gravity = glm::vec3(0.0f, -1.0f, 0.0f); // default @@ -335,6 +335,11 @@ void Avatar::simulate(float deltaTime) { // update avatar skeleton updateSkeleton(); + //detect and respond to collisions with other avatars... + if (_isMine) { + updateAvatarCollisions(deltaTime); + } + //update the movement of the hand and process handshaking with other avatars... updateHandMovementAndTouching(deltaTime); @@ -431,7 +436,6 @@ void Avatar::simulate(float deltaTime) { -//update the movement of the hand and process handshaking with other avatars... void Avatar::updateHandMovementAndTouching(float deltaTime) { // reset hand and arm positions according to hand movement @@ -441,110 +445,43 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { + _orientation.getFront() * -_movedHandOffset.y * 1.0f; _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position += transformedHandMovement; - - if (_isMine) { - _handState = _mousePressed; - } - - /* - //reset these for the next go-round - _avatarTouch.setAbleToReachOtherAvatar (false); - _avatarTouch.setHandsCloseEnoughToGrasp(false); - - // if the avatar being simulated is mine, then loop through - // all the other avatars for potential interactions... + if (_isMine) { // Reset detector for nearest avatar _distanceToNearestAvatar = std::numeric_limits::max(); + //loop through all the other avatars for potential interactions... AgentList* agentList = AgentList::getInstance(); 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 - updateCollisionWithOtherAvatar(otherAvatar, deltaTime ); - + //applyCollisionWithOtherAvatar(otherAvatar, deltaTime ); + // test other avatar hand position for proximity glm::vec3 v(_joint[ AVATAR_JOINT_RIGHT_SHOULDER ].position); v -= otherAvatar->getJointPosition(AVATAR_JOINT_RIGHT_SHOULDER); - float distance = glm::length(v); - if (distance < _distanceToNearestAvatar) {_distanceToNearestAvatar = distance;} - - if (distance < _maxArmLength + _maxArmLength) { - - _interactingOther = otherAvatar; - - if (! _avatarTouch.getAbleToReachOtherAvatar()) { - //initialize _handHolding - _handHoldingPosition = _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position; - _avatarTouch.setAbleToReachOtherAvatar(true); - } - - glm::vec3 vectorBetweenHands(_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position); - vectorBetweenHands -= otherAvatar->getJointPosition(AVATAR_JOINT_RIGHT_FINGERTIPS); - float distanceBetweenHands = glm::length(vectorBetweenHands); - - if (distanceBetweenHands < HANDS_CLOSE_ENOUGH_TO_GRASP) { - _avatarTouch.setHandsCloseEnoughToGrasp(true); - } - - // if I am holding hands with another avatar, a force is applied - if ((_handState == 1) || (_interactingOther->_handState == 1)) { - - // if the hands are close enough to grasp... - if (distanceBetweenHands < HANDS_CLOSE_ENOUGH_TO_GRASP) - { - // apply the forces... - glm::vec3 vectorToOtherHand = _interactingOther->_handPosition - _handHoldingPosition; - glm::vec3 vectorToMyHand = _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position - _handHoldingPosition; - - _handHoldingPosition += vectorToOtherHand * YOUR_HAND_HOLDING_PULL; - _handHoldingPosition += vectorToMyHand * MY_HAND_HOLDING_PULL; - _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position = _handHoldingPosition; - - // apply a force to the avatar body - if (glm::length(vectorToOtherHand) > _maxArmLength * 0.9) { - _velocity += vectorToOtherHand; - } - } - } - } + //float distance = glm::length(v); + //if (distance < _distanceToNearestAvatar) { + // _distanceToNearestAvatar = distance; + //} } } }//if (_isMine) - */ - //constrain right arm length and re-adjust elbow position as it bends updateArmIKAndConstraints(deltaTime); if (_isMine) { - // Set the vector we send for hand position to other people to be our right hand + //Set the vector we send for hand position to other people to be our right hand setHandPosition(_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position); + _handState = _mousePressed; } - - /* - // set hand positions for _avatarTouch.setMyHandPosition AFTER calling updateArmIKAndConstraints - if (_interactingOther) { - if (_isMine) { - _avatarTouch.setMyHandPosition (_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position); - _avatarTouch.setYourHandPosition(_interactingOther->_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position); - _avatarTouch.setMyHandState (_handState); - _avatarTouch.setYourHandState (_interactingOther->_handState); - _avatarTouch.simulate(deltaTime); - } - } - - if (!_avatarTouch.getAbleToReachOtherAvatar() ) { - _interactingOther = NULL; - } - - */ -} + } @@ -702,66 +639,96 @@ void Avatar::updateCollisionWithSphere(glm::vec3 position, float radius, float d } -//detect collisions with other avatars and respond -void Avatar::updateCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime) { - // check if the bounding spheres of the two avatars are colliding - glm::vec3 vectorBetweenBoundingSpheres(_position - otherAvatar->_position); - if (glm::length(vectorBetweenBoundingSpheres) < _height * ONE_HALF + otherAvatar->_height * ONE_HALF) { + +void Avatar::updateAvatarCollisions(float deltaTime) { + + // Reset detector for nearest avatar + _distanceToNearestAvatar = std::numeric_limits::max(); + + //loop through all the other avatars for potential interactions... + AgentList* agentList = AgentList::getInstance(); + 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 if the bounding spheres of the two avatars are colliding + glm::vec3 vectorBetweenBoundingSpheres(_position - otherAvatar->_position); + if (glm::length(vectorBetweenBoundingSpheres) < _height * ONE_HALF + otherAvatar->_height * ONE_HALF) { + //apply forces from collision + applyCollisionWithOtherAvatar(otherAvatar, deltaTime ); + } + + // test other avatar hand position for proximity + glm::vec3 v(_joint[ AVATAR_JOINT_RIGHT_SHOULDER ].position); + v -= otherAvatar->getPosition(); + + float distance = glm::length(v); + if (distance < _distanceToNearestAvatar) { + _distanceToNearestAvatar = distance; + } + } + } +} + + + + +//detect collisions with other avatars and respond +void Avatar::applyCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime) { float bodyMomentum = 1.0f; glm::vec3 bodyPushForce = glm::vec3(0.0f, 0.0f, 0.0f); - // loop through the joints of each avatar to check for every possible collision - for (int b=1; b_joint[o].isCollidable) { + for (int o=b+1; o_joint[o].isCollidable) { + + glm::vec3 vectorBetweenJoints(_joint[b].springyPosition - otherAvatar->_joint[o].springyPosition); + float distanceBetweenJoints = glm::length(vectorBetweenJoints); - glm::vec3 vectorBetweenJoints(_joint[b].springyPosition - otherAvatar->_joint[o].springyPosition); - float distanceBetweenJoints = glm::length(vectorBetweenJoints); - - if (distanceBetweenJoints > 0.0 ) { // to avoid divide by zero - float combinedRadius = _joint[b].radius + otherAvatar->_joint[o].radius; + if (distanceBetweenJoints > 0.0 ) { // to avoid divide by zero + float combinedRadius = _joint[b].radius + otherAvatar->_joint[o].radius; - // check for collision - if (distanceBetweenJoints < combinedRadius * COLLISION_RADIUS_SCALAR) { - glm::vec3 directionVector = vectorBetweenJoints / distanceBetweenJoints; + // check for collision + if (distanceBetweenJoints < combinedRadius * COLLISION_RADIUS_SCALAR) { + glm::vec3 directionVector = vectorBetweenJoints / distanceBetweenJoints; + + // push balls away from each other and apply friction + glm::vec3 ballPushForce = directionVector * COLLISION_BALL_FORCE * deltaTime; + + float ballMomentum = 1.0 - COLLISION_BALL_FRICTION * deltaTime; + if (ballMomentum < 0.0 ) { ballMomentum = 0.0;} + + _joint[b].springyVelocity += ballPushForce; + otherAvatar->_joint[o].springyVelocity -= ballPushForce; + + _joint[b].springyVelocity *= ballMomentum; + otherAvatar->_joint[o].springyVelocity *= ballMomentum; + + // accumulate forces and frictions to apply to the velocities of avatar bodies + bodyPushForce += directionVector * COLLISION_BODY_FORCE * deltaTime; + bodyMomentum -= COLLISION_BODY_FRICTION * deltaTime; + if (bodyMomentum < 0.0 ) { bodyMomentum = 0.0;} + + }// check for collision + } // to avoid divide by zero + } // o loop + } // collidable + } // b loop + } // collidable + + + //apply forces and frictions on the bodies of both avatars + _velocity += bodyPushForce; + otherAvatar->_velocity -= bodyPushForce; + _velocity *= bodyMomentum; + otherAvatar->_velocity *= bodyMomentum; +} - // push balls away from each other and apply friction - glm::vec3 ballPushForce = directionVector * COLLISION_BALL_FORCE * deltaTime; - - float ballMomentum = 1.0 - COLLISION_BALL_FRICTION * deltaTime; - if (ballMomentum < 0.0 ) { ballMomentum = 0.0;} - - _joint[b].springyVelocity += ballPushForce; - otherAvatar->_joint[o].springyVelocity -= ballPushForce; - - _joint[b].springyVelocity *= ballMomentum; - otherAvatar->_joint[o].springyVelocity *= ballMomentum; - - // accumulate forces and frictions to apply to the velocities of avatar bodies - bodyPushForce += directionVector * COLLISION_BODY_FORCE * deltaTime; - bodyMomentum -= COLLISION_BODY_FRICTION * deltaTime; - if (bodyMomentum < 0.0 ) { bodyMomentum = 0.0;} - - }// check for collision - } // to avoid divide by zero - } // o loop - } // collidable - } // b loop - } // collidable - - - //apply forces and frictions on the bodies of both avatars - _velocity += bodyPushForce; - otherAvatar->_velocity -= bodyPushForce; - _velocity *= bodyMomentum; - otherAvatar->_velocity *= bodyMomentum; - - } // bounding sphere collision -} //method void Avatar::setDisplayingHead(bool displayingHead ) { diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index 6fb8ee01ee..8bb98aadf3 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -241,7 +241,7 @@ private: float _transmitterHz; int _transmitterPackets; glm::vec3 _transmitterInitialReading; - Avatar* _interactingOther; + //Avatar* _interactingOther; float _pelvisStandingHeight; float _height; Balls* _balls; @@ -260,8 +260,9 @@ private: void readSensors(); void updateHead( float deltaTime ); void updateHandMovementAndTouching(float deltaTime); + void updateAvatarCollisions(float deltaTime); void updateCollisionWithSphere( glm::vec3 position, float radius, float deltaTime ); - void updateCollisionWithOtherAvatar( Avatar * other, float deltaTime ); + void applyCollisionWithOtherAvatar( Avatar * other, float deltaTime ); void setHeadFromGyros(glm::vec3 * eulerAngles, glm::vec3 * angularVelocity, float deltaTime, float smoothingTime); void setHeadSpringScale(float s) { _head.returnSpringScale = s; } }; From fd4a0c9acd42985b8318822284dda478c9a8bd90 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Mon, 6 May 2013 16:17:16 -0700 Subject: [PATCH 05/41] working on detection of avatars entering into each other's peripersonal space --- interface/src/Avatar.cpp | 38 +++++++++++++++------------ interface/src/AvatarTouch.cpp | 49 +++++++++++++++++++++++++++++++---- interface/src/AvatarTouch.h | 22 ++++++++++------ 3 files changed, 79 insertions(+), 30 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index c103d93e37..58ec217e06 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -151,6 +151,8 @@ Avatar::Avatar(bool isMine) { initializeSkeleton(); + _avatarTouch.setReachableRadius(0.4); + if (iris_texture.size() == 0) { switchToResourcesParentIfRequired(); unsigned error = lodepng::decode(iris_texture, iris_texture_width, iris_texture_height, iris_texture_file); @@ -342,7 +344,8 @@ void Avatar::simulate(float deltaTime) { //update the movement of the hand and process handshaking with other avatars... updateHandMovementAndTouching(deltaTime); - + + _avatarTouch.simulate(deltaTime); // apply gravity and collision with the ground/floor if (USING_AVATAR_GRAVITY) { @@ -448,32 +451,35 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { if (_isMine) { - // Reset detector for nearest avatar - _distanceToNearestAvatar = std::numeric_limits::max(); + _avatarTouch.setMyBodyPosition(_position); + + Avatar * _interactingOther = NULL; + float closestDistance = 10000.0f; //loop through all the other avatars for potential interactions... AgentList* agentList = AgentList::getInstance(); 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 - //applyCollisionWithOtherAvatar(otherAvatar, deltaTime ); - - // test other avatar hand position for proximity - glm::vec3 v(_joint[ AVATAR_JOINT_RIGHT_SHOULDER ].position); - v -= otherAvatar->getJointPosition(AVATAR_JOINT_RIGHT_SHOULDER); - - //float distance = glm::length(v); - //if (distance < _distanceToNearestAvatar) { - // _distanceToNearestAvatar = distance; - //} + + // test whether shoulders are close enough to allow for reaching to touch hands + glm::vec3 v(_position - otherAvatar->_position); + float distance = glm::length(v); + if (distance < closestDistance) { + closestDistance = distance; + _interactingOther = otherAvatar; + } } } + + if (_interactingOther) { + _avatarTouch.setYourHandPosition(_interactingOther->_position); + } }//if (_isMine) //constrain right arm length and re-adjust elbow position as it bends + // NOTE - the following must be called on all avatars - not just _isMine updateArmIKAndConstraints(deltaTime); if (_isMine) { @@ -483,8 +489,6 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { } } - - diff --git a/interface/src/AvatarTouch.cpp b/interface/src/AvatarTouch.cpp index 37c4c7fb2f..5dd44d46cc 100644 --- a/interface/src/AvatarTouch.cpp +++ b/interface/src/AvatarTouch.cpp @@ -17,8 +17,11 @@ AvatarTouch::AvatarTouch() { _myHandPosition = glm::vec3( 0.0f, 0.0f, 0.0f ); _yourHandPosition = glm::vec3( 0.0f, 0.0f, 0.0f ); + _myBodyPosition = glm::vec3( 0.0f, 0.0f, 0.0f ); + _yourBodyPosition = glm::vec3( 0.0f, 0.0f, 0.0f ); _myHandState = 0; - _yourHandState = 0; + _yourHandState = 0; + _reachableRadius = 0.0f; _canReachToOtherAvatar = false; _handsCloseEnoughToGrasp = false; @@ -36,6 +39,14 @@ void AvatarTouch::setYourHandPosition( glm::vec3 position ) { _yourHandPosition = position; } +void AvatarTouch::setMyBodyPosition( glm::vec3 position ) { + _myBodyPosition = position; +} + +void AvatarTouch::setYourBodyPosition( glm::vec3 position ) { + _yourBodyPosition = position; +} + void AvatarTouch::setMyHandState( int state ) { _myHandState = state; } @@ -44,12 +55,19 @@ void AvatarTouch::setYourHandState( int state ) { _yourHandState = state; } +void AvatarTouch::setReachableRadius( float r ) { + _reachableRadius = r; +} + void AvatarTouch::render() { - glm::vec3 v1( _myHandPosition ); - glm::vec3 v2( _yourHandPosition ); +if (_canReachToOtherAvatar) { + glPushMatrix(); + glTranslatef(_myBodyPosition.x, _myBodyPosition.y, _myBodyPosition.z); + glColor4f( 0.3, 0.4, 0.5, 0.3 ); glutSolidSphere( _reachableRadius, 30.0f, 30.0f ); + glPopMatrix(); - if (_canReachToOtherAvatar) { + /* // if my hand is grasping, show it... if ( _myHandState == 1 ) { glPushMatrix(); @@ -69,9 +87,15 @@ void AvatarTouch::render() { glColor4f( 1.0, 1.0, 0.2, 0.1 ); glutSolidSphere( 0.030f, 10.0f, 10.0f ); glPopMatrix(); } + */ } + /* //show beam + + glm::vec3 v1( _myHandPosition ); + glm::vec3 v2( _yourHandPosition ); + if (_handsCloseEnoughToGrasp) { glLineWidth( 2.0 ); glColor4f( 0.7f, 0.4f, 0.1f, 0.3 ); @@ -88,16 +112,31 @@ void AvatarTouch::render() { glEnd(); } } + */ + } void AvatarTouch::simulate (float deltaTime) { - glm::vec3 v = _yourHandPosition - _myHandPosition; + glm::vec3 v = _yourBodyPosition - _myBodyPosition; + + float distance = glm::length(v); + + if (distance < _reachableRadius * 2.0f ) { + _canReachToOtherAvatar = true; + } else { + _canReachToOtherAvatar = false; + } + +/* + for (int p=0; p Date: Mon, 6 May 2013 16:18:27 -0700 Subject: [PATCH 06/41] Created a drawVector() call that will draw a vector in 3-space with axes for testing --- interface/src/Util.cpp | 50 +++++++++++++++++++++--------------------- interface/src/Util.h | 4 +++- interface/src/main.cpp | 9 ++++++++ 3 files changed, 37 insertions(+), 26 deletions(-) diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 94e0e826d1..355dec185c 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -65,46 +65,47 @@ float angle_to(glm::vec3 head_pos, glm::vec3 source_pos, float render_yaw, float return atan2(head_pos.x - source_pos.x, head_pos.z - source_pos.z) * 180.0f / PIf + render_yaw + head_yaw; } -void render_vector(glm::vec3 * vec) +// Draw a 3D vector floating in space +void drawVector(glm::vec3 * vector) { - // Show edge of world glDisable(GL_LIGHTING); - glColor4f(1.0, 1.0, 1.0, 1.0); - glLineWidth(1.0); - glBegin(GL_LINES); + glEnable(GL_POINT_SMOOTH); + glPointSize(3.0); + glLineWidth(2.0); + // Draw axes + glBegin(GL_LINES); glColor3f(1,0,0); - glVertex3f(-1,0,0); + glVertex3f(0,0,0); glVertex3f(1,0,0); glColor3f(0,1,0); - glVertex3f(0,-1,0); + glVertex3f(0,0,0); glVertex3f(0, 1, 0); glColor3f(0,0,1); - glVertex3f(0,0,-1); + glVertex3f(0,0,0); glVertex3f(0, 0, 1); - // Draw vector + glEnd(); + + // Draw the vector itself + glBegin(GL_LINES); glColor3f(1,1,1); glVertex3f(0,0,0); - glVertex3f(vec->x, vec->y, vec->z); - // Draw marker dots for magnitude + glVertex3f(vector->x, vector->y, vector->z); glEnd(); - float particleAttenuationQuadratic[] = { 0.0f, 0.0f, 2.0f }; // larger Z = smaller particles - float particleAttenuationConstant[] = { 1.0f, 0.0f, 0.0f }; - - glPointParameterfvARB( GL_POINT_DISTANCE_ATTENUATION_ARB, particleAttenuationQuadratic ); - glEnable(GL_POINT_SMOOTH); - glPointSize(10.0); - glBegin(GL_POINTS); + // Draw spheres for magnitude + glPushMatrix(); glColor3f(1,0,0); - glVertex3f(vec->x,0,0); + glTranslatef(vector->x,0,0); + glutSolidSphere(0.02, 10, 10); glColor3f(0,1,0); - glVertex3f(0,vec->y,0); + glTranslatef(-vector->x, vector->y, 0); + glutSolidSphere(0.02, 10, 10); glColor3f(0,0,1); - glVertex3f(0,0,vec->z); - glEnd(); + glTranslatef(0, -vector->y, vector->z); + glutSolidSphere(0.02, 10, 10); + glPopMatrix(); - glPointParameterfvARB( GL_POINT_DISTANCE_ATTENUATION_ARB, particleAttenuationConstant ); } void render_world_box() @@ -184,7 +185,6 @@ void drawtext(int x, int y, float scale, float rotate, float thick, int mono, } - void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, glm::vec3 vec, float r, float g, float b) { @@ -209,7 +209,7 @@ void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, gl } glPopMatrix(); -} +} void drawGroundPlaneGrid(float size) { diff --git a/interface/src/Util.h b/interface/src/Util.h index ed253f4393..7ea65bef4c 100644 --- a/interface/src/Util.h +++ b/interface/src/Util.h @@ -33,13 +33,15 @@ float angle_to(glm::vec3 head_pos, glm::vec3 source_pos, float render_yaw, float float randFloat(); void render_world_box(); -void render_vector(glm::vec3 * vec); int widthText(float scale, int mono, char const* string); float widthChar(float scale, int mono, char ch); void drawtext(int x, int y, float scale, float rotate, float thick, int mono, char const* string, float r=1.0, float g=1.0, float b=1.0); void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, glm::vec3 vec, float r=1.0, float g=1.0, float b=1.0); + +void drawVector(glm::vec3* vector); + double diffclock(timeval *clock1,timeval *clock2); void drawGroundPlaneGrid(float size); diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 8916fcd319..44b450ce46 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -1081,6 +1081,15 @@ void display(void) // important... myCamera.update( 1.f/FPS ); + + // Render anything (like HUD items) that we want to be in 3D but not in worldspace + const float HUD_Z_OFFSET = -5.f; + glPushMatrix(); + glm::vec3 test(0.5, 0.5, 0.5); + glTranslatef(1, 1, HUD_Z_OFFSET); + drawVector(&test); + glPopMatrix(); + // 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 9fc56a6230a76384e8d0ac35dd51b24b3ebffcbe Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Mon, 6 May 2013 16:59:43 -0700 Subject: [PATCH 07/41] working out avatar touch stuff --- interface/src/Avatar.cpp | 18 ++++++++++-------- interface/src/AvatarTouch.cpp | 32 +++++++++++++++----------------- interface/src/AvatarTouch.h | 9 ++++----- interface/src/main.cpp | 7 +++++-- 4 files changed, 34 insertions(+), 32 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 58ec217e06..41cc3ee04d 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -297,7 +297,6 @@ void Avatar::UpdateGyros(float frametime, SerialInterface* serialInterface, glm: if ((_headYaw < MAX_YAW) && (_headYaw > MIN_YAW)) { addHeadYaw(_head.yawRate * HEAD_ROTATION_SCALE * frametime); } - } float Avatar::getAbsoluteHeadYaw() const { @@ -322,12 +321,10 @@ void Avatar::setMousePressed(bool d) { _mousePressed = d; } - bool Avatar::getIsNearInteractingOther() { return _avatarTouch.getAbleToReachOtherAvatar(); } - void Avatar::simulate(float deltaTime) { @@ -454,7 +451,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { _avatarTouch.setMyBodyPosition(_position); Avatar * _interactingOther = NULL; - float closestDistance = 10000.0f; + float closestDistance = std::numeric_limits::max();; //loop through all the other avatars for potential interactions... AgentList* agentList = AgentList::getInstance(); @@ -473,7 +470,8 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { } if (_interactingOther) { - _avatarTouch.setYourHandPosition(_interactingOther->_position); + _avatarTouch.setYourBodyPosition(_interactingOther->_position); + _avatarTouch.setYourHandPosition(_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].springyPosition); } }//if (_isMine) @@ -486,12 +484,16 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { //Set the vector we send for hand position to other people to be our right hand setHandPosition(_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position); _handState = _mousePressed; + + _avatarTouch.setMyHandState(_handState); + + if (_handState == 1) { + _avatarTouch.setMyHandPosition(_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].springyPosition); + } } - } +} - - void Avatar::updateHead(float deltaTime) { //apply the head lean values to the springy position... diff --git a/interface/src/AvatarTouch.cpp b/interface/src/AvatarTouch.cpp index 5dd44d46cc..712a7af030 100644 --- a/interface/src/AvatarTouch.cpp +++ b/interface/src/AvatarTouch.cpp @@ -61,23 +61,12 @@ void AvatarTouch::setReachableRadius( float r ) { void AvatarTouch::render() { -if (_canReachToOtherAvatar) { + if (_canReachToOtherAvatar) { glPushMatrix(); - glTranslatef(_myBodyPosition.x, _myBodyPosition.y, _myBodyPosition.z); + glTranslatef(_yourBodyPosition.x, _yourBodyPosition.y, _yourBodyPosition.z); glColor4f( 0.3, 0.4, 0.5, 0.3 ); glutSolidSphere( _reachableRadius, 30.0f, 30.0f ); glPopMatrix(); - - /* - // if my hand is grasping, show it... - if ( _myHandState == 1 ) { - glPushMatrix(); - glTranslatef(_myHandPosition.x, _myHandPosition.y, _myHandPosition.z); - glColor4f( 1.0, 1.0, 0.8, 0.3 ); glutSolidSphere( 0.020f, 10.0f, 10.0f ); - glColor4f( 1.0, 1.0, 0.4, 0.2 ); glutSolidSphere( 0.025f, 10.0f, 10.0f ); - glColor4f( 1.0, 1.0, 0.2, 0.1 ); glutSolidSphere( 0.030f, 10.0f, 10.0f ); - glPopMatrix(); - } - + // if your hand is grasping, show it... if ( _yourHandState == 1 ) { glPushMatrix(); @@ -87,7 +76,16 @@ if (_canReachToOtherAvatar) { glColor4f( 1.0, 1.0, 0.2, 0.1 ); glutSolidSphere( 0.030f, 10.0f, 10.0f ); glPopMatrix(); } - */ + } + + // if my hand is grasping, show it... + if ( _myHandState == 1 ) { + glPushMatrix(); + glTranslatef(_myHandPosition.x, _myHandPosition.y, _myHandPosition.z); + glColor4f( 1.0, 1.0, 0.8, 0.3 ); glutSolidSphere( 0.020f, 10.0f, 10.0f ); + glColor4f( 1.0, 1.0, 0.4, 0.2 ); glutSolidSphere( 0.025f, 10.0f, 10.0f ); + glColor4f( 1.0, 1.0, 0.2, 0.1 ); glutSolidSphere( 0.030f, 10.0f, 10.0f ); + glPopMatrix(); } /* @@ -123,12 +121,12 @@ void AvatarTouch::simulate (float deltaTime) { float distance = glm::length(v); - if (distance < _reachableRadius * 2.0f ) { + if (distance < _reachableRadius * 2.3f ) { _canReachToOtherAvatar = true; } else { _canReachToOtherAvatar = false; } - + /* for (int p=0; p Date: Mon, 6 May 2013 18:21:33 -0700 Subject: [PATCH 08/41] null change --- libraries/voxels/src/AABox.cpp | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 libraries/voxels/src/AABox.cpp diff --git a/libraries/voxels/src/AABox.cpp b/libraries/voxels/src/AABox.cpp old mode 100755 new mode 100644 From 22a0e39d6c5f1d071e70e85c29ca7dfae0321ae1 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Mon, 6 May 2013 18:29:20 -0700 Subject: [PATCH 09/41] more work on avatar touch, reachable radius, and hand states --- interface/src/Avatar.cpp | 25 ++++++------- interface/src/Avatar.h | 12 +----- interface/src/AvatarRenderer.cpp | 13 +++++++ interface/src/AvatarTouch.cpp | 63 ++++++++++++++++---------------- interface/src/AvatarTouch.h | 2 +- interface/src/Util.cpp | 57 ++++++++++++++++++++++++----- interface/src/Util.h | 3 ++ interface/src/main.cpp | 17 +++------ 8 files changed, 116 insertions(+), 76 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 41cc3ee04d..fc2177c1d3 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -34,10 +34,6 @@ const float BODY_ROLL_WHILE_TURNING = 0.1; const float LIN_VEL_DECAY = 5.0; const float MY_HAND_HOLDING_PULL = 0.2; const float YOUR_HAND_HOLDING_PULL = 1.0; - -//const float BODY_SPRING_DEFAULT_TIGHTNESS = 20.0f; -//const float BODY_SPRING_FORCE = 6.0f; - const float BODY_SPRING_DEFAULT_TIGHTNESS = 1500.0f; const float BODY_SPRING_FORCE = 300.0f; @@ -144,14 +140,13 @@ Avatar::Avatar(bool isMine) { _renderYaw = 0.0; _renderPitch = 0.0; _sphere = NULL; - //_interactingOther = NULL; _handHoldingPosition = glm::vec3(0.0f, 0.0f, 0.0f); _distanceToNearestAvatar = std::numeric_limits::max(); _gravity = glm::vec3(0.0f, -1.0f, 0.0f); // default initializeSkeleton(); - _avatarTouch.setReachableRadius(0.4); + _avatarTouch.setReachableRadius(0.6); if (iris_texture.size() == 0) { switchToResourcesParentIfRequired(); @@ -317,8 +312,8 @@ void Avatar::setLeanSideways(float dist){ _head.leanSideways = dist; } -void Avatar::setMousePressed(bool d) { - _mousePressed = d; +void Avatar::setMousePressed( bool mousePressed ) { + _mousePressed = mousePressed; } bool Avatar::getIsNearInteractingOther() { @@ -435,7 +430,6 @@ void Avatar::simulate(float deltaTime) { } - void Avatar::updateHandMovementAndTouching(float deltaTime) { // reset hand and arm positions according to hand movement @@ -472,6 +466,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { if (_interactingOther) { _avatarTouch.setYourBodyPosition(_interactingOther->_position); _avatarTouch.setYourHandPosition(_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].springyPosition); + _avatarTouch.setYourHandState (_interactingOther->_handState); } }//if (_isMine) @@ -483,7 +478,12 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { if (_isMine) { //Set the vector we send for hand position to other people to be our right hand setHandPosition(_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position); - _handState = _mousePressed; + + if ( _mousePressed ) { + _handState = 1; + } else { + _handState = 0; + } _avatarTouch.setMyHandState(_handState); @@ -493,7 +493,6 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { } } - void Avatar::updateHead(float deltaTime) { //apply the head lean values to the springy position... @@ -753,7 +752,7 @@ void Avatar::setGravity(glm::vec3 gravity) { } -void Avatar::render(bool lookingInMirror) { +void Avatar::render(bool lookingInMirror, glm::vec3 cameraPosition) { // render a simple round on the ground projected down from the avatar's position renderDiskShadow(_position, glm::vec3(0.0f, 1.0f, 0.0f ), 0.1f, 0.2f ); @@ -788,7 +787,7 @@ void Avatar::render(bool lookingInMirror) { // if this is my avatar, then render my interactions with the other avatar if (_isMine ) { - _avatarTouch.render(); + _avatarTouch.render(cameraPosition); } // Render the balls diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index 8bb98aadf3..29896556a5 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -101,13 +101,6 @@ public: void setLeanForward(float dist); void setLeanSideways(float dist); void addLean(float x, float z); - - /* - const glm::vec3& getHeadRightDirection() const { return _orientation.getRight(); }; - const glm::vec3& getHeadUpDirection () const { return _orientation.getUp (); }; - const glm::vec3& getHeadFrontDirection() const { return _orientation.getFront(); }; - */ - const glm::vec3& getHeadPosition() const ; const glm::vec3& getJointPosition(AvatarJointID j) const { return _joint[j].position; }; const glm::vec3& getBodyUpDirection() const { return _orientation.getUp(); }; @@ -117,8 +110,8 @@ public: AvatarMode getMode(); - void setMousePressed( bool pressed ); - void render(bool lookingInMirror); + void setMousePressed(bool pressed); + void render(bool lookingInMirrorm, glm::vec3 cameraPosition); void renderBody(); void renderHead(bool lookingInMirror); void simulate(float); @@ -241,7 +234,6 @@ private: float _transmitterHz; int _transmitterPackets; glm::vec3 _transmitterInitialReading; - //Avatar* _interactingOther; float _pelvisStandingHeight; float _height; Balls* _balls; diff --git a/interface/src/AvatarRenderer.cpp b/interface/src/AvatarRenderer.cpp index b1ed54d083..52d3fc0026 100644 --- a/interface/src/AvatarRenderer.cpp +++ b/interface/src/AvatarRenderer.cpp @@ -11,6 +11,19 @@ #include "AvatarRenderer.h" #include "InterfaceConfig.h" + +#include +#include +#include +#include +#include "Avatar.h" +#include "Log.h" +#include "ui/TextRenderer.h" +#include +#include +#include + + AvatarRenderer::AvatarRenderer() { } diff --git a/interface/src/AvatarTouch.cpp b/interface/src/AvatarTouch.cpp index 712a7af030..b56a8ac7e8 100644 --- a/interface/src/AvatarTouch.cpp +++ b/interface/src/AvatarTouch.cpp @@ -10,6 +10,7 @@ #include #include "AvatarTouch.h" #include "InterfaceConfig.h" +#include "Util.h" const float THREAD_RADIUS = 0.012; @@ -59,14 +60,16 @@ void AvatarTouch::setReachableRadius( float r ) { _reachableRadius = r; } -void AvatarTouch::render() { + +void AvatarTouch::render(glm::vec3 cameraPosition) { if (_canReachToOtherAvatar) { - glPushMatrix(); - glTranslatef(_yourBodyPosition.x, _yourBodyPosition.y, _yourBodyPosition.z); - glColor4f( 0.3, 0.4, 0.5, 0.3 ); glutSolidSphere( _reachableRadius, 30.0f, 30.0f ); - glPopMatrix(); - + + glColor4f( 0.3, 0.4, 0.5, 0.5 ); + glm::vec3 p(_yourBodyPosition); + p.y = 0.0005f; + renderCircle(p, _reachableRadius, glm::vec3(0.0f, 1.0f, 0.0f), 30); + // if your hand is grasping, show it... if ( _yourHandState == 1 ) { glPushMatrix(); @@ -76,6 +79,27 @@ void AvatarTouch::render() { glColor4f( 1.0, 1.0, 0.2, 0.1 ); glutSolidSphere( 0.030f, 10.0f, 10.0f ); glPopMatrix(); } + + //show beam + glm::vec3 v1( _myHandPosition ); + glm::vec3 v2( _yourHandPosition ); + + if (_handsCloseEnoughToGrasp) { + glLineWidth( 2.0 ); + glColor4f( 0.7f, 0.4f, 0.1f, 0.3 ); + glBegin( GL_LINE_STRIP ); + glVertex3f( v1.x, v1.y, v1.z ); + glVertex3f( v2.x, v2.y, v2.z ); + glEnd(); + + glColor4f( 1.0f, 1.0f, 0.0f, 0.8 ); + + for (int p=0; pbegin(); agent != agentList->end(); agent++) { if (agent->getLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) { Avatar *avatar = (Avatar *)agent->getLinkedData(); - avatar->render(0); + avatar->render(0, ::myCamera.getPosition()); } } agentList->unlock(); @@ -723,7 +723,7 @@ void displaySide(Camera& whichCamera) { if (::frustumOn) renderViewFrustum(::viewFrustum); //Render my own avatar - myAvatar.render(::lookingInMirror); + myAvatar.render(::lookingInMirror, ::myCamera.getPosition()); glPopMatrix(); } @@ -1671,15 +1671,10 @@ void idle(void) { myAvatar.setHandMovementValues( handControl.getValues() ); // tell my avatar if the mouse is being pressed... - myAvatar.setMousePressed(mousePressed); - /* - if ( mousePressed == 1 ) { - myAvatar.setMousePressed( true ); - } else { - myAvatar.setMousePressed( false ); - } - */ - + if ( mousePressed) { + myAvatar.setMousePressed(mousePressed); + } + // walking triggers the handControl to stop if ( myAvatar.getMode() == AVATAR_MODE_WALKING ) { handControl.stop(); From 00c8673cebeb654d210c3291a2c43a10b81c4eec Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Mon, 6 May 2013 18:45:06 -0700 Subject: [PATCH 10/41] Added Utility function angleBetween() which returns the positive angle between any two 3D vectors. --- interface/src/Avatar.cpp | 8 ++++++++ interface/src/Util.cpp | 5 +++++ interface/src/Util.h | 2 ++ 3 files changed, 15 insertions(+) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index a1a93fbfe3..70e3907b4a 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -469,6 +469,14 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { glm::vec3 v(_joint[ AVATAR_JOINT_RIGHT_SHOULDER ].position); v -= otherAvatar->getJointPosition(AVATAR_JOINT_RIGHT_SHOULDER); + /* + // Test: Show angle between your fwd vector and nearest avatar + glm::vec3 vectorBetweenUs = otherAvatar->getJointPosition(AVATAR_JOINT_PELVIS) - + getJointPosition(AVATAR_JOINT_PELVIS); + glm::vec3 myForwardVector = _orientation.getFront(); + printLog("Angle between: %f\n", angleBetween(&vectorBetweenUs, &myForwardVector)); + */ + float distance = glm::length(v); if (distance < _distanceToNearestAvatar) {_distanceToNearestAvatar = distance;} diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 355dec185c..430d200af1 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -65,6 +65,11 @@ float angle_to(glm::vec3 head_pos, glm::vec3 source_pos, float render_yaw, float return atan2(head_pos.x - source_pos.x, head_pos.z - source_pos.z) * 180.0f / PIf + render_yaw + head_yaw; } +// Helper function computes the angle between two 3D vectors +float angleBetween(glm::vec3 * v1, glm::vec3 * v2) { + return acos((glm::dot(*v1,*v2))/(glm::length(*v1) * glm::length(*v2))) * 180.f/PI; +} + // Draw a 3D vector floating in space void drawVector(glm::vec3 * vector) { diff --git a/interface/src/Util.h b/interface/src/Util.h index 7ea65bef4c..add347fb3b 100644 --- a/interface/src/Util.h +++ b/interface/src/Util.h @@ -42,6 +42,8 @@ void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, gl void drawVector(glm::vec3* vector); +float angleBetween(glm::vec3 * v1, glm::vec3 * v2); + double diffclock(timeval *clock1,timeval *clock2); void drawGroundPlaneGrid(float size); From 31593dccd419d09a4c0649c3266d8130b93ae024 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Mon, 6 May 2013 18:46:19 -0700 Subject: [PATCH 11/41] improved comment of function --- interface/src/Util.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 430d200af1..9159fb77cc 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -65,7 +65,7 @@ float angle_to(glm::vec3 head_pos, glm::vec3 source_pos, float render_yaw, float return atan2(head_pos.x - source_pos.x, head_pos.z - source_pos.z) * 180.0f / PIf + render_yaw + head_yaw; } -// Helper function computes the angle between two 3D vectors +// Helper function returns the positive angle in degrees between two 3D vectors float angleBetween(glm::vec3 * v1, glm::vec3 * v2) { return acos((glm::dot(*v1,*v2))/(glm::length(*v1) * glm::length(*v2))) * 180.f/PI; } From 65181cb4e01a636002956a4af963ff074e183d28 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Mon, 6 May 2013 22:23:16 -0700 Subject: [PATCH 12/41] changed some spacing formatting things --- interface/src/Avatar.cpp | 6 +-- interface/src/AvatarRenderer.cpp | 22 --------- interface/src/AvatarTouch.cpp | 26 +++++----- interface/src/AvatarTouch.h | 6 +-- interface/src/main.cpp | 82 ++++++++++++++------------------ 5 files changed, 54 insertions(+), 88 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index fc2177c1d3..9a4a1b16c8 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -312,7 +312,7 @@ void Avatar::setLeanSideways(float dist){ _head.leanSideways = dist; } -void Avatar::setMousePressed( bool mousePressed ) { +void Avatar::setMousePressed(bool mousePressed) { _mousePressed = mousePressed; } @@ -445,7 +445,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { _avatarTouch.setMyBodyPosition(_position); Avatar * _interactingOther = NULL; - float closestDistance = std::numeric_limits::max();; + float closestDistance = std::numeric_limits::max(); //loop through all the other avatars for potential interactions... AgentList* agentList = AgentList::getInstance(); @@ -479,7 +479,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { //Set the vector we send for hand position to other people to be our right hand setHandPosition(_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position); - if ( _mousePressed ) { + if (_mousePressed) { _handState = 1; } else { _handState = 0; diff --git a/interface/src/AvatarRenderer.cpp b/interface/src/AvatarRenderer.cpp index 52d3fc0026..02a2f1db83 100644 --- a/interface/src/AvatarRenderer.cpp +++ b/interface/src/AvatarRenderer.cpp @@ -11,31 +11,9 @@ #include "AvatarRenderer.h" #include "InterfaceConfig.h" - -#include -#include -#include -#include -#include "Avatar.h" -#include "Log.h" -#include "ui/TextRenderer.h" -#include -#include -#include - - AvatarRenderer::AvatarRenderer() { } // this method renders the avatar void AvatarRenderer::render(Avatar *avatar, bool lookingInMirror) { -/* - // show avatar position - glColor4f( 0.5f, 0.5f, 0.5f, 0.6 ); - glPushMatrix(); - glTranslatef(avatar->_position.x, avatar->_position.y, avatar->_position.z); - glScalef( 0.03, 0.03, 0.03 ); - glutSolidSphere( 1, 10, 10 ); - glPopMatrix(); - */ } \ No newline at end of file diff --git a/interface/src/AvatarTouch.cpp b/interface/src/AvatarTouch.cpp index b56a8ac7e8..45d1eac1ed 100644 --- a/interface/src/AvatarTouch.cpp +++ b/interface/src/AvatarTouch.cpp @@ -32,31 +32,31 @@ AvatarTouch::AvatarTouch() { } } -void AvatarTouch::setMyHandPosition( glm::vec3 position ) { +void AvatarTouch::setMyHandPosition(glm::vec3 position) { _myHandPosition = position; } -void AvatarTouch::setYourHandPosition( glm::vec3 position ) { +void AvatarTouch::setYourHandPosition(glm::vec3 position) { _yourHandPosition = position; } -void AvatarTouch::setMyBodyPosition( glm::vec3 position ) { +void AvatarTouch::setMyBodyPosition(glm::vec3 position) { _myBodyPosition = position; } -void AvatarTouch::setYourBodyPosition( glm::vec3 position ) { +void AvatarTouch::setYourBodyPosition(glm::vec3 position) { _yourBodyPosition = position; } -void AvatarTouch::setMyHandState( int state ) { +void AvatarTouch::setMyHandState(int state) { _myHandState = state; } -void AvatarTouch::setYourHandState( int state ) { +void AvatarTouch::setYourHandState(int state) { _yourHandState = state; } -void AvatarTouch::setReachableRadius( float r ) { +void AvatarTouch::setReachableRadius(float r) { _reachableRadius = r; } @@ -71,7 +71,7 @@ void AvatarTouch::render(glm::vec3 cameraPosition) { renderCircle(p, _reachableRadius, glm::vec3(0.0f, 1.0f, 0.0f), 30); // if your hand is grasping, show it... - if ( _yourHandState == 1 ) { + if (_yourHandState == 1) { glPushMatrix(); glTranslatef(_yourHandPosition.x, _yourHandPosition.y, _yourHandPosition.z); glColor4f( 1.0, 1.0, 0.8, 0.3 ); glutSolidSphere( 0.020f, 10.0f, 10.0f ); @@ -81,13 +81,13 @@ void AvatarTouch::render(glm::vec3 cameraPosition) { } //show beam - glm::vec3 v1( _myHandPosition ); - glm::vec3 v2( _yourHandPosition ); + glm::vec3 v1(_myHandPosition); + glm::vec3 v2(_yourHandPosition); if (_handsCloseEnoughToGrasp) { - glLineWidth( 2.0 ); + glLineWidth(2.0); glColor4f( 0.7f, 0.4f, 0.1f, 0.3 ); - glBegin( GL_LINE_STRIP ); + glBegin(GL_LINE_STRIP); glVertex3f( v1.x, v1.y, v1.z ); glVertex3f( v2.x, v2.y, v2.z ); glEnd(); @@ -103,7 +103,7 @@ void AvatarTouch::render(glm::vec3 cameraPosition) { } // if my hand is grasping, show it... - if ( _myHandState == 1 ) { + if (_myHandState == 1) { glPushMatrix(); glTranslatef(_myHandPosition.x, _myHandPosition.y, _myHandPosition.z); glColor4f( 1.0, 1.0, 0.8, 0.3 ); glutSolidSphere( 0.020f, 10.0f, 10.0f ); diff --git a/interface/src/AvatarTouch.h b/interface/src/AvatarTouch.h index 81803bd051..7da3df5adc 100644 --- a/interface/src/AvatarTouch.h +++ b/interface/src/AvatarTouch.h @@ -30,9 +30,9 @@ public: void setReachableRadius (float r); void setAbleToReachOtherAvatar (bool a) {_canReachToOtherAvatar = a;} void setHandsCloseEnoughToGrasp(bool h) {_handsCloseEnoughToGrasp = h;} - - bool getAbleToReachOtherAvatar () {return _canReachToOtherAvatar;} - bool getHandsCloseEnoughToGrasp() {return _handsCloseEnoughToGrasp;} + + bool getAbleToReachOtherAvatar () const {return _canReachToOtherAvatar;} + bool getHandsCloseEnoughToGrasp() const {return _handsCloseEnoughToGrasp;} private: diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 2c4c886171..78aa3ebf33 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -692,14 +692,14 @@ void displaySide(Camera& whichCamera) { float sphereRadius = 0.25f; glColor3f(1,0,0); glPushMatrix(); - glutSolidSphere( sphereRadius, 15, 15 ); + glutSolidSphere(sphereRadius, 15, 15); glPopMatrix(); //draw a grid ground plane.... drawGroundPlaneGrid(10.f); // Draw voxels - if ( showingVoxels ) + if (showingVoxels) { voxels.render(); } @@ -984,15 +984,15 @@ void display(void) glMateriali(GL_FRONT, GL_SHININESS, 96); // camera settings - if ( ::lookingInMirror ) { + if (::lookingInMirror) { // set the camera to looking at my own face - myCamera.setTargetPosition ( myAvatar.getHeadPosition() ); - myCamera.setTargetYaw ( myAvatar.getBodyYaw() - 180.0f ); // 180 degrees from body yaw - myCamera.setPitch ( 0.0 ); - myCamera.setRoll ( 0.0 ); - myCamera.setUpShift ( 0.0 ); - myCamera.setDistance ( 0.2 ); - myCamera.setTightness ( 100.0f ); + myCamera.setTargetPosition (myAvatar.getHeadPosition()); + myCamera.setTargetYaw (myAvatar.getBodyYaw() - 180.0f); // 180 degrees from body yaw + myCamera.setPitch (0.0); + myCamera.setRoll (0.0); + myCamera.setUpShift (0.0); + myCamera.setDistance (0.2); + myCamera.setTightness (100.0f); } else { //float firstPersonPitch = 20.0f; @@ -1010,36 +1010,24 @@ void display(void) float thirdPersonDistance = 1.2f; float thirdPersonTightness = 8.0f; - if ( USING_FIRST_PERSON_EFFECT ) { + if (USING_FIRST_PERSON_EFFECT) { float ff = 0.0; float min = 0.1; float max = 0.5; - if ( myAvatar.getIsNearInteractingOther()){ - if ( myAvatar.getSpeed() < max ) { + if (myAvatar.getIsNearInteractingOther()){ + if (myAvatar.getSpeed() < max) { float s = (myAvatar.getSpeed()- min)/max ; ff = 1.0 - s; } } - - /* - if ( ff < 0.8 ) { - myAvatar.setDisplayingHead( true ); - } else { - myAvatar.setDisplayingHead( false ); - } - */ - - //printf( "ff = %f\n", ff ); - myCamera.setPitch ( thirdPersonPitch + ff * ( firstPersonPitch - thirdPersonPitch )); - myCamera.setUpShift ( thirdPersonUpShift + ff * ( firstPersonUpShift - thirdPersonUpShift )); - myCamera.setDistance ( thirdPersonDistance + ff * ( firstPersonDistance - thirdPersonDistance )); - myCamera.setTightness ( thirdPersonTightness + ff * ( firstPersonTightness - thirdPersonTightness )); + myCamera.setPitch (thirdPersonPitch + ff * (firstPersonPitch - thirdPersonPitch )); + myCamera.setUpShift (thirdPersonUpShift + ff * (firstPersonUpShift - thirdPersonUpShift )); + myCamera.setDistance (thirdPersonDistance + ff * (firstPersonDistance - thirdPersonDistance )); + myCamera.setTightness (thirdPersonTightness + ff * (firstPersonTightness - thirdPersonTightness)); - - // this version uses a ramp-up/ramp-down timer in the camera to determine shift between first and thirs-person view /* if ( myAvatar.getSpeed() < 0.02 ) { @@ -1073,13 +1061,13 @@ void display(void) myCamera.setTightness(thirdPersonTightness); } - myCamera.setTargetPosition( myAvatar.getHeadPosition() ); - myCamera.setTargetYaw ( myAvatar.getBodyYaw() ); - myCamera.setRoll ( 0.0 ); + myCamera.setTargetPosition(myAvatar.getHeadPosition()); + myCamera.setTargetYaw (myAvatar.getBodyYaw()); + myCamera.setRoll (0.0); } // important... - myCamera.update( 1.f/FPS ); + 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 @@ -1095,11 +1083,11 @@ void display(void) if (::viewFrustumFromOffset && ::frustumOn) { // set the camera to third-person view but offset so we can see the frustum - viewFrustumOffsetCamera.setTargetYaw( ::viewFrustumOffsetYaw + myAvatar.getBodyYaw() ); - viewFrustumOffsetCamera.setPitch ( ::viewFrustumOffsetPitch ); - viewFrustumOffsetCamera.setRoll ( ::viewFrustumOffsetRoll ); - viewFrustumOffsetCamera.setUpShift ( ::viewFrustumOffsetUp ); - viewFrustumOffsetCamera.setDistance ( ::viewFrustumOffsetDistance ); + viewFrustumOffsetCamera.setTargetYaw(::viewFrustumOffsetYaw + myAvatar.getBodyYaw() ); + viewFrustumOffsetCamera.setPitch (::viewFrustumOffsetPitch ); + viewFrustumOffsetCamera.setRoll (::viewFrustumOffsetRoll ); + viewFrustumOffsetCamera.setUpShift (::viewFrustumOffsetUp ); + viewFrustumOffsetCamera.setDistance (::viewFrustumOffsetDistance); viewFrustumOffsetCamera.update(1.f/FPS); whichCamera = viewFrustumOffsetCamera; } @@ -1109,11 +1097,11 @@ void display(void) // or could be viewFrustumOffsetCamera if in offset mode // I changed the ordering here - roll is FIRST (JJV) - glRotatef ( whichCamera.getRoll(), IDENTITY_FRONT.x, IDENTITY_FRONT.y, IDENTITY_FRONT.z ); - glRotatef ( whichCamera.getPitch(), IDENTITY_RIGHT.x, IDENTITY_RIGHT.y, IDENTITY_RIGHT.z ); - glRotatef ( 180.0 - whichCamera.getYaw(), IDENTITY_UP.x, IDENTITY_UP.y, IDENTITY_UP.z ); + glRotatef ( whichCamera.getRoll(), IDENTITY_FRONT.x, IDENTITY_FRONT.y, IDENTITY_FRONT.z); + glRotatef ( whichCamera.getPitch(), IDENTITY_RIGHT.x, IDENTITY_RIGHT.y, IDENTITY_RIGHT.z); + glRotatef (180.0 - whichCamera.getYaw(), IDENTITY_UP.x, IDENTITY_UP.y, IDENTITY_UP.z ); - glTranslatef( -whichCamera.getPosition().x, -whichCamera.getPosition().y, -whichCamera.getPosition().z ); + glTranslatef(-whichCamera.getPosition().x, -whichCamera.getPosition().y, -whichCamera.getPosition().z); if (::oculusOn) { displayOculus(whichCamera); @@ -1666,16 +1654,16 @@ void idle(void) { // update behaviors for avatar hand movement: handControl takes mouse values as input, // and gives back 3D values modulated for smooth transitioning between interaction modes. - handControl.update( mouseX, mouseY ); - myAvatar.setHandMovementValues( handControl.getValues() ); + handControl.update(mouseX, mouseY); + myAvatar.setHandMovementValues(handControl.getValues()); // tell my avatar if the mouse is being pressed... - if ( mousePressed) { + if (mousePressed) { myAvatar.setMousePressed(mousePressed); } // walking triggers the handControl to stop - if ( myAvatar.getMode() == AVATAR_MODE_WALKING ) { + if (myAvatar.getMode() == AVATAR_MODE_WALKING) { handControl.stop(); } @@ -1868,7 +1856,7 @@ int main(int argc, const char * argv[]) #ifdef _WIN32 WSADATA WsaData; - int wsaresult = WSAStartup( MAKEWORD(2,2), &WsaData ); + int wsaresult = WSAStartup(MAKEWORD(2,2), &WsaData); #endif // start the agentList threads From fe11d929e398ffe282612fa749a02bc158aabee5 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Tue, 7 May 2013 08:43:14 -0700 Subject: [PATCH 13/41] cleaned up code spacing --- interface/src/Avatar.cpp | 185 +++++++++++++++++----------------- interface/src/AvatarTouch.cpp | 42 ++++---- interface/src/Camera.cpp | 31 +++--- interface/src/HandControl.cpp | 26 ++--- interface/src/Util.cpp | 38 +++---- interface/src/main.cpp | 30 +++--- 6 files changed, 172 insertions(+), 180 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 9a4a1b16c8..3e97fd32b6 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -322,7 +322,6 @@ bool Avatar::getIsNearInteractingOther() { void Avatar::simulate(float deltaTime) { - // update balls if (_balls) { _balls->simulate(deltaTime); } @@ -496,7 +495,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { void Avatar::updateHead(float deltaTime) { //apply the head lean values to the springy position... - if (fabs( _head.leanSideways + _head.leanForward ) > 0.0f) { + if (fabs(_head.leanSideways + _head.leanForward) > 0.0f) { glm::vec3 headLean = _orientation.getRight() * _head.leanSideways + _orientation.getFront() * _head.leanForward; @@ -514,7 +513,7 @@ void Avatar::updateHead(float deltaTime) { if (_head.noise) { // 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); + _headYaw += (_head.yawTarget - _headYaw ) * 10 * deltaTime; // (1.f - DECAY*deltaTime); _headRoll *= 1.f - (DECAY * deltaTime); } @@ -661,7 +660,7 @@ void Avatar::updateAvatarCollisions(float deltaTime) { glm::vec3 vectorBetweenBoundingSpheres(_position - otherAvatar->_position); if (glm::length(vectorBetweenBoundingSpheres) < _height * ONE_HALF + otherAvatar->_height * ONE_HALF) { //apply forces from collision - applyCollisionWithOtherAvatar(otherAvatar, deltaTime ); + applyCollisionWithOtherAvatar(otherAvatar, deltaTime); } // test other avatar hand position for proximity @@ -695,7 +694,7 @@ void Avatar::applyCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime glm::vec3 vectorBetweenJoints(_joint[b].springyPosition - otherAvatar->_joint[o].springyPosition); float distanceBetweenJoints = glm::length(vectorBetweenJoints); - if (distanceBetweenJoints > 0.0 ) { // to avoid divide by zero + if (distanceBetweenJoints > 0.0) { // to avoid divide by zero float combinedRadius = _joint[b].radius + otherAvatar->_joint[o].radius; // check for collision @@ -706,7 +705,7 @@ void Avatar::applyCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime glm::vec3 ballPushForce = directionVector * COLLISION_BALL_FORCE * deltaTime; float ballMomentum = 1.0 - COLLISION_BALL_FRICTION * deltaTime; - if (ballMomentum < 0.0 ) { ballMomentum = 0.0;} + if (ballMomentum < 0.0) { ballMomentum = 0.0;} _joint[b].springyVelocity += ballPushForce; otherAvatar->_joint[o].springyVelocity -= ballPushForce; @@ -717,7 +716,7 @@ void Avatar::applyCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime // accumulate forces and frictions to apply to the velocities of avatar bodies bodyPushForce += directionVector * COLLISION_BODY_FORCE * deltaTime; bodyMomentum -= COLLISION_BODY_FRICTION * deltaTime; - if (bodyMomentum < 0.0 ) { bodyMomentum = 0.0;} + if (bodyMomentum < 0.0) { bodyMomentum = 0.0;} }// check for collision } // to avoid divide by zero @@ -736,7 +735,7 @@ void Avatar::applyCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime -void Avatar::setDisplayingHead(bool displayingHead ) { +void Avatar::setDisplayingHead(bool displayingHead) { _displayingHead = displayingHead; } @@ -755,25 +754,25 @@ void Avatar::setGravity(glm::vec3 gravity) { void Avatar::render(bool lookingInMirror, glm::vec3 cameraPosition) { // render a simple round on the ground projected down from the avatar's position - renderDiskShadow(_position, glm::vec3(0.0f, 1.0f, 0.0f ), 0.1f, 0.2f ); + renderDiskShadow(_position, glm::vec3(0.0f, 1.0f, 0.0f), 0.1f, 0.2f); /* // show avatar position - glColor4f(0.5f, 0.5f, 0.5f, 0.6 ); + glColor4f(0.5f, 0.5f, 0.5f, 0.6); glPushMatrix(); glTranslatef(_position.x, _position.y, _position.z); - glScalef(0.03, 0.03, 0.03 ); - glutSolidSphere(1, 10, 10 ); + glScalef(0.03, 0.03, 0.03); + glutSolidSphere(1, 10, 10); glPopMatrix(); */ - if (usingBigSphereCollisionTest ) { + if (usingBigSphereCollisionTest) { // show TEST big sphere - glColor4f(0.5f, 0.6f, 0.8f, 0.7 ); + glColor4f(0.5f, 0.6f, 0.8f, 0.7); glPushMatrix(); glTranslatef(_TEST_bigSpherePosition.x, _TEST_bigSpherePosition.y, _TEST_bigSpherePosition.z); - glScalef(_TEST_bigSphereRadius, _TEST_bigSphereRadius, _TEST_bigSphereRadius ); - glutSolidSphere(1, 20, 20 ); + glScalef(_TEST_bigSphereRadius, _TEST_bigSphereRadius, _TEST_bigSphereRadius); + glutSolidSphere(1, 20, 20); glPopMatrix(); } @@ -786,7 +785,7 @@ void Avatar::render(bool lookingInMirror, glm::vec3 cameraPosition) { } // if this is my avatar, then render my interactions with the other avatar - if (_isMine ) { + if (_isMine) { _avatarTouch.render(cameraPosition); } @@ -847,7 +846,7 @@ void Avatar::renderHead(bool lookingInMirror) { glEnable(GL_RESCALE_NORMAL); // show head orientation - //renderOrientationDirections(_joint[ AVATAR_JOINT_HEAD_BASE ].springyPosition, _joint[ AVATAR_JOINT_HEAD_BASE ].orientation, 0.2f ); + //renderOrientationDirections(_joint[ AVATAR_JOINT_HEAD_BASE ].springyPosition, _joint[ AVATAR_JOINT_HEAD_BASE ].orientation, 0.2f); glPushMatrix(); @@ -875,7 +874,7 @@ void Avatar::renderHead(bool lookingInMirror) { //glRotatef(_bodyPitch + _headPitch, 1, 0, 0); //glRotatef(_bodyRoll - _headRoll, 0, 0, 1); // don't let body pitch and roll affect the head.. - glRotatef( _headPitch, 1, 0, 0); + glRotatef(_headPitch, 1, 0, 0); glRotatef(-_headRoll, 0, 0, 1); } else { glRotatef(_bodyYaw + _headYaw, 0, 1, 0); @@ -1012,7 +1011,7 @@ void Avatar::renderHead(bool lookingInMirror) { glPopMatrix(); } -void Avatar::setHandMovementValues(glm::vec3 handOffset ) { +void Avatar::setHandMovementValues(glm::vec3 handOffset) { _movedHandOffset = handOffset; } @@ -1025,11 +1024,11 @@ void Avatar::initializeSkeleton() { for (int b=0; b 0.0f ) { + if (length > 0.0f) { glm::vec3 springDirection = springVector / length; float force = (length - _joint[b].length) * BODY_SPRING_FORCE * deltaTime; _joint[b].springyVelocity -= springDirection * force; - if ( _joint[b].parent != AVATAR_JOINT_NULL ) { + if (_joint[b].parent != AVATAR_JOINT_NULL) { _joint[_joint[b].parent].springyVelocity += springDirection * force; } } @@ -1271,7 +1270,7 @@ void Avatar::updateBodySprings( float deltaTime ) { _joint[b].springyVelocity *= decay; } else { - _joint[b].springyVelocity = glm::vec3( 0.0f, 0.0f, 0.0f ); + _joint[b].springyVelocity = glm::vec3(0.0f, 0.0f, 0.0f); } _joint[b].springyPosition += _joint[b].springyVelocity * deltaTime; @@ -1290,17 +1289,17 @@ const glm::vec3& Avatar::getHeadPosition() const { -void Avatar::updateArmIKAndConstraints( float deltaTime ) { +void Avatar::updateArmIKAndConstraints(float deltaTime) { // determine the arm vector glm::vec3 armVector = _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position; armVector -= _joint[ AVATAR_JOINT_RIGHT_SHOULDER ].position; // test to see if right hand is being dragged beyond maximum arm length - float distance = glm::length( armVector ); + float distance = glm::length(armVector); // don't let right hand get dragged beyond maximum arm length... - if ( distance > _maxArmLength ) { + if (distance > _maxArmLength) { // reset right hand to be constrained to maximum arm length _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position = _joint[ AVATAR_JOINT_RIGHT_SHOULDER ].position; glm::vec3 armNormal = armVector / distance; @@ -1315,13 +1314,13 @@ void Avatar::updateArmIKAndConstraints( float deltaTime ) { glm::vec3 newElbowPosition = _joint[ AVATAR_JOINT_RIGHT_SHOULDER ].position; newElbowPosition += armVector * ONE_HALF; - glm::vec3 perpendicular = glm::cross( _orientation.getFront(), armVector ); + glm::vec3 perpendicular = glm::cross(_orientation.getFront(), armVector); - newElbowPosition += perpendicular * ( 1.0f - ( _maxArmLength / distance ) ) * ONE_HALF; + newElbowPosition += perpendicular * (1.0f - (_maxArmLength / distance)) * ONE_HALF; _joint[ AVATAR_JOINT_RIGHT_ELBOW ].position = newElbowPosition; // set wrist position - glm::vec3 vv( _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position ); + glm::vec3 vv(_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position); vv -= _joint[ AVATAR_JOINT_RIGHT_ELBOW ].position; glm::vec3 newWristPosition = _joint[ AVATAR_JOINT_RIGHT_ELBOW ].position + vv * 0.7f; _joint[ AVATAR_JOINT_RIGHT_WRIST ].position = newWristPosition; @@ -1333,53 +1332,53 @@ void Avatar::renderBody() { // Render joint positions as spheres for (int b = 0; b < NUM_AVATAR_JOINTS; b++) { - if ( b != AVATAR_JOINT_HEAD_BASE ) { // the head is rendered as a special case in "renderHead" + if (b != AVATAR_JOINT_HEAD_BASE) { // the head is rendered as a special case in "renderHead" //render bone orientation - //renderOrientationDirections( _joint[b].springyPosition, _joint[b].orientation, _joint[b].radius * 2.0 ); + //renderOrientationDirections(_joint[b].springyPosition, _joint[b].orientation, _joint[b].radius * 2.0); - if ( _usingBodySprings ) { - glColor3fv( skinColor ); + if (_usingBodySprings) { + glColor3fv(skinColor); glPushMatrix(); - glTranslatef( _joint[b].springyPosition.x, _joint[b].springyPosition.y, _joint[b].springyPosition.z ); - glutSolidSphere( _joint[b].radius, 20.0f, 20.0f ); + glTranslatef(_joint[b].springyPosition.x, _joint[b].springyPosition.y, _joint[b].springyPosition.z); + glutSolidSphere(_joint[b].radius, 20.0f, 20.0f); glPopMatrix(); } else { - glColor3fv( skinColor ); + glColor3fv(skinColor); glPushMatrix(); - glTranslatef( _joint[b].position.x, _joint[b].position.y, _joint[b].position.z ); - glutSolidSphere( _joint[b].radius, 20.0f, 20.0f ); + glTranslatef(_joint[b].position.x, _joint[b].position.y, _joint[b].position.z); + glutSolidSphere(_joint[b].radius, 20.0f, 20.0f); glPopMatrix(); } } } // Render lines connecting the joint positions - if ( _usingBodySprings ) { - glColor3f( 0.4f, 0.5f, 0.6f ); + if (_usingBodySprings) { + glColor3f(0.4f, 0.5f, 0.6f); glLineWidth(3.0); for (int b = 1; b < NUM_AVATAR_JOINTS; b++) { - if ( _joint[b].parent != AVATAR_JOINT_NULL ) - if ( b != AVATAR_JOINT_HEAD_TOP ) { - glBegin( GL_LINE_STRIP ); - glVertex3fv( &_joint[ _joint[ b ].parent ].springyPosition.x ); - glVertex3fv( &_joint[ b ].springyPosition.x ); + if (_joint[b].parent != AVATAR_JOINT_NULL) + if (b != AVATAR_JOINT_HEAD_TOP) { + glBegin(GL_LINE_STRIP); + glVertex3fv(&_joint[ _joint[ b ].parent ].springyPosition.x); + glVertex3fv(&_joint[ b ].springyPosition.x); glEnd(); } } } /* else { - glColor3fv( skinColor ); + glColor3fv(skinColor); glLineWidth(3.0); for (int b = 1; b < NUM_AVATAR_JOINTS; b++) { - if ( _joint[b].parent != AVATAR_JOINT_NULL ) { - glBegin( GL_LINE_STRIP ); - glVertex3fv( &_joint[ _joint[ b ].parent ].position.x ); - glVertex3fv( &_joint[ b ].position.x); + if (_joint[b].parent != AVATAR_JOINT_NULL) { + glBegin(GL_LINE_STRIP); + glVertex3fv(&_joint[ _joint[ b ].parent ].position.x); + glVertex3fv(&_joint[ b ].position.x); glEnd(); } } @@ -1442,9 +1441,7 @@ void Avatar::processTransmitterData(unsigned char* packetData, int numBytes) { //printLog("Packet: [%s]\n", packetData); //printLog("Version: %s\n", device); - _transmitterInitialReading = glm::vec3( rot3, - rot2, - rot1 ); + _transmitterInitialReading = glm::vec3(rot3, rot2, rot1); } const int TRANSMITTER_COUNT = 100; if (_transmitterPackets % TRANSMITTER_COUNT == 0) { @@ -1452,7 +1449,7 @@ void Avatar::processTransmitterData(unsigned char* packetData, int numBytes) { timeval now; gettimeofday(&now, NULL); double msecsElapsed = diffclock(&_transmitterTimer, &now); - _transmitterHz = static_cast( (double)TRANSMITTER_COUNT / (msecsElapsed / 1000.0) ); + _transmitterHz = static_cast((double)TRANSMITTER_COUNT / (msecsElapsed / 1000.0)); _transmitterTimer = now; printLog("Transmitter Hz: %3.1f\n", _transmitterHz); } @@ -1469,12 +1466,12 @@ void Avatar::processTransmitterData(unsigned char* packetData, int numBytes) { glm::vec3 angularVelocity; if (deviceType != DEVICE_GLASS) { angularVelocity = glm::vec3(glm::degrees(gyrZ), glm::degrees(-gyrX), glm::degrees(gyrY)); - setHeadFromGyros( &eulerAngles, &angularVelocity, + setHeadFromGyros(&eulerAngles, &angularVelocity, (_transmitterHz == 0.f) ? 0.f : 1.f / _transmitterHz, 1.0); } else { angularVelocity = glm::vec3(glm::degrees(gyrY), glm::degrees(-gyrX), glm::degrees(-gyrZ)); - setHeadFromGyros( &eulerAngles, &angularVelocity, + setHeadFromGyros(&eulerAngles, &angularVelocity, (_transmitterHz == 0.f) ? 0.f : 1.f / _transmitterHz, 1000.0); } diff --git a/interface/src/AvatarTouch.cpp b/interface/src/AvatarTouch.cpp index 45d1eac1ed..89e9889005 100644 --- a/interface/src/AvatarTouch.cpp +++ b/interface/src/AvatarTouch.cpp @@ -16,10 +16,10 @@ const float THREAD_RADIUS = 0.012; AvatarTouch::AvatarTouch() { - _myHandPosition = glm::vec3( 0.0f, 0.0f, 0.0f ); - _yourHandPosition = glm::vec3( 0.0f, 0.0f, 0.0f ); - _myBodyPosition = glm::vec3( 0.0f, 0.0f, 0.0f ); - _yourBodyPosition = glm::vec3( 0.0f, 0.0f, 0.0f ); + _myHandPosition = glm::vec3(0.0f, 0.0f, 0.0f); + _yourHandPosition = glm::vec3(0.0f, 0.0f, 0.0f); + _myBodyPosition = glm::vec3(0.0f, 0.0f, 0.0f); + _yourBodyPosition = glm::vec3(0.0f, 0.0f, 0.0f); _myHandState = 0; _yourHandState = 0; _reachableRadius = 0.0f; @@ -28,7 +28,7 @@ AvatarTouch::AvatarTouch() { _handsCloseEnoughToGrasp = false; for (int p=0; p 1.0f ) { + if (_modeShift > 1.0f) { _modeShift = 1.0f; } } @@ -53,22 +53,19 @@ void Camera::update( float deltaTime ) { generateOrientation(); } - - // generate the ortho-normals for the orientation based on the three Euler angles void Camera::generateOrientation() { _orientation.setToIdentity(); - _orientation.pitch( _pitch ); - _orientation.yaw ( _yaw ); - _orientation.roll ( _roll ); + _orientation.pitch(_pitch); + _orientation.yaw (_yaw ); + _orientation.roll (_roll ); } - // use iterative forces to keep the camera at the desired position and angle -void Camera::updateFollowMode( float deltaTime ) { +void Camera::updateFollowMode(float deltaTime) { // derive t from tightness float t = _tightness * deltaTime; - if ( t > 1.0 ) { + if (t > 1.0) { t = 1.0; } @@ -114,8 +111,6 @@ void Camera::setFarClip (float f) { _frustumNeedsReshape = true; } - - // call to find out if the view frustum needs to be reshaped bool Camera::getFrustumNeedsReshape() { return _frustumNeedsReshape; diff --git a/interface/src/HandControl.cpp b/interface/src/HandControl.cpp index 37efc755c2..1d95388dd9 100644 --- a/interface/src/HandControl.cpp +++ b/interface/src/HandControl.cpp @@ -33,14 +33,14 @@ HandControl::HandControl() { _envelope = 0.0f; } -void HandControl::setScreenDimensions( int width, int height ) { +void HandControl::setScreenDimensions(int width, int height) { _width = width; _height = height; _startX = _width / 2; _startY = _height / 2; } -void HandControl::update( int x, int y ) { +void HandControl::update(int x, int y) { _lastX = _x; _lastY = _y; _x = x; @@ -49,22 +49,22 @@ void HandControl::update( int x, int y ) { _velocityY = _y - _lastY; // if the mouse is moving, ramp up the envelope to increase amplitude of hand movement... - if (( _velocityX != 0 ) - || ( _velocityY != 0 )) { + if ((_velocityX != 0) + || (_velocityY != 0)) { _enabled = true; - if ( _envelope < 1.0 ) { + if (_envelope < 1.0) { _envelope += _rampUpRate; - if ( _envelope >= 1.0 ) { + if (_envelope >= 1.0) { _envelope = 1.0; } } } // if not enabled ramp down the envelope to decrease amplitude of hand movement... - if ( ! _enabled ) { - if ( _envelope > 0.0 ) { + if (! _enabled) { + if (_envelope > 0.0) { _envelope -= _rampDownRate; - if ( _envelope <= 0.0 ) { + if (_envelope <= 0.0) { _startX = _width / 2; _startY = _height / 2; _envelope = 0.0; @@ -77,14 +77,14 @@ void HandControl::update( int x, int y ) { _backFront = 0.0; // if envelope is greater than zero, apply mouse movement to values to be output - if ( _envelope > 0.0 ) { - _leftRight += ( ( _x - _startX ) / (float)_width ) * _envelope; - _downUp += ( ( _y - _startY ) / (float)_height ) * _envelope; + if (_envelope > 0.0) { + _leftRight += ((_x - _startX) / (float)_width ) * _envelope; + _downUp += ((_y - _startY) / (float)_height) * _envelope; } } glm::vec3 HandControl::getValues() { - return glm::vec3( _leftRight, _downUp, _backFront ); + return glm::vec3(_leftRight, _downUp, _backFront); } void HandControl::stop() { diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 69054e5bad..8d931f27c8 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -172,7 +172,7 @@ void drawtext(int x, int y, float scale, float rotate, float thick, int mono, // Draws text on screen as stroked so it can be resized // glPushMatrix(); - glTranslatef( static_cast(x), static_cast(y), 0.0f); + glTranslatef(static_cast(x), static_cast(y), 0.0f); glColor3f(r,g,b); glRotated(rotate,0,0,1); // glLineWidth(thick); @@ -208,7 +208,7 @@ void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, gl } void drawGroundPlaneGrid(float size) { - glColor3f( 0.4f, 0.5f, 0.3f ); + glColor3f(0.4f, 0.5f, 0.3f); glLineWidth(2.0); for (float x = 0; x <= size; x++) { @@ -234,7 +234,7 @@ void drawGroundPlaneGrid(float size) { void renderDiskShadow(glm::vec3 position, glm::vec3 upDirection, float radius, float darkness) { - glColor4f( 0.0f, 0.0f, 0.0f, darkness ); + glColor4f(0.0f, 0.0f, 0.0f, darkness); int num = 20; float y = 0.001f; @@ -264,7 +264,7 @@ void renderDiskShadow(glm::vec3 position, glm::vec3 upDirection, float radius, f void renderSphereOutline(glm::vec3 position, float radius, int numSides, glm::vec3 cameraPosition) { glm::vec3 vectorToPosition(glm::normalize(position - cameraPosition)); - glm::vec3 right = glm::cross(vectorToPosition, glm::vec3( 0.0f, 1.0f, 0.0f)); + glm::vec3 right = glm::cross(vectorToPosition, glm::vec3(0.0f, 1.0f, 0.0f)); glm::vec3 up = glm::cross(right, vectorToPosition); glBegin(GL_LINE_STRIP); @@ -285,7 +285,7 @@ void renderSphereOutline(glm::vec3 position, float radius, int numSides, glm::ve } -void renderCircle(glm::vec3 position, float radius, glm::vec3 surfaceNormal, int numSides ) { +void renderCircle(glm::vec3 position, float radius, glm::vec3 surfaceNormal, int numSides) { glm::vec3 perp1 = glm::vec3(surfaceNormal.y, surfaceNormal.z, surfaceNormal.x); glm::vec3 perp2 = glm::vec3(surfaceNormal.z, surfaceNormal.x, surfaceNormal.y); @@ -306,27 +306,27 @@ void renderCircle(glm::vec3 position, float radius, glm::vec3 surfaceNormal, int } -void renderOrientationDirections( glm::vec3 position, Orientation orientation, float size ) { +void renderOrientationDirections(glm::vec3 position, Orientation orientation, float size) { glm::vec3 pRight = position + orientation.getRight() * size; - glm::vec3 pUp = position + orientation.getUp() * 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 ); - glVertex3f( position.x, position.y, position.z ); - glVertex3f( pRight.x, pRight.y, pRight.z ); + glColor3f(1.0f, 0.0f, 0.0f); + glBegin(GL_LINE_STRIP); + glVertex3f(position.x, position.y, position.z); + glVertex3f(pRight.x, pRight.y, pRight.z); glEnd(); - glColor3f( 0.0f, 1.0f, 0.0f ); - glBegin( GL_LINE_STRIP ); - glVertex3f( position.x, position.y, position.z ); - glVertex3f( pUp.x, pUp.y, pUp.z ); + glColor3f(0.0f, 1.0f, 0.0f); + glBegin(GL_LINE_STRIP); + glVertex3f(position.x, position.y, position.z); + glVertex3f(pUp.x, pUp.y, pUp.z); glEnd(); - glColor3f( 0.0f, 0.0f, 1.0f ); - glBegin( GL_LINE_STRIP ); - glVertex3f( position.x, position.y, position.z ); - glVertex3f( pFront.x, pFront.y, pFront.z ); + glColor3f(0.0f, 0.0f, 1.0f); + glBegin(GL_LINE_STRIP); + glVertex3f(position.x, position.y, position.z); + glVertex3f(pFront.x, pFront.y, pFront.z); glEnd(); } diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 78aa3ebf33..c2425957a5 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -1030,27 +1030,27 @@ void display(void) // this version uses a ramp-up/ramp-down timer in the camera to determine shift between first and thirs-person view /* - if ( myAvatar.getSpeed() < 0.02 ) { + if (myAvatar.getSpeed() < 0.02) { - if (myCamera.getMode() != CAMERA_MODE_FIRST_PERSON ) { + 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 )); + //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 { - if (myCamera.getMode() != CAMERA_MODE_THIRD_PERSON ) { + 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 )); + //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)); } */ @@ -1083,7 +1083,7 @@ void display(void) if (::viewFrustumFromOffset && ::frustumOn) { // set the camera to third-person view but offset so we can see the frustum - viewFrustumOffsetCamera.setTargetYaw(::viewFrustumOffsetYaw + myAvatar.getBodyYaw() ); + viewFrustumOffsetCamera.setTargetYaw(::viewFrustumOffsetYaw + myAvatar.getBodyYaw()); viewFrustumOffsetCamera.setPitch (::viewFrustumOffsetPitch ); viewFrustumOffsetCamera.setRoll (::viewFrustumOffsetRoll ); viewFrustumOffsetCamera.setUpShift (::viewFrustumOffsetUp ); @@ -1778,7 +1778,7 @@ glm::vec3 getGravity(glm::vec3 pos) { } void mouseFunc(int button, int state, int x, int y) { - if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN ) { + if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { if (state == GLUT_DOWN && !menu.mouseClick(x, y)) { mouseX = x; mouseY = y; From 27540f1286139aa9723b90493b7bbf3403cabd17 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Tue, 7 May 2013 09:59:37 -0700 Subject: [PATCH 14/41] Fixes per code review --- interface/src/Util.cpp | 45 ++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 282acd1f03..e70aabcd2a 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -67,12 +67,11 @@ float angle_to(glm::vec3 head_pos, glm::vec3 source_pos, float render_yaw, float // Helper function returns the positive angle in degrees between two 3D vectors float angleBetween(glm::vec3 * v1, glm::vec3 * v2) { - return acos((glm::dot(*v1,*v2))/(glm::length(*v1) * glm::length(*v2))) * 180.f/PI; + return acos((glm::dot(*v1, *v2)) / (glm::length(*v1) * glm::length(*v2))) * 180.f / PI; } // Draw a 3D vector floating in space -void drawVector(glm::vec3 * vector) -{ +void drawVector(glm::vec3 * vector) { glDisable(GL_LIGHTING); glEnable(GL_POINT_SMOOTH); glPointSize(3.0); @@ -101,7 +100,7 @@ void drawVector(glm::vec3 * vector) // Draw spheres for magnitude glPushMatrix(); glColor3f(1,0,0); - glTranslatef(vector->x,0,0); + glTranslatef(vector->x, 0, 0); glutSolidSphere(0.02, 10, 10); glColor3f(0,1,0); glTranslatef(-vector->x, vector->y, 0); @@ -113,39 +112,38 @@ void drawVector(glm::vec3 * vector) } -void render_world_box() -{ +void render_world_box() { // Show edge of world glDisable(GL_LIGHTING); glColor4f(1.0, 1.0, 1.0, 1.0); glLineWidth(1.0); glBegin(GL_LINES); - glColor3f(1,0,0); - glVertex3f(0,0,0); - glVertex3f(WORLD_SIZE,0,0); - glColor3f(0,1,0); - glVertex3f(0,0,0); + glColor3f(1, 0, 0); + glVertex3f(0, 0, 0); + glVertex3f(WORLD_SIZE, 0, 0); + glColor3f(0, 1, 0); + glVertex3f(0, 0, 0); glVertex3f(0, WORLD_SIZE, 0); - glColor3f(0,0,1); - glVertex3f(0,0,0); + glColor3f(0, 0, 1); + glVertex3f(0, 0, 0); glVertex3f(0, 0, WORLD_SIZE); glEnd(); // Draw little marker dots along the axis glEnable(GL_LIGHTING); glPushMatrix(); - glTranslatef(WORLD_SIZE,0,0); - glColor3f(1,0,0); - glutSolidSphere(0.125,10,10); + glTranslatef(WORLD_SIZE, 0, 0); + glColor3f(1, 0, 0); + glutSolidSphere(0.125, 10, 10); glPopMatrix(); glPushMatrix(); - glTranslatef(0,WORLD_SIZE,0); - glColor3f(0,1,0); - glutSolidSphere(0.125,10,10); + glTranslatef(0, WORLD_SIZE, 0); + glColor3f(0, 1, 0); + glutSolidSphere(0.125, 10, 10); glPopMatrix(); glPushMatrix(); - glTranslatef(0,0,WORLD_SIZE); - glColor3f(0,0,1); - glutSolidSphere(0.125,10,10); + glTranslatef(0, 0, WORLD_SIZE); + glColor3f(0, 0, 1); + glutSolidSphere(0.125, 10, 10); glPopMatrix(); } @@ -172,8 +170,7 @@ float widthChar(float scale, int mono, char ch) { } void drawtext(int x, int y, float scale, float rotate, float thick, int mono, - char const* string, float r, float g, float b) -{ + char const* string, float r, float g, float b) { // // Draws text on screen as stroked so it can be resized // From be1b80365652fc47bae22ef3ee25a6415266e34c Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Tue, 7 May 2013 10:41:39 -0700 Subject: [PATCH 15/41] Noise Test function, adjust chat position --- interface/src/Avatar.cpp | 4 ++-- interface/src/Util.cpp | 23 +++++++++++++++++++++++ interface/src/Util.h | 2 ++ interface/src/main.cpp | 2 ++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index b658096ea8..1983de906a 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -62,8 +62,8 @@ bool usingBigSphereCollisionTest = true; char iris_texture_file[] = "resources/images/green_eye.png"; -float chatMessageScale = 0.001; -float chatMessageHeight = 0.4; +float chatMessageScale = 0.0015; +float chatMessageHeight = 0.45; vector iris_texture; unsigned int iris_texture_width = 512; diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index e70aabcd2a..58cf1f61ad 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -112,6 +113,28 @@ void drawVector(glm::vec3 * vector) { } +// Render a 2D set of squares using perlin/fractal noise +void noiseTest(int w, int h) { + const float CELLS = 100; + float xStep = (float) w / CELLS; + float yStep = (float) h / CELLS; + glBegin(GL_QUADS); + for (float x = 0; x < (float)w; x += xStep) { + for (float y = 0; y < (float)h; y += yStep) { + // Generate a vector varying between 0-1 corresponding to the screen location + glm::vec2 position(x / (float) w, y / (float) h); + // Set the cell color using the noise value at that location + float color = glm::simplex(position); + glColor4f(color, color, color, 1.0); + glVertex2f(x, y); + glVertex2f(x + xStep, y); + glVertex2f(x + xStep, y + yStep); + glVertex2f(x, y + yStep); + } + } + glEnd(); +} + void render_world_box() { // Show edge of world glDisable(GL_LIGHTING); diff --git a/interface/src/Util.h b/interface/src/Util.h index b81edd8c87..d4a6ba6b03 100644 --- a/interface/src/Util.h +++ b/interface/src/Util.h @@ -40,6 +40,8 @@ void drawtext(int x, int y, float scale, float rotate, float thick, int mono, void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, glm::vec3 vec, float r=1.0, float g=1.0, float b=1.0); +void noiseTest(int w, int h); + void drawVector(glm::vec3* vector); float angleBetween(glm::vec3 * v1, glm::vec3 * v2); diff --git a/interface/src/main.cpp b/interface/src/main.cpp index a4ef86024b..a341835206 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -893,6 +893,8 @@ void displayOverlay() { audioScope.render(); #endif + // noiseTest(WIDTH, HEIGHT); + if (displayHeadMouse && !::lookingInMirror && statsOn) { // Display small target box at center or head mouse target that can also be used to measure LOD glColor3f(1.0, 1.0, 1.0); From 331d4116d904bd36381df70a1c2520375f5ae636 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Tue, 7 May 2013 11:14:12 -0700 Subject: [PATCH 16/41] Finished noiseTest example (in util.h) that uses Perlin noise to draw a bitmap in 2D. --- interface/src/Util.cpp | 7 ++++--- interface/src/main.cpp | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 58cf1f61ad..b4c7f3d6b0 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -115,16 +115,17 @@ void drawVector(glm::vec3 * vector) { // Render a 2D set of squares using perlin/fractal noise void noiseTest(int w, int h) { - const float CELLS = 100; + const float CELLS = 500; + const float NOISE_SCALE = 10.0; float xStep = (float) w / CELLS; float yStep = (float) h / CELLS; glBegin(GL_QUADS); for (float x = 0; x < (float)w; x += xStep) { for (float y = 0; y < (float)h; y += yStep) { // Generate a vector varying between 0-1 corresponding to the screen location - glm::vec2 position(x / (float) w, y / (float) h); + glm::vec2 position(NOISE_SCALE * x / (float) w, NOISE_SCALE * y / (float) h); // Set the cell color using the noise value at that location - float color = glm::simplex(position); + float color = glm::perlin(position); glColor4f(color, color, color, 1.0); glVertex2f(x, y); glVertex2f(x + xStep, y); diff --git a/interface/src/main.cpp b/interface/src/main.cpp index a341835206..a448a1c2fa 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -893,7 +893,7 @@ void displayOverlay() { audioScope.render(); #endif - // noiseTest(WIDTH, HEIGHT); + //noiseTest(WIDTH, HEIGHT); if (displayHeadMouse && !::lookingInMirror && statsOn) { // Display small target box at center or head mouse target that can also be used to measure LOD From 589e524090e9184fe527f99b6a7ff4865cd3b7e2 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 7 May 2013 10:24:09 -0700 Subject: [PATCH 17/41] remove debugging and a couple of lines --- audio-mixer/src/main.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index 9b594ec054..1427a4097b 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -199,9 +199,7 @@ void *sendBuffer(void *args) { if (s < numSamplesDelay) { // pull the earlier sample for the delayed channel - int earlierSample = delaySamplePointer[s] * attenuationCoefficient; - plateauAdditionOfSamples(delayedChannel[s], earlierSample * weakChannelAmplitudeRatio); } From 43a377563356a3fd32e0b0f4aa2c34dbd160f334 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 7 May 2013 11:16:05 -0700 Subject: [PATCH 18/41] add _ownerID member variable to AgentList --- libraries/shared/src/AgentList.cpp | 7 ++----- libraries/shared/src/AgentList.h | 9 +++++++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/libraries/shared/src/AgentList.cpp b/libraries/shared/src/AgentList.cpp index 51a14d8cb1..8f17b75af3 100644 --- a/libraries/shared/src/AgentList.cpp +++ b/libraries/shared/src/AgentList.cpp @@ -62,8 +62,9 @@ AgentList::AgentList(char newOwnerType, unsigned int newSocketListenPort) : _agentBuckets(), _numAgents(0), agentSocket(newSocketListenPort), - ownerType(newOwnerType), + _ownerType(newOwnerType), socketListenPort(newSocketListenPort), + _ownerID(-1), lastAgentId(0) { pthread_mutex_init(&mutex, 0); } @@ -81,10 +82,6 @@ UDPSocket& AgentList::getAgentSocket() { return agentSocket; } -char AgentList::getOwnerType() { - return ownerType; -} - unsigned int AgentList::getSocketListenPort() { return socketListenPort; } diff --git a/libraries/shared/src/AgentList.h b/libraries/shared/src/AgentList.h index 1a7a99b751..5544c3c0fd 100644 --- a/libraries/shared/src/AgentList.h +++ b/libraries/shared/src/AgentList.h @@ -70,9 +70,13 @@ public: int updateAgentWithData(Agent *agent, unsigned char *packetData, int dataBytes); void broadcastToAgents(unsigned char *broadcastData, size_t dataBytes, const char* agentTypes, int numAgentTypes); - char getOwnerType(); unsigned int getSocketListenPort(); + char getOwnerType() const { return _ownerType; } + + uint16_t getOwnerID() const { return _ownerID; } + void setOwnerID(uint16_t ownerID) { _ownerID = ownerID; } + Agent* soloAgentOfType(char agentType); void startSilentAgentRemovalThread(); @@ -96,8 +100,9 @@ private: Agent** _agentBuckets[MAX_NUM_AGENTS / AGENTS_PER_BUCKET]; int _numAgents; UDPSocket agentSocket; - char ownerType; + char _ownerType; unsigned int socketListenPort; + uint16_t _ownerID; uint16_t lastAgentId; pthread_t removeSilentAgentsThread; pthread_t checkInWithDomainServerThread; From 722205682e868e07486ddc590a50aa7197648938 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 7 May 2013 11:28:10 -0700 Subject: [PATCH 19/41] expect domain server to append one's own ID to end of packet --- domain-server/src/main.cpp | 21 ++++++++++++++------- libraries/shared/src/AgentList.cpp | 11 +++++++---- libraries/shared/src/AgentList.h | 2 +- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/domain-server/src/main.cpp b/domain-server/src/main.cpp index 753009ffa9..95da95c210 100644 --- a/domain-server/src/main.cpp +++ b/domain-server/src/main.cpp @@ -86,7 +86,6 @@ int main(int argc, const char * argv[]) unsigned char* currentBufferPos; unsigned char* startPointer; - int packetBytesWithoutLeadingChar; sockaddr_in agentPublicAddress, agentLocalAddress; agentLocalAddress.sin_family = AF_INET; @@ -95,6 +94,8 @@ int main(int argc, const char * argv[]) agentList->startSilentAgentRemovalThread(); + uint16_t packetAgentID = 0; + while (true) { if (agentList->getAgentSocket().receive((sockaddr *)&agentPublicAddress, packetData, &receivedBytes) && (packetData[0] == PACKET_HEADER_DOMAIN_RFD || packetData[0] == PACKET_HEADER_DOMAIN_LIST_REQUEST)) { @@ -143,13 +144,17 @@ int main(int argc, const char * argv[]) } } else { double timeNow = usecTimestampNow(); + // this is the agent, just update last receive to now agent->setLastHeardMicrostamp(timeNow); + // grab the ID for this agent so we can send it back with the packet + packetAgentID = agent->getAgentId(); + if (packetData[0] == PACKET_HEADER_DOMAIN_RFD && memchr(SOLO_AGENT_TYPES, agentType, sizeof(SOLO_AGENT_TYPES))) { agent->setWakeMicrostamp(timeNow); - } + } } } @@ -160,11 +165,13 @@ int main(int argc, const char * argv[]) currentBufferPos = addAgentToBroadcastPacket(currentBufferPos, soloAgent->second); } - if ((packetBytesWithoutLeadingChar = (currentBufferPos - startPointer))) { - agentList->getAgentSocket().send((sockaddr*) &agentPublicAddress, - broadcastPacket, - packetBytesWithoutLeadingChar + 1); - } + // add the agent ID to the end of the pointer + currentBufferPos += packAgentId(currentBufferPos, packetAgentID); + + // send the constructed list back to this agent + agentList->getAgentSocket().send((sockaddr*) &agentPublicAddress, + broadcastPacket, + (currentBufferPos - startPointer) + 1); } } diff --git a/libraries/shared/src/AgentList.cpp b/libraries/shared/src/AgentList.cpp index 8f17b75af3..213a6a55ab 100644 --- a/libraries/shared/src/AgentList.cpp +++ b/libraries/shared/src/AgentList.cpp @@ -89,7 +89,7 @@ unsigned int AgentList::getSocketListenPort() { void AgentList::processAgentData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes) { switch (((char *)packetData)[0]) { case PACKET_HEADER_DOMAIN: { - updateList(packetData, dataBytes); + processDomainServerList(packetData, dataBytes); break; } case PACKET_HEADER_PING: { @@ -200,7 +200,7 @@ void AgentList::increaseAgentId() { ++lastAgentId; } -int AgentList::updateList(unsigned char *packetData, size_t dataBytes) { +int AgentList::processDomainServerList(unsigned char *packetData, size_t dataBytes) { int readAgents = 0; char agentType; @@ -215,14 +215,17 @@ int AgentList::updateList(unsigned char *packetData, size_t dataBytes) { unsigned char *readPtr = packetData + 1; unsigned char *startPtr = packetData; - while((readPtr - startPtr) < dataBytes) { + while((readPtr - startPtr) < dataBytes - sizeof(uint16_t)) { agentType = *readPtr++; readPtr += unpackAgentId(readPtr, (uint16_t *)&agentId); readPtr += unpackSocket(readPtr, (sockaddr *)&agentPublicSocket); readPtr += unpackSocket(readPtr, (sockaddr *)&agentLocalSocket); addOrUpdateAgent((sockaddr *)&agentPublicSocket, (sockaddr *)&agentLocalSocket, agentType, agentId); - } + } + + // read out our ID from the packet + unpackAgentId(readPtr, &_ownerID); return readAgents; } diff --git a/libraries/shared/src/AgentList.h b/libraries/shared/src/AgentList.h index 5544c3c0fd..f9c9b35341 100644 --- a/libraries/shared/src/AgentList.h +++ b/libraries/shared/src/AgentList.h @@ -56,7 +56,7 @@ public: void lock() { pthread_mutex_lock(&mutex); } void unlock() { pthread_mutex_unlock(&mutex); } - int updateList(unsigned char *packetData, size_t dataBytes); + int processDomainServerList(unsigned char *packetData, size_t dataBytes); Agent* agentWithAddress(sockaddr *senderAddress); Agent* agentWithID(uint16_t agentID); From 4eeb1ed5b1295e8ab5af6ab6b031fcbe35e135c4 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 7 May 2013 11:44:27 -0700 Subject: [PATCH 20/41] have interface clients tell the avatar-mixer and voxel-server what their ID is --- avatar-mixer/src/main.cpp | 13 ++++++++----- interface/src/main.cpp | 23 ++++++++++++++--------- libraries/avatars/src/AvatarData.cpp | 4 ++-- voxel-server/src/main.cpp | 9 +++------ 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/avatar-mixer/src/main.cpp b/avatar-mixer/src/main.cpp index e3fb26ade3..5f1de38da7 100644 --- a/avatar-mixer/src/main.cpp +++ b/avatar-mixer/src/main.cpp @@ -69,17 +69,20 @@ int main(int argc, const char* argv[]) *broadcastPacket = PACKET_HEADER_BULK_AVATAR_DATA; unsigned char* currentBufferPosition = NULL; + + uint16_t agentID = 0; while (true) { if (agentList->getAgentSocket().receive(agentAddress, packetData, &receivedBytes)) { switch (packetData[0]) { case PACKET_HEADER_HEAD_DATA: - // add this agent if we don't have them yet - if (agentList->addOrUpdateAgent(agentAddress, agentAddress, AGENT_TYPE_AVATAR, agentList->getLastAgentId())) { - agentList->increaseAgentId(); - } + // grab the agent ID from the packet + unpackAgentId(packetData + 1, &agentID); - // this is positional data from an agent + // add or update the agent in our list + agentList->addOrUpdateAgent(agentAddress, agentAddress, AGENT_TYPE_AVATAR, agentID); + + // parse positional data from an agent agentList->updateAgentWithData(agentAddress, packetData, receivedBytes); currentBufferPosition = broadcastPacket + 1; diff --git a/interface/src/main.cpp b/interface/src/main.cpp index a341835206..cd11a39063 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -436,17 +436,22 @@ void updateAvatar(float frametime) { myAvatar.setCameraAspectRatio(::viewFrustum.getAspectRatio()); myAvatar.setCameraNearClip(::viewFrustum.getNearClip()); myAvatar.setCameraFarClip(::viewFrustum.getFarClip()); - - // Send my stream of head/hand data to the avatar mixer and voxel server - unsigned char broadcastString[200]; - *broadcastString = PACKET_HEADER_HEAD_DATA; - int broadcastBytes = myAvatar.getBroadcastData(broadcastString + 1); - broadcastBytes++; + AgentList *agentList = AgentList::getInstance(); - const char broadcastReceivers[2] = {AGENT_TYPE_VOXEL, AGENT_TYPE_AVATAR_MIXER}; - - AgentList::getInstance()->broadcastToAgents(broadcastString, broadcastBytes, broadcastReceivers, 2); + if (agentList->getOwnerID() >= 0) { + // if I know my ID, send head/hand data to the avatar mixer and voxel server + unsigned char broadcastString[200]; + unsigned char* endOfBroadcastStringWrite = broadcastString; + + *(endOfBroadcastStringWrite++) = PACKET_HEADER_HEAD_DATA; + endOfBroadcastStringWrite += packAgentId(endOfBroadcastStringWrite, agentList->getOwnerID()); + + endOfBroadcastStringWrite += myAvatar.getBroadcastData(endOfBroadcastStringWrite); + + const char broadcastReceivers[2] = {AGENT_TYPE_VOXEL, AGENT_TYPE_AVATAR_MIXER}; + AgentList::getInstance()->broadcastToAgents(broadcastString, endOfBroadcastStringWrite - broadcastString, broadcastReceivers, 2); + } // If I'm in paint mode, send a voxel out to VOXEL server agents. if (::paintOn) { diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 8881c397af..bd866091a0 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -128,8 +128,8 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) { // called on the other agents - assigns it to my views of the others int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) { - // increment to push past the packet header - sourceBuffer++; + // increment to push past the packet header and agent ID + sourceBuffer += 3; unsigned char* startPosition = sourceBuffer; diff --git a/voxel-server/src/main.cpp b/voxel-server/src/main.cpp index 7e39eb5483..4ba05b4ac2 100644 --- a/voxel-server/src/main.cpp +++ b/voxel-server/src/main.cpp @@ -547,12 +547,9 @@ int main(int argc, const char * argv[]) // If we got a PACKET_HEADER_HEAD_DATA, then we're talking to an AGENT_TYPE_AVATAR, and we // need to make sure we have it in our agentList. if (packetData[0] == PACKET_HEADER_HEAD_DATA) { - if (agentList->addOrUpdateAgent(&agentPublicAddress, - &agentPublicAddress, - AGENT_TYPE_AVATAR, - agentList->getLastAgentId())) { - agentList->increaseAgentId(); - } + uint16_t agentID = 0; + unpackAgentId(packetData + 1, &agentID); + agentList->addOrUpdateAgent(&agentPublicAddress, &agentPublicAddress, AGENT_TYPE_AVATAR, agentID); agentList->updateAgentWithData(&agentPublicAddress, packetData, receivedBytes); } From 5c90b4575e27c42ec096fd5aaa56dc4d18783d43 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 7 May 2013 11:48:02 -0700 Subject: [PATCH 21/41] trivial deletions for cleanup --- avatar-mixer/src/main.cpp | 3 +-- interface/src/main.cpp | 10 ++-------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/avatar-mixer/src/main.cpp b/avatar-mixer/src/main.cpp index 5f1de38da7..74b731fdc5 100644 --- a/avatar-mixer/src/main.cpp +++ b/avatar-mixer/src/main.cpp @@ -51,8 +51,7 @@ void attachAvatarDataToAgent(Agent *newAgent) { } } -int main(int argc, const char* argv[]) -{ +int main(int argc, const char* argv[]) { AgentList* agentList = AgentList::createInstance(AGENT_TYPE_AVATAR_MIXER, AVATAR_LISTEN_PORT); setvbuf(stdout, NULL, _IOLBF, 0); diff --git a/interface/src/main.cpp b/interface/src/main.cpp index cd11a39063..4945c44123 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -1438,8 +1438,7 @@ void setupPaintingVoxel() { shiftPaintingColor(); } -void addRandomSphere(bool wantColorRandomizer) -{ +void addRandomSphere(bool wantColorRandomizer) { float r = randFloatInRange(0.05,0.1); float xc = randFloatInRange(r,(1-r)); float yc = randFloatInRange(r,(1-r)); @@ -1770,10 +1769,6 @@ void reshape(int width, int height) { glLoadIdentity(); } - - - - //Find and return the gravity vector at this location glm::vec3 getGravity(glm::vec3 pos) { // @@ -1832,8 +1827,7 @@ void audioMixerUpdate(in_addr_t newMixerAddress, in_port_t newMixerPort) { } #endif -int main(int argc, const char * argv[]) -{ +int main(int argc, const char * argv[]) { voxels.setViewFrustum(&::viewFrustum); shared_lib::printLog = & ::printLog; From 83e59b1aa89dc4921e38382cf5ca86ca9e52300d Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 7 May 2013 11:49:14 -0700 Subject: [PATCH 22/41] more deletions --- interface/src/main.cpp | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 4945c44123..d27dabecc2 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -14,14 +14,6 @@ // // Welcome Aboard! // -// -// Keyboard Commands: -// -// / = toggle stats display -// spacebar = reset gyros/head position -// h = render Head facing yourself (mirror) -// l = show incoming gyro levels -// #include "InterfaceConfig.h" #include @@ -1385,8 +1377,7 @@ void initMenu() { menuColumnDebug->addRow("Show TRUE Colors", doTrueVoxelColors); } -void testPointToVoxel() -{ +void testPointToVoxel() { float y=0; float z=0; float s=0.1; @@ -1455,7 +1446,6 @@ void addRandomSphere(bool wantColorRandomizer) { voxels.createSphere(r,xc,yc,zc,s,solid,wantColorRandomizer); } - const float KEYBOARD_YAW_RATE = 0.8; const float KEYBOARD_PITCH_RATE = 0.6; const float KEYBOARD_STRAFE_RATE = 0.03; @@ -1509,7 +1499,6 @@ void specialkey(int k, int x, int y) { } } - void keyUp(unsigned char k, int x, int y) { if (::chatEntryOn) { myAvatar.setKeyState(NO_KEY_DOWN); @@ -1524,8 +1513,7 @@ void keyUp(unsigned char k, int x, int y) { if (k == 'd') myAvatar.setDriveKeys(ROT_RIGHT, 0); } -void key(unsigned char k, int x, int y) -{ +void key(unsigned char k, int x, int y) { if (::chatEntryOn) { if (chatEntry.key(k)) { myAvatar.setKeyState(k == '\b' || k == 127 ? // backspace or delete From 85dfb23fbd766cd86b663261dd03761c5f9cdefe Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 7 May 2013 12:39:35 -0700 Subject: [PATCH 23/41] add constant for UNKNOWN_AGENT_ID --- interface/src/main.cpp | 2 +- libraries/shared/src/AgentList.cpp | 2 +- libraries/shared/src/AgentList.h | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index d27dabecc2..74fccc50c4 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -431,7 +431,7 @@ void updateAvatar(float frametime) { AgentList *agentList = AgentList::getInstance(); - if (agentList->getOwnerID() >= 0) { + if (agentList->getOwnerID() != UNKNOWN_AGENT_ID) { // if I know my ID, send head/hand data to the avatar mixer and voxel server unsigned char broadcastString[200]; unsigned char* endOfBroadcastStringWrite = broadcastString; diff --git a/libraries/shared/src/AgentList.cpp b/libraries/shared/src/AgentList.cpp index 213a6a55ab..82a21ae479 100644 --- a/libraries/shared/src/AgentList.cpp +++ b/libraries/shared/src/AgentList.cpp @@ -64,7 +64,7 @@ AgentList::AgentList(char newOwnerType, unsigned int newSocketListenPort) : agentSocket(newSocketListenPort), _ownerType(newOwnerType), socketListenPort(newSocketListenPort), - _ownerID(-1), + _ownerID(UNKNOWN_AGENT_ID), lastAgentId(0) { pthread_mutex_init(&mutex, 0); } diff --git a/libraries/shared/src/AgentList.h b/libraries/shared/src/AgentList.h index f9c9b35341..1956916211 100644 --- a/libraries/shared/src/AgentList.h +++ b/libraries/shared/src/AgentList.h @@ -31,6 +31,8 @@ extern char DOMAIN_HOSTNAME[]; extern char DOMAIN_IP[100]; // IP Address will be re-set by lookup on startup extern const int DOMAINSERVER_PORT; +const int UNKNOWN_AGENT_ID = -1; + class AgentListIterator; class AgentList { From 5ccc6d6d203b740e83920fadfe712461226fa4e9 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 7 May 2013 12:42:10 -0700 Subject: [PATCH 24/41] prefer sizeOf to hardcoded byte --- voxel-server/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/voxel-server/src/main.cpp b/voxel-server/src/main.cpp index 4ba05b4ac2..380f2cc794 100644 --- a/voxel-server/src/main.cpp +++ b/voxel-server/src/main.cpp @@ -548,7 +548,7 @@ int main(int argc, const char * argv[]) // need to make sure we have it in our agentList. if (packetData[0] == PACKET_HEADER_HEAD_DATA) { uint16_t agentID = 0; - unpackAgentId(packetData + 1, &agentID); + unpackAgentId(packetData + sizeof(PACKET_HEADER_HEAD_DATA), &agentID); agentList->addOrUpdateAgent(&agentPublicAddress, &agentPublicAddress, AGENT_TYPE_AVATAR, agentID); agentList->updateAgentWithData(&agentPublicAddress, packetData, receivedBytes); From 0566330a8a2a07a7c35702b080bbd4c954b553d5 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 7 May 2013 12:44:45 -0700 Subject: [PATCH 25/41] some magic number removals --- interface/src/main.cpp | 2 +- libraries/avatars/src/AvatarData.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 74fccc50c4..704200d24c 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -442,7 +442,7 @@ void updateAvatar(float frametime) { endOfBroadcastStringWrite += myAvatar.getBroadcastData(endOfBroadcastStringWrite); const char broadcastReceivers[2] = {AGENT_TYPE_VOXEL, AGENT_TYPE_AVATAR_MIXER}; - AgentList::getInstance()->broadcastToAgents(broadcastString, endOfBroadcastStringWrite - broadcastString, broadcastReceivers, 2); + AgentList::getInstance()->broadcastToAgents(broadcastString, endOfBroadcastStringWrite - broadcastString, broadcastReceivers, sizeof(broadcastReceivers)); } // If I'm in paint mode, send a voxel out to VOXEL server agents. diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index bd866091a0..3136b3e30a 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -129,7 +129,7 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) { int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) { // increment to push past the packet header and agent ID - sourceBuffer += 3; + sourceBuffer += sizeof(PACKET_HEADER_HEAD_DATA) + sizeof(uint16_t); unsigned char* startPosition = sourceBuffer; From d5d9479b65a65170b5932902940c48c97c058b02 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 7 May 2013 13:38:56 -0700 Subject: [PATCH 26/41] make eve send her ID to identify with the avatar mixer --- eve/src/main.cpp | 22 +++++++++++----------- interface/src/main.cpp | 5 ++--- libraries/shared/src/PacketHeaders.h | 27 ++++++++++++++------------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/eve/src/main.cpp b/eve/src/main.cpp index ad0081fc3b..b72d1194a4 100644 --- a/eve/src/main.cpp +++ b/eve/src/main.cpp @@ -130,8 +130,6 @@ int main(int argc, const char* argv[]) { unsigned char broadcastPacket[MAX_PACKET_SIZE]; broadcastPacket[0] = PACKET_HEADER_HEAD_DATA; - int numBytesToSend = 0; - timeval thisSend; double numMicrosecondsSleep = 0; @@ -148,13 +146,16 @@ int main(int argc, const char* argv[]) { Agent *avatarMixer = agentList->soloAgentOfType(AGENT_TYPE_AVATAR_MIXER); // make sure we actually have an avatar mixer with an active socket - if (avatarMixer != NULL && avatarMixer->getActiveSocket() != NULL) { + if (agentList->getOwnerID() != UNKNOWN_AGENT_ID && avatarMixer != NULL && avatarMixer->getActiveSocket() != NULL) { + unsigned char* packetPosition = broadcastPacket + sizeof(PACKET_HEADER); + packetPosition += packAgentId(packetPosition, agentList->getOwnerID()); + // use the getBroadcastData method in the AvatarData class to populate the broadcastPacket buffer - numBytesToSend = eve.getBroadcastData((broadcastPacket + 1)); + packetPosition += eve.getBroadcastData(packetPosition); // use the UDPSocket instance attached to our agent list to send avatar data to mixer - agentList->getAgentSocket().send(avatarMixer->getActiveSocket(), broadcastPacket, numBytesToSend); - } + agentList->getAgentSocket().send(avatarMixer->getActiveSocket(), broadcastPacket, packetPosition - broadcastPacket); + } // temporarily disable Eve's audio sending until the file is actually available on EC2 box if (numIterationsLeftBeforeAudioSend == 0) { @@ -175,13 +176,12 @@ int main(int argc, const char* argv[]) { // simulate the effect of pressing and un-pressing the mouse button/pad handStateTimer++; - if ( handStateTimer == 100 ) { + + if (handStateTimer == 100) { eve.setHandState(1); - } - if ( handStateTimer == 150 ) { + } else if (handStateTimer == 150) { eve.setHandState(0); - } - if ( handStateTimer >= 200 ) { + } else if (handStateTimer >= 200) { handStateTimer = 0; } } diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 704200d24c..756a1481c5 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -696,13 +696,12 @@ void displaySide(Camera& whichCamera) { drawGroundPlaneGrid(10.f); // Draw voxels - if (showingVoxels) - { + if (showingVoxels) { voxels.render(); } // Render avatars of other agents - AgentList* agentList = AgentList::getInstance(); + AgentList *agentList = AgentList::getInstance(); agentList->lock(); for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { if (agent->getLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) { diff --git a/libraries/shared/src/PacketHeaders.h b/libraries/shared/src/PacketHeaders.h index 1ceb3fcc5a..152adc5805 100644 --- a/libraries/shared/src/PacketHeaders.h +++ b/libraries/shared/src/PacketHeaders.h @@ -13,18 +13,19 @@ #ifndef hifi_PacketHeaders_h #define hifi_PacketHeaders_h -const char PACKET_HEADER_DOMAIN = 'D'; -const char PACKET_HEADER_PING = 'P'; -const char PACKET_HEADER_PING_REPLY = 'R'; -const char PACKET_HEADER_HEAD_DATA = 'H'; -const char PACKET_HEADER_Z_COMMAND = 'Z'; -const char PACKET_HEADER_INJECT_AUDIO = 'I'; -const char PACKET_HEADER_SET_VOXEL = 'S'; -const char PACKET_HEADER_ERASE_VOXEL = 'E'; -const char PACKET_HEADER_VOXEL_DATA = 'V'; -const char PACKET_HEADER_BULK_AVATAR_DATA = 'X'; -const char PACKET_HEADER_TRANSMITTER_DATA = 't'; -const char PACKET_HEADER_DOMAIN_LIST_REQUEST = 'L'; -const char PACKET_HEADER_DOMAIN_RFD = 'C'; +typedef char PACKET_HEADER; +const PACKET_HEADER PACKET_HEADER_DOMAIN = 'D'; +const PACKET_HEADER PACKET_HEADER_PING = 'P'; +const PACKET_HEADER PACKET_HEADER_PING_REPLY = 'R'; +const PACKET_HEADER PACKET_HEADER_HEAD_DATA = 'H'; +const PACKET_HEADER PACKET_HEADER_Z_COMMAND = 'Z'; +const PACKET_HEADER PACKET_HEADER_INJECT_AUDIO = 'I'; +const PACKET_HEADER PACKET_HEADER_SET_VOXEL = 'S'; +const PACKET_HEADER PACKET_HEADER_ERASE_VOXEL = 'E'; +const PACKET_HEADER PACKET_HEADER_VOXEL_DATA = 'V'; +const PACKET_HEADER PACKET_HEADER_BULK_AVATAR_DATA = 'X'; +const PACKET_HEADER PACKET_HEADER_TRANSMITTER_DATA = 't'; +const PACKET_HEADER PACKET_HEADER_DOMAIN_LIST_REQUEST = 'L'; +const PACKET_HEADER PACKET_HEADER_DOMAIN_RFD = 'C'; #endif From 9be92cebdd4638dc267db30bb26cb5ee19ea001e Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 7 May 2013 13:41:48 -0700 Subject: [PATCH 27/41] revert type squish, spacing, code review comment --- eve/src/main.cpp | 4 ++-- interface/src/main.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/eve/src/main.cpp b/eve/src/main.cpp index b72d1194a4..08200c6606 100644 --- a/eve/src/main.cpp +++ b/eve/src/main.cpp @@ -143,10 +143,10 @@ int main(int argc, const char* argv[]) { gettimeofday(&thisSend, NULL); // find the current avatar mixer - Agent *avatarMixer = agentList->soloAgentOfType(AGENT_TYPE_AVATAR_MIXER); + Agent* avatarMixer = agentList->soloAgentOfType(AGENT_TYPE_AVATAR_MIXER); // make sure we actually have an avatar mixer with an active socket - if (agentList->getOwnerID() != UNKNOWN_AGENT_ID && avatarMixer != NULL && avatarMixer->getActiveSocket() != NULL) { + if (agentList->getOwnerID() != UNKNOWN_AGENT_ID && avatarMixer && avatarMixer->getActiveSocket() != NULL) { unsigned char* packetPosition = broadcastPacket + sizeof(PACKET_HEADER); packetPosition += packAgentId(packetPosition, agentList->getOwnerID()); diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 756a1481c5..fad68d9c13 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -429,7 +429,7 @@ void updateAvatar(float frametime) { myAvatar.setCameraNearClip(::viewFrustum.getNearClip()); myAvatar.setCameraFarClip(::viewFrustum.getFarClip()); - AgentList *agentList = AgentList::getInstance(); + AgentList* agentList = AgentList::getInstance(); if (agentList->getOwnerID() != UNKNOWN_AGENT_ID) { // if I know my ID, send head/hand data to the avatar mixer and voxel server @@ -451,9 +451,9 @@ void updateAvatar(float frametime) { glm::vec3 avatarPos = myAvatar.getPosition(); // For some reason, we don't want to flip X and Z here. - ::paintingVoxel.x = avatarPos.x/10.0; - ::paintingVoxel.y = avatarPos.y/10.0; - ::paintingVoxel.z = avatarPos.z/10.0; + ::paintingVoxel.x = avatarPos.x / 10.0; + ::paintingVoxel.y = avatarPos.y / 10.0; + ::paintingVoxel.z = avatarPos.z / 10.0; unsigned char* bufferOut; int sizeOut; From 92daa8e6e05f31f9c3413ba7f9bb8c20ccd6c8f0 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 7 May 2013 13:43:07 -0700 Subject: [PATCH 28/41] revert the type squish --- 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 fad68d9c13..4b34f9a2b0 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -701,7 +701,7 @@ void displaySide(Camera& whichCamera) { } // Render avatars of other agents - AgentList *agentList = AgentList::getInstance(); + AgentList* agentList = AgentList::getInstance(); agentList->lock(); for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { if (agent->getLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) { From 3719454abd5904c00cab290d3a1373584cacfbe2 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 7 May 2013 13:47:12 -0700 Subject: [PATCH 29/41] use constants for eve's hand grabbing behavior --- eve/src/main.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/eve/src/main.cpp b/eve/src/main.cpp index 08200c6606..7c4bde7a2d 100644 --- a/eve/src/main.cpp +++ b/eve/src/main.cpp @@ -25,6 +25,10 @@ const int MIN_ITERATIONS_BETWEEN_AUDIO_SENDS = (MIN_AUDIO_SEND_INTERVAL_SECS * 1 const int MAX_AUDIO_SEND_INTERVAL_SECS = 15; const float MAX_ITERATIONS_BETWEEN_AUDIO_SENDS = (MAX_AUDIO_SEND_INTERVAL_SECS * 1000) / DATA_SEND_INTERVAL_MSECS; +const int ITERATIONS_BEFORE_HAND_GRAB = 100; +const int HAND_GRAB_DURATION_ITERATIONS = 50; +const int HAND_TIMER_SLEEP_ITERATIONS = 50; + bool stopReceiveAgentDataThread; bool injectAudioThreadRunning = false; @@ -177,11 +181,11 @@ int main(int argc, const char* argv[]) { // simulate the effect of pressing and un-pressing the mouse button/pad handStateTimer++; - if (handStateTimer == 100) { + if (handStateTimer == ITERATIONS_BEFORE_HAND_GRAB) { eve.setHandState(1); - } else if (handStateTimer == 150) { + } else if (handStateTimer == ITERATIONS_BEFORE_HAND_GRAB + HAND_GRAB_DURATION_ITERATIONS) { eve.setHandState(0); - } else if (handStateTimer >= 200) { + } else if (handStateTimer >= ITERATIONS_BEFORE_HAND_GRAB + HAND_GRAB_DURATION_ITERATIONS + HAND_TIMER_SLEEP_ITERATIONS) { handStateTimer = 0; } } From 00c11d82b270196d188c1e33aa2df00408ab98d1 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 7 May 2013 13:50:01 -0700 Subject: [PATCH 30/41] if the agent stops asking for loopback make sure the flag is set false --- libraries/shared/src/AudioRingBuffer.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/shared/src/AudioRingBuffer.cpp b/libraries/shared/src/AudioRingBuffer.cpp index f7cd256809..d48f95c754 100644 --- a/libraries/shared/src/AudioRingBuffer.cpp +++ b/libraries/shared/src/AudioRingBuffer.cpp @@ -122,6 +122,8 @@ int AudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) { bearing = bearing > 0 ? bearing - AGENT_LOOPBACK_MODIFIER : bearing + AGENT_LOOPBACK_MODIFIER; + } else { + _shouldLoopbackForAgent = false; } dataPtr += sizeof(float); From 82cff262b1906d79dae0479e97fe5d913b3da5ca Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 7 May 2013 14:28:48 -0700 Subject: [PATCH 31/41] for agent loopback perform no distance and angle calculations --- audio-mixer/src/main.cpp | 127 ++++++++++++----------- libraries/shared/src/AudioRingBuffer.cpp | 5 +- 2 files changed, 68 insertions(+), 64 deletions(-) diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index 1427a4097b..82f307f8d4 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -120,73 +120,78 @@ void *sendBuffer(void *args) { AudioRingBuffer* otherAgentBuffer = (AudioRingBuffer*) otherAgent->getLinkedData(); if (otherAgentBuffer->shouldBeAddedToMix()) { - float *agentPosition = agentRingBuffer->getPosition(); - float *otherAgentPosition = otherAgentBuffer->getPosition(); + + float bearingRelativeAngleToSource = 0.f; + float attenuationCoefficient = 1.f; - // 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(agent.getAgentIndex(), otherAgent.getAgentIndex()); - int highAgentIndex = std::max(agent.getAgentIndex(), otherAgent.getAgentIndex()); - - if (distanceCoefficients[lowAgentIndex][highAgentIndex] == 0) { - float distanceToAgent = sqrtf(powf(agentPosition[0] - otherAgentPosition[0], 2) + - powf(agentPosition[1] - otherAgentPosition[1], 2) + - powf(agentPosition[2] - otherAgentPosition[2], 2)); + if (otherAgent != agent) { + float *agentPosition = agentRingBuffer->getPosition(); + float *otherAgentPosition = otherAgentBuffer->getPosition(); - float minCoefficient = std::min(1.0f, - powf(0.5, (logf(DISTANCE_RATIO * distanceToAgent) / logf(3)) - 1)); - distanceCoefficients[lowAgentIndex][highAgentIndex] = minCoefficient; - } - - - // get the angle from the right-angle triangle - float triangleAngle = atan2f(fabsf(agentPosition[2] - otherAgentPosition[2]), - fabsf(agentPosition[0] - otherAgentPosition[0])) * (180 / M_PI); - float absoluteAngleToSource = 0; - float bearingRelativeAngleToSource = 0; - - - // find the angle we need for calculation based on the orientation of the triangle - if (otherAgentPosition[0] > agentPosition[0]) { - if (otherAgentPosition[2] > agentPosition[2]) { - absoluteAngleToSource = -90 + triangleAngle; - } else { - absoluteAngleToSource = -90 - triangleAngle; + // 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(agent.getAgentIndex(), otherAgent.getAgentIndex()); + int highAgentIndex = std::max(agent.getAgentIndex(), otherAgent.getAgentIndex()); + + if (distanceCoefficients[lowAgentIndex][highAgentIndex] == 0) { + float distanceToAgent = sqrtf(powf(agentPosition[0] - otherAgentPosition[0], 2) + + powf(agentPosition[1] - otherAgentPosition[1], 2) + + powf(agentPosition[2] - otherAgentPosition[2], 2)); + + float minCoefficient = std::min(1.0f, + powf(0.5, (logf(DISTANCE_RATIO * distanceToAgent) / logf(3)) - 1)); + distanceCoefficients[lowAgentIndex][highAgentIndex] = minCoefficient; } - } else { - if (otherAgentPosition[2] > agentPosition[2]) { - absoluteAngleToSource = 90 - triangleAngle; + + + // get the angle from the right-angle triangle + float triangleAngle = atan2f(fabsf(agentPosition[2] - otherAgentPosition[2]), + fabsf(agentPosition[0] - otherAgentPosition[0])) * (180 / M_PI); + float absoluteAngleToSource = 0; + float bearingRelativeAngleToSource = 0; + + // find the angle we need for calculation based on the orientation of the triangle + if (otherAgentPosition[0] > agentPosition[0]) { + if (otherAgentPosition[2] > agentPosition[2]) { + absoluteAngleToSource = -90 + triangleAngle; + } else { + absoluteAngleToSource = -90 - triangleAngle; + } } else { - absoluteAngleToSource = 90 + triangleAngle; + if (otherAgentPosition[2] > agentPosition[2]) { + absoluteAngleToSource = 90 - triangleAngle; + } else { + absoluteAngleToSource = 90 + triangleAngle; + } } - } - - if (absoluteAngleToSource > 180) { - absoluteAngleToSource -= 360; - } else if (absoluteAngleToSource < -180) { - absoluteAngleToSource += 360; - } - - bearingRelativeAngleToSource = absoluteAngleToSource - agentBearing; - bearingRelativeAngleToSource *= (M_PI / 180); - - float angleOfDelivery = absoluteAngleToSource - otherAgentBuffer->getBearing(); - - if (angleOfDelivery < -180) { - angleOfDelivery += 360; - } - - float offAxisCoefficient = MAX_OFF_AXIS_ATTENUATION + + + if (absoluteAngleToSource > 180) { + absoluteAngleToSource -= 360; + } else if (absoluteAngleToSource < -180) { + absoluteAngleToSource += 360; + } + + bearingRelativeAngleToSource = absoluteAngleToSource - agentBearing; + bearingRelativeAngleToSource *= (M_PI / 180); + + float angleOfDelivery = absoluteAngleToSource - otherAgentBuffer->getBearing(); + + if (angleOfDelivery < -180) { + angleOfDelivery += 360; + } + + float offAxisCoefficient = MAX_OFF_AXIS_ATTENUATION + (OFF_AXIS_ATTENUATION_FORMULA_STEP * (fabsf(angleOfDelivery) / 90.0f)); - - float attenuationCoefficient = distanceCoefficients[lowAgentIndex][highAgentIndex] - * otherAgentBuffer->getAttenuationRatio() - * offAxisCoefficient; - - float sinRatio = fabsf(sinf(bearingRelativeAngleToSource)); - int numSamplesDelay = PHASE_DELAY_AT_90 * sinRatio; - float weakChannelAmplitudeRatio = 1 - (PHASE_AMPLITUDE_RATIO_AT_90 * sinRatio); + + attenuationCoefficient = distanceCoefficients[lowAgentIndex][highAgentIndex] + * otherAgentBuffer->getAttenuationRatio() + * offAxisCoefficient; + + float sinRatio = fabsf(sinf(bearingRelativeAngleToSource)); + int numSamplesDelay = PHASE_DELAY_AT_90 * sinRatio; + float weakChannelAmplitudeRatio = 1 - (PHASE_AMPLITUDE_RATIO_AT_90 * sinRatio); + } int16_t* goodChannel = bearingRelativeAngleToSource > 0 ? clientMix + BUFFER_LENGTH_SAMPLES_PER_CHANNEL : clientMix; int16_t* delayedChannel = bearingRelativeAngleToSource > 0 ? clientMix : clientMix + BUFFER_LENGTH_SAMPLES_PER_CHANNEL; diff --git a/libraries/shared/src/AudioRingBuffer.cpp b/libraries/shared/src/AudioRingBuffer.cpp index d48f95c754..5079582544 100644 --- a/libraries/shared/src/AudioRingBuffer.cpp +++ b/libraries/shared/src/AudioRingBuffer.cpp @@ -113,6 +113,7 @@ int AudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) { attenuationRatio = attenuationByte / 255.0f; memcpy(&bearing, dataPtr, sizeof(float)); + dataPtr += sizeof(bearing); if (bearing > 180 || bearing < -180) { // we were passed an invalid bearing because this agent wants loopback (pressed the H key) @@ -124,9 +125,7 @@ int AudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) { : bearing + AGENT_LOOPBACK_MODIFIER; } else { _shouldLoopbackForAgent = false; - } - - dataPtr += sizeof(float); + } sourceBuffer = dataPtr; } From a87e0d7f7fc7c26db6f49c930201f24906ad78a0 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 7 May 2013 14:32:15 -0700 Subject: [PATCH 32/41] variable fixes for audio-mixer loopback --- audio-mixer/src/main.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index 82f307f8d4..e7126083a7 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -123,6 +123,8 @@ void *sendBuffer(void *args) { float bearingRelativeAngleToSource = 0.f; float attenuationCoefficient = 1.f; + int numSamplesDelay = 0; + float weakChannelAmplitudeRatio = 1.f; if (otherAgent != agent) { float *agentPosition = agentRingBuffer->getPosition(); @@ -189,8 +191,8 @@ void *sendBuffer(void *args) { * offAxisCoefficient; float sinRatio = fabsf(sinf(bearingRelativeAngleToSource)); - int numSamplesDelay = PHASE_DELAY_AT_90 * sinRatio; - float weakChannelAmplitudeRatio = 1 - (PHASE_AMPLITUDE_RATIO_AT_90 * sinRatio); + numSamplesDelay = PHASE_DELAY_AT_90 * sinRatio; + weakChannelAmplitudeRatio = 1 - (PHASE_AMPLITUDE_RATIO_AT_90 * sinRatio); } int16_t* goodChannel = bearingRelativeAngleToSource > 0 ? clientMix + BUFFER_LENGTH_SAMPLES_PER_CHANNEL : clientMix; From 6bad72a18e0b38edfaddfd8ce6b496fc8c0698ef Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 7 May 2013 14:41:20 -0700 Subject: [PATCH 33/41] spacing cleanup in audio-mixer main --- audio-mixer/src/main.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index e7126083a7..4e47da8776 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -215,8 +215,7 @@ void *sendBuffer(void *args) { if (s + numSamplesDelay < BUFFER_LENGTH_SAMPLES_PER_CHANNEL) { plateauAdditionOfSamples(delayedChannel[s + numSamplesDelay], - currentSample * - weakChannelAmplitudeRatio); + currentSample * weakChannelAmplitudeRatio); } } } From e8fbfcab05ce79665cc5cc86791630954a840b2d Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 7 May 2013 14:57:24 -0700 Subject: [PATCH 34/41] fix unpacking of other avatars in avatar mixer bulk packet --- avatar-mixer/src/main.cpp | 7 ++----- eve/src/main.cpp | 10 +++++----- libraries/shared/src/AgentList.cpp | 2 +- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/avatar-mixer/src/main.cpp b/avatar-mixer/src/main.cpp index 74b731fdc5..2f031a6f0a 100644 --- a/avatar-mixer/src/main.cpp +++ b/avatar-mixer/src/main.cpp @@ -88,15 +88,12 @@ int main(int argc, const char* argv[]) { // send back a packet with other active agent data to this agent for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { - if (agent->getLinkedData() != NULL - && !socketMatch(agentAddress, agent->getActiveSocket())) { + if (agent->getLinkedData() && !socketMatch(agentAddress, agent->getActiveSocket())) { currentBufferPosition = addAgentToBroadcastPacket(currentBufferPosition, &*agent); } } - agentList->getAgentSocket().send(agentAddress, - broadcastPacket, - currentBufferPosition - broadcastPacket); + agentList->getAgentSocket().send(agentAddress, broadcastPacket, currentBufferPosition - broadcastPacket); break; case PACKET_HEADER_DOMAIN: diff --git a/eve/src/main.cpp b/eve/src/main.cpp index 7c4bde7a2d..b8025d5dd8 100644 --- a/eve/src/main.cpp +++ b/eve/src/main.cpp @@ -52,7 +52,7 @@ void *receiveAgentData(void *args) { // avatar mixer - this makes sure it won't be killed during silent agent removal avatarMixer = agentList->soloAgentOfType(AGENT_TYPE_AVATAR_MIXER); - if (avatarMixer != NULL) { + if (avatarMixer) { avatarMixer->setLastHeardMicrostamp(usecTimestampNow()); } @@ -77,9 +77,9 @@ void *injectAudio(void *args) { // look for an audio mixer in our agent list Agent* audioMixer = AgentList::getInstance()->soloAgentOfType(AGENT_TYPE_AUDIO_MIXER); - if (audioMixer != NULL) { + if (audioMixer) { // until the audio mixer is setup for ping-reply, activate the public socket if it's not active - if (audioMixer->getActiveSocket() == NULL) { + if (!audioMixer->getActiveSocket()) { audioMixer->activatePublicSocket(); } @@ -117,9 +117,9 @@ 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), + eve.setPosition(glm::vec3(randFloatInRange(0, RANDOM_POSITION_MAX_DIMENSION), 1.33, // this should be the same as the avatar's pelvis standing height - randFloatInRange(-RANDOM_POSITION_MAX_DIMENSION, RANDOM_POSITION_MAX_DIMENSION))); + randFloatInRange(0, RANDOM_POSITION_MAX_DIMENSION))); // face any instance of eve down the z-axis eve.setBodyYaw(0); diff --git a/libraries/shared/src/AgentList.cpp b/libraries/shared/src/AgentList.cpp index 82a21ae479..0ff8184f07 100644 --- a/libraries/shared/src/AgentList.cpp +++ b/libraries/shared/src/AgentList.cpp @@ -123,7 +123,7 @@ void AgentList::processBulkAgentData(sockaddr *senderAddress, unsigned char *pac uint16_t agentID = -1; while ((currentPosition - startPosition) < numTotalBytes) { - currentPosition += unpackAgentId(currentPosition, &agentID); + unpackAgentId(currentPosition, &agentID); memcpy(packetHolder + 1, currentPosition, numTotalBytes - (currentPosition - startPosition)); Agent* matchingAgent = agentWithID(agentID); From 11b2271b918a6a03d2a5e50e1acb133b3522d48a Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 7 May 2013 15:05:31 -0700 Subject: [PATCH 35/41] size of agent ID must be included in bytes read per avatar --- eve/src/main.cpp | 2 +- libraries/avatars/src/AvatarData.cpp | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/eve/src/main.cpp b/eve/src/main.cpp index b8025d5dd8..cb774d70a7 100644 --- a/eve/src/main.cpp +++ b/eve/src/main.cpp @@ -17,7 +17,7 @@ const int EVE_AGENT_LISTEN_PORT = 55441; -const float RANDOM_POSITION_MAX_DIMENSION = 5.0f; +const float RANDOM_POSITION_MAX_DIMENSION = 10.0f; const float DATA_SEND_INTERVAL_MSECS = 15; const float MIN_AUDIO_SEND_INTERVAL_SECS = 10; diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 3136b3e30a..e1af4da4a2 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -128,11 +128,14 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) { // called on the other agents - assigns it to my views of the others int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) { - // increment to push past the packet header and agent ID - sourceBuffer += sizeof(PACKET_HEADER_HEAD_DATA) + sizeof(uint16_t); + // increment to push past the packet header + sourceBuffer += sizeof(PACKET_HEADER_HEAD_DATA); unsigned char* startPosition = sourceBuffer; + // push past the agent ID + sourceBuffer += + sizeof(uint16_t); + // Body world position memcpy(&_position, sourceBuffer, sizeof(float) * 3); sourceBuffer += sizeof(float) * 3; From 8daae1dd1d05c0a30d754011aa96e3fa412d40cd Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 7 May 2013 15:11:01 -0700 Subject: [PATCH 36/41] bring eve closer to the ground after scale changes --- eve/src/main.cpp | 4 +++- libraries/avatars/src/AvatarData.cpp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/eve/src/main.cpp b/eve/src/main.cpp index cb774d70a7..fd66d6911c 100644 --- a/eve/src/main.cpp +++ b/eve/src/main.cpp @@ -29,6 +29,8 @@ const int ITERATIONS_BEFORE_HAND_GRAB = 100; const int HAND_GRAB_DURATION_ITERATIONS = 50; const int HAND_TIMER_SLEEP_ITERATIONS = 50; +const float EVE_PELVIS_HEIGHT = 0.5f; + bool stopReceiveAgentDataThread; bool injectAudioThreadRunning = false; @@ -118,7 +120,7 @@ int main(int argc, const char* argv[]) { // pick a random point inside a 10x10 grid eve.setPosition(glm::vec3(randFloatInRange(0, RANDOM_POSITION_MAX_DIMENSION), - 1.33, // this should be the same as the avatar's pelvis standing height + EVE_PELVIS_HEIGHT, // this should be the same as the avatar's pelvis standing height randFloatInRange(0, RANDOM_POSITION_MAX_DIMENSION))); // face any instance of eve down the z-axis diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index e1af4da4a2..3b8e06e81e 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -139,7 +139,7 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) { // Body world position memcpy(&_position, sourceBuffer, sizeof(float) * 3); sourceBuffer += sizeof(float) * 3; - + // Body rotation (NOTE: This needs to become a quaternion to save two bytes) sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t *)sourceBuffer, &_bodyYaw); sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t *)sourceBuffer, &_bodyPitch); From 681044e3a6ace0b8ad0d7c6df156e68e615172d7 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 7 May 2013 15:24:15 -0700 Subject: [PATCH 37/41] add debugging output and value change for off-axis --- audio-mixer/src/main.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index 4e47da8776..8215a32e80 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -60,7 +60,7 @@ const float DISTANCE_RATIO = 3.0f / 0.3f; const float PHASE_AMPLITUDE_RATIO_AT_90 = 0.5; const int PHASE_DELAY_AT_90 = 20; -const float MAX_OFF_AXIS_ATTENUATION = 0.5f; +const float MAX_OFF_AXIS_ATTENUATION = 0.1f; const float OFF_AXIS_ATTENUATION_FORMULA_STEP = (1 - MAX_OFF_AXIS_ATTENUATION) / 2.0f; void plateauAdditionOfSamples(int16_t &mixSample, int16_t sampleToAdd) { @@ -186,10 +186,13 @@ void *sendBuffer(void *args) { float offAxisCoefficient = MAX_OFF_AXIS_ATTENUATION + (OFF_AXIS_ATTENUATION_FORMULA_STEP * (fabsf(angleOfDelivery) / 90.0f)); + printf("AD: %f, OC: %f\n", angleOfDelivery, offAxisCoefficient); + attenuationCoefficient = distanceCoefficients[lowAgentIndex][highAgentIndex] * otherAgentBuffer->getAttenuationRatio() * offAxisCoefficient; + float sinRatio = fabsf(sinf(bearingRelativeAngleToSource)); numSamplesDelay = PHASE_DELAY_AT_90 * sinRatio; weakChannelAmplitudeRatio = 1 - (PHASE_AMPLITUDE_RATIO_AT_90 * sinRatio); From 37aee099686036ae4c37192327cb94a9302c3af6 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 7 May 2013 15:43:28 -0700 Subject: [PATCH 38/41] fix order of angle calculations --- audio-mixer/src/main.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index 8215a32e80..06250c42af 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -168,23 +168,20 @@ void *sendBuffer(void *args) { } } - if (absoluteAngleToSource > 180) { - absoluteAngleToSource -= 360; - } else if (absoluteAngleToSource < -180) { - absoluteAngleToSource += 360; + bearingRelativeAngleToSource = absoluteAngleToSource - agentBearing; + + if (bearingRelativeAngleToSource > 180) { + bearingRelativeAngleToSource -= 360; + } else if (bearingRelativeAngleToSource < -180) { + bearingRelativeAngleToSource += 360; } - bearingRelativeAngleToSource = absoluteAngleToSource - agentBearing; bearingRelativeAngleToSource *= (M_PI / 180); float angleOfDelivery = absoluteAngleToSource - otherAgentBuffer->getBearing(); - if (angleOfDelivery < -180) { - angleOfDelivery += 360; - } - float offAxisCoefficient = MAX_OFF_AXIS_ATTENUATION + - (OFF_AXIS_ATTENUATION_FORMULA_STEP * (fabsf(angleOfDelivery) / 90.0f)); + (OFF_AXIS_ATTENUATION_FORMULA_STEP * (fabsf(angleOfDelivery) / 90.0f)); printf("AD: %f, OC: %f\n", angleOfDelivery, offAxisCoefficient); From 70a6466a56308c0dc8c5d0b07313fa171d2f4de9 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 7 May 2013 17:02:41 -0700 Subject: [PATCH 39/41] fix for bearingRelativeAngleToSource breaking spatialised audio --- audio-mixer/src/main.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index 06250c42af..b554d011d3 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -60,7 +60,7 @@ const float DISTANCE_RATIO = 3.0f / 0.3f; const float PHASE_AMPLITUDE_RATIO_AT_90 = 0.5; const int PHASE_DELAY_AT_90 = 20; -const float MAX_OFF_AXIS_ATTENUATION = 0.1f; +const float MAX_OFF_AXIS_ATTENUATION = 0.2f; const float OFF_AXIS_ATTENUATION_FORMULA_STEP = (1 - MAX_OFF_AXIS_ATTENUATION) / 2.0f; void plateauAdditionOfSamples(int16_t &mixSample, int16_t sampleToAdd) { @@ -111,7 +111,6 @@ void *sendBuffer(void *args) { for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { AudioRingBuffer* agentRingBuffer = (AudioRingBuffer*) agent->getLinkedData(); - float agentBearing = agentRingBuffer->getBearing(); int16_t clientMix[BUFFER_LENGTH_SAMPLES_PER_CHANNEL * 2] = {}; @@ -151,7 +150,7 @@ void *sendBuffer(void *args) { float triangleAngle = atan2f(fabsf(agentPosition[2] - otherAgentPosition[2]), fabsf(agentPosition[0] - otherAgentPosition[0])) * (180 / M_PI); float absoluteAngleToSource = 0; - float bearingRelativeAngleToSource = 0; + bearingRelativeAngleToSource = 0; // find the angle we need for calculation based on the orientation of the triangle if (otherAgentPosition[0] > agentPosition[0]) { @@ -168,7 +167,7 @@ void *sendBuffer(void *args) { } } - bearingRelativeAngleToSource = absoluteAngleToSource - agentBearing; + bearingRelativeAngleToSource = absoluteAngleToSource - agentRingBuffer->getBearing(); if (bearingRelativeAngleToSource > 180) { bearingRelativeAngleToSource -= 360; @@ -176,27 +175,30 @@ void *sendBuffer(void *args) { bearingRelativeAngleToSource += 360; } - bearingRelativeAngleToSource *= (M_PI / 180); - float angleOfDelivery = absoluteAngleToSource - otherAgentBuffer->getBearing(); + if (angleOfDelivery > 180) { + angleOfDelivery -= 360; + } else if (angleOfDelivery < -180) { + angleOfDelivery += 360; + } + float offAxisCoefficient = MAX_OFF_AXIS_ATTENUATION + (OFF_AXIS_ATTENUATION_FORMULA_STEP * (fabsf(angleOfDelivery) / 90.0f)); - printf("AD: %f, OC: %f\n", angleOfDelivery, offAxisCoefficient); - attenuationCoefficient = distanceCoefficients[lowAgentIndex][highAgentIndex] * otherAgentBuffer->getAttenuationRatio() * offAxisCoefficient; + bearingRelativeAngleToSource *= (M_PI / 180); float sinRatio = fabsf(sinf(bearingRelativeAngleToSource)); numSamplesDelay = PHASE_DELAY_AT_90 * sinRatio; weakChannelAmplitudeRatio = 1 - (PHASE_AMPLITUDE_RATIO_AT_90 * sinRatio); } - int16_t* goodChannel = bearingRelativeAngleToSource > 0 ? clientMix + BUFFER_LENGTH_SAMPLES_PER_CHANNEL : clientMix; - int16_t* delayedChannel = bearingRelativeAngleToSource > 0 ? clientMix : clientMix + BUFFER_LENGTH_SAMPLES_PER_CHANNEL; + int16_t* goodChannel = bearingRelativeAngleToSource > 0.0f ? clientMix + BUFFER_LENGTH_SAMPLES_PER_CHANNEL : clientMix; + int16_t* delayedChannel = bearingRelativeAngleToSource > 0.0f ? clientMix : clientMix + BUFFER_LENGTH_SAMPLES_PER_CHANNEL; int16_t* delaySamplePointer = otherAgentBuffer->getNextOutput() == otherAgentBuffer->getBuffer() ? otherAgentBuffer->getBuffer() + RING_BUFFER_SAMPLES - numSamplesDelay From 75ba88923fd564bd4a350394d0d54a0290622eb2 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 7 May 2013 17:09:49 -0700 Subject: [PATCH 40/41] remove the serial interface close in destructor, incorrect solution --- interface/src/SerialInterface.cpp | 6 ------ interface/src/SerialInterface.h | 1 - 2 files changed, 7 deletions(-) diff --git a/interface/src/SerialInterface.cpp b/interface/src/SerialInterface.cpp index 3453321d26..8929dbb2f5 100644 --- a/interface/src/SerialInterface.cpp +++ b/interface/src/SerialInterface.cpp @@ -33,12 +33,6 @@ const int GRAVITY_SAMPLES = 200; // Use the first samples to const bool USING_INVENSENSE_MPU9150 = 1; -SerialInterface::~SerialInterface() { -#ifdef __APPLE__ - close(_serialDescriptor); -#endif -} - void SerialInterface::pair() { #ifdef __APPLE__ diff --git a/interface/src/SerialInterface.h b/interface/src/SerialInterface.h index 4aafb46994..e84fa2ddde 100644 --- a/interface/src/SerialInterface.h +++ b/interface/src/SerialInterface.h @@ -38,7 +38,6 @@ class SerialInterface { public: SerialInterface() : active(false), _failedOpenAttempts(0) {} - ~SerialInterface(); void pair(); void readData(); From 9658c40dd6126ffabdf8c62b6a29b699e956e125 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 7 May 2013 17:17:47 -0700 Subject: [PATCH 41/41] change lastAgentId member variable to _lastAgentID --- audio-mixer/src/main.cpp | 4 ++-- domain-server/src/main.cpp | 4 ++-- libraries/shared/src/AgentList.cpp | 10 +--------- libraries/shared/src/AgentList.h | 8 ++++---- 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index b554d011d3..c47fbb2170 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -282,8 +282,8 @@ int main(int argc, const char* argv[]) { if(agentList->getAgentSocket().receive(agentAddress, packetData, &receivedBytes)) { if (packetData[0] == PACKET_HEADER_INJECT_AUDIO) { - if (agentList->addOrUpdateAgent(agentAddress, agentAddress, packetData[0], agentList->getLastAgentId())) { - agentList->increaseAgentId(); + if (agentList->addOrUpdateAgent(agentAddress, agentAddress, packetData[0], agentList->getLastAgentID())) { + agentList->increaseAgentID(); } agentList->updateAgentWithData(agentAddress, packetData, receivedBytes); diff --git a/domain-server/src/main.cpp b/domain-server/src/main.cpp index 95da95c210..be906e194d 100644 --- a/domain-server/src/main.cpp +++ b/domain-server/src/main.cpp @@ -118,8 +118,8 @@ int main(int argc, const char * argv[]) if (agentList->addOrUpdateAgent((sockaddr*) &agentPublicAddress, (sockaddr*) &agentLocalAddress, agentType, - agentList->getLastAgentId())) { - agentList->increaseAgentId(); + agentList->getLastAgentID())) { + agentList->increaseAgentID(); } currentBufferPos = broadcastPacket + 1; diff --git a/libraries/shared/src/AgentList.cpp b/libraries/shared/src/AgentList.cpp index 0ff8184f07..df591524c0 100644 --- a/libraries/shared/src/AgentList.cpp +++ b/libraries/shared/src/AgentList.cpp @@ -65,7 +65,7 @@ AgentList::AgentList(char newOwnerType, unsigned int newSocketListenPort) : _ownerType(newOwnerType), socketListenPort(newSocketListenPort), _ownerID(UNKNOWN_AGENT_ID), - lastAgentId(0) { + _lastAgentID(0) { pthread_mutex_init(&mutex, 0); } @@ -192,14 +192,6 @@ Agent* AgentList::agentWithID(uint16_t agentID) { return NULL; } -uint16_t AgentList::getLastAgentId() { - return lastAgentId; -} - -void AgentList::increaseAgentId() { - ++lastAgentId; -} - int AgentList::processDomainServerList(unsigned char *packetData, size_t dataBytes) { int readAgents = 0; diff --git a/libraries/shared/src/AgentList.h b/libraries/shared/src/AgentList.h index 1956916211..db71357114 100644 --- a/libraries/shared/src/AgentList.h +++ b/libraries/shared/src/AgentList.h @@ -52,9 +52,6 @@ public: UDPSocket& getAgentSocket(); - uint16_t getLastAgentId(); - void increaseAgentId(); - void lock() { pthread_mutex_lock(&mutex); } void unlock() { pthread_mutex_unlock(&mutex); } @@ -76,6 +73,9 @@ public: char getOwnerType() const { return _ownerType; } + uint16_t getLastAgentID() const { return _lastAgentID; } + void increaseAgentID() { ++_lastAgentID; } + uint16_t getOwnerID() const { return _ownerID; } void setOwnerID(uint16_t ownerID) { _ownerID = ownerID; } @@ -105,7 +105,7 @@ private: char _ownerType; unsigned int socketListenPort; uint16_t _ownerID; - uint16_t lastAgentId; + uint16_t _lastAgentID; pthread_t removeSilentAgentsThread; pthread_t checkInWithDomainServerThread; pthread_t pingUnknownAgentsThread;