improved hand holding algorithm

This commit is contained in:
Jeffrey Ventrella 2013-04-27 22:00:02 -07:00
parent 37e304fd14
commit caac600030
5 changed files with 59 additions and 64 deletions

View file

@ -116,10 +116,7 @@ Avatar::Avatar(bool isMine) {
_sphere = NULL;
_interactingOther = NULL;
_interactingOtherIsNearby = false;
_handHolding.position = glm::vec3( 0.0, 0.0, 0.0 );
_handHolding.velocity = glm::vec3( 0.0, 0.0, 0.0 );
_handHolding.force = 10.0f;
_handHoldingPosition = glm::vec3( 0.0, 0.0, 0.0 );
initializeSkeleton();
@ -309,8 +306,7 @@ void Avatar::simulate(float deltaTime) {
if ( !_interactingOtherIsNearby ) {
//initialize _handHolding
_handHolding.position = _bone[ AVATAR_BONE_RIGHT_HAND ].position;
_handHolding.velocity = glm::vec3( 0.0, 0.0, 0.0 );
_handHoldingPosition = _bone[ AVATAR_BONE_RIGHT_HAND ].position;
}
_interactingOtherIsNearby = false;
@ -337,27 +333,20 @@ void Avatar::simulate(float deltaTime) {
float distance = glm::length( v );
if ( distance < _maxArmLength + _maxArmLength ) {
//if ( distance < closestDistance ) { // perhaps I don't need this if we want to allow multi-avatar interactions
{
closestDistance = distance;
_interactingOther = otherAvatar;
_interactingOtherIsNearby = true;
// if I am holding hands with another avatar, a force is applied
if (( _handState == 1 ) || ( _interactingOther->_handState == 1 )) {
glm::vec3 vectorToOtherHand = _interactingOther->_handPosition - _handHolding.position;
glm::vec3 vectorToMyHand = _bone[ AVATAR_BONE_RIGHT_HAND ].position - _handHolding.position;
_handHolding.velocity *= 0.7;
_handHolding.velocity += ( vectorToOtherHand + vectorToMyHand ) * _handHolding.force * deltaTime;
_handHolding.position += _handHolding.velocity;
_bone[ AVATAR_BONE_RIGHT_HAND ].position = _handHolding.position;
}
}
closestDistance = distance;
_interactingOther = otherAvatar;
_interactingOtherIsNearby = true;
_avatarTouch.setMyHandPosition( _bone[ AVATAR_BONE_RIGHT_HAND ].position );
_avatarTouch.setYourPosition( otherAvatar->getBonePosition( AVATAR_BONE_RIGHT_HAND ) );
// if I am holding hands with another avatar, a force is applied
if (( _handState == 1 ) || ( _interactingOther->_handState == 1 )) {
glm::vec3 vectorToOtherHand = _interactingOther->_handPosition - _handHoldingPosition;
glm::vec3 vectorToMyHand = _bone[ AVATAR_BONE_RIGHT_HAND ].position - _handHoldingPosition;
_handHoldingPosition += vectorToOtherHand * YOUR_HAND_HOLDING_PULL;
_handHoldingPosition += vectorToMyHand * MY_HAND_HOLDING_PULL;
_bone[ AVATAR_BONE_RIGHT_HAND ].position = _handHoldingPosition;
}
_avatarTouch.setYourHandPosition( _interactingOther->_handPosition );
}
}
}
@ -370,8 +359,13 @@ void Avatar::simulate(float deltaTime) {
}//if ( _isMine )
//constrain right arm length and re-adjust elbow position as it bends
updateArmIKAndConstraints( deltaTime );
if (_isMine) {
_avatarTouch.setMyHandPosition( _bone[ AVATAR_BONE_RIGHT_HAND ].position );
}
if (!_interactingOtherIsNearby) {
_interactingOther = NULL;
}
@ -867,19 +861,6 @@ void Avatar::renderHead(bool lookingInMirror) {
glPopMatrix();
}
void Avatar::startHandMovement() {
if (!_usingBodySprings) {
initializeBodySprings();
_usingBodySprings = true;
}
}
void Avatar::stopHandMovement() {
//_usingBodySprings = false;
}
void Avatar::setHandMovementValues( glm::vec3 handOffset ) {
_movedHandOffset = handOffset;
}
@ -1135,7 +1116,7 @@ void Avatar::updateArmIKAndConstraints( float deltaTime ) {
// test to see if right hand is being dragged beyond maximum arm length
float distance = glm::length( armVector );
// if right hand is being dragged beyond maximum arm length...
// don't let right hand get dragged beyond maximum arm length...
if ( distance > _maxArmLength ) {
// reset right hand to be constrained to maximum arm length
_bone[ AVATAR_BONE_RIGHT_HAND ].position = _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position;

View file

@ -37,10 +37,11 @@ const float COLLISION_RADIUS_SCALAR = 1.8;
const float COLLISION_BALL_FORCE = 0.1;
const float COLLISION_BODY_FORCE = 3.0;
const float MY_HAND_HOLDING_PULL = 0.2;
const float YOUR_HAND_HOLDING_PULL = 1.0;
enum eyeContactTargets {LEFT_EYE, RIGHT_EYE, MOUTH};
enum DriveKeys
{
FWD = 0,
@ -108,14 +109,6 @@ enum AvatarBoneID
NUM_AVATAR_BONES
};
struct AvatarHandHolding //think of this as one half of a distributed spring :)
{
glm::vec3 position;
glm::vec3 velocity;
float force;
};
struct AvatarBone
{
AvatarBoneID parent; // which bone is this bone connected to?
@ -216,8 +209,6 @@ public:
void renderBody();
void renderHead(bool lookingInMirror);
void simulate(float);
void startHandMovement();
void stopHandMovement();
void setHandMovementValues( glm::vec3 movement );
void updateHandMovement( float deltaTime );
void updateArmIKAndConstraints( float deltaTime );
@ -258,7 +249,7 @@ private:
glm::quat _rotation; // the rotation of the avatar body as a whole expressed as a quaternion
AvatarBone _bone[ NUM_AVATAR_BONES ];
AvatarMode _mode;
AvatarHandHolding _handHolding;
glm::vec3 _handHoldingPosition;
glm::vec3 _velocity;
glm::vec3 _thrust;
float _speed;

View file

@ -3,41 +3,61 @@
// interface
//
// Created by Jeffrey Ventrella
// Copyright (c) 2012 High Fidelity, Inc. All rights reserved.
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
//
#include <iostream>
#include <glm/glm.hpp>
#include <SharedUtil.h>
#include "AvatarTouch.h"
#include "InterfaceConfig.h"
AvatarTouch::AvatarTouch() {
_myHandPosition = glm::vec3( 0.0f, 0.0f, 0.0f );
_yourHandPosition = glm::vec3( 0.0f, 0.0f, 0.0f );
for (int p=0; p<NUM_POINTS; p++) {
_point[p] = glm::vec3( 0.0, 0.0, 0.0 );
}
}
void AvatarTouch::setMyHandPosition( glm::vec3 position ) {
_myHandPosition = position;
}
void AvatarTouch::setYourPosition( glm::vec3 position ) {
void AvatarTouch::setYourHandPosition( glm::vec3 position ) {
_yourHandPosition = position;
}
void AvatarTouch::render() {
glm::vec3 v1( _myHandPosition );
glm::vec3 v2( _yourHandPosition );
glLineWidth( 8.0 );
glColor4f( 0.7f, 0.4f, 0.1f, 0.6 );
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; p<NUM_POINTS; p++) {
glBegin(GL_POINTS);
glVertex3f(_point[p].x, _point[p].y, _point[p].z);
glEnd();
}
}
void AvatarTouch::simulate (float deltaTime) {
glm::vec3 v = _yourHandPosition - _myHandPosition;
for (int p=0; p<NUM_POINTS; p++) {
_point[p] = _myHandPosition + v * ( (float)p / (float)NUM_POINTS );
_point[p].x += randFloatInRange( -0.007, 0.007 );
_point[p].y += randFloatInRange( -0.007, 0.007 );
_point[p].z += randFloatInRange( -0.007, 0.007 );
}
}

View file

@ -15,12 +15,16 @@ class AvatarTouch {
public:
AvatarTouch();
void setMyHandPosition( glm::vec3 position );
void setYourPosition ( glm::vec3 position );
void setMyHandPosition ( glm::vec3 position );
void setYourHandPosition( glm::vec3 position );
void simulate(float deltaTime);
void render();
private:
static const int NUM_POINTS = 100;
glm::vec3 _point [NUM_POINTS];
glm::vec3 _myHandPosition;
glm::vec3 _yourHandPosition;
};

View file

@ -1512,8 +1512,7 @@ void idle(void) {
// tell my avatar if the mouse is being pressed...
if ( mousePressed == 1 ) {
myAvatar.setMousePressed( true );
}
else {
} else {
myAvatar.setMousePressed( false );
}
@ -1532,7 +1531,7 @@ void idle(void) {
networkReceive(0);
}
//loop through all the other avatars and simulate them...
//loop through all the remote avatars and simulate them...
AgentList* agentList = AgentList::getInstance();
for(AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) {
if (agent->getLinkedData() != NULL) {