working on detection of avatars entering into each other's peripersonal space

This commit is contained in:
Jeffrey Ventrella 2013-05-06 16:17:16 -07:00
parent 1f2335da26
commit fd4a0c9acd
3 changed files with 79 additions and 30 deletions

View file

@ -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<float>::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) {
}
}

View file

@ -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<NUM_POINTS; p++) {
_point[p] = _myHandPosition + v * ( (float)p / (float)NUM_POINTS );
_point[p].x += randFloatInRange( -THREAD_RADIUS, THREAD_RADIUS );
_point[p].y += randFloatInRange( -THREAD_RADIUS, THREAD_RADIUS );
_point[p].z += randFloatInRange( -THREAD_RADIUS, THREAD_RADIUS );
}
*/
}

View file

@ -21,28 +21,34 @@ public:
void simulate(float deltaTime);
void render();
void setMyHandPosition ( glm::vec3 position );
void setYourHandPosition( glm::vec3 position );
void setMyHandState ( int state );
void setYourHandState ( int state );
void setMyHandPosition (glm::vec3 position);
void setYourHandPosition(glm::vec3 position);
void setMyBodyPosition (glm::vec3 position);
void setYourBodyPosition(glm::vec3 position);
void setMyHandState (int state );
void setYourHandState (int state );
void setReachableRadius (float r);
void setAbleToReachOtherAvatar ( bool a ) { _canReachToOtherAvatar = a; }
void setHandsCloseEnoughToGrasp( bool h ) { _handsCloseEnoughToGrasp = h; }
void setAbleToReachOtherAvatar (bool a) { _canReachToOtherAvatar = a;}
void setHandsCloseEnoughToGrasp(bool h) { _handsCloseEnoughToGrasp = h;}
bool getAbleToReachOtherAvatar () { return _canReachToOtherAvatar; }
bool getHandsCloseEnoughToGrasp() { return _handsCloseEnoughToGrasp; }
bool getAbleToReachOtherAvatar () {return _canReachToOtherAvatar;}
bool getHandsCloseEnoughToGrasp() {return _handsCloseEnoughToGrasp;}
private:
static const int NUM_POINTS = 100;
glm::vec3 _point [NUM_POINTS];
glm::vec3 _myBodyPosition;
glm::vec3 _yourBodyPosition;
glm::vec3 _myHandPosition;
glm::vec3 _yourHandPosition;
int _myHandState;
int _yourHandState;
bool _canReachToOtherAvatar;
bool _handsCloseEnoughToGrasp;
float _reachableRadius;
};
#endif