mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-05 21:30:08 +02:00
just did a fairly major re-ordering of avatar interaction logic in Head.cpp
This commit is contained in:
parent
7ae91c4b7b
commit
86086ef20c
2 changed files with 153 additions and 172 deletions
|
@ -71,9 +71,6 @@ Head::Head(bool isMine) {
|
|||
_head.interPupilDistance = 0.6;
|
||||
_head.interBrowDistance = 0.75;
|
||||
_head.nominalPupilSize = 0.10;
|
||||
//_head.yaw = 0.0;
|
||||
//_head.pitch = 0.0;
|
||||
//_head.roll = 0.0;
|
||||
_head.pitchRate = 0.0;
|
||||
_head.yawRate = 0.0;
|
||||
_head.rollRate = 0.0;
|
||||
|
@ -106,15 +103,15 @@ Head::Head(bool isMine) {
|
|||
_head.lastLoudness = 0.0;
|
||||
_head.browAudioLift = 0.0;
|
||||
_head.noise = 0;
|
||||
|
||||
_movedHandOffset = glm::vec3( 0.0, 0.0, 0.0 );
|
||||
_usingBodySprings = true;
|
||||
_springForce = 6.0f;
|
||||
_springVelocityDecay = 16.0f;
|
||||
_renderYaw = 0.0;
|
||||
_renderPitch = 0.0;
|
||||
|
||||
_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 );
|
||||
|
@ -127,10 +124,6 @@ Head::Head(bool isMine) {
|
|||
printLog("error %u: %s\n", error, lodepng_error_text(error));
|
||||
}
|
||||
}
|
||||
|
||||
_otherAvatar.nearby = false;
|
||||
_otherAvatar.handPosition = glm::vec3( 0.0f, 0.0f, 0.0f );
|
||||
_otherAvatar.handState = 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -140,7 +133,7 @@ Head::Head(const Head &otherAvatar) {
|
|||
_velocity = otherAvatar._velocity;
|
||||
_thrust = otherAvatar._thrust;
|
||||
_rotation = otherAvatar._rotation;
|
||||
_otherAvatar.nearby = otherAvatar._otherAvatar.nearby;
|
||||
_interactingOtherIsNearby = otherAvatar._interactingOtherIsNearby;
|
||||
_bodyYaw = otherAvatar._bodyYaw;
|
||||
_bodyPitch = otherAvatar._bodyPitch;
|
||||
_bodyRoll = otherAvatar._bodyRoll;
|
||||
|
@ -172,9 +165,6 @@ Head::Head(const Head &otherAvatar) {
|
|||
_head.interPupilDistance = otherAvatar._head.interPupilDistance;
|
||||
_head.interBrowDistance = otherAvatar._head.interBrowDistance;
|
||||
_head.nominalPupilSize = otherAvatar._head.nominalPupilSize;
|
||||
//_head.yaw = otherAvatar._head.yaw;
|
||||
//_head.pitch = otherAvatar._head.pitch;
|
||||
//_head.roll = otherAvatar._head.roll;
|
||||
_head.yawRate = otherAvatar._head.yawRate;
|
||||
_head.pitchRate = otherAvatar._head.pitchRate;
|
||||
_head.rollRate = otherAvatar._head.rollRate;
|
||||
|
@ -208,7 +198,6 @@ Head::Head(const Head &otherAvatar) {
|
|||
_head.browAudioLift = otherAvatar._head.browAudioLift;
|
||||
_head.noise = otherAvatar._head.noise;
|
||||
|
||||
|
||||
if (iris_texture.size() == 0) {
|
||||
switchToResourcesParentIfRequired();
|
||||
unsigned error = lodepng::decode(iris_texture, iris_texture_width, iris_texture_height, iris_texture_file);
|
||||
|
@ -296,13 +285,30 @@ void Head::setMousePressed( bool d ) {
|
|||
|
||||
void Head::simulate(float deltaTime) {
|
||||
|
||||
//------------------------
|
||||
// update avatar skeleton
|
||||
//------------------------
|
||||
updateSkeleton();
|
||||
|
||||
//------------------------------------------------------------
|
||||
// reset hand and arm positions according to hand movement
|
||||
//------------------------------------------------------------
|
||||
updateHandMovement( deltaTime );
|
||||
|
||||
if ( !_interactingOtherIsNearby ) {
|
||||
//initialize _handHolding
|
||||
_handHolding.position = _bone[ AVATAR_BONE_RIGHT_HAND ].position;
|
||||
_handHolding.velocity = glm::vec3( 0.0, 0.0, 0.0 );
|
||||
}
|
||||
|
||||
_interactingOtherIsNearby = false;
|
||||
|
||||
//-------------------------------------------------------------
|
||||
// if the avatar being simulated is mine, then loop through
|
||||
// all the other avatars to get information about them...
|
||||
// all the other avatars for potential interactions...
|
||||
//-------------------------------------------------------------
|
||||
if ( _isMine )
|
||||
{
|
||||
_otherAvatar.nearby = false;
|
||||
float closestDistance = 10000.0f;
|
||||
|
||||
AgentList * agentList = AgentList::getInstance();
|
||||
|
@ -333,18 +339,44 @@ void Head::simulate(float deltaTime) {
|
|||
|
||||
float distance = glm::length( v );
|
||||
if ( distance < _maxArmLength ) {
|
||||
if ( distance < closestDistance ) {
|
||||
|
||||
//if ( distance < closestDistance ) { // perhaps I don't need this if we want to allow multi-avatar interactions
|
||||
{
|
||||
closestDistance = distance;
|
||||
_otherAvatar.nearby = true;
|
||||
_otherAvatar.handPosition = otherAvatar->getBonePosition( AVATAR_BONE_RIGHT_HAND );
|
||||
_otherAvatar.handState = (int)otherAvatar->getHandState();
|
||||
_interactingOther = otherAvatar;
|
||||
_interactingOtherIsNearby = true;
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// if I am holding hands with another avatar, a force is applied
|
||||
//---------------------------------------------------------------------
|
||||
if (( getHandState() == 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set the vector we send for hand position to other people to be our right hand
|
||||
setHandPosition(_bone[ AVATAR_BONE_RIGHT_HAND ].position);
|
||||
|
||||
}//if ( _isMine )
|
||||
|
||||
|
||||
updateArmIKAndConstraints( deltaTime );
|
||||
|
||||
if ( ! _interactingOtherIsNearby ) {
|
||||
_interactingOther = NULL;
|
||||
}
|
||||
|
||||
if ( usingBigSphereCollisionTest ) {
|
||||
//--------------------------------------------------------------
|
||||
// test for avatar collision response (using a big sphere :)
|
||||
|
@ -371,18 +403,9 @@ void Head::simulate(float deltaTime) {
|
|||
}
|
||||
}
|
||||
|
||||
//------------------------
|
||||
// update avatar skeleton
|
||||
//------------------------
|
||||
updateSkeleton();
|
||||
|
||||
//------------------------------------------------------------
|
||||
// reset hand and arm positions according to hand movement
|
||||
//------------------------------------------------------------
|
||||
if (_usingBodySprings) {
|
||||
updateHandMovement( deltaTime );
|
||||
// update body springs
|
||||
updateBodySprings( deltaTime );
|
||||
}
|
||||
|
||||
|
||||
if ( _isMine ) { // driving the avatar around should only apply if this is my avatar (as opposed to an avatar being driven remotely)
|
||||
//-------------------------------------------------
|
||||
|
@ -442,7 +465,6 @@ void Head::simulate(float deltaTime) {
|
|||
_bodyYaw += _bodyYawDelta * deltaTime;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------
|
||||
// decay body yaw delta
|
||||
//----------------------------------------------------------
|
||||
|
@ -620,8 +642,6 @@ void Head::updateAvatarCollisionDetectionAndResponse
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Head::render(bool lookingInMirror) {
|
||||
|
||||
//---------------------------------------------------
|
||||
|
@ -646,9 +666,9 @@ void Head::render(bool lookingInMirror) {
|
|||
glPopMatrix();
|
||||
}
|
||||
|
||||
//---------------------------------------------------
|
||||
//---------------
|
||||
// render body
|
||||
//---------------------------------------------------
|
||||
//---------------
|
||||
renderBody();
|
||||
|
||||
//---------------------------------------------------
|
||||
|
@ -657,15 +677,14 @@ void Head::render(bool lookingInMirror) {
|
|||
renderHead(lookingInMirror);
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// if this is my avatar, then render my interactions with the other avatars
|
||||
// if this is my avatar, then render my interactions with the other avatar
|
||||
//---------------------------------------------------------------------------
|
||||
if ( _isMine )
|
||||
{
|
||||
if (_usingBodySprings) {
|
||||
if ( _otherAvatar.nearby ) {
|
||||
if ( _interactingOtherIsNearby ) {
|
||||
|
||||
glm::vec3 v1( _bone[ AVATAR_BONE_RIGHT_HAND ].position );
|
||||
glm::vec3 v2( _otherAvatar.handPosition );
|
||||
glm::vec3 v2( _interactingOther->_handPosition );
|
||||
|
||||
glLineWidth( 8.0 );
|
||||
glColor4f( 0.7f, 0.4f, 0.1f, 0.6 );
|
||||
|
@ -675,11 +694,9 @@ void Head::render(bool lookingInMirror) {
|
|||
glEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Head::renderHead(bool lookingInMirror) {
|
||||
int side = 0;
|
||||
|
||||
|
@ -962,9 +979,9 @@ void Head::initializeSkeleton() {
|
|||
//----------------------------------------------------------------------------
|
||||
calculateBoneLengths();
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
//---------------------------
|
||||
// generate world positions
|
||||
//----------------------------------------------------------------------------
|
||||
//---------------------------
|
||||
updateSkeleton();
|
||||
}
|
||||
|
||||
|
@ -1121,50 +1138,13 @@ void Head::updateHandMovement( float deltaTime ) {
|
|||
|
||||
_bone[ AVATAR_BONE_RIGHT_HAND ].position += transformedHandMovement;
|
||||
|
||||
if (_isMine) {
|
||||
setHandState(_mousePressed);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if ( _otherAvatar.nearby ) {
|
||||
if ( _otherAvatar.handState == 1 ) {
|
||||
printf( "(1)" );
|
||||
}
|
||||
else {
|
||||
printf( "(0)" );
|
||||
}
|
||||
|
||||
if ( _handState == 1 ) {
|
||||
printf( "1" );
|
||||
}
|
||||
else {
|
||||
printf( "0" );
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// if I am holding hands with another avatar, a force is added
|
||||
// to my hand, causing it to move closer to the other avatar's hand...
|
||||
//---------------------------------------------------------------------
|
||||
if ( _isMine )
|
||||
{
|
||||
if ( _otherAvatar.nearby ) {
|
||||
if (( getHandState() == 1 )
|
||||
|| ( _otherAvatar.handState == 1 )) {
|
||||
glm::vec3 vectorToOtherHand = _otherAvatar.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;
|
||||
}
|
||||
}
|
||||
else {
|
||||
_handHolding.position = _bone[ AVATAR_BONE_RIGHT_HAND ].position;
|
||||
_handHolding.velocity = glm::vec3( 0.0, 0.0, 0.0 );
|
||||
}
|
||||
}
|
||||
void Head::updateArmIKAndConstraints( float deltaTime ) {
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
// determine the arm vector
|
||||
|
@ -1210,14 +1190,11 @@ void Head::updateHandMovement( float deltaTime ) {
|
|||
glm::vec3 newWristPosition = _bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position;
|
||||
newWristPosition += vv * 0.7f;
|
||||
_bone[ AVATAR_BONE_RIGHT_FOREARM ].position = newWristPosition;
|
||||
|
||||
// Set the vector we send for hand position to other people to be our right hand
|
||||
setHandPosition(_bone[ AVATAR_BONE_RIGHT_HAND ].position);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Head::renderBody() {
|
||||
//-----------------------------------------
|
||||
// Render bone positions as spheres
|
||||
|
|
|
@ -100,12 +100,14 @@ struct AvatarHandHolding
|
|||
float force;
|
||||
};
|
||||
|
||||
/*
|
||||
struct OtherAvatar
|
||||
{
|
||||
bool nearby;
|
||||
glm::vec3 handPosition;
|
||||
int handState;
|
||||
//glm::vec3 handPosition;
|
||||
//int handState;
|
||||
};
|
||||
*/
|
||||
|
||||
struct AvatarBone
|
||||
{
|
||||
|
@ -205,6 +207,7 @@ class Head : public AvatarData {
|
|||
void stopHandMovement();
|
||||
void setHandMovementValues( glm::vec3 movement );
|
||||
void updateHandMovement( float deltaTime );
|
||||
void updateArmIKAndConstraints( float deltaTime );
|
||||
|
||||
float getAverageLoudness() {return _head.averageLoudness;};
|
||||
void setAverageLoudness(float al) {_head.averageLoudness = al;};
|
||||
|
@ -229,7 +232,6 @@ class Head : public AvatarData {
|
|||
bool _isMine;
|
||||
glm::vec3 _TEST_bigSpherePosition;
|
||||
float _TEST_bigSphereRadius;
|
||||
OtherAvatar _otherAvatar;
|
||||
bool _mousePressed;
|
||||
float _bodyYawDelta;
|
||||
bool _usingBodySprings;
|
||||
|
@ -251,6 +253,8 @@ class Head : public AvatarData {
|
|||
timeval _transmitterTimer;
|
||||
float _transmitterHz;
|
||||
int _transmitterPackets;
|
||||
Head* _interactingOther;
|
||||
bool _interactingOtherIsNearby;
|
||||
|
||||
//-----------------------------
|
||||
// private methods...
|
||||
|
|
Loading…
Reference in a new issue