From 8f969f9ca9c96132c6debbed354b06b52d9b3b87 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Wed, 10 Apr 2013 01:03:35 -0700 Subject: [PATCH] adding ground plane grid (again???) --- interface/src/Head.cpp | 278 ++++++++++++++++++++++++++--------------- interface/src/Head.h | 8 +- 2 files changed, 185 insertions(+), 101 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index d06f35cc39..13f30084bc 100755 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -19,6 +19,7 @@ using namespace std; float skinColor[] = {1.0, 0.84, 0.66}; +float lightBlue[] = { 0.7, 0.8, 1.0 }; float browColor[] = {210.0/255.0, 105.0/255.0, 30.0/255.0}; float mouthColor[] = {1, 0, 0}; @@ -502,9 +503,9 @@ void Head::renderHead( int faceToFace, int isMine ) glTranslatef ( - avatar.bone[ AVATAR_BONE_HEAD ].worldPosition.x, - avatar.bone[ AVATAR_BONE_HEAD ].worldPosition.y, - avatar.bone[ AVATAR_BONE_HEAD ].worldPosition.z + avatar.bone[ AVATAR_BONE_HEAD ].position.x, + avatar.bone[ AVATAR_BONE_HEAD ].position.y, + avatar.bone[ AVATAR_BONE_HEAD ].position.z ); glScalef( 0.03, 0.03, 0.03 ); @@ -669,9 +670,9 @@ void Head::setHandMovement( glm::vec3 movement ) //----------------------------------------- void Head::initializeAvatar() { - avatar.position = glm::vec3( 0.0, 0.0, 0.0 ); - avatar.velocity = glm::vec3( 0.0, 0.0, 0.0 ); - avatar.thrust = glm::vec3( 0.0, 0.0, 0.0 ); + avatar.position = glm::vec3( 0.0, 0.0, 0.0 ); + avatar.velocity = glm::vec3( 0.0, 0.0, 0.0 ); + avatar.thrust = glm::vec3( 0.0, 0.0, 0.0 ); avatar.orientation.setToIdentity(); avatar.yaw = 90.0; @@ -682,9 +683,10 @@ void Head::initializeAvatar() for (int b=0; b avatar.maxArmLength ) { - avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].worldPosition += v * 0.2; + avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position += v * 0.2; } */ @@ -878,7 +885,7 @@ void Head::updateAvatarSkeleton() //------------------------------------------------------------------------ for (int b=0; b 0.0f ) + { + glm::vec3 springDirection = springVector / length; + + float force = ( length - avatar.bone[b].length ) * 0.01; + + avatar.bone[ b ].springyVelocity -= springDirection * force; + avatar.bone[ avatar.bone[b].parent ].springyVelocity += springDirection * force; + } + + avatar.bone[b].springyVelocity += ( avatar.bone[b].position - avatar.bone[b].springyPosition ) * 0.01f; + avatar.bone[b].springyVelocity *= 0.8; + avatar.bone[b].springyPosition += avatar.bone[b].springyVelocity; + } + } +} + + //------------------------------- float Head::getAvatarYaw() { @@ -901,9 +955,9 @@ glm::vec3 Head::getAvatarHeadLookatDirection() { return glm::vec3 ( - avatar.bone[ AVATAR_BONE_HEAD ].worldOrientation.getFront().x, - avatar.bone[ AVATAR_BONE_HEAD ].worldOrientation.getFront().y, - avatar.bone[ AVATAR_BONE_HEAD ].worldOrientation.getFront().z + avatar.bone[ AVATAR_BONE_HEAD ].orientation.getFront().x, + avatar.bone[ AVATAR_BONE_HEAD ].orientation.getFront().y, + avatar.bone[ AVATAR_BONE_HEAD ].orientation.getFront().z ); } @@ -915,9 +969,9 @@ void Head::updateHandMovement() //---------------------------------------------------------------- // adjust right hand and elbow according to hand offset //---------------------------------------------------------------- - avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition += handOffset; - glm::vec3 armVector = avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition; - armVector -= avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].worldPosition; + avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position += handOffset; + glm::vec3 armVector = avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position; + armVector -= avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; //------------------------------------------------------------------------------- // test to see if right hand is being dragged beyond maximum arm length @@ -932,32 +986,32 @@ void Head::updateHandMovement() //------------------------------------------------------------------------------- // reset right hand to be constrained to maximum arm length //------------------------------------------------------------------------------- - avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition = avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].worldPosition; + avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position = avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; glm::vec3 armNormal = armVector / distance; armVector = armNormal * (float)avatar.maxArmLength; distance = avatar.maxArmLength; - glm::vec3 constrainedPosition = avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].worldPosition; + glm::vec3 constrainedPosition = avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; constrainedPosition += armVector; - avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition = constrainedPosition; + avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position = constrainedPosition; } //----------------------------------------------------------------------------- // set elbow position //----------------------------------------------------------------------------- - glm::vec3 newElbowPosition = avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].worldPosition; + glm::vec3 newElbowPosition = avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; newElbowPosition += armVector * (float)ONE_HALF; glm::vec3 perpendicular = glm::vec3( -armVector.y, armVector.x, armVector.z ); newElbowPosition += perpendicular * (float)( ( 1.0 - ( avatar.maxArmLength / distance ) ) * ONE_HALF ); - avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].worldPosition = newElbowPosition; + avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position = newElbowPosition; //----------------------------------------------------------------------------- // set wrist position //----------------------------------------------------------------------------- - glm::vec3 vv( avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition ); - vv -= avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].worldPosition; - glm::vec3 newWristPosition = avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].worldPosition; + glm::vec3 vv( avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position ); + vv -= avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position; + glm::vec3 newWristPosition = avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position; newWristPosition += vv * 0.7f; - avatar.bone[ AVATAR_BONE_RIGHT_FOREARM ].worldPosition = newWristPosition; + avatar.bone[ AVATAR_BONE_RIGHT_FOREARM ].position = newWristPosition; } @@ -966,68 +1020,96 @@ void Head::updateHandMovement() //----------------------------------------- void Head::renderBody() { - glColor3fv(skinColor); - //----------------------------------------- - // Render bones as spheres + // Render bone positions as spheres //----------------------------------------- for (int b=0; bgetPos().x, hand->getPos().y, hand->getPos().z); //previous to Ventrella change - avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition.x, - avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition.y, - avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition.z ); // Ventrella change + avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position.x, + avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position.y, + avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position.z ); // Ventrella change return strlen(data); } @@ -1058,7 +1140,7 @@ int Head::getBroadcastData(char* data) //--------------------------------------------------- void Head::parseData(void *data, int size) { - //glm::vec3 pos;//( (glm::vec3)avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition ); + //glm::vec3 pos;//( (glm::vec3)avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position ); // parse head data for this agent glm::vec3 handPos( 0,0,0 ); @@ -1069,9 +1151,9 @@ void Head::parseData(void *data, int size) &Pitch, &Yaw, &Roll, &position.x, &position.y, &position.z, &loudness, &averageLoudness, - &avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition.x, - &avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition.y, - &avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition.z + &avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position.x, + &avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position.y, + &avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position.z ); if (glm::length(handPos) > 0.0) hand->setPos(handPos); diff --git a/interface/src/Head.h b/interface/src/Head.h index bf8318ef61..74c69492a9 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -104,13 +104,14 @@ enum AvatarBones struct AvatarBone { AvatarBones parent; // which bone is this bone connected to? - glm::vec3 worldPosition; // the position at the "end" of the bone + glm::vec3 position; // the position at the "end" of the bone glm::vec3 defaultPosePosition; // the parent relative position when the avatar is in the "T-pose" - glm::dvec3 velocity; // pertains to spring physics + glm::vec3 springyPosition; // used for special effects (a 'flexible' variant of position) + glm::dvec3 springyVelocity; // used for special effects ( the velocity of the springy position) float yaw; // the yaw Euler angle of the bone rotation off the parent float pitch; // the pitch Euler angle of the bone rotation off the parent float roll; // the roll Euler angle of the bone rotation off the parent - Orientation worldOrientation; // three orthogonal normals determined by yaw, pitch, roll + Orientation orientation; // three orthogonal normals determined by yaw, pitch, roll float length; // the length of the bone }; @@ -246,6 +247,7 @@ class Head : public AgentData { void initializeAvatar(); void updateAvatarSkeleton(); + void updateAvatarSprings(); void calculateBoneLengths(); void readSensors();