From b7d6ce9747871715c8f91fc04dc131fdaf6d3b14 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Mon, 22 Apr 2013 13:15:46 -0700 Subject: [PATCH] fixed avatar hand position by making avatars simulate all the time,and also fixing logic of _isMine --- interface/src/Head.cpp | 133 ++++++++++++++++++++++------------------- interface/src/Head.h | 11 ++-- interface/src/main.cpp | 20 ++++--- 3 files changed, 87 insertions(+), 77 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 50ebeed4ae..24d04b2c7b 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -57,13 +57,14 @@ Head::Head(bool isMine) { _bodyPitch = 0.0; _bodyRoll = 0.0; _bodyYawDelta = 0.0; - _triggeringAction = false; + _mousePressed = false; _mode = AVATAR_MODE_STANDING; _isMine = isMine; _maxArmLength = 0.0; //_transmitterTimer = 0; _transmitterHz = 0.0; _transmitterPackets = 0; + _numOtherAvatarsInView = 0; initializeSkeleton(); @@ -114,7 +115,8 @@ Head::Head(bool isMine) { _head.noise = 0; _movedHandOffset = glm::vec3( 0.0, 0.0, 0.0 ); - _usingBodySprings = false; +_usingBodySprings = true; +//_usingBodySprings = false; _springForce = 6.0f; _springVelocityDecay = 16.0f; _renderYaw = 0.0; @@ -133,11 +135,11 @@ Head::Head(bool isMine) { //-------------------------------------------------- // test... just slam them into random positions... //-------------------------------------------------- - _DEBUG_otherAvatarListPosition[ 0 ] = glm::vec3( 0.0f, 0.3f, 2.0f ); - _DEBUG_otherAvatarListPosition[ 1 ] = glm::vec3( 4.0f, 0.3f, 2.0f ); - _DEBUG_otherAvatarListPosition[ 2 ] = glm::vec3( 2.0f, 0.3f, 2.0f ); - _DEBUG_otherAvatarListPosition[ 3 ] = glm::vec3( 1.0f, 0.3f, -4.0f ); - _DEBUG_otherAvatarListPosition[ 4 ] = glm::vec3( -2.0f, 0.3f, -2.0f ); + _otherAvatarHandPosition[ 0 ] = glm::vec3( 0.0f, 0.3f, 2.0f ); + _otherAvatarHandPosition[ 1 ] = glm::vec3( 4.0f, 0.3f, 2.0f ); + _otherAvatarHandPosition[ 2 ] = glm::vec3( 2.0f, 0.3f, 2.0f ); + _otherAvatarHandPosition[ 3 ] = glm::vec3( 1.0f, 0.3f, -4.0f ); + _otherAvatarHandPosition[ 4 ] = glm::vec3( -2.0f, 0.3f, -2.0f ); } Head::Head(const Head &otherAvatar) { @@ -150,7 +152,7 @@ Head::Head(const Head &otherAvatar) { _bodyPitch = otherAvatar._bodyPitch; _bodyRoll = otherAvatar._bodyRoll; _bodyYawDelta = otherAvatar._bodyYawDelta; - _triggeringAction = otherAvatar._triggeringAction; + _mousePressed = otherAvatar._mousePressed; _mode = otherAvatar._mode; _isMine = otherAvatar._isMine; _renderYaw = otherAvatar._renderYaw; @@ -305,8 +307,8 @@ void Head::setLeanSideways(float dist){ _head.leanSideways = dist; } -void Head::setTriggeringAction( bool d ) { - _triggeringAction = d; +void Head::setMousePressed( bool d ) { + _mousePressed = d; } @@ -325,21 +327,38 @@ void Head::simulate(float deltaTime) { _closestOtherAvatar = -1; float closestDistance = 10000.0f; - /* AgentList * agentList = AgentList::getInstance(); + + _numOtherAvatarsInView =0; for(std::vector::iterator agent = agentList->getAgents().begin(); agent != agentList->getAgents().end(); agent++) { if (( agent->getLinkedData() != NULL && ( agent->getType() == AGENT_TYPE_INTERFACE ) )) { Head *otherAvatar = (Head *)agent->getLinkedData(); - - // when this is working, I will grab the position here... - //glm::vec3 otherAvatarPosition = otherAvatar->getBodyPosition(); + + if ( _numOtherAvatarsInView < MAX_OTHER_AVATARS ) { + + //----------------------------------------------------------- + // test other avatar hand position for proximity... + //----------------------------------------------------------- + _otherAvatarHandPosition[ _numOtherAvatarsInView ] = otherAvatar->getBonePosition( AVATAR_BONE_RIGHT_HAND ); + glm::vec3 v( _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position ); + v -= _otherAvatarHandPosition[ _numOtherAvatarsInView ]; + + float distance = glm::length( v ); + if ( distance < _maxArmLength ) { + if ( distance < closestDistance ) { + closestDistance = distance; + _closestOtherAvatar = _numOtherAvatarsInView; + _numOtherAvatarsInView++; + } + } + } } } - */ + /* ///for testing only (prior to having real avs working) for (int o=0; ogetLinkedData() != NULL) { Head *avatar = (Head *)agent->getLinkedData(); //glPushMatrix(); + +//printf( "rendering remote avatar\n" ); + avatar->render(0); //glPopMatrix(); } @@ -1390,7 +1393,6 @@ void key(unsigned char k, int x, int y) { myAvatar.setNoise(0); } - } if (k == 'h') { @@ -1467,13 +1469,12 @@ void idle(void) { // update behaviors for avatar hand movement updateHandController( mouseX, mouseY ); - // when the mouse is being pressed, an 'action' is being - // triggered in the avatar. The action is context-based. + // tell my avatar if the mouse is being pressed... if ( mousePressed == 1 ) { - myAvatar.setTriggeringAction( true ); + myAvatar.setMousePressed( true ); } else { - myAvatar.setTriggeringAction( false ); + myAvatar.setMousePressed( false ); } // walking triggers the handController to stop @@ -1486,7 +1487,6 @@ void idle(void) { // updateAvatar( 1.f/FPS ); - //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++) @@ -1494,11 +1494,13 @@ void idle(void) { if (agent->getLinkedData() != NULL) { Head *avatar = (Head *)agent->getLinkedData(); + +//printf( "simulating remote avatar\n" ); + avatar->simulate(deltaTime); } } - //updateAvatarHand(1.f/FPS); field.simulate (deltaTime);