diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 0d585ff5bf..9dbfdbf07f 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -157,7 +157,7 @@ int audioCallback (const void *inputBuffer, // memcpy the three float positions for (int p = 0; p < 3; p++) { - memcpy(currentPacketPtr, &data->linkedHead->getBodyPosition()[p], sizeof(float)); + memcpy(currentPacketPtr, &data->linkedHead->getPosition()[p], sizeof(float)); currentPacketPtr += sizeof(float); } diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index b29ddfc4bc..f0c071b9ee 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -48,7 +48,7 @@ Head::Head(bool isMine) { _velocity = glm::vec3( 0.0, 0.0, 0.0 ); _thrust = glm::vec3( 0.0, 0.0, 0.0 ); _rotation = glm::quat( 0.0f, 0.0f, 0.0f, 0.0f ); - _closestOtherAvatar = 0; + _nearOtherAvatar = false; _bodyYaw = -90.0; _bodyPitch = 0.0; _bodyRoll = 0.0; @@ -60,7 +60,7 @@ Head::Head(bool isMine) { //_transmitterTimer = 0; _transmitterHz = 0.0; _transmitterPackets = 0; - _numOtherAvatarsInView = 0; + //_numOtherAvatars = 0; initializeSkeleton(); @@ -117,13 +117,11 @@ Head::Head(bool isMine) { _renderPitch = 0.0; _sphere = NULL; - - _collisionElipsoid.colliding = false; - _collisionElipsoid.position = glm::vec3( 0.0, 0.0, 0.0 ); - _collisionElipsoid.upVector = glm::vec3( 0.0, 0.0, 0.0 ); - _collisionElipsoid.girth = 0.0; - _collisionElipsoid.height = 0.0; - + + _handHolding.position = glm::vec3( 0.0, 0.0, 0.0 ); + _handHolding.velocity = glm::vec3( 0.0, 0.0, 0.0 ); + _handHolding.force = 10.0f; + if (iris_texture.size() == 0) { switchToResourcesParentIfRequired(); unsigned error = lodepng::decode(iris_texture, iris_texture_width, iris_texture_height, iris_texture_file); @@ -131,19 +129,19 @@ Head::Head(bool isMine) { printLog("error %u: %s\n", error, lodepng_error_text(error)); } } - - for (int o=0; o::iterator agent = agentList->getAgents().begin(); agent != agentList->getAgents().end(); @@ -318,21 +316,34 @@ void Head::simulate(float deltaTime) { if (( agent->getLinkedData() != NULL && ( agent->getType() == AGENT_TYPE_AVATAR ) )) { Head *otherAvatar = (Head *)agent->getLinkedData(); - if ( _numOtherAvatarsInView < MAX_OTHER_AVATARS ) { + // if ( _numOtherAvatars < MAX_OTHER_AVATARS ) + { - //----------------------------------------------------------- - // test other avatar hand position for proximity... - //----------------------------------------------------------- - _otherAvatarHandPosition[ _numOtherAvatarsInView ] = otherAvatar->getBonePosition( AVATAR_BONE_RIGHT_HAND ); + //------------------------------------------------------ + // check for collisions with other avatars and respond + //------------------------------------------------------ + updateAvatarCollisionDetectionAndResponse + ( + otherAvatar->getPosition(), + otherAvatar->getGirth(), + otherAvatar->getHeight(), + otherAvatar->getBodyUpDirection(), + deltaTime + ); + + //------------------------------------------------- + // test other avatar hand position for proximity + //------------------------------------------------ glm::vec3 v( _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position ); - v -= _otherAvatarHandPosition[ _numOtherAvatarsInView ]; + v -= otherAvatar->getBonePosition( AVATAR_BONE_RIGHT_HAND ); float distance = glm::length( v ); if ( distance < _maxArmLength ) { if ( distance < closestDistance ) { closestDistance = distance; - _closestOtherAvatar = _numOtherAvatarsInView; - _numOtherAvatarsInView++; + _nearOtherAvatar = true; + _otherAvatar.handPosition = otherAvatar->getBonePosition( AVATAR_BONE_RIGHT_HAND ); + _otherAvatar.handState = (int)otherAvatar->getHandState(); } } } @@ -345,16 +356,23 @@ void Head::simulate(float deltaTime) { //-------------------------------------------------------------- // test for avatar collision response (using a big sphere :) //-------------------------------------------------------------- - updateAvatarCollisionDetectionAndResponse(_TEST_bigSpherePosition, _TEST_bigSphereRadius, deltaTime); + updateAvatarCollisionDetectionAndResponse + ( + _TEST_bigSpherePosition, + _TEST_bigSphereRadius, + _TEST_bigSphereRadius, + glm::vec3( 0.0, 1.0, 0.0 ), + deltaTime + ); } if ( AVATAR_GRAVITY ) { - if ( _bodyPosition.y > _bone[ AVATAR_BONE_RIGHT_FOOT ].radius * 2.0 ) { + if ( _position.y > _bone[ AVATAR_BONE_RIGHT_FOOT ].radius * 2.0 ) { _velocity += glm::dvec3( 0.0, -1.0, 0.0 ) * ( 6.0 * deltaTime ); } else { - if ( _bodyPosition.y < _bone[ AVATAR_BONE_RIGHT_FOOT ].radius ) { - _bodyPosition.y = _bone[ AVATAR_BONE_RIGHT_FOOT ].radius; + if ( _position.y < _bone[ AVATAR_BONE_RIGHT_FOOT ].radius ) { + _position.y = _bone[ AVATAR_BONE_RIGHT_FOOT ].radius; _velocity.y = 0.0; } } @@ -369,7 +387,7 @@ void Head::simulate(float deltaTime) { // reset hand and arm positions according to hand movement //------------------------------------------------------------ if (_usingBodySprings) { - updateHandMovement(); + updateHandMovement( deltaTime ); updateBodySprings( deltaTime ); } @@ -445,7 +463,7 @@ void Head::simulate(float deltaTime) { //---------------------------------------------------------- // update position by velocity //---------------------------------------------------------- - _bodyPosition += (glm::vec3)_velocity * deltaTime; + _position += (glm::vec3)_velocity * deltaTime; //---------------------------------------------------------- // decay velocity @@ -563,37 +581,25 @@ float Head::getHeight() { glm::vec3 Head::getBodyUpDirection() { return _orientation.getUp(); } - - -bool Head::testForCollision( glm::vec3 collisionPosition, float collisionGirth, float collisionHeight, glm::vec3 collisionUpVector ) { - _collisionElipsoid.colliding = false; - _collisionElipsoid.position = glm::vec3( 0.0, 0.0, 0.0 ); - _collisionElipsoid.upVector = glm::vec3( 0.0, 0.0, 0.0 ); - _collisionElipsoid.girth = 0.0; - _collisionElipsoid.height = 0.0; - - return false; -} - - //-------------------------------------------------------------------------------- // This is a workspace for testing avatar body collision detection and response //-------------------------------------------------------------------------------- -void Head::updateAvatarCollisionDetectionAndResponse( glm::vec3 collisionPosition, float collisionRadius, float deltaTime ) { +void Head::updateAvatarCollisionDetectionAndResponse +( glm::vec3 collisionPosition, float collisionGirth, float collisionHeight, glm::vec3 collisionUpVector, float deltaTime ) { float myBodyApproximateBoundingRadius = 1.0f; - glm::vec3 vectorFromMyBodyToBigSphere(_bodyPosition - collisionPosition); + glm::vec3 vectorFromMyBodyToBigSphere(_position - collisionPosition); bool jointCollision = false; float distanceToBigSphere = glm::length(vectorFromMyBodyToBigSphere); - if ( distanceToBigSphere < myBodyApproximateBoundingRadius + collisionRadius ) + if ( distanceToBigSphere < myBodyApproximateBoundingRadius + collisionGirth ) { for (int b=0; boctalCode) * (0.5 * TREE_SCALE); - glm::vec3 viewerPosition = viewerHead->getBodyPosition(); + glm::vec3 viewerPosition = viewerHead->getPosition(); // debug LOD code glm::vec3 debugNodePosition; diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 74e92ebb42..119473ef9e 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -306,7 +306,7 @@ void displayStats(void) char legend2[] = "* - toggle stars, & - toggle paint mode, '-' - send erase all, '%' - send add scene"; drawtext(10, statsVerticalOffset + 32, 0.10f, 0, 1.0, 0, legend2); - glm::vec3 avatarPos = myAvatar.getBodyPosition(); + glm::vec3 avatarPos = myAvatar.getPosition(); char stats[200]; sprintf(stats, "FPS = %3.0f Pkts/s = %d Bytes/s = %d Head(x,y,z)= %4.2f, %4.2f, %4.2f ", @@ -398,8 +398,8 @@ void init(void) if (noiseOn) { myAvatar.setNoise(noise); } - myAvatar.setBodyPosition(start_location); - myCamera.setPosition( start_location ); + myAvatar.setPosition(start_location); + myCamera.setPosition(start_location); #ifdef MARKER_CAPTURE @@ -440,7 +440,7 @@ void reset_sensors() renderYawRate = 0; renderPitchRate = 0; - myAvatar.setBodyPosition(start_location); + myAvatar.setPosition(start_location); headMouseX = WIDTH/2; headMouseY = HEIGHT/2; @@ -540,7 +540,7 @@ void updateAvatar(float frametime) // If I'm in paint mode, send a voxel out to VOXEL server agents. if (::paintOn) { - glm::vec3 avatarPos = myAvatar.getBodyPosition(); + glm::vec3 avatarPos = myAvatar.getPosition(); // For some reason, we don't want to flip X and Z here. ::paintingVoxel.x = avatarPos.x/10.0; @@ -822,7 +822,7 @@ void display(void) //---------------------------------------------------- // set the camera to third-person view behind my av //---------------------------------------------------- - myCamera.setTargetPosition ( myAvatar.getBodyPosition() ); + myCamera.setTargetPosition ( myAvatar.getPosition() ); myCamera.setYaw ( 180.0 - myAvatar.getBodyYaw() ); myCamera.setPitch ( 0.0 ); // temporarily, this must be 0.0 or else bad juju myCamera.setRoll ( 0.0 ); @@ -1264,7 +1264,7 @@ void shiftPaintingColor() } void setupPaintingVoxel() { - glm::vec3 avatarPos = myAvatar.getBodyPosition(); + glm::vec3 avatarPos = myAvatar.getPosition(); ::paintingVoxel.x = avatarPos.z/-10.0; // voxel space x is negative z head space ::paintingVoxel.y = avatarPos.y/-10.0; // voxel space y is negative y head space @@ -1493,7 +1493,7 @@ void idle(void) { // updateAvatar(deltaTime); - //loop through all the other avatars and simulate them. + //loop through all the other avatars and simulate them... AgentList * agentList = AgentList::getInstance(); for(std::vector::iterator agent = agentList->getAgents().begin(); agent != agentList->getAgents().end(); agent++) { @@ -1501,9 +1501,6 @@ void idle(void) { { Head *avatar = (Head *)agent->getLinkedData(); avatar->simulate(deltaTime); - - //not ready yet... - //myAvatar.testForCollision( avatar->getBodyPosition(), avatar->getGirth(), avatar->getHeight(), avatar->getBodyUpDirection() ); } } @@ -1514,7 +1511,6 @@ void idle(void) { glutPostRedisplay(); lastTimeIdle = check; - } // Read serial data diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 295348a098..fd20e099c0 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -69,7 +69,7 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) { // and return the number of bytes to push the pointer // Body world position - memcpy(destinationBuffer, &_bodyPosition, sizeof(float) * 3); + memcpy(destinationBuffer, &_position, sizeof(float) * 3); destinationBuffer += sizeof(float) * 3; // Body rotation (NOTE: This needs to become a quaternion to save two bytes) @@ -125,7 +125,7 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) { unsigned char* startPosition = sourceBuffer; // Body world position - memcpy(&_bodyPosition, sourceBuffer, sizeof(float) * 3); + memcpy(&_position, sourceBuffer, sizeof(float) * 3); sourceBuffer += sizeof(float) * 3; // Body rotation (NOTE: This needs to become a quaternion to save two bytes) @@ -171,14 +171,14 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) { return sourceBuffer - startPosition; } -glm::vec3 AvatarData::getBodyPosition() { - return glm::vec3(_bodyPosition.x, - _bodyPosition.y, - _bodyPosition.z); +glm::vec3 AvatarData::getPosition() { + return glm::vec3(_position.x, + _position.y, + _position.z); } -void AvatarData::setBodyPosition(glm::vec3 bodyPosition) { - _bodyPosition = bodyPosition; +void AvatarData::setPosition(glm::vec3 position) { + _position = position; } void AvatarData::setHandPosition(glm::vec3 handPosition) { diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index 4655873dcd..c403a1683a 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -20,8 +20,8 @@ public: AvatarData* clone() const; - glm::vec3 getBodyPosition(); - void setBodyPosition(glm::vec3 bodyPosition); + glm::vec3 getPosition(); + void setPosition(glm::vec3 position); void setHandPosition(glm::vec3 handPosition); int getBroadcastData(unsigned char* destinationBuffer); @@ -48,7 +48,7 @@ public: // Hand State void setHandState(char s) { _handState = s; }; - const float getHandState() const {return _handState; }; + const float getHandState() const {return _handState; }; //@Philip - shouldn't this be an int or a char? // Instantaneous audio loudness to drive mouth/facial animation void setLoudness(float l) { _audioLoudness = l; }; @@ -75,7 +75,7 @@ public: void setCameraFarClip(float farClip) { _cameraFarClip = farClip; } protected: - glm::vec3 _bodyPosition; + glm::vec3 _position; glm::vec3 _handPosition; // Body rotation