From 66c7da6552004fdc60ab30f034e7f95895dbaa4d Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Wed, 29 May 2013 15:24:37 -0700 Subject: [PATCH 01/14] simplify avatar proximity check for 1p transition --- interface/src/Avatar.cpp | 5 ++--- interface/src/AvatarTouch.cpp | 5 +++-- interface/src/Head.cpp | 5 ++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 68fd9b1c8e..8d3f3c27ac 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -1096,10 +1096,9 @@ void Avatar::updateArmIKAndConstraints(float deltaTime) { } // set elbow position - glm::vec3 newElbowPosition = _joint[ AVATAR_JOINT_RIGHT_SHOULDER ].position; - newElbowPosition += armVector * ONE_HALF; + glm::vec3 newElbowPosition = _joint[ AVATAR_JOINT_RIGHT_SHOULDER ].position + armVector * ONE_HALF; - glm::vec3 perpendicular = glm::cross(_orientation.getFront(), armVector); + glm::vec3 perpendicular = glm::cross( _orientation.getRight(), armVector); newElbowPosition += perpendicular * (1.0f - (_maxArmLength / distance)) * ONE_HALF; _joint[ AVATAR_JOINT_RIGHT_ELBOW ].position = newElbowPosition; diff --git a/interface/src/AvatarTouch.cpp b/interface/src/AvatarTouch.cpp index 93899c8400..e7703a3f00 100644 --- a/interface/src/AvatarTouch.cpp +++ b/interface/src/AvatarTouch.cpp @@ -54,8 +54,9 @@ void AvatarTouch::simulate (float deltaTime) { facingEachOther = true; } - if ((distanceBetweenBodies < _reachableRadius) - && (facingEachOther)) { + if (distanceBetweenBodies < _reachableRadius) + //&& (facingEachOther)) + { _canReachToOtherAvatar = true; _vectorBetweenHands = _yourHandPosition - _myHandPosition; diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 6f7f330010..a68e36d53b 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -18,7 +18,6 @@ const float EYE_RIGHT_OFFSET = 0.27f; const float EYE_UP_OFFSET = 0.36f; const float EYE_FRONT_OFFSET = 0.8f; const float EAR_RIGHT_OFFSET = 1.0; -//const float MOUTH_FRONT_OFFSET = 0.9f; const float MOUTH_UP_OFFSET = -0.3f; const float HEAD_MOTION_DECAY = 0.1; const float MINIMUM_EYE_ROTATION_DOT = 0.5f; // based on a dot product: 1.0 is straight ahead, 0.0 is 90 degrees off @@ -281,7 +280,7 @@ void Head::renderMohawk(bool lookingInMirror, glm::vec3 cameraPosition) { glm::vec3 mid2 = _hairTuft[t].midPosition + midPerpendicular * _hairTuft[t].thickness * ONE_HALF * ONE_HALF; glColor3f(_mohawkColors[t].x, _mohawkColors[t].y, _mohawkColors[t].z); - + glBegin(GL_TRIANGLES); glVertex3f(base1.x, base1.y, base1.z ); glVertex3f(base2.x, base2.y, base2.z ); @@ -354,7 +353,7 @@ void Head::renderMouth() { glm::vec3 rightBottom = _mouthPosition + r * 0.4f - u * 1.0f + f * 0.7f; // constrain all mouth vertices to a sphere slightly larger than the head... - float constrainedRadius = _scale + 0.001f; + float constrainedRadius = _scale + 0.002f; middle = _position + glm::normalize(middle - _position) * constrainedRadius; leftCorner = _position + glm::normalize(leftCorner - _position) * constrainedRadius; rightCorner = _position + glm::normalize(rightCorner - _position) * constrainedRadius; From 5750adf6fd1d977395568d2985348f2c3179f02e Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Wed, 29 May 2013 15:53:47 -0700 Subject: [PATCH 02/14] test --- interface/src/AvatarTouch.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/interface/src/AvatarTouch.cpp b/interface/src/AvatarTouch.cpp index e7703a3f00..b7d8fffcbb 100644 --- a/interface/src/AvatarTouch.cpp +++ b/interface/src/AvatarTouch.cpp @@ -53,6 +53,8 @@ void AvatarTouch::simulate (float deltaTime) { && ( glm::dot(_myOrientation.getFront(), directionBetweenBodies ) > AVATAR_FACING_THRESHOLD)) { // I'm facing you facingEachOther = true; } + + ///udhfhduf if (distanceBetweenBodies < _reachableRadius) //&& (facingEachOther)) From 63434da23cf7f3968e47a231f3cc7a35ba59358e Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Wed, 29 May 2013 16:14:55 -0700 Subject: [PATCH 03/14] testing avatar touch --- interface/src/Application.cpp | 41 +++++++++++++++++++++-------------- interface/src/Avatar.cpp | 15 ++++++++----- interface/src/AvatarTouch.cpp | 2 -- 3 files changed, 34 insertions(+), 24 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index f307efa470..95b4d88b33 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -50,6 +50,8 @@ using namespace std; +const bool TESTING_AVATAR_TOUCH = true; + // Starfield information static char STAR_FILE[] = "https://s3-us-west-1.amazonaws.com/highfidelity/stars.txt"; static char STAR_CACHE_FILE[] = "cachedStars.txt"; @@ -915,29 +917,36 @@ void Application::idle() { _myAvatar.simulate(deltaTime, NULL); } - if (_myCamera.getMode() != CAMERA_MODE_MIRROR && !OculusManager::isConnected()) { - if (_manualFirstPerson) { - if (_myCamera.getMode() != CAMERA_MODE_FIRST_PERSON ) { - _myCamera.setMode(CAMERA_MODE_FIRST_PERSON); - _myCamera.setModeShiftRate(1.0f); - } - } else { - - if (_myAvatar.getIsNearInteractingOther()) { - if (_myCamera.getMode() != CAMERA_MODE_FIRST_PERSON) { + if ( TESTING_AVATAR_TOUCH) { + if (_myCamera.getMode() != CAMERA_MODE_THIRD_PERSON) { + _myCamera.setMode(CAMERA_MODE_THIRD_PERSON); + _myCamera.setModeShiftRate(1.0f); + } + } else { + if (_myCamera.getMode() != CAMERA_MODE_MIRROR && !OculusManager::isConnected()) { + if (_manualFirstPerson) { + if (_myCamera.getMode() != CAMERA_MODE_FIRST_PERSON ) { _myCamera.setMode(CAMERA_MODE_FIRST_PERSON); _myCamera.setModeShiftRate(1.0f); } - } - else { - if (_myCamera.getMode() != CAMERA_MODE_THIRD_PERSON) { - _myCamera.setMode(CAMERA_MODE_THIRD_PERSON); - _myCamera.setModeShiftRate(1.0f); + } else { + + if (_myAvatar.getIsNearInteractingOther()) { + if (_myCamera.getMode() != CAMERA_MODE_FIRST_PERSON) { + _myCamera.setMode(CAMERA_MODE_FIRST_PERSON); + _myCamera.setModeShiftRate(1.0f); + } + } + else { + if (_myCamera.getMode() != CAMERA_MODE_THIRD_PERSON) { + _myCamera.setMode(CAMERA_MODE_THIRD_PERSON); + _myCamera.setModeShiftRate(1.0f); + } } } } } - + // Update audio stats for procedural sounds #ifndef _WIN32 _audio.setLastAcceleration(_myAvatar.getThrust()); diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 8d3f3c27ac..6e37d5807f 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -37,11 +37,11 @@ const float YOUR_HAND_HOLDING_PULL = 1.0; const float BODY_SPRING_DEFAULT_TIGHTNESS = 1000.0f; const float BODY_SPRING_FORCE = 300.0f; const float BODY_SPRING_DECAY = 16.0f; -const float COLLISION_RADIUS_SCALAR = 1.8; -const float COLLISION_BALL_FORCE = 1.0; -const float COLLISION_BODY_FORCE = 6.0; -const float COLLISION_BALL_FRICTION = 60.0; -const float COLLISION_BODY_FRICTION = 0.5; +const float COLLISION_RADIUS_SCALAR = 1.8; //pertains to avatar-to-avatar collisions +const float COLLISION_BALL_FORCE = 1.0; //pertains to avatar-to-avatar collisions +const float COLLISION_BODY_FORCE = 6.0; //pertains to avatar-to-avatar collisions +const float COLLISION_BALL_FRICTION = 60.0; //pertains to avatar-to-avatar collisions +const float COLLISION_BODY_FRICTION = 0.5; //pertains to avatar-to-avatar collisions const float HEAD_ROTATION_SCALE = 0.70; const float HEAD_ROLL_SCALE = 0.40; const float HEAD_MAX_PITCH = 45; @@ -689,6 +689,8 @@ void Avatar::applyCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime for (int o=b+1; o_joint[o].isCollidable) { + /* + glm::vec3 vectorBetweenJoints(_joint[b].springyPosition - otherAvatar->_joint[o].springyPosition); float distanceBetweenJoints = glm::length(vectorBetweenJoints); @@ -718,12 +720,13 @@ void Avatar::applyCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime }// check for collision } // to avoid divide by zero + */ + } // o loop } // collidable } // b loop } // collidable - //apply forces and frictions on the bodies of both avatars _velocity += bodyPushForce; otherAvatar->_velocity -= bodyPushForce; diff --git a/interface/src/AvatarTouch.cpp b/interface/src/AvatarTouch.cpp index b7d8fffcbb..a6b4a168cb 100644 --- a/interface/src/AvatarTouch.cpp +++ b/interface/src/AvatarTouch.cpp @@ -54,8 +54,6 @@ void AvatarTouch::simulate (float deltaTime) { facingEachOther = true; } - ///udhfhduf - if (distanceBetweenBodies < _reachableRadius) //&& (facingEachOther)) { From 4c7d75b39e97e7f00ff52f692e594b875a1724f8 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Wed, 29 May 2013 16:52:48 -0700 Subject: [PATCH 04/14] testing avatar touch --- interface/src/Avatar.cpp | 36 +++++++++++++++++++++++++++--------- interface/src/Head.cpp | 2 +- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 6e37d5807f..c7dfeb2834 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -37,11 +37,22 @@ const float YOUR_HAND_HOLDING_PULL = 1.0; const float BODY_SPRING_DEFAULT_TIGHTNESS = 1000.0f; const float BODY_SPRING_FORCE = 300.0f; const float BODY_SPRING_DECAY = 16.0f; + +/* const float COLLISION_RADIUS_SCALAR = 1.8; //pertains to avatar-to-avatar collisions const float COLLISION_BALL_FORCE = 1.0; //pertains to avatar-to-avatar collisions const float COLLISION_BODY_FORCE = 6.0; //pertains to avatar-to-avatar collisions const float COLLISION_BALL_FRICTION = 60.0; //pertains to avatar-to-avatar collisions const float COLLISION_BODY_FRICTION = 0.5; //pertains to avatar-to-avatar collisions +*/ + +const float COLLISION_RADIUS_SCALAR = 1.2; //pertains to avatar-to-avatar collisions +const float COLLISION_BALL_FORCE = 20.0; //pertains to avatar-to-avatar collisions +const float COLLISION_BODY_FORCE = 6.0; //pertains to avatar-to-avatar collisions +const float COLLISION_BALL_FRICTION = 60.0; //pertains to avatar-to-avatar collisions +const float COLLISION_BODY_FRICTION = 0.5; //pertains to avatar-to-avatar collisions + + const float HEAD_ROTATION_SCALE = 0.70; const float HEAD_ROLL_SCALE = 0.40; const float HEAD_MAX_PITCH = 45; @@ -50,7 +61,7 @@ const float HEAD_MAX_YAW = 85; const float HEAD_MIN_YAW = -85; const float PERIPERSONAL_RADIUS = 1.0f; const float AVATAR_BRAKING_STRENGTH = 40.0f; -const float JOINT_TOUCH_RANGE = 0.0005f; +const float JOINT_TOUCH_RANGE = 0.01f; const float ANGULAR_RIGHTING_SPEED = 45.0f; const float FLOATING_HEIGHT = 0.13f; const bool USING_HEAD_LEAN = false; @@ -452,8 +463,10 @@ void Avatar::checkForMouseRayTouching() { glm::vec3 directionToBodySphere = glm::normalize(_joint[b].springyPosition - _mouseRayOrigin); float dot = glm::dot(directionToBodySphere, _mouseRayDirection); - if (dot > (1.0f - JOINT_TOUCH_RANGE)) { - _joint[b].touchForce = (dot - (1.0f - JOINT_TOUCH_RANGE)) / JOINT_TOUCH_RANGE; + float range = _joint[b].radius * JOINT_TOUCH_RANGE; + + if (dot > (1.0f - range)) { + _joint[b].touchForce = (dot - (1.0f - range)) / range; } else { _joint[b].touchForce = 0.0; } @@ -689,8 +702,6 @@ void Avatar::applyCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime for (int o=b+1; o_joint[o].isCollidable) { - /* - glm::vec3 vectorBetweenJoints(_joint[b].springyPosition - otherAvatar->_joint[o].springyPosition); float distanceBetweenJoints = glm::length(vectorBetweenJoints); @@ -703,13 +714,21 @@ void Avatar::applyCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime // push balls away from each other and apply friction glm::vec3 ballPushForce = directionVector * COLLISION_BALL_FORCE * deltaTime; - + + /* float ballMomentum = 1.0 - COLLISION_BALL_FRICTION * deltaTime; if (ballMomentum < 0.0) { ballMomentum = 0.0;} - + */ + _joint[b].springyVelocity += ballPushForce; otherAvatar->_joint[o].springyVelocity -= ballPushForce; + + float shift = distanceBetweenJoints - combinedRadius * COLLISION_RADIUS_SCALAR; + _joint[b].springyPosition += directionVector * shift; + otherAvatar->_joint[o].springyPosition -= directionVector * shift; + + /* _joint[b].springyVelocity *= ballMomentum; otherAvatar->_joint[o].springyVelocity *= ballMomentum; @@ -717,11 +736,10 @@ void Avatar::applyCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime bodyPushForce += directionVector * COLLISION_BODY_FORCE * deltaTime; bodyMomentum -= COLLISION_BODY_FRICTION * deltaTime; if (bodyMomentum < 0.0) { bodyMomentum = 0.0;} + */ }// check for collision } // to avoid divide by zero - */ - } // o loop } // collidable } // b loop diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index a68e36d53b..cdc11b4506 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -361,7 +361,7 @@ void Head::renderMouth() { rightTop = _position + glm::normalize(rightTop - _position) * constrainedRadius; leftBottom = _position + glm::normalize(leftBottom - _position) * constrainedRadius; rightBottom = _position + glm::normalize(rightBottom - _position) * constrainedRadius; - + glColor3f(0.2f, 0.0f, 0.0f); glBegin(GL_TRIANGLES); From 88ff0ea7aa5038b34b12515184f56ea741430a14 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Wed, 29 May 2013 16:54:15 -0700 Subject: [PATCH 05/14] merge --- interface/src/Head.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index cdc11b4506..28d7a23b2f 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -353,7 +353,9 @@ void Head::renderMouth() { glm::vec3 rightBottom = _mouthPosition + r * 0.4f - u * 1.0f + f * 0.7f; // constrain all mouth vertices to a sphere slightly larger than the head... - float constrainedRadius = _scale + 0.002f; + const float MOUTH_OFFSET_OFF_FACE = 0.003f; + + float constrainedRadius = _scale + MOUTH_OFFSET_OFF_FACE; middle = _position + glm::normalize(middle - _position) * constrainedRadius; leftCorner = _position + glm::normalize(leftCorner - _position) * constrainedRadius; rightCorner = _position + glm::normalize(rightCorner - _position) * constrainedRadius; From d839312cd6a594091980b4d10639ad6c07cfb23e Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Wed, 29 May 2013 17:28:44 -0700 Subject: [PATCH 06/14] testing avatar touch --- interface/src/Avatar.cpp | 42 ++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index c7dfeb2834..99862cfc98 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -38,21 +38,12 @@ const float BODY_SPRING_DEFAULT_TIGHTNESS = 1000.0f; const float BODY_SPRING_FORCE = 300.0f; const float BODY_SPRING_DECAY = 16.0f; -/* -const float COLLISION_RADIUS_SCALAR = 1.8; //pertains to avatar-to-avatar collisions -const float COLLISION_BALL_FORCE = 1.0; //pertains to avatar-to-avatar collisions -const float COLLISION_BODY_FORCE = 6.0; //pertains to avatar-to-avatar collisions -const float COLLISION_BALL_FRICTION = 60.0; //pertains to avatar-to-avatar collisions -const float COLLISION_BODY_FRICTION = 0.5; //pertains to avatar-to-avatar collisions -*/ - const float COLLISION_RADIUS_SCALAR = 1.2; //pertains to avatar-to-avatar collisions -const float COLLISION_BALL_FORCE = 20.0; //pertains to avatar-to-avatar collisions -const float COLLISION_BODY_FORCE = 6.0; //pertains to avatar-to-avatar collisions +const float COLLISION_BALL_FORCE = 200.0; //pertains to avatar-to-avatar collisions +const float COLLISION_BODY_FORCE = 30.0; //pertains to avatar-to-avatar collisions const float COLLISION_BALL_FRICTION = 60.0; //pertains to avatar-to-avatar collisions const float COLLISION_BODY_FRICTION = 0.5; //pertains to avatar-to-avatar collisions - const float HEAD_ROTATION_SCALE = 0.70; const float HEAD_ROLL_SCALE = 0.40; const float HEAD_MAX_PITCH = 45; @@ -713,7 +704,11 @@ void Avatar::applyCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime glm::vec3 directionVector = vectorBetweenJoints / distanceBetweenJoints; // push balls away from each other and apply friction - glm::vec3 ballPushForce = directionVector * COLLISION_BALL_FORCE * deltaTime; + + float penetration = 1.0f - (distanceBetweenJoints / (combinedRadius * COLLISION_RADIUS_SCALAR)); + + glm::vec3 ballPushForce = directionVector * COLLISION_BALL_FORCE * penetration * deltaTime; + bodyPushForce += directionVector * COLLISION_BODY_FORCE * penetration * deltaTime; /* float ballMomentum = 1.0 - COLLISION_BALL_FRICTION * deltaTime; @@ -722,21 +717,26 @@ void Avatar::applyCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime _joint[b].springyVelocity += ballPushForce; otherAvatar->_joint[o].springyVelocity -= ballPushForce; + + /* float shift = distanceBetweenJoints - combinedRadius * COLLISION_RADIUS_SCALAR; - _joint[b].springyPosition += directionVector * shift; - otherAvatar->_joint[o].springyPosition -= directionVector * shift; + _joint[b].springyPosition += directionVector * 2.0f * deltaTime; + otherAvatar->_joint[o].springyPosition -= directionVector * 2.0f * deltaTime; + */ + /* _joint[b].springyVelocity *= ballMomentum; otherAvatar->_joint[o].springyVelocity *= ballMomentum; + */ // accumulate forces and frictions to apply to the velocities of avatar bodies - bodyPushForce += directionVector * COLLISION_BODY_FORCE * deltaTime; - bodyMomentum -= COLLISION_BODY_FRICTION * deltaTime; - if (bodyMomentum < 0.0) { bodyMomentum = 0.0;} - */ + //bodyPushForce += directionVector * COLLISION_BODY_FORCE * deltaTime; + //bodyMomentum -= COLLISION_BODY_FRICTION * deltaTime; + //if (bodyMomentum < 0.0) { bodyMomentum = 0.0;} + }// check for collision } // to avoid divide by zero @@ -747,9 +747,9 @@ void Avatar::applyCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime //apply forces and frictions on the bodies of both avatars _velocity += bodyPushForce; - otherAvatar->_velocity -= bodyPushForce; - _velocity *= bodyMomentum; - otherAvatar->_velocity *= bodyMomentum; +//otherAvatar->_velocity -= bodyPushForce; + // _velocity *= bodyMomentum; + //otherAvatar->_velocity *= bodyMomentum; } From 108ce62d1a05a419e3efbe815776352ba21c8b4c Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Fri, 31 May 2013 11:51:03 -0700 Subject: [PATCH 07/14] committing latest skeleton-separation changes (more to come as Andrzej and I work on it more) --- interface/src/Avatar.cpp | 395 ++++++++++--------------------------- interface/src/Avatar.h | 11 +- interface/src/Camera.cpp | 2 +- interface/src/Skeleton.cpp | 214 +++++++++++++++++++- interface/src/Skeleton.h | 38 +++- 5 files changed, 360 insertions(+), 300 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 99862cfc98..7e5ce36387 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -107,7 +107,11 @@ Avatar::Avatar(Agent* owningAgent) : _driveKeys[i] = false; } - initializeSkeleton(); + _skeleton.initialize(); + + _maxArmLength = _skeleton.getArmLength(); + _pelvisStandingHeight = _skeleton.getPelvisStandingHeight(); + _pelvisFloatingHeight = _skeleton.getPelvisFloatingHeight(); _avatarTouch.setReachableRadius(PERIPERSONAL_RADIUS); @@ -218,10 +222,20 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) { // update balls if (_balls) { _balls->simulate(deltaTime); } - // if other avatar, update head position from network data - + // create orientation directions based on yaw/pitch/roll... + _orientation.setToIdentity(); + _orientation.yaw (_bodyYaw ); + _orientation.pitch(_bodyPitch); + _orientation.roll (_bodyRoll ); + _orientation.rotate(_righting); + // update avatar skeleton - updateSkeleton(); + _skeleton.update(deltaTime, _orientation, _position); + + // if this is not my avatar, then hand position comes from transmitted data + if (_owningAgent) { + _skeleton.joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position = _handPosition; + } //detect and respond to collisions with other avatars... if (!_owningAgent) { @@ -405,22 +419,22 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) { _orientation.getRight() * _head.getLeanSideways() + _orientation.getFront() * _head.getLeanForward(); - _joint[ AVATAR_JOINT_TORSO ].springyPosition += headLean * 0.1f; - _joint[ AVATAR_JOINT_CHEST ].springyPosition += headLean * 0.4f; - _joint[ AVATAR_JOINT_NECK_BASE ].springyPosition += headLean * 0.7f; - _joint[ AVATAR_JOINT_HEAD_BASE ].springyPosition += headLean * 1.0f; + _skeleton.joint[ AVATAR_JOINT_TORSO ].springyPosition += headLean * 0.1f; + _skeleton.joint[ AVATAR_JOINT_CHEST ].springyPosition += headLean * 0.4f; + _skeleton.joint[ AVATAR_JOINT_NECK_BASE ].springyPosition += headLean * 0.7f; + _skeleton.joint[ AVATAR_JOINT_HEAD_BASE ].springyPosition += headLean * 1.0f; - _joint[ AVATAR_JOINT_LEFT_COLLAR ].springyPosition += headLean * 0.6f; - _joint[ AVATAR_JOINT_LEFT_SHOULDER ].springyPosition += headLean * 0.6f; - _joint[ AVATAR_JOINT_LEFT_ELBOW ].springyPosition += headLean * 0.2f; - _joint[ AVATAR_JOINT_LEFT_WRIST ].springyPosition += headLean * 0.1f; - _joint[ AVATAR_JOINT_LEFT_FINGERTIPS ].springyPosition += headLean * 0.0f; + _skeleton.joint[ AVATAR_JOINT_LEFT_COLLAR ].springyPosition += headLean * 0.6f; + _skeleton.joint[ AVATAR_JOINT_LEFT_SHOULDER ].springyPosition += headLean * 0.6f; + _skeleton.joint[ AVATAR_JOINT_LEFT_ELBOW ].springyPosition += headLean * 0.2f; + _skeleton.joint[ AVATAR_JOINT_LEFT_WRIST ].springyPosition += headLean * 0.1f; + _skeleton.joint[ AVATAR_JOINT_LEFT_FINGERTIPS ].springyPosition += headLean * 0.0f; - _joint[ AVATAR_JOINT_RIGHT_COLLAR ].springyPosition += headLean * 0.6f; - _joint[ AVATAR_JOINT_RIGHT_SHOULDER ].springyPosition += headLean * 0.6f; - _joint[ AVATAR_JOINT_RIGHT_ELBOW ].springyPosition += headLean * 0.2f; - _joint[ AVATAR_JOINT_RIGHT_WRIST ].springyPosition += headLean * 0.1f; - _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].springyPosition += headLean * 0.0f; + _skeleton.joint[ AVATAR_JOINT_RIGHT_COLLAR ].springyPosition += headLean * 0.6f; + _skeleton.joint[ AVATAR_JOINT_RIGHT_SHOULDER ].springyPosition += headLean * 0.6f; + _skeleton.joint[ AVATAR_JOINT_RIGHT_ELBOW ].springyPosition += headLean * 0.2f; + _skeleton.joint[ AVATAR_JOINT_RIGHT_WRIST ].springyPosition += headLean * 0.1f; + _skeleton.joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].springyPosition += headLean * 0.0f; } } @@ -434,8 +448,8 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) { } _head.setBodyRotation (glm::vec3(_bodyPitch, _bodyYaw, _bodyRoll)); - _head.setPosition(_joint[ AVATAR_JOINT_HEAD_BASE ].springyPosition); - _head.setScale (_joint[ AVATAR_JOINT_HEAD_BASE ].radius); + _head.setPosition(_skeleton.joint[ AVATAR_JOINT_HEAD_BASE ].springyPosition); + _head.setScale (_skeleton.joint[ AVATAR_JOINT_HEAD_BASE ].radius); _head.setSkinColor(glm::vec3(SKIN_COLOR[0], SKIN_COLOR[1], SKIN_COLOR[2])); _head.simulate(deltaTime, !_owningAgent); @@ -451,15 +465,15 @@ void Avatar::checkForMouseRayTouching() { for (int b = 0; b < NUM_AVATAR_JOINTS; b++) { - glm::vec3 directionToBodySphere = glm::normalize(_joint[b].springyPosition - _mouseRayOrigin); + glm::vec3 directionToBodySphere = glm::normalize(_skeleton.joint[b].springyPosition - _mouseRayOrigin); float dot = glm::dot(directionToBodySphere, _mouseRayDirection); - float range = _joint[b].radius * JOINT_TOUCH_RANGE; + float range = _skeleton.joint[b].radius * JOINT_TOUCH_RANGE; if (dot > (1.0f - range)) { - _joint[b].touchForce = (dot - (1.0f - range)) / range; + _skeleton.joint[b].touchForce = (dot - (1.0f - range)) / range; } else { - _joint[b].touchForce = 0.0; + _skeleton.joint[b].touchForce = 0.0; } } } @@ -477,7 +491,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { + _orientation.getUp() * -_movedHandOffset.y * 2.0f + _orientation.getFront() * -_movedHandOffset.y * 2.0f; - _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position += transformedHandMovement; + _skeleton.joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position += transformedHandMovement; if (!_owningAgent) { _avatarTouch.setMyBodyPosition(_position); @@ -516,7 +530,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { _avatarTouch.setHasInteractingOther(true); _avatarTouch.setYourBodyPosition(_interactingOther->_position); _avatarTouch.setYourOrientation (_interactingOther->_orientation); - _avatarTouch.setYourHandPosition(_interactingOther->_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].springyPosition); + _avatarTouch.setYourHandPosition(_interactingOther->_skeleton.joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].springyPosition); _avatarTouch.setYourHandState (_interactingOther->_handState); //if hand-holding is initiated by either avatar, turn on hand-holding... @@ -531,8 +545,8 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { glm::vec3 vectorFromMyHandToYourHand ( - _interactingOther->_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position - - _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position + _interactingOther->_skeleton.joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position - + _skeleton.joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position ); float distanceBetweenOurHands = glm::length(vectorFromMyHandToYourHand); @@ -554,10 +568,10 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { //if holding hands, apply the appropriate forces if (_avatarTouch.getHoldingHands()) { - _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position += + _skeleton.joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position += ( - _interactingOther->_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position - - _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position + _interactingOther->_skeleton.joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position + - _skeleton.joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position ) * 0.5f; if (distanceBetweenOurHands > 0.3) { @@ -577,7 +591,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { //Set right hand position and state to be transmitted, and also tell AvatarTouch about it if (!_owningAgent) { - setHandPosition(_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position); + setHandPosition(_skeleton.joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position); if (_mousePressed) { _handState = HAND_STATE_GRASPING; @@ -586,7 +600,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { } _avatarTouch.setMyHandState(_handState); - _avatarTouch.setMyHandPosition(_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].springyPosition); + _avatarTouch.setMyHandPosition(_skeleton.joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].springyPosition); } } @@ -598,9 +612,9 @@ void Avatar::updateCollisionWithSphere(glm::vec3 position, float radius, float d float distanceToBigSphere = glm::length(vectorFromMyBodyToBigSphere); if (distanceToBigSphere < myBodyApproximateBoundingRadius + radius) { for (int b = 0; b < NUM_AVATAR_JOINTS; b++) { - glm::vec3 vectorFromJointToBigSphereCenter(_joint[b].springyPosition - position); + glm::vec3 vectorFromJointToBigSphereCenter(_skeleton.joint[b].springyPosition - position); float distanceToBigSphereCenter = glm::length(vectorFromJointToBigSphereCenter); - float combinedRadius = _joint[b].radius + radius; + float combinedRadius = _skeleton.joint[b].radius + radius; if (distanceToBigSphereCenter < combinedRadius) { jointCollision = true; @@ -610,9 +624,9 @@ void Avatar::updateCollisionWithSphere(glm::vec3 position, float radius, float d float penetration = 1.0 - (distanceToBigSphereCenter / combinedRadius); glm::vec3 collisionForce = vectorFromJointToBigSphereCenter * penetration; - _joint[b].springyVelocity += collisionForce * 0.0f * deltaTime; + _skeleton.joint[b].springyVelocity += collisionForce * 0.0f * deltaTime; _velocity += collisionForce * 40.0f * deltaTime; - _joint[b].springyPosition = position + directionVector * combinedRadius; + _skeleton.joint[b].springyPosition = position + directionVector * combinedRadius; } } } @@ -669,7 +683,7 @@ void Avatar::updateAvatarCollisions(float deltaTime) { } // test other avatar hand position for proximity - glm::vec3 v(_joint[ AVATAR_JOINT_RIGHT_SHOULDER ].position); + glm::vec3 v(_skeleton.joint[ AVATAR_JOINT_RIGHT_SHOULDER ].position); v -= otherAvatar->getPosition(); float distance = glm::length(v); @@ -688,16 +702,16 @@ void Avatar::applyCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime // loop through the joints of each avatar to check for every possible collision for (int b=1; b_joint[o].isCollidable) { + if (otherAvatar->_skeleton.joint[o].isCollidable) { - glm::vec3 vectorBetweenJoints(_joint[b].springyPosition - otherAvatar->_joint[o].springyPosition); + glm::vec3 vectorBetweenJoints(_skeleton.joint[b].springyPosition - otherAvatar->_skeleton.joint[o].springyPosition); float distanceBetweenJoints = glm::length(vectorBetweenJoints); if (distanceBetweenJoints > 0.0) { // to avoid divide by zero - float combinedRadius = _joint[b].radius + otherAvatar->_joint[o].radius; + float combinedRadius = _skeleton.joint[b].radius + otherAvatar->_skeleton.joint[o].radius; // check for collision if (distanceBetweenJoints < combinedRadius * COLLISION_RADIUS_SCALAR) { @@ -715,21 +729,21 @@ void Avatar::applyCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime if (ballMomentum < 0.0) { ballMomentum = 0.0;} */ - _joint[b].springyVelocity += ballPushForce; - otherAvatar->_joint[o].springyVelocity -= ballPushForce; + _skeleton.joint[b].springyVelocity += ballPushForce; + otherAvatar->_skeleton.joint[o].springyVelocity -= ballPushForce; /* float shift = distanceBetweenJoints - combinedRadius * COLLISION_RADIUS_SCALAR; - _joint[b].springyPosition += directionVector * 2.0f * deltaTime; - otherAvatar->_joint[o].springyPosition -= directionVector * 2.0f * deltaTime; + _skeleton.joint[b].springyPosition += directionVector * 2.0f * deltaTime; + otherAvatar->_skeleton.joint[o].springyPosition -= directionVector * 2.0f * deltaTime; */ /* - _joint[b].springyVelocity *= ballMomentum; - otherAvatar->_joint[o].springyVelocity *= ballMomentum; + _skeleton.joint[b].springyVelocity *= ballMomentum; + otherAvatar->_skeleton.joint[o].springyVelocity *= ballMomentum; */ // accumulate forces and frictions to apply to the velocities of avatar bodies @@ -810,9 +824,9 @@ void Avatar::render(bool lookingInMirror, glm::vec3 cameraPosition) { float modelview[16]; glGetFloatv(GL_MODELVIEW_MATRIX, modelview); - glTranslatef(_joint[AVATAR_JOINT_HEAD_BASE].springyPosition.x, - _joint[AVATAR_JOINT_HEAD_BASE].springyPosition.y + chatMessageHeight, - _joint[AVATAR_JOINT_HEAD_BASE].springyPosition.z); + glTranslatef(_skeleton.joint[AVATAR_JOINT_HEAD_BASE].springyPosition.x, + _skeleton.joint[AVATAR_JOINT_HEAD_BASE].springyPosition.y + chatMessageHeight, + _skeleton.joint[AVATAR_JOINT_HEAD_BASE].springyPosition.z); glRotatef(atan2(-modelview[2], -modelview[10]) * 180 / PI, 0, 1, 0); glColor3f(0, 0.8, 0); @@ -842,219 +856,20 @@ void Avatar::render(bool lookingInMirror, glm::vec3 cameraPosition) { } } -void Avatar::initializeSkeleton() { - - for (int b=0; b BEYOND_BODY_SPRING_RANGE) { - initializeBodySprings(); + if (glm::length(_position - _skeleton.joint[AVATAR_JOINT_PELVIS].springyPosition) > BEYOND_BODY_SPRING_RANGE) { + _skeleton.initializeBodySprings(); } for (int b = 0; b < NUM_AVATAR_JOINTS; b++) { - glm::vec3 springVector(_joint[b].springyPosition); + glm::vec3 springVector(_skeleton.joint[b].springyPosition); - if (_joint[b].parent == AVATAR_JOINT_NULL) { + if (_skeleton.joint[b].parent == AVATAR_JOINT_NULL) { springVector -= _position; } else { - springVector -= _joint[ _joint[b].parent ].springyPosition; + springVector -= _skeleton.joint[ _skeleton.joint[b].parent ].springyPosition; } float length = glm::length(springVector); @@ -1062,44 +877,44 @@ void Avatar::updateBodySprings(float deltaTime) { if (length > 0.0f) { // to avoid divide by zero glm::vec3 springDirection = springVector / length; - float force = (length - _joint[b].length) * BODY_SPRING_FORCE * deltaTime; + float force = (length - _skeleton.joint[b].length) * BODY_SPRING_FORCE * deltaTime; - _joint[b].springyVelocity -= springDirection * force; + _skeleton.joint[b].springyVelocity -= springDirection * force; - if (_joint[b].parent != AVATAR_JOINT_NULL) { - _joint[_joint[b].parent].springyVelocity += springDirection * force; + if (_skeleton.joint[b].parent != AVATAR_JOINT_NULL) { + _skeleton.joint[_skeleton.joint[b].parent].springyVelocity += springDirection * force; } } // apply tightness force - (causing springy position to be close to rigid body position) - _joint[b].springyVelocity += (_joint[b].position - _joint[b].springyPosition) * _joint[b].springBodyTightness * deltaTime; + _skeleton.joint[b].springyVelocity += (_skeleton.joint[b].position - _skeleton.joint[b].springyPosition) * _skeleton.joint[b].springBodyTightness * deltaTime; // apply decay float decay = 1.0 - BODY_SPRING_DECAY * deltaTime; if (decay > 0.0) { - _joint[b].springyVelocity *= decay; + _skeleton.joint[b].springyVelocity *= decay; } else { - _joint[b].springyVelocity = glm::vec3(0.0f, 0.0f, 0.0f); + _skeleton.joint[b].springyVelocity = glm::vec3(0.0f, 0.0f, 0.0f); } /* //apply forces from touch... - if (_joint[b].touchForce > 0.0) { - _joint[b].springyVelocity += _mouseRayDirection * _joint[b].touchForce * 0.7f; + if (_skeleton.joint[b].touchForce > 0.0) { + _skeleton.joint[b].springyVelocity += _mouseRayDirection * _skeleton.joint[b].touchForce * 0.7f; } */ //update position by velocity... - _joint[b].springyPosition += _joint[b].springyVelocity * deltaTime; + _skeleton.joint[b].springyPosition += _skeleton.joint[b].springyVelocity * deltaTime; } } void Avatar::updateArmIKAndConstraints(float deltaTime) { // determine the arm vector - glm::vec3 armVector = _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position; - armVector -= _joint[ AVATAR_JOINT_RIGHT_SHOULDER ].position; + glm::vec3 armVector = _skeleton.joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position; + armVector -= _skeleton.joint[ AVATAR_JOINT_RIGHT_SHOULDER ].position; // test to see if right hand is being dragged beyond maximum arm length float distance = glm::length(armVector); @@ -1107,28 +922,28 @@ void Avatar::updateArmIKAndConstraints(float deltaTime) { // don't let right hand get dragged beyond maximum arm length... if (distance > _maxArmLength) { // reset right hand to be constrained to maximum arm length - _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position = _joint[ AVATAR_JOINT_RIGHT_SHOULDER ].position; + _skeleton.joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position = _skeleton.joint[ AVATAR_JOINT_RIGHT_SHOULDER ].position; glm::vec3 armNormal = armVector / distance; armVector = armNormal * _maxArmLength; distance = _maxArmLength; - glm::vec3 constrainedPosition = _joint[ AVATAR_JOINT_RIGHT_SHOULDER ].position; + glm::vec3 constrainedPosition = _skeleton.joint[ AVATAR_JOINT_RIGHT_SHOULDER ].position; constrainedPosition += armVector; - _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position = constrainedPosition; + _skeleton.joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position = constrainedPosition; } // set elbow position - glm::vec3 newElbowPosition = _joint[ AVATAR_JOINT_RIGHT_SHOULDER ].position + armVector * ONE_HALF; + glm::vec3 newElbowPosition = _skeleton.joint[ AVATAR_JOINT_RIGHT_SHOULDER ].position + armVector * ONE_HALF; glm::vec3 perpendicular = glm::cross( _orientation.getRight(), armVector); newElbowPosition += perpendicular * (1.0f - (_maxArmLength / distance)) * ONE_HALF; - _joint[ AVATAR_JOINT_RIGHT_ELBOW ].position = newElbowPosition; + _skeleton.joint[ AVATAR_JOINT_RIGHT_ELBOW ].position = newElbowPosition; // set wrist position - glm::vec3 vv(_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position); - vv -= _joint[ AVATAR_JOINT_RIGHT_ELBOW ].position; - glm::vec3 newWristPosition = _joint[ AVATAR_JOINT_RIGHT_ELBOW ].position + vv * 0.7f; - _joint[ AVATAR_JOINT_RIGHT_WRIST ].position = newWristPosition; + glm::vec3 vv(_skeleton.joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position); + vv -= _skeleton.joint[ AVATAR_JOINT_RIGHT_ELBOW ].position; + glm::vec3 newWristPosition = _skeleton.joint[ AVATAR_JOINT_RIGHT_ELBOW ].position + vv * 0.7f; + _skeleton.joint[ AVATAR_JOINT_RIGHT_WRIST ].position = newWristPosition; } @@ -1139,7 +954,7 @@ void Avatar::renderBody(bool lookingInMirror) { // Render the body as balls and cones for (int b = 0; b < NUM_AVATAR_JOINTS; b++) { - float distanceToCamera = glm::length(_cameraPosition - _joint[b].position); + float distanceToCamera = glm::length(_cameraPosition - _skeleton.joint[b].position); float alpha = glm::clamp((distanceToCamera - RENDER_TRANSLUCENT_BEYOND) / (RENDER_OPAQUE_BEYOND - RENDER_TRANSLUCENT_BEYOND), 0.f, 1.f); @@ -1160,26 +975,26 @@ void Avatar::renderBody(bool lookingInMirror) { if (_owningAgent || b == AVATAR_JOINT_RIGHT_ELBOW || b == AVATAR_JOINT_RIGHT_WRIST || b == AVATAR_JOINT_RIGHT_FINGERTIPS ) { - glColor3f(SKIN_COLOR[0] + _joint[b].touchForce * 0.3f, - SKIN_COLOR[1] - _joint[b].touchForce * 0.2f, - SKIN_COLOR[2] - _joint[b].touchForce * 0.1f); + glColor3f(SKIN_COLOR[0] + _skeleton.joint[b].touchForce * 0.3f, + SKIN_COLOR[1] - _skeleton.joint[b].touchForce * 0.2f, + SKIN_COLOR[2] - _skeleton.joint[b].touchForce * 0.1f); } else { - glColor4f(SKIN_COLOR[0] + _joint[b].touchForce * 0.3f, - SKIN_COLOR[1] - _joint[b].touchForce * 0.2f, - SKIN_COLOR[2] - _joint[b].touchForce * 0.1f, + glColor4f(SKIN_COLOR[0] + _skeleton.joint[b].touchForce * 0.3f, + SKIN_COLOR[1] - _skeleton.joint[b].touchForce * 0.2f, + SKIN_COLOR[2] - _skeleton.joint[b].touchForce * 0.1f, alpha); } if ((b != AVATAR_JOINT_HEAD_TOP ) && (b != AVATAR_JOINT_HEAD_BASE )) { glPushMatrix(); - glTranslatef(_joint[b].springyPosition.x, _joint[b].springyPosition.y, _joint[b].springyPosition.z); - glutSolidSphere(_joint[b].radius, 20.0f, 20.0f); + glTranslatef(_skeleton.joint[b].springyPosition.x, _skeleton.joint[b].springyPosition.y, _skeleton.joint[b].springyPosition.z); + glutSolidSphere(_skeleton.joint[b].radius, 20.0f, 20.0f); glPopMatrix(); } // Render the cone connecting this joint to its parent - if (_joint[b].parent != AVATAR_JOINT_NULL) { + if (_skeleton.joint[b].parent != AVATAR_JOINT_NULL) { if ((b != AVATAR_JOINT_HEAD_TOP ) && (b != AVATAR_JOINT_HEAD_BASE ) && (b != AVATAR_JOINT_PELVIS ) @@ -1191,15 +1006,15 @@ void Avatar::renderBody(bool lookingInMirror) { && (b != AVATAR_JOINT_RIGHT_SHOULDER)) { glColor3fv(DARK_SKIN_COLOR); - float r1 = _joint[_joint[b].parent ].radius * 0.8; - float r2 = _joint[b ].radius * 0.8; + float r1 = _skeleton.joint[_skeleton.joint[b].parent ].radius * 0.8; + float r2 = _skeleton.joint[b ].radius * 0.8; if (b == AVATAR_JOINT_HEAD_BASE) { r1 *= 0.5f; } renderJointConnectingCone ( - _joint[_joint[b].parent ].springyPosition, - _joint[b ].springyPosition, r2, r2 + _skeleton.joint[_skeleton.joint[b].parent ].springyPosition, + _skeleton.joint[b ].springyPosition, r2, r2 ); } } diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index 1ef5675d9b..0518561322 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -67,9 +67,9 @@ public: float getHeadYawRate () const { return _head.yawRate;} float getBodyYaw () const { return _bodyYaw;} bool getIsNearInteractingOther() const { return _avatarTouch.getAbleToReachOtherAvatar();} - const glm::vec3& getHeadPosition () const { return _joint[ AVATAR_JOINT_HEAD_BASE ].position;} - const glm::vec3& getSpringyHeadPosition () const { return _joint[ AVATAR_JOINT_HEAD_BASE ].springyPosition;} - const glm::vec3& getJointPosition (AvatarJointID j) const { return _joint[j].springyPosition;} + const glm::vec3& getHeadPosition () const { return _skeleton.joint[ AVATAR_JOINT_HEAD_BASE ].position;} + const glm::vec3& getSpringyHeadPosition () const { return _skeleton.joint[ AVATAR_JOINT_HEAD_BASE ].springyPosition;} + const glm::vec3& getJointPosition (AvatarJointID j) const { return _skeleton.joint[j].springyPosition;} const glm::vec3& getBodyUpDirection () const { return _orientation.getUp();} const glm::vec3& getVelocity () const { return _velocity;} float getSpeed () const { return _speed;} @@ -96,6 +96,7 @@ private: Avatar(const Avatar&); Avatar& operator= (const Avatar&); +/* struct AvatarJoint { AvatarJointID parent; // which joint is this joint connected to? @@ -114,6 +115,7 @@ private: bool isCollidable; // when false, the joint position will not register a collision float touchForce; // if being touched, what's the degree of influence? (0 to 1) }; +*/ Head _head; Skeleton _skeleton; @@ -125,7 +127,7 @@ private: float _bodyRollDelta; glm::vec3 _movedHandOffset; glm::quat _rotation; // the rotation of the avatar body as a whole expressed as a quaternion - AvatarJoint _joint[ NUM_AVATAR_JOINTS ]; + //AvatarJoint _joint[ NUM_AVATAR_JOINTS ]; AvatarMode _mode; glm::vec3 _cameraPosition; glm::vec3 _handHoldingPosition; @@ -153,7 +155,6 @@ private: glm::vec3 caclulateAverageEyePosition() { return _head.caclulateAverageEyePosition(); } // get the position smack-dab between the eyes (for lookat) void renderBody(bool lookingInMirror); void initializeSkeleton(); - void updateSkeleton(); void initializeBodySprings(); void updateBodySprings( float deltaTime ); void calculateBoneLengths(); diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index fa0744bf49..8290e2b418 100644 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -30,7 +30,7 @@ Camera::Camera() { _needsToInitialize = true; _frustumNeedsReshape = true; - _modeShift = 0.0f; + _modeShift = 1.0f; _modeShiftRate = 1.0f; _linearModeShift = 0.0f; _mode = CAMERA_MODE_THIRD_PERSON; diff --git a/interface/src/Skeleton.cpp b/interface/src/Skeleton.cpp index 49e8dea053..37f37516ea 100644 --- a/interface/src/Skeleton.cpp +++ b/interface/src/Skeleton.cpp @@ -6,15 +6,225 @@ #include "Skeleton.h" +const float BODY_SPRING_DEFAULT_TIGHTNESS = 1000.0f; +const float FLOATING_HEIGHT = 0.13f; + +float test = 0.0f; + +/* +float testYaw = 0.0f; +float testPitch = 0.0f; +float testRoll = 0.0f; +*/ + Skeleton::Skeleton() { } void Skeleton::initialize() { + + for (int b=0; b +#include +#include + enum AvatarJointID { AVATAR_JOINT_NULL = -1, @@ -45,10 +49,40 @@ public: Skeleton(); void initialize(); - void simulate(float deltaTime); + void initializeBodySprings(); + void update(float deltaTime, Orientation orientation, glm::vec3 position); void render(); + float getArmLength(); + float getHeight(); + float getPelvisStandingHeight(); + float getPelvisFloatingHeight(); + + struct AvatarJoint + { + AvatarJointID parent; // which joint is this joint connected to? + glm::vec3 position; // the position at the "end" of the joint - in global space + glm::vec3 defaultPosePosition; // the parent relative position when the avatar is in the "T-pose" + glm::vec3 springyPosition; // used for special effects (a 'flexible' variant of position) + glm::vec3 springyVelocity; // used for special effects ( the velocity of the springy position) + float springBodyTightness; // how tightly the springy position tries to stay on the position + glm::quat rotation; // this will eventually replace yaw, pitch and roll (and maybe orientation) + float yaw; // the yaw Euler angle of the joint rotation off the parent + float pitch; // the pitch Euler angle of the joint rotation off the parent + float roll; // the roll Euler angle of the joint rotation off the parent + Orientation orientation; // three orthogonal normals determined by yaw, pitch, roll + float length; // the length of vector connecting the joint and its parent + float radius; // used for detecting collisions for certain physical effects + bool isCollidable; // when false, the joint position will not register a collision + float touchForce; // if being touched, what's the degree of influence? (0 to 1) + }; + + AvatarJoint joint[ NUM_AVATAR_JOINTS ]; + private: -}; + + void calculateBoneLengths(); + + }; #endif From 3ce051bff7c11232238ee03dc90a92665c8f7022 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Fri, 31 May 2013 14:11:46 -0700 Subject: [PATCH 08/14] merge --- interface/src/Application.cpp | 2 +- interface/src/Avatar.cpp | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index cb7596c79d..4d3628d5b9 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -50,7 +50,7 @@ using namespace std; -const bool TESTING_AVATAR_TOUCH = false; +const bool TESTING_AVATAR_TOUCH = true; // Starfield information static char STAR_FILE[] = "https://s3-us-west-1.amazonaws.com/highfidelity/stars.txt"; diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index adab703f96..c22f00f120 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -677,9 +677,10 @@ void Avatar::updateAvatarCollisions(float deltaTime) { 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 if the bounding spheres of the two avatars are colliding glm::vec3 vectorBetweenBoundingSpheres(_position - otherAvatar->_position); + if (glm::length(vectorBetweenBoundingSpheres) < _height * ONE_HALF + otherAvatar->_height * ONE_HALF) { //apply forces from collision applyCollisionWithOtherAvatar(otherAvatar, deltaTime); @@ -699,8 +700,8 @@ void Avatar::updateAvatarCollisions(float deltaTime) { //detect collisions with other avatars and respond void Avatar::applyCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime) { - - float bodyMomentum = 1.0f; + + //float bodyMomentum = 1.0f; glm::vec3 bodyPushForce = glm::vec3(0.0f, 0.0f, 0.0f); // loop through the joints of each avatar to check for every possible collision @@ -721,7 +722,6 @@ void Avatar::applyCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime glm::vec3 directionVector = vectorBetweenJoints / distanceBetweenJoints; // push balls away from each other and apply friction - float penetration = 1.0f - (distanceBetweenJoints / (combinedRadius * COLLISION_RADIUS_SCALAR)); glm::vec3 ballPushForce = directionVector * COLLISION_BALL_FORCE * penetration * deltaTime; @@ -763,8 +763,10 @@ void Avatar::applyCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime } // collidable //apply forces and frictions on the bodies of both avatars - _velocity += bodyPushForce; -//otherAvatar->_velocity -= bodyPushForce; + +// _velocity += bodyPushForce; + + //otherAvatar->_velocity -= bodyPushForce; // _velocity *= bodyMomentum; //otherAvatar->_velocity *= bodyMomentum; } From f1fc3fe704dd01a7c0243bcf7bf6d9203a75e3fd Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Fri, 31 May 2013 14:52:24 -0700 Subject: [PATCH 09/14] merge --- interface/src/Avatar.cpp | 50 ++++++++------------------------------ interface/src/Skeleton.cpp | 4 ++- interface/src/Skeleton.h | 6 +---- 3 files changed, 14 insertions(+), 46 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index c22f00f120..ce742e1236 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -107,6 +107,7 @@ Avatar::Avatar(Agent* owningAgent) : _skeleton.initialize(); + _height = _skeleton.getHeight(); _maxArmLength = _skeleton.getArmLength(); _pelvisStandingHeight = _skeleton.getPelvisStandingHeight(); _pelvisFloatingHeight = _skeleton.getPelvisFloatingHeight(); @@ -485,13 +486,13 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { // reset hand and arm positions according to hand movement glm::vec3 right = orientation * AVATAR_RIGHT; - glm::vec3 up = orientation * AVATAR_UP; + glm::vec3 up = orientation * AVATAR_UP; glm::vec3 front = orientation * AVATAR_FRONT; glm::vec3 transformedHandMovement = right * _movedHandOffset.x * 2.0f - + up * -_movedHandOffset.y * 2.0f - + front * -_movedHandOffset.z * 2.0f; + + up * -_movedHandOffset.y * 2.0f + + front * -_movedHandOffset.y * 2.0f; _skeleton.joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position += transformedHandMovement; @@ -677,13 +678,13 @@ void Avatar::updateAvatarCollisions(float deltaTime) { 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 if the bounding spheres of the two avatars are colliding glm::vec3 vectorBetweenBoundingSpheres(_position - otherAvatar->_position); if (glm::length(vectorBetweenBoundingSpheres) < _height * ONE_HALF + otherAvatar->_height * ONE_HALF) { - //apply forces from collision - applyCollisionWithOtherAvatar(otherAvatar, deltaTime); + //apply forces from collision + applyCollisionWithOtherAvatar(otherAvatar, deltaTime); } // test other avatar hand position for proximity @@ -701,7 +702,6 @@ void Avatar::updateAvatarCollisions(float deltaTime) { //detect collisions with other avatars and respond void Avatar::applyCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime) { - //float bodyMomentum = 1.0f; glm::vec3 bodyPushForce = glm::vec3(0.0f, 0.0f, 0.0f); // loop through the joints of each avatar to check for every possible collision @@ -727,33 +727,8 @@ void Avatar::applyCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime glm::vec3 ballPushForce = directionVector * COLLISION_BALL_FORCE * penetration * deltaTime; bodyPushForce += directionVector * COLLISION_BODY_FORCE * penetration * deltaTime; - /* - float ballMomentum = 1.0 - COLLISION_BALL_FRICTION * deltaTime; - if (ballMomentum < 0.0) { ballMomentum = 0.0;} - */ - _skeleton.joint[b].springyVelocity += ballPushForce; otherAvatar->_skeleton.joint[o].springyVelocity -= ballPushForce; - - - /* - float shift = distanceBetweenJoints - combinedRadius * COLLISION_RADIUS_SCALAR; - - _skeleton.joint[b].springyPosition += directionVector * 2.0f * deltaTime; - otherAvatar->_skeleton.joint[o].springyPosition -= directionVector * 2.0f * deltaTime; - */ - - - /* - _skeleton.joint[b].springyVelocity *= ballMomentum; - otherAvatar->_skeleton.joint[o].springyVelocity *= ballMomentum; - */ - - // accumulate forces and frictions to apply to the velocities of avatar bodies - //bodyPushForce += directionVector * COLLISION_BODY_FORCE * deltaTime; - //bodyMomentum -= COLLISION_BODY_FRICTION * deltaTime; - //if (bodyMomentum < 0.0) { bodyMomentum = 0.0;} - }// check for collision } // to avoid divide by zero @@ -762,13 +737,8 @@ void Avatar::applyCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime } // b loop } // collidable - //apply forces and frictions on the bodies of both avatars - -// _velocity += bodyPushForce; - - //otherAvatar->_velocity -= bodyPushForce; - // _velocity *= bodyMomentum; - //otherAvatar->_velocity *= bodyMomentum; + //apply force on the whole body + _velocity += bodyPushForce; } @@ -948,7 +918,7 @@ void Avatar::updateArmIKAndConstraints(float deltaTime) { // set elbow position glm::vec3 newElbowPosition = _skeleton.joint[ AVATAR_JOINT_RIGHT_SHOULDER ].position + armVector * ONE_HALF; - glm::vec3 perpendicular = glm::cross(getBodyFrontDirection(), armVector); + glm::vec3 perpendicular = glm::cross(getBodyRightDirection(), armVector); newElbowPosition += perpendicular * (1.0f - (_maxArmLength / distance)) * ONE_HALF; _skeleton.joint[ AVATAR_JOINT_RIGHT_ELBOW ].position = newElbowPosition; diff --git a/interface/src/Skeleton.cpp b/interface/src/Skeleton.cpp index a328ffb4c5..78c40986af 100644 --- a/interface/src/Skeleton.cpp +++ b/interface/src/Skeleton.cpp @@ -112,11 +112,13 @@ void Skeleton::initialize() { joint[ AVATAR_JOINT_RIGHT_HEEL ].radius = 0.025; joint[ AVATAR_JOINT_RIGHT_TOES ].radius = 0.025; + /* // to aid in hand-shaking and hand-holding, the right hand is not collidable joint[ AVATAR_JOINT_RIGHT_ELBOW ].isCollidable = false; joint[ AVATAR_JOINT_RIGHT_WRIST ].isCollidable = false; joint[ AVATAR_JOINT_RIGHT_FINGERTIPS].isCollidable = false; - + */ + // calculate bone length calculateBoneLengths(); diff --git a/interface/src/Skeleton.h b/interface/src/Skeleton.h index 362cab6080..69d2fe0d2b 100644 --- a/interface/src/Skeleton.h +++ b/interface/src/Skeleton.h @@ -65,11 +65,7 @@ public: glm::vec3 springyPosition; // used for special effects (a 'flexible' variant of position) glm::vec3 springyVelocity; // used for special effects ( the velocity of the springy position) float springBodyTightness; // how tightly the springy position tries to stay on the position - glm::quat rotation; // this will eventually replace yaw, pitch and roll (and maybe orientation) - //float yaw; // the yaw Euler angle of the joint rotation off the parent - //float pitch; // the pitch Euler angle of the joint rotation off the parent - //float roll; // the roll Euler angle of the joint rotation off the parent - //Orientation orientation; // three orthogonal normals determined by yaw, pitch, roll + glm::quat rotation; // the parent-relative rotation (orientation) of the joint as a quaternion float length; // the length of vector connecting the joint and its parent float radius; // used for detecting collisions for certain physical effects bool isCollidable; // when false, the joint position will not register a collision From 303643e921face2fcafa9cf5187998626dd501a7 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Fri, 31 May 2013 15:01:08 -0700 Subject: [PATCH 10/14] cleanup --- interface/src/Avatar.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 5af0874f5a..080d9e31ca 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -33,13 +33,9 @@ const float YOUR_HAND_HOLDING_PULL = 1.0; const float BODY_SPRING_DEFAULT_TIGHTNESS = 1000.0f; const float BODY_SPRING_FORCE = 300.0f; const float BODY_SPRING_DECAY = 16.0f; - const float COLLISION_RADIUS_SCALAR = 1.2; //pertains to avatar-to-avatar collisions const float COLLISION_BALL_FORCE = 200.0; //pertains to avatar-to-avatar collisions const float COLLISION_BODY_FORCE = 30.0; //pertains to avatar-to-avatar collisions -const float COLLISION_BALL_FRICTION = 60.0; //pertains to avatar-to-avatar collisions -const float COLLISION_BODY_FRICTION = 0.5; //pertains to avatar-to-avatar collisions - const float HEAD_ROTATION_SCALE = 0.70; const float HEAD_ROLL_SCALE = 0.40; const float HEAD_MAX_PITCH = 45; From 1061b3eb4dccdd25fa7c367e42e60c2ab3cc64b6 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Fri, 31 May 2013 15:05:05 -0700 Subject: [PATCH 11/14] cleanup --- interface/src/Application.cpp | 39 ++++++++++++++--------------------- 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 4d3628d5b9..fe84ec4748 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -50,8 +50,6 @@ using namespace std; -const bool TESTING_AVATAR_TOUCH = true; - // Starfield information static char STAR_FILE[] = "https://s3-us-west-1.amazonaws.com/highfidelity/stars.txt"; static char STAR_CACHE_FILE[] = "cachedStars.txt"; @@ -1080,31 +1078,24 @@ void Application::idle() { _myAvatar.simulate(deltaTime, NULL); } - if ( TESTING_AVATAR_TOUCH) { - if (_myCamera.getMode() != CAMERA_MODE_THIRD_PERSON) { - _myCamera.setMode(CAMERA_MODE_THIRD_PERSON); - _myCamera.setModeShiftRate(1.0f); - } - } else { - if (_myCamera.getMode() != CAMERA_MODE_MIRROR && !OculusManager::isConnected()) { - if (_manualFirstPerson) { - if (_myCamera.getMode() != CAMERA_MODE_FIRST_PERSON ) { + if (_myCamera.getMode() != CAMERA_MODE_MIRROR && !OculusManager::isConnected()) { + if (_manualFirstPerson) { + if (_myCamera.getMode() != CAMERA_MODE_FIRST_PERSON ) { + _myCamera.setMode(CAMERA_MODE_FIRST_PERSON); + _myCamera.setModeShiftRate(1.0f); + } + } else { + + if (_myAvatar.getIsNearInteractingOther()) { + if (_myCamera.getMode() != CAMERA_MODE_FIRST_PERSON) { _myCamera.setMode(CAMERA_MODE_FIRST_PERSON); _myCamera.setModeShiftRate(1.0f); } - } else { - - if (_myAvatar.getIsNearInteractingOther()) { - if (_myCamera.getMode() != CAMERA_MODE_FIRST_PERSON) { - _myCamera.setMode(CAMERA_MODE_FIRST_PERSON); - _myCamera.setModeShiftRate(1.0f); - } - } - else { - if (_myCamera.getMode() != CAMERA_MODE_THIRD_PERSON) { - _myCamera.setMode(CAMERA_MODE_THIRD_PERSON); - _myCamera.setModeShiftRate(1.0f); - } + } + else { + if (_myCamera.getMode() != CAMERA_MODE_THIRD_PERSON) { + _myCamera.setMode(CAMERA_MODE_THIRD_PERSON); + _myCamera.setModeShiftRate(1.0f); } } } From 4f49f1769e5f2c70c734513ad4de1c9b6fcea112 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Fri, 31 May 2013 16:54:56 -0700 Subject: [PATCH 12/14] separated springy balls from skeleton --- interface/src/Avatar.cpp | 176 ++++++++++++++++++++++++------------- interface/src/Avatar.h | 30 +++---- interface/src/Skeleton.cpp | 79 ++--------------- interface/src/Skeleton.h | 16 +--- 4 files changed, 136 insertions(+), 165 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 080d9e31ca..61974dd9b1 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -98,12 +98,14 @@ Avatar::Avatar(Agent* owningAgent) : } _skeleton.initialize(); - - _height = _skeleton.getHeight(); - _maxArmLength = _skeleton.getArmLength(); - _pelvisStandingHeight = _skeleton.getPelvisStandingHeight(); - _pelvisFloatingHeight = _skeleton.getPelvisFloatingHeight(); + initializeBalls(); + + _height = _skeleton.getHeight() + _ball[ AVATAR_JOINT_LEFT_HEEL ].radius + _ball[ AVATAR_JOINT_HEAD_BASE ].radius; + _maxArmLength = _skeleton.getArmLength(); + _pelvisStandingHeight = _skeleton.getPelvisStandingHeight() + _ball[ AVATAR_JOINT_LEFT_HEEL ].radius; + _pelvisFloatingHeight = _skeleton.getPelvisFloatingHeight() + _ball[ AVATAR_JOINT_LEFT_HEEL ].radius; + _avatarTouch.setReachableRadius(PERIPERSONAL_RADIUS); if (BALLS_ON) { @@ -113,6 +115,56 @@ Avatar::Avatar(Agent* owningAgent) : } } + +void Avatar::initializeBalls() { + + for (int b=0; b (1.0f - range)) { - _skeleton.joint[b].touchForce = (dot - (1.0f - range)) / range; + _ball[b].touchForce = (dot - (1.0f - range)) / range; } else { - _skeleton.joint[b].touchForce = 0.0; + _ball[b].touchForce = 0.0; } } } @@ -527,7 +579,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { _avatarTouch.setHasInteractingOther(true); _avatarTouch.setYourBodyPosition(_interactingOther->_position); - _avatarTouch.setYourHandPosition(_interactingOther->_skeleton.joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].springyPosition); + _avatarTouch.setYourHandPosition(_interactingOther->_ball[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position); _avatarTouch.setYourOrientation (_interactingOther->getOrientation()); _avatarTouch.setYourHandState (_interactingOther->_handState); @@ -598,7 +650,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { } _avatarTouch.setMyHandState(_handState); - _avatarTouch.setMyHandPosition(_skeleton.joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].springyPosition); + _avatarTouch.setMyHandPosition(_ball[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position); } } @@ -610,9 +662,9 @@ void Avatar::updateCollisionWithSphere(glm::vec3 position, float radius, float d float distanceToBigSphere = glm::length(vectorFromMyBodyToBigSphere); if (distanceToBigSphere < myBodyApproximateBoundingRadius + radius) { for (int b = 0; b < NUM_AVATAR_JOINTS; b++) { - glm::vec3 vectorFromJointToBigSphereCenter(_skeleton.joint[b].springyPosition - position); + glm::vec3 vectorFromJointToBigSphereCenter(_ball[b].position - position); float distanceToBigSphereCenter = glm::length(vectorFromJointToBigSphereCenter); - float combinedRadius = _skeleton.joint[b].radius + radius; + float combinedRadius = _ball[b].radius + radius; if (distanceToBigSphereCenter < combinedRadius) { jointCollision = true; @@ -622,9 +674,9 @@ void Avatar::updateCollisionWithSphere(glm::vec3 position, float radius, float d float penetration = 1.0 - (distanceToBigSphereCenter / combinedRadius); glm::vec3 collisionForce = vectorFromJointToBigSphereCenter * penetration; - _skeleton.joint[b].springyVelocity += collisionForce * 0.0f * deltaTime; + _ball[b].velocity += collisionForce * 0.0f * deltaTime; _velocity += collisionForce * 40.0f * deltaTime; - _skeleton.joint[b].springyPosition = position + directionVector * combinedRadius; + _ball[b].position = position + directionVector * combinedRadius; } } } @@ -710,16 +762,16 @@ void Avatar::applyCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime // loop through the joints of each avatar to check for every possible collision for (int b=1; b_skeleton.joint[o].isCollidable) { + if (otherAvatar->_ball[o].isCollidable) { - glm::vec3 vectorBetweenJoints(_skeleton.joint[b].springyPosition - otherAvatar->_skeleton.joint[o].springyPosition); + glm::vec3 vectorBetweenJoints(_ball[b].position - otherAvatar->_ball[o].position); float distanceBetweenJoints = glm::length(vectorBetweenJoints); if (distanceBetweenJoints > 0.0) { // to avoid divide by zero - float combinedRadius = _skeleton.joint[b].radius + otherAvatar->_skeleton.joint[o].radius; + float combinedRadius = _ball[b].radius + otherAvatar->_ball[o].radius; // check for collision if (distanceBetweenJoints < combinedRadius * COLLISION_RADIUS_SCALAR) { @@ -731,8 +783,8 @@ void Avatar::applyCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime glm::vec3 ballPushForce = directionVector * COLLISION_BALL_FORCE * penetration * deltaTime; bodyPushForce += directionVector * COLLISION_BODY_FORCE * penetration * deltaTime; - _skeleton.joint[b].springyVelocity += ballPushForce; - otherAvatar->_skeleton.joint[o].springyVelocity -= ballPushForce; + _ball[b].velocity += ballPushForce; + otherAvatar->_ball[o].velocity -= ballPushForce; }// check for collision } // to avoid divide by zero @@ -805,7 +857,7 @@ void Avatar::render(bool lookingInMirror) { } glPushMatrix(); - glm::vec3 chatPosition = _skeleton.joint[AVATAR_JOINT_HEAD_BASE].springyPosition + getBodyUpDirection() * chatMessageHeight; + glm::vec3 chatPosition = _ball[AVATAR_JOINT_HEAD_BASE].position + getBodyUpDirection() * chatMessageHeight; glTranslatef(chatPosition.x, chatPosition.y, chatPosition.z); glm::quat chatRotation = Application::getInstance()->getCamera()->getRotation(); glm::vec3 chatAxis = glm::axis(chatRotation); @@ -842,25 +894,25 @@ void Avatar::render(bool lookingInMirror) { void Avatar::initializeBodySprings() { for (int b = 0; b < NUM_AVATAR_JOINTS; b++) { - _skeleton.joint[b].springyPosition = _skeleton.joint[b].position; - _skeleton.joint[b].springyVelocity = glm::vec3(0.0f, 0.0f, 0.0f); + _ball[b].position = _skeleton.joint[b].position; + _ball[b].velocity = glm::vec3(0.0f, 0.0f, 0.0f); } } void Avatar::updateBodySprings(float deltaTime) { // Check for a large repositioning, and re-initialize body springs if this has happened const float BEYOND_BODY_SPRING_RANGE = 2.f; - if (glm::length(_position - _skeleton.joint[AVATAR_JOINT_PELVIS].springyPosition) > BEYOND_BODY_SPRING_RANGE) { - _skeleton.initializeBodySprings(); + if (glm::length(_position - _ball[AVATAR_JOINT_PELVIS].position) > BEYOND_BODY_SPRING_RANGE) { + initializeBodySprings(); } for (int b = 0; b < NUM_AVATAR_JOINTS; b++) { - glm::vec3 springVector(_skeleton.joint[b].springyPosition); + glm::vec3 springVector(_ball[b].position); if (_skeleton.joint[b].parent == AVATAR_JOINT_NULL) { springVector -= _position; } else { - springVector -= _skeleton.joint[ _skeleton.joint[b].parent ].springyPosition; + springVector -= _ball[ _skeleton.joint[b].parent ].position; } float length = glm::length(springVector); @@ -869,23 +921,23 @@ void Avatar::updateBodySprings(float deltaTime) { glm::vec3 springDirection = springVector / length; float force = (length - _skeleton.joint[b].length) * BODY_SPRING_FORCE * deltaTime; - _skeleton.joint[b].springyVelocity -= springDirection * force; + _ball[b].velocity -= springDirection * force; if (_skeleton.joint[b].parent != AVATAR_JOINT_NULL) { - _skeleton.joint[_skeleton.joint[b].parent].springyVelocity += springDirection * force; + _ball[_skeleton.joint[b].parent].velocity += springDirection * force; } } // apply tightness force - (causing springy position to be close to rigid body position) - _skeleton.joint[b].springyVelocity += (_skeleton.joint[b].position - _skeleton.joint[b].springyPosition) * _skeleton.joint[b].springBodyTightness * deltaTime; + _ball[b].velocity += (_skeleton.joint[b].position - _ball[b].position) * _ball[b].jointTightness * deltaTime; // apply decay float decay = 1.0 - BODY_SPRING_DECAY * deltaTime; if (decay > 0.0) { - _skeleton.joint[b].springyVelocity *= decay; + _ball[b].velocity *= decay; } else { - _skeleton.joint[b].springyVelocity = glm::vec3(0.0f, 0.0f, 0.0f); + _ball[b].velocity = glm::vec3(0.0f, 0.0f, 0.0f); } /* @@ -896,7 +948,7 @@ void Avatar::updateBodySprings(float deltaTime) { */ //update position by velocity... - _skeleton.joint[b].springyPosition += _skeleton.joint[b].springyVelocity * deltaTime; + _ball[b].position += _ball[b].velocity * deltaTime; } } @@ -981,21 +1033,21 @@ void Avatar::renderBody(bool lookingInMirror) { if (_owningAgent || b == AVATAR_JOINT_RIGHT_ELBOW || b == AVATAR_JOINT_RIGHT_WRIST || b == AVATAR_JOINT_RIGHT_FINGERTIPS ) { - glColor3f(SKIN_COLOR[0] + _skeleton.joint[b].touchForce * 0.3f, - SKIN_COLOR[1] - _skeleton.joint[b].touchForce * 0.2f, - SKIN_COLOR[2] - _skeleton.joint[b].touchForce * 0.1f); + glColor3f(SKIN_COLOR[0] + _ball[b].touchForce * 0.3f, + SKIN_COLOR[1] - _ball[b].touchForce * 0.2f, + SKIN_COLOR[2] - _ball[b].touchForce * 0.1f); } else { - glColor4f(SKIN_COLOR[0] + _skeleton.joint[b].touchForce * 0.3f, - SKIN_COLOR[1] - _skeleton.joint[b].touchForce * 0.2f, - SKIN_COLOR[2] - _skeleton.joint[b].touchForce * 0.1f, + glColor4f(SKIN_COLOR[0] + _ball[b].touchForce * 0.3f, + SKIN_COLOR[1] - _ball[b].touchForce * 0.2f, + SKIN_COLOR[2] - _ball[b].touchForce * 0.1f, alpha); } if ((b != AVATAR_JOINT_HEAD_TOP ) && (b != AVATAR_JOINT_HEAD_BASE )) { glPushMatrix(); - glTranslatef(_skeleton.joint[b].springyPosition.x, _skeleton.joint[b].springyPosition.y, _skeleton.joint[b].springyPosition.z); - glutSolidSphere(_skeleton.joint[b].radius, 20.0f, 20.0f); + glTranslatef(_ball[b].position.x, _ball[b].position.y, _ball[b].position.z); + glutSolidSphere(_ball[b].radius, 20.0f, 20.0f); glPopMatrix(); } @@ -1012,15 +1064,15 @@ void Avatar::renderBody(bool lookingInMirror) { && (b != AVATAR_JOINT_RIGHT_SHOULDER)) { glColor3fv(DARK_SKIN_COLOR); - float r1 = _skeleton.joint[_skeleton.joint[b].parent ].radius * 0.8; - float r2 = _skeleton.joint[b ].radius * 0.8; + float r1 = _ball[_skeleton.joint[b].parent ].radius * 0.8; + float r2 = _ball[b ].radius * 0.8; if (b == AVATAR_JOINT_HEAD_BASE) { r1 *= 0.5f; } renderJointConnectingCone ( - _skeleton.joint[_skeleton.joint[b].parent ].springyPosition, - _skeleton.joint[b ].springyPosition, r2, r2 + _ball[_skeleton.joint[b].parent ].position, + _ball[b ].position, r2, r2 ); } } diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index 5cc7d66f8b..462cb1bb12 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -69,8 +69,8 @@ public: float getBodyYaw () const { return _bodyYaw;} bool getIsNearInteractingOther() const { return _avatarTouch.getAbleToReachOtherAvatar();} const glm::vec3& getHeadPosition () const { return _skeleton.joint[ AVATAR_JOINT_HEAD_BASE ].position;} - const glm::vec3& getSpringyHeadPosition () const { return _skeleton.joint[ AVATAR_JOINT_HEAD_BASE ].springyPosition;} - const glm::vec3& getJointPosition (AvatarJointID j) const { return _skeleton.joint[j].springyPosition;} + const glm::vec3& getSpringyHeadPosition () const { return _ball[ AVATAR_JOINT_HEAD_BASE ].position;} + const glm::vec3& getJointPosition (AvatarJointID j) const { return _ball[j].position;} glm::vec3 getBodyRightDirection () const { return getOrientation() * AVATAR_RIGHT; } glm::vec3 getBodyUpDirection () const { return getOrientation() * AVATAR_UP; } @@ -104,22 +104,15 @@ private: Avatar(const Avatar&); Avatar& operator= (const Avatar&); -/* - struct AvatarJoint + struct AvatarBall { - AvatarJointID parent; // which joint is this joint connected to? - glm::vec3 position; // the position at the "end" of the joint - in global space - glm::vec3 defaultPosePosition; // the parent relative position when the avatar is in the "T-pose" - glm::vec3 springyPosition; // used for special effects (a 'flexible' variant of position) - glm::vec3 springyVelocity; // used for special effects ( the velocity of the springy position) - float springBodyTightness; // how tightly the springy position tries to stay on the position - glm::quat orientation; // this will eventually replace yaw, pitch and roll (and maybe orientation) - float length; // the length of vector connecting the joint and its parent - float radius; // used for detecting collisions for certain physical effects - bool isCollidable; // when false, the joint position will not register a collision - float touchForce; // if being touched, what's the degree of influence? (0 to 1) + glm::vec3 position; + glm::vec3 velocity; + float jointTightness; + float radius; + bool isCollidable; + float touchForce; }; -*/ Head _head; Skeleton _skeleton; @@ -131,7 +124,7 @@ private: float _bodyRollDelta; glm::vec3 _movedHandOffset; glm::quat _rotation; // the rotation of the avatar body as a whole expressed as a quaternion - //AvatarJoint _joint[ NUM_AVATAR_JOINTS ]; + AvatarBall _ball[ NUM_AVATAR_JOINTS ]; AvatarMode _mode; glm::vec3 _cameraPosition; glm::vec3 _handHoldingPosition; @@ -159,7 +152,8 @@ private: glm::vec3 caclulateAverageEyePosition() { return _head.caclulateAverageEyePosition(); } // get the position smack-dab between the eyes (for lookat) glm::quat computeRotationFromBodyToWorldUp(float proportion = 1.0f) const; void renderBody(bool lookingInMirror); - void initializeSkeleton(); + //void initializeSkeleton(); + void initializeBalls(); void initializeBodySprings(); void updateBodySprings( float deltaTime ); void calculateBoneLengths(); diff --git a/interface/src/Skeleton.cpp b/interface/src/Skeleton.cpp index 78c40986af..97dded3254 100644 --- a/interface/src/Skeleton.cpp +++ b/interface/src/Skeleton.cpp @@ -15,17 +15,11 @@ Skeleton::Skeleton() { void Skeleton::initialize() { for (int b=0; b Date: Fri, 31 May 2013 16:58:58 -0700 Subject: [PATCH 13/14] cleanup --- interface/src/Avatar.cpp | 4 ++-- interface/src/Avatar.h | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 61974dd9b1..acf71db0b1 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -892,7 +892,7 @@ void Avatar::render(bool lookingInMirror) { } } -void Avatar::initializeBodySprings() { +void Avatar::resetBodySprings() { for (int b = 0; b < NUM_AVATAR_JOINTS; b++) { _ball[b].position = _skeleton.joint[b].position; _ball[b].velocity = glm::vec3(0.0f, 0.0f, 0.0f); @@ -903,7 +903,7 @@ void Avatar::updateBodySprings(float deltaTime) { // Check for a large repositioning, and re-initialize body springs if this has happened const float BEYOND_BODY_SPRING_RANGE = 2.f; if (glm::length(_position - _ball[AVATAR_JOINT_PELVIS].position) > BEYOND_BODY_SPRING_RANGE) { - initializeBodySprings(); + resetBodySprings(); } for (int b = 0; b < NUM_AVATAR_JOINTS; b++) { glm::vec3 springVector(_ball[b].position); diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index 462cb1bb12..b775de15e7 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -152,9 +152,8 @@ private: glm::vec3 caclulateAverageEyePosition() { return _head.caclulateAverageEyePosition(); } // get the position smack-dab between the eyes (for lookat) glm::quat computeRotationFromBodyToWorldUp(float proportion = 1.0f) const; void renderBody(bool lookingInMirror); - //void initializeSkeleton(); void initializeBalls(); - void initializeBodySprings(); + void resetBodySprings(); void updateBodySprings( float deltaTime ); void calculateBoneLengths(); void readSensors(); From de49d7fc6c63b33d81a7038807e66b92332cfd89 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Fri, 31 May 2013 17:32:30 -0700 Subject: [PATCH 14/14] more fixes --- interface/src/Avatar.cpp | 202 +++++++++++++++++----------------- interface/src/Avatar.h | 12 +- interface/src/AvatarTouch.cpp | 10 +- interface/src/Skeleton.cpp | 5 +- 4 files changed, 115 insertions(+), 114 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index acf71db0b1..46a4d302ca 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -99,12 +99,12 @@ Avatar::Avatar(Agent* owningAgent) : _skeleton.initialize(); - initializeBalls(); + initializeBodyBalls(); - _height = _skeleton.getHeight() + _ball[ AVATAR_JOINT_LEFT_HEEL ].radius + _ball[ AVATAR_JOINT_HEAD_BASE ].radius; + _height = _skeleton.getHeight() + _bodyBall[ AVATAR_JOINT_LEFT_HEEL ].radius + _bodyBall[ AVATAR_JOINT_HEAD_BASE ].radius; _maxArmLength = _skeleton.getArmLength(); - _pelvisStandingHeight = _skeleton.getPelvisStandingHeight() + _ball[ AVATAR_JOINT_LEFT_HEEL ].radius; - _pelvisFloatingHeight = _skeleton.getPelvisFloatingHeight() + _ball[ AVATAR_JOINT_LEFT_HEEL ].radius; + _pelvisStandingHeight = _skeleton.getPelvisStandingHeight() + _bodyBall[ AVATAR_JOINT_LEFT_HEEL ].radius; + _pelvisFloatingHeight = _skeleton.getPelvisFloatingHeight() + _bodyBall[ AVATAR_JOINT_LEFT_HEEL ].radius; _avatarTouch.setReachableRadius(PERIPERSONAL_RADIUS); @@ -116,51 +116,51 @@ Avatar::Avatar(Agent* owningAgent) : } -void Avatar::initializeBalls() { +void Avatar::initializeBodyBalls() { for (int b=0; b 0.0f) { glm::vec3 headLean = right * _head.getLeanSideways() + front * _head.getLeanForward(); - _ball[ AVATAR_JOINT_TORSO ].position += headLean * 0.1f; - _ball[ AVATAR_JOINT_CHEST ].position += headLean * 0.4f; - _ball[ AVATAR_JOINT_NECK_BASE ].position += headLean * 0.7f; - _ball[ AVATAR_JOINT_HEAD_BASE ].position += headLean * 1.0f; + _bodyBall[ AVATAR_JOINT_TORSO ].position += headLean * 0.1f; + _bodyBall[ AVATAR_JOINT_CHEST ].position += headLean * 0.4f; + _bodyBall[ AVATAR_JOINT_NECK_BASE ].position += headLean * 0.7f; + _bodyBall[ AVATAR_JOINT_HEAD_BASE ].position += headLean * 1.0f; - _ball[ AVATAR_JOINT_LEFT_COLLAR ].position += headLean * 0.6f; - _ball[ AVATAR_JOINT_LEFT_SHOULDER ].position += headLean * 0.6f; - _ball[ AVATAR_JOINT_LEFT_ELBOW ].position += headLean * 0.2f; - _ball[ AVATAR_JOINT_LEFT_WRIST ].position += headLean * 0.1f; - _ball[ AVATAR_JOINT_LEFT_FINGERTIPS ].position += headLean * 0.0f; + _bodyBall[ AVATAR_JOINT_LEFT_COLLAR ].position += headLean * 0.6f; + _bodyBall[ AVATAR_JOINT_LEFT_SHOULDER ].position += headLean * 0.6f; + _bodyBall[ AVATAR_JOINT_LEFT_ELBOW ].position += headLean * 0.2f; + _bodyBall[ AVATAR_JOINT_LEFT_WRIST ].position += headLean * 0.1f; + _bodyBall[ AVATAR_JOINT_LEFT_FINGERTIPS ].position += headLean * 0.0f; - _ball[ AVATAR_JOINT_RIGHT_COLLAR ].position += headLean * 0.6f; - _ball[ AVATAR_JOINT_RIGHT_SHOULDER ].position += headLean * 0.6f; - _ball[ AVATAR_JOINT_RIGHT_ELBOW ].position += headLean * 0.2f; - _ball[ AVATAR_JOINT_RIGHT_WRIST ].position += headLean * 0.1f; - _ball[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position += headLean * 0.0f; + _bodyBall[ AVATAR_JOINT_RIGHT_COLLAR ].position += headLean * 0.6f; + _bodyBall[ AVATAR_JOINT_RIGHT_SHOULDER ].position += headLean * 0.6f; + _bodyBall[ AVATAR_JOINT_RIGHT_ELBOW ].position += headLean * 0.2f; + _bodyBall[ AVATAR_JOINT_RIGHT_WRIST ].position += headLean * 0.1f; + _bodyBall[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position += headLean * 0.0f; } } @@ -485,8 +485,8 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) { } _head.setBodyRotation (glm::vec3(_bodyPitch, _bodyYaw, _bodyRoll)); - _head.setPosition(_ball[ AVATAR_JOINT_HEAD_BASE ].position); - _head.setScale (_ball[ AVATAR_JOINT_HEAD_BASE ].radius); + _head.setPosition(_bodyBall[ AVATAR_JOINT_HEAD_BASE ].position); + _head.setScale (_bodyBall[ AVATAR_JOINT_HEAD_BASE ].radius); _head.setSkinColor(glm::vec3(SKIN_COLOR[0], SKIN_COLOR[1], SKIN_COLOR[2])); _head.simulate(deltaTime, !_owningAgent); @@ -502,15 +502,15 @@ void Avatar::checkForMouseRayTouching() { for (int b = 0; b < NUM_AVATAR_JOINTS; b++) { - glm::vec3 directionToBodySphere = glm::normalize(_ball[b].position - _mouseRayOrigin); + glm::vec3 directionToBodySphere = glm::normalize(_bodyBall[b].position - _mouseRayOrigin); float dot = glm::dot(directionToBodySphere, _mouseRayDirection); - float range = _ball[b].radius * JOINT_TOUCH_RANGE; + float range = _bodyBall[b].radius * JOINT_TOUCH_RANGE; if (dot > (1.0f - range)) { - _ball[b].touchForce = (dot - (1.0f - range)) / range; + _bodyBall[b].touchForce = (dot - (1.0f - range)) / range; } else { - _ball[b].touchForce = 0.0; + _bodyBall[b].touchForce = 0.0; } } } @@ -579,7 +579,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { _avatarTouch.setHasInteractingOther(true); _avatarTouch.setYourBodyPosition(_interactingOther->_position); - _avatarTouch.setYourHandPosition(_interactingOther->_ball[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position); + _avatarTouch.setYourHandPosition(_interactingOther->_bodyBall[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position); _avatarTouch.setYourOrientation (_interactingOther->getOrientation()); _avatarTouch.setYourHandState (_interactingOther->_handState); @@ -650,7 +650,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { } _avatarTouch.setMyHandState(_handState); - _avatarTouch.setMyHandPosition(_ball[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position); + _avatarTouch.setMyHandPosition(_bodyBall[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position); } } @@ -662,9 +662,9 @@ void Avatar::updateCollisionWithSphere(glm::vec3 position, float radius, float d float distanceToBigSphere = glm::length(vectorFromMyBodyToBigSphere); if (distanceToBigSphere < myBodyApproximateBoundingRadius + radius) { for (int b = 0; b < NUM_AVATAR_JOINTS; b++) { - glm::vec3 vectorFromJointToBigSphereCenter(_ball[b].position - position); + glm::vec3 vectorFromJointToBigSphereCenter(_bodyBall[b].position - position); float distanceToBigSphereCenter = glm::length(vectorFromJointToBigSphereCenter); - float combinedRadius = _ball[b].radius + radius; + float combinedRadius = _bodyBall[b].radius + radius; if (distanceToBigSphereCenter < combinedRadius) { jointCollision = true; @@ -674,9 +674,9 @@ void Avatar::updateCollisionWithSphere(glm::vec3 position, float radius, float d float penetration = 1.0 - (distanceToBigSphereCenter / combinedRadius); glm::vec3 collisionForce = vectorFromJointToBigSphereCenter * penetration; - _ball[b].velocity += collisionForce * 0.0f * deltaTime; + _bodyBall[b].velocity += collisionForce * 0.0f * deltaTime; _velocity += collisionForce * 40.0f * deltaTime; - _ball[b].position = position + directionVector * combinedRadius; + _bodyBall[b].position = position + directionVector * combinedRadius; } } } @@ -762,16 +762,16 @@ void Avatar::applyCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime // loop through the joints of each avatar to check for every possible collision for (int b=1; b_ball[o].isCollidable) { + if (otherAvatar->_bodyBall[o].isCollidable) { - glm::vec3 vectorBetweenJoints(_ball[b].position - otherAvatar->_ball[o].position); + glm::vec3 vectorBetweenJoints(_bodyBall[b].position - otherAvatar->_bodyBall[o].position); float distanceBetweenJoints = glm::length(vectorBetweenJoints); if (distanceBetweenJoints > 0.0) { // to avoid divide by zero - float combinedRadius = _ball[b].radius + otherAvatar->_ball[o].radius; + float combinedRadius = _bodyBall[b].radius + otherAvatar->_bodyBall[o].radius; // check for collision if (distanceBetweenJoints < combinedRadius * COLLISION_RADIUS_SCALAR) { @@ -783,8 +783,8 @@ void Avatar::applyCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime glm::vec3 ballPushForce = directionVector * COLLISION_BALL_FORCE * penetration * deltaTime; bodyPushForce += directionVector * COLLISION_BODY_FORCE * penetration * deltaTime; - _ball[b].velocity += ballPushForce; - otherAvatar->_ball[o].velocity -= ballPushForce; + _bodyBall[b].velocity += ballPushForce; + otherAvatar->_bodyBall[o].velocity -= ballPushForce; }// check for collision } // to avoid divide by zero @@ -857,7 +857,7 @@ void Avatar::render(bool lookingInMirror) { } glPushMatrix(); - glm::vec3 chatPosition = _ball[AVATAR_JOINT_HEAD_BASE].position + getBodyUpDirection() * chatMessageHeight; + glm::vec3 chatPosition = _bodyBall[AVATAR_JOINT_HEAD_BASE].position + getBodyUpDirection() * chatMessageHeight; glTranslatef(chatPosition.x, chatPosition.y, chatPosition.z); glm::quat chatRotation = Application::getInstance()->getCamera()->getRotation(); glm::vec3 chatAxis = glm::axis(chatRotation); @@ -892,27 +892,27 @@ void Avatar::render(bool lookingInMirror) { } } -void Avatar::resetBodySprings() { +void Avatar::resetBodyBalls() { for (int b = 0; b < NUM_AVATAR_JOINTS; b++) { - _ball[b].position = _skeleton.joint[b].position; - _ball[b].velocity = glm::vec3(0.0f, 0.0f, 0.0f); + _bodyBall[b].position = _skeleton.joint[b].position; + _bodyBall[b].velocity = glm::vec3(0.0f, 0.0f, 0.0f); } } -void Avatar::updateBodySprings(float deltaTime) { - // Check for a large repositioning, and re-initialize body springs if this has happened +void Avatar::updateBodyBalls(float deltaTime) { + // Check for a large repositioning, and re-initialize balls if this has happened const float BEYOND_BODY_SPRING_RANGE = 2.f; - if (glm::length(_position - _ball[AVATAR_JOINT_PELVIS].position) > BEYOND_BODY_SPRING_RANGE) { - resetBodySprings(); + if (glm::length(_position - _bodyBall[AVATAR_JOINT_PELVIS].position) > BEYOND_BODY_SPRING_RANGE) { + resetBodyBalls(); } for (int b = 0; b < NUM_AVATAR_JOINTS; b++) { - glm::vec3 springVector(_ball[b].position); + glm::vec3 springVector(_bodyBall[b].position); if (_skeleton.joint[b].parent == AVATAR_JOINT_NULL) { springVector -= _position; } else { - springVector -= _ball[ _skeleton.joint[b].parent ].position; + springVector -= _bodyBall[ _skeleton.joint[b].parent ].position; } float length = glm::length(springVector); @@ -921,23 +921,23 @@ void Avatar::updateBodySprings(float deltaTime) { glm::vec3 springDirection = springVector / length; float force = (length - _skeleton.joint[b].length) * BODY_SPRING_FORCE * deltaTime; - _ball[b].velocity -= springDirection * force; + _bodyBall[b].velocity -= springDirection * force; if (_skeleton.joint[b].parent != AVATAR_JOINT_NULL) { - _ball[_skeleton.joint[b].parent].velocity += springDirection * force; + _bodyBall[_skeleton.joint[b].parent].velocity += springDirection * force; } } - // apply tightness force - (causing springy position to be close to rigid body position) - _ball[b].velocity += (_skeleton.joint[b].position - _ball[b].position) * _ball[b].jointTightness * deltaTime; + // apply tightness force - (causing ball position to be close to skeleton joint position) + _bodyBall[b].velocity += (_skeleton.joint[b].position - _bodyBall[b].position) * _bodyBall[b].jointTightness * deltaTime; // apply decay float decay = 1.0 - BODY_SPRING_DECAY * deltaTime; if (decay > 0.0) { - _ball[b].velocity *= decay; + _bodyBall[b].velocity *= decay; } else { - _ball[b].velocity = glm::vec3(0.0f, 0.0f, 0.0f); + _bodyBall[b].velocity = glm::vec3(0.0f, 0.0f, 0.0f); } /* @@ -948,7 +948,7 @@ void Avatar::updateBodySprings(float deltaTime) { */ //update position by velocity... - _ball[b].position += _ball[b].velocity * deltaTime; + _bodyBall[b].position += _bodyBall[b].velocity * deltaTime; } } @@ -1033,21 +1033,21 @@ void Avatar::renderBody(bool lookingInMirror) { if (_owningAgent || b == AVATAR_JOINT_RIGHT_ELBOW || b == AVATAR_JOINT_RIGHT_WRIST || b == AVATAR_JOINT_RIGHT_FINGERTIPS ) { - glColor3f(SKIN_COLOR[0] + _ball[b].touchForce * 0.3f, - SKIN_COLOR[1] - _ball[b].touchForce * 0.2f, - SKIN_COLOR[2] - _ball[b].touchForce * 0.1f); + glColor3f(SKIN_COLOR[0] + _bodyBall[b].touchForce * 0.3f, + SKIN_COLOR[1] - _bodyBall[b].touchForce * 0.2f, + SKIN_COLOR[2] - _bodyBall[b].touchForce * 0.1f); } else { - glColor4f(SKIN_COLOR[0] + _ball[b].touchForce * 0.3f, - SKIN_COLOR[1] - _ball[b].touchForce * 0.2f, - SKIN_COLOR[2] - _ball[b].touchForce * 0.1f, + glColor4f(SKIN_COLOR[0] + _bodyBall[b].touchForce * 0.3f, + SKIN_COLOR[1] - _bodyBall[b].touchForce * 0.2f, + SKIN_COLOR[2] - _bodyBall[b].touchForce * 0.1f, alpha); } if ((b != AVATAR_JOINT_HEAD_TOP ) && (b != AVATAR_JOINT_HEAD_BASE )) { glPushMatrix(); - glTranslatef(_ball[b].position.x, _ball[b].position.y, _ball[b].position.z); - glutSolidSphere(_ball[b].radius, 20.0f, 20.0f); + glTranslatef(_bodyBall[b].position.x, _bodyBall[b].position.y, _bodyBall[b].position.z); + glutSolidSphere(_bodyBall[b].radius, 20.0f, 20.0f); glPopMatrix(); } @@ -1064,15 +1064,15 @@ void Avatar::renderBody(bool lookingInMirror) { && (b != AVATAR_JOINT_RIGHT_SHOULDER)) { glColor3fv(DARK_SKIN_COLOR); - float r1 = _ball[_skeleton.joint[b].parent ].radius * 0.8; - float r2 = _ball[b ].radius * 0.8; + float r1 = _bodyBall[_skeleton.joint[b].parent ].radius * 0.8; + float r2 = _bodyBall[b ].radius * 0.8; if (b == AVATAR_JOINT_HEAD_BASE) { r1 *= 0.5f; } renderJointConnectingCone ( - _ball[_skeleton.joint[b].parent ].position, - _ball[b ].position, r2, r2 + _bodyBall[_skeleton.joint[b].parent ].position, + _bodyBall[b ].position, r2, r2 ); } } diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index b775de15e7..6746ba51cd 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -69,8 +69,8 @@ public: float getBodyYaw () const { return _bodyYaw;} bool getIsNearInteractingOther() const { return _avatarTouch.getAbleToReachOtherAvatar();} const glm::vec3& getHeadPosition () const { return _skeleton.joint[ AVATAR_JOINT_HEAD_BASE ].position;} - const glm::vec3& getSpringyHeadPosition () const { return _ball[ AVATAR_JOINT_HEAD_BASE ].position;} - const glm::vec3& getJointPosition (AvatarJointID j) const { return _ball[j].position;} + const glm::vec3& getSpringyHeadPosition () const { return _bodyBall[ AVATAR_JOINT_HEAD_BASE ].position;} + const glm::vec3& getJointPosition (AvatarJointID j) const { return _bodyBall[j].position;} glm::vec3 getBodyRightDirection () const { return getOrientation() * AVATAR_RIGHT; } glm::vec3 getBodyUpDirection () const { return getOrientation() * AVATAR_UP; } @@ -124,7 +124,7 @@ private: float _bodyRollDelta; glm::vec3 _movedHandOffset; glm::quat _rotation; // the rotation of the avatar body as a whole expressed as a quaternion - AvatarBall _ball[ NUM_AVATAR_JOINTS ]; + AvatarBall _bodyBall[ NUM_AVATAR_JOINTS ]; AvatarMode _mode; glm::vec3 _cameraPosition; glm::vec3 _handHoldingPosition; @@ -152,9 +152,9 @@ private: glm::vec3 caclulateAverageEyePosition() { return _head.caclulateAverageEyePosition(); } // get the position smack-dab between the eyes (for lookat) glm::quat computeRotationFromBodyToWorldUp(float proportion = 1.0f) const; void renderBody(bool lookingInMirror); - void initializeBalls(); - void resetBodySprings(); - void updateBodySprings( float deltaTime ); + void initializeBodyBalls(); + void resetBodyBalls(); + void updateBodyBalls( float deltaTime ); void calculateBoneLengths(); void readSensors(); void updateHandMovementAndTouching(float deltaTime); diff --git a/interface/src/AvatarTouch.cpp b/interface/src/AvatarTouch.cpp index 6f7456dd09..1e06663b01 100644 --- a/interface/src/AvatarTouch.cpp +++ b/interface/src/AvatarTouch.cpp @@ -43,6 +43,10 @@ void AvatarTouch::simulate (float deltaTime) { glm::vec3 vectorBetweenBodies = _yourBodyPosition - _myBodyPosition; float distanceBetweenBodies = glm::length(vectorBetweenBodies); + + //KEEP THIS - it is another variation that we are considering getting rid of + //the following code take into account of the two avatars are facing each other + /* glm::vec3 directionBetweenBodies = vectorBetweenBodies / distanceBetweenBodies; bool facingEachOther = false; @@ -50,13 +54,13 @@ void AvatarTouch::simulate (float deltaTime) { glm::vec3 myFront = _myOrientation * AVATAR_FRONT; glm::vec3 yourFront = _yourOrientation * AVATAR_FRONT; - if (( glm::dot(myFront, yourFront) < -AVATAR_FACING_THRESHOLD) // we're facing each other - && ( glm::dot(myFront, directionBetweenBodies ) > AVATAR_FACING_THRESHOLD)) { // I'm facing you + if (( glm::dot(myFront, yourFront ) < -AVATAR_FACING_THRESHOLD) // we're facing each other + && ( glm::dot(myFront, directionBetweenBodies ) > AVATAR_FACING_THRESHOLD)) { // I'm facing you facingEachOther = true; } + */ if (distanceBetweenBodies < _reachableRadius) - //&& (facingEachOther)) { _canReachToOtherAvatar = true; diff --git a/interface/src/Skeleton.cpp b/interface/src/Skeleton.cpp index 97dded3254..64a8645247 100644 --- a/interface/src/Skeleton.cpp +++ b/interface/src/Skeleton.cpp @@ -83,10 +83,9 @@ void Skeleton::initialize() { } } - +// calculate positions and rotations of all bones by traversing the skeleton tree: void Skeleton::update(float deltaTime, const glm::quat& orientation, glm::vec3 position) { - // calculate positions of all bones by traversing the skeleton tree: for (int b = 0; b < NUM_AVATAR_JOINTS; b++) { if (joint[b].parent == AVATAR_JOINT_NULL) { joint[b].rotation = orientation; @@ -97,9 +96,7 @@ void Skeleton::update(float deltaTime, const glm::quat& orientation, glm::vec3 p joint[b].position = joint[ joint[b].parent ].position; } - // the following will be replaced by a proper rotation...close glm::vec3 rotatedJointVector = joint[b].rotation * joint[b].defaultPosePosition; - joint[b].position += rotatedJointVector; } }