Merge branch 'master' of git://github.com/worklist/hifi into 19188

This commit is contained in:
tosh 2013-04-18 00:18:38 +02:00
commit 3175ba7d45
6 changed files with 288 additions and 287 deletions

View file

@ -45,29 +45,24 @@ vector<unsigned char> iris_texture;
unsigned int iris_texture_width = 512; unsigned int iris_texture_width = 512;
unsigned int iris_texture_height = 256; unsigned int iris_texture_height = 256;
Head::Head() { Head::Head(bool isMine) {
initializeAvatar(); initializeAvatar();
_avatar.orientation.setToIdentity();
avatar.velocity = 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.thrust = glm::vec3( 0.0, 0.0, 0.0 );
avatar.orientation.setToIdentity(); _rotation = glm::quat( 0.0f, 0.0f, 0.0f, 0.0f );
_closestOtherAvatar = 0;
closestOtherAvatar = 0; _bodyYaw = -90.0;
_bodyPitch = 0.0;
_bodyYaw = -90.0; _bodyRoll = 0.0;
_bodyPitch = 0.0; _bodyYawDelta = 0.0;
_bodyRoll = 0.0; _triggeringAction = false;
_mode = AVATAR_MODE_STANDING;
bodyYawDelta = 0.0; _isMine = isMine;
triggeringAction = false;
mode = AVATAR_MODE_STANDING;
initializeSkeleton(); initializeSkeleton();
for (int i = 0; i < MAX_DRIVE_KEYS; i++) driveKeys[i] = false; for (int i = 0; i < MAX_DRIVE_KEYS; i++) driveKeys[i] = false;
PupilSize = 0.10; PupilSize = 0.10;
@ -102,17 +97,15 @@ Head::Head() {
browAudioLift = 0.0; browAudioLift = 0.0;
noise = 0; noise = 0;
handBeingMoved = false; _handBeingMoved = false;
previousHandBeingMoved = false; _previousHandBeingMoved = false;
movedHandOffset = glm::vec3( 0.0, 0.0, 0.0 ); _movedHandOffset = glm::vec3( 0.0, 0.0, 0.0 );
_usingSprings = false;
_springForce = 6.0f;
_springVelocityDecay = 16.0f;
sphere = NULL; sphere = NULL;
usingSprings = false;
springForce = 6.0f;
springVelocityDecay = 16.0f;
if (iris_texture.size() == 0) { if (iris_texture.size() == 0) {
switchToResourcesParentIfRequired(); switchToResourcesParentIfRequired();
unsigned error = lodepng::decode(iris_texture, iris_texture_width, iris_texture_height, iris_texture_file); unsigned error = lodepng::decode(iris_texture, iris_texture_width, iris_texture_height, iris_texture_file);
@ -137,30 +130,23 @@ Head::Head() {
} }
Head::Head(const Head &otherHead) { Head::Head(const Head &otherHead) {
initializeAvatar(); initializeAvatar();
avatar.velocity = otherHead.avatar.velocity; _avatar.orientation.set( otherHead._avatar.orientation );
avatar.thrust = otherHead.avatar.thrust; _avatar.velocity = otherHead._avatar.velocity;
avatar.orientation.set( otherHead.avatar.orientation ); _avatar.thrust = otherHead._avatar.thrust;
_rotation = otherHead._rotation;
closestOtherAvatar = otherHead.closestOtherAvatar; _closestOtherAvatar = otherHead._closestOtherAvatar;
_bodyYaw = otherHead._bodyYaw;
_bodyYaw = otherHead._bodyYaw; _bodyPitch = otherHead._bodyPitch;
_bodyPitch = otherHead._bodyPitch; _bodyRoll = otherHead._bodyRoll;
_bodyRoll = otherHead._bodyRoll; _bodyYawDelta = otherHead._bodyYawDelta;
_triggeringAction = otherHead._triggeringAction;
bodyYawDelta = otherHead.bodyYawDelta; _mode = otherHead._mode;
triggeringAction = otherHead.triggeringAction;
mode = otherHead.mode;
initializeSkeleton(); initializeSkeleton();
for (int i = 0; i < MAX_DRIVE_KEYS; i++) driveKeys[i] = otherHead.driveKeys[i]; for (int i = 0; i < MAX_DRIVE_KEYS; i++) driveKeys[i] = otherHead.driveKeys[i];
PupilSize = otherHead.PupilSize; PupilSize = otherHead.PupilSize;
@ -223,7 +209,7 @@ void Head::reset() {
//this pertains to moving the head with the glasses //this pertains to moving the head with the glasses
//--------------------------------------------------- //---------------------------------------------------
void Head::UpdatePos(float frametime, SerialInterface * serialInterface, int head_mirror, glm::vec3 * gravity) void Head::UpdateGyros(float frametime, SerialInterface * serialInterface, int head_mirror, glm::vec3 * gravity)
// Using serial data, update avatar/render position and angles // Using serial data, update avatar/render position and angles
{ {
const float PITCH_ACCEL_COUPLING = 0.5; const float PITCH_ACCEL_COUPLING = 0.5;
@ -283,7 +269,7 @@ void Head::setLeanSideways(float dist){
} }
void Head::setTriggeringAction( bool d ) { void Head::setTriggeringAction( bool d ) {
triggeringAction = d; _triggeringAction = d;
} }
@ -294,7 +280,7 @@ void Head::simulate(float deltaTime) {
// DEBUG - other avatars... // DEBUG - other avatars...
//------------------------------------- //-------------------------------------
//closeEnoughToInteract = 0.3f; //closeEnoughToInteract = 0.3f;
closestOtherAvatar = -1; _closestOtherAvatar = -1;
float closestDistance = 10000.0f; float closestDistance = 10000.0f;
@ -318,15 +304,15 @@ void Head::simulate(float deltaTime) {
//------------------------------------- //-------------------------------------
// test other avs for proximity... // test other avs for proximity...
//------------------------------------- //-------------------------------------
glm::vec3 v( bone[ AVATAR_BONE_RIGHT_SHOULDER ].position ); glm::vec3 v( _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position );
v -= DEBUG_otherAvatarListPosition[o]; v -= DEBUG_otherAvatarListPosition[o];
float distance = glm::length( v ); float distance = glm::length( v );
if ( distance < avatar.maxArmLength ) { if ( distance < _avatar.maxArmLength ) {
if ( distance < closestDistance ) { if ( distance < closestDistance ) {
closestDistance = distance; closestDistance = distance;
closestOtherAvatar = o; _closestOtherAvatar = o;
} }
} }
} }
@ -342,80 +328,80 @@ void Head::simulate(float deltaTime) {
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// reset hand and elbow position according to hand movement // reset hand and elbow position according to hand movement
//------------------------------------------------------------------------ //------------------------------------------------------------------------
if ( handBeingMoved ){ if ( _handBeingMoved ){
if (! previousHandBeingMoved ){ if (! _previousHandBeingMoved ){
initializeBodySprings(); initializeBodySprings();
usingSprings = true; _usingSprings = true;
//printf( "just started moving hand\n" ); //printf( "just started moving hand\n" );
} }
} }
else { else {
if ( previousHandBeingMoved ){ if ( _previousHandBeingMoved ){
usingSprings = false; _usingSprings = false;
//printf( "just stopped moving hand\n" ); //printf( "just stopped moving hand\n" );
} }
} }
if ( handBeingMoved ) { if ( _handBeingMoved ) {
updateHandMovement(); updateHandMovement();
updateBodySprings( deltaTime ); updateBodySprings( deltaTime );
} }
previousHandBeingMoved = handBeingMoved; _previousHandBeingMoved = _handBeingMoved;
handBeingMoved = false; _handBeingMoved = false;
//------------------------------------------------- //-------------------------------------------------
// this handles the avatar being driven around... // this handles the avatar being driven around...
//------------------------------------------------- //-------------------------------------------------
avatar.thrust = glm::vec3( 0.0, 0.0, 0.0 ); _avatar.thrust = glm::vec3( 0.0, 0.0, 0.0 );
if (driveKeys[FWD]) { if (driveKeys[FWD]) {
glm::vec3 front( avatar.orientation.getFront().x, avatar.orientation.getFront().y, avatar.orientation.getFront().z ); glm::vec3 front( _avatar.orientation.getFront().x, _avatar.orientation.getFront().y, _avatar.orientation.getFront().z );
avatar.thrust += front * THRUST_MAG; _avatar.thrust += front * THRUST_MAG;
} }
if (driveKeys[BACK]) { if (driveKeys[BACK]) {
glm::vec3 front( avatar.orientation.getFront().x, avatar.orientation.getFront().y, avatar.orientation.getFront().z ); glm::vec3 front( _avatar.orientation.getFront().x, _avatar.orientation.getFront().y, _avatar.orientation.getFront().z );
avatar.thrust -= front * THRUST_MAG; _avatar.thrust -= front * THRUST_MAG;
} }
if (driveKeys[RIGHT]) { if (driveKeys[RIGHT]) {
glm::vec3 right( avatar.orientation.getRight().x, avatar.orientation.getRight().y, avatar.orientation.getRight().z ); glm::vec3 right( _avatar.orientation.getRight().x, _avatar.orientation.getRight().y, _avatar.orientation.getRight().z );
avatar.thrust -= right * THRUST_MAG; _avatar.thrust -= right * THRUST_MAG;
} }
if (driveKeys[LEFT]) { if (driveKeys[LEFT]) {
glm::vec3 right( avatar.orientation.getRight().x, avatar.orientation.getRight().y, avatar.orientation.getRight().z ); glm::vec3 right( _avatar.orientation.getRight().x, _avatar.orientation.getRight().y, _avatar.orientation.getRight().z );
avatar.thrust += right * THRUST_MAG; _avatar.thrust += right * THRUST_MAG;
} }
if (driveKeys[UP]) { if (driveKeys[UP]) {
glm::vec3 up( avatar.orientation.getUp().x, avatar.orientation.getUp().y, avatar.orientation.getUp().z ); glm::vec3 up( _avatar.orientation.getUp().x, _avatar.orientation.getUp().y, _avatar.orientation.getUp().z );
avatar.thrust += up * THRUST_MAG; _avatar.thrust += up * THRUST_MAG;
} }
if (driveKeys[DOWN]) { if (driveKeys[DOWN]) {
glm::vec3 up( avatar.orientation.getUp().x, avatar.orientation.getUp().y, avatar.orientation.getUp().z ); glm::vec3 up( _avatar.orientation.getUp().x, _avatar.orientation.getUp().y, _avatar.orientation.getUp().z );
avatar.thrust -= up * THRUST_MAG; _avatar.thrust -= up * THRUST_MAG;
} }
if (driveKeys[ROT_RIGHT]) { if (driveKeys[ROT_RIGHT]) {
bodyYawDelta -= YAW_MAG * deltaTime; _bodyYawDelta -= YAW_MAG * deltaTime;
} }
if (driveKeys[ROT_LEFT]) { if (driveKeys[ROT_LEFT]) {
bodyYawDelta += YAW_MAG * deltaTime; _bodyYawDelta += YAW_MAG * deltaTime;
} }
//---------------------------------------------------------- //----------------------------------------------------------
float translationalSpeed = glm::length( avatar.velocity ); float translationalSpeed = glm::length( _avatar.velocity );
float rotationalSpeed = fabs( bodyYawDelta ); float rotationalSpeed = fabs( _bodyYawDelta );
if ( translationalSpeed + rotationalSpeed > 0.2 ) if ( translationalSpeed + rotationalSpeed > 0.2 )
{ {
mode = AVATAR_MODE_WALKING; _mode = AVATAR_MODE_WALKING;
} }
else else
{ {
mode = AVATAR_MODE_COMMUNICATING; _mode = AVATAR_MODE_COMMUNICATING;
} }
//---------------------------------------------------------- //----------------------------------------------------------
// update body yaw by body yaw delta // update body yaw by body yaw delta
//---------------------------------------------------------- //----------------------------------------------------------
_bodyYaw += bodyYawDelta * deltaTime; _bodyYaw += _bodyYawDelta * deltaTime;
//---------------------------------------------------------- //----------------------------------------------------------
// (for now) set head yaw to body yaw // (for now) set head yaw to body yaw
@ -426,23 +412,23 @@ void Head::simulate(float deltaTime) {
// decay body yaw delta // decay body yaw delta
//---------------------------------------------------------- //----------------------------------------------------------
const float TEST_YAW_DECAY = 5.0; const float TEST_YAW_DECAY = 5.0;
bodyYawDelta *= ( 1.0 - TEST_YAW_DECAY * deltaTime ); _bodyYawDelta *= ( 1.0 - TEST_YAW_DECAY * deltaTime );
//---------------------------------------------------------- //----------------------------------------------------------
// add thrust to velocity // add thrust to velocity
//---------------------------------------------------------- //----------------------------------------------------------
avatar.velocity += glm::dvec3( avatar.thrust * deltaTime ); _avatar.velocity += glm::dvec3( _avatar.thrust * deltaTime );
//---------------------------------------------------------- //----------------------------------------------------------
// update position by velocity // update position by velocity
//---------------------------------------------------------- //----------------------------------------------------------
_bodyPosition += (glm::vec3)avatar.velocity * deltaTime; _bodyPosition += (glm::vec3)_avatar.velocity * deltaTime;
//---------------------------------------------------------- //----------------------------------------------------------
// decay velocity // decay velocity
//---------------------------------------------------------- //----------------------------------------------------------
const float LIN_VEL_DECAY = 5.0; const float LIN_VEL_DECAY = 5.0;
avatar.velocity *= ( 1.0 - LIN_VEL_DECAY * deltaTime ); _avatar.velocity *= ( 1.0 - LIN_VEL_DECAY * deltaTime );
@ -480,8 +466,6 @@ void Head::simulate(float deltaTime) {
} }
} }
const float DEGREES_BETWEEN_VIEWER_EYES = 3; const float DEGREES_BETWEEN_VIEWER_EYES = 3;
const float DEGREES_TO_VIEWER_MOUTH = 7; const float DEGREES_TO_VIEWER_MOUTH = 7;
@ -546,7 +530,7 @@ void Head::simulate(float deltaTime) {
void Head::render(int faceToFace, int isMine) { void Head::render(int faceToFace) {
//--------------------------------------------------- //---------------------------------------------------
// show avatar position // show avatar position
@ -560,7 +544,7 @@ void Head::render(int faceToFace, int isMine) {
//--------------------------------------------------- //---------------------------------------------------
// show avatar orientation // show avatar orientation
//--------------------------------------------------- //---------------------------------------------------
renderOrientationDirections(bone[ AVATAR_BONE_HEAD ].position, bone[ AVATAR_BONE_HEAD ].orientation, 0.2f ); renderOrientationDirections( _bone[ AVATAR_BONE_HEAD ].position, _bone[ AVATAR_BONE_HEAD ].orientation, 0.2f );
//--------------------------------------------------- //---------------------------------------------------
// render body // render body
@ -570,7 +554,7 @@ void Head::render(int faceToFace, int isMine) {
//--------------------------------------------------- //---------------------------------------------------
// render head // render head
//--------------------------------------------------- //---------------------------------------------------
renderHead( faceToFace, isMine ); renderHead(faceToFace);
//--------------------------------------------------- //---------------------------------------------------
// render other avatars (DEBUG TEST) // render other avatars (DEBUG TEST)
@ -583,11 +567,11 @@ void Head::render(int faceToFace, int isMine) {
glPopMatrix(); glPopMatrix();
} }
if ( usingSprings ) { if ( _usingSprings ) {
if ( closestOtherAvatar != -1 ) { if ( _closestOtherAvatar != -1 ) {
glm::vec3 v1( bone[ AVATAR_BONE_RIGHT_HAND ].position ); glm::vec3 v1( _bone[ AVATAR_BONE_RIGHT_HAND ].position );
glm::vec3 v2( DEBUG_otherAvatarListPosition[ closestOtherAvatar ] ); glm::vec3 v2( DEBUG_otherAvatarListPosition[ _closestOtherAvatar ] );
glLineWidth( 5.0 ); glLineWidth( 5.0 );
glColor4f( 0.9f, 0.5f, 0.2f, 0.6 ); glColor4f( 0.9f, 0.5f, 0.2f, 0.6 );
@ -630,7 +614,7 @@ void Head::renderOrientationDirections( glm::vec3 position, Orientation orientat
void Head::renderHead( int faceToFace, int isMine ) { void Head::renderHead( int faceToFace) {
int side = 0; int side = 0;
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
@ -639,20 +623,20 @@ void Head::renderHead( int faceToFace, int isMine ) {
glPushMatrix(); glPushMatrix();
if ( usingSprings ) { if ( _usingSprings ) {
glTranslatef glTranslatef
( (
bone[ AVATAR_BONE_HEAD ].springyPosition.x, _bone[ AVATAR_BONE_HEAD ].springyPosition.x,
bone[ AVATAR_BONE_HEAD ].springyPosition.y, _bone[ AVATAR_BONE_HEAD ].springyPosition.y,
bone[ AVATAR_BONE_HEAD ].springyPosition.z _bone[ AVATAR_BONE_HEAD ].springyPosition.z
); );
} }
else { else {
glTranslatef glTranslatef
( (
bone[ AVATAR_BONE_HEAD ].position.x, _bone[ AVATAR_BONE_HEAD ].position.x,
bone[ AVATAR_BONE_HEAD ].position.y, _bone[ AVATAR_BONE_HEAD ].position.y,
bone[ AVATAR_BONE_HEAD ].position.z _bone[ AVATAR_BONE_HEAD ].position.z
); );
} }
@ -676,6 +660,7 @@ void Head::renderHead( int faceToFace, int isMine ) {
glColor3fv(skinColor); glColor3fv(skinColor);
// Head // Head
if (!_isMine) glColor3f(0,0,1); // Temp: Other people are BLUE
glutSolidSphere(1, 30, 30); glutSolidSphere(1, 30, 30);
// Ears // Ears
@ -801,12 +786,12 @@ void Head::renderHead( int faceToFace, int isMine ) {
void Head::setHandMovement( glm::vec3 movement ) { void Head::setHandMovement( glm::vec3 movement ) {
handBeingMoved = true; _handBeingMoved = true;
movedHandOffset = movement; _movedHandOffset = movement;
} }
AvatarMode Head::getMode() { AvatarMode Head::getMode() {
return mode; return _mode;
} }
@ -833,16 +818,21 @@ void Head::initializeAvatar() {
} }
void Head::initializeSkeleton() { void Head::initializeSkeleton() {
for (int b=0; b<NUM_AVATAR_BONES; b++) { for (int b=0; b<NUM_AVATAR_BONES; b++) {
bone[b].position = glm::vec3( 0.0, 0.0, 0.0 ); _bone[b].parent = AVATAR_BONE_NULL;
bone[b].springyPosition = glm::vec3( 0.0, 0.0, 0.0 ); _bone[b].position = glm::vec3( 0.0, 0.0, 0.0 );
bone[b].springyVelocity = glm::vec3( 0.0, 0.0, 0.0 ); _bone[b].defaultPosePosition = glm::vec3( 0.0, 0.0, 0.0 );
bone[b].springBodyTightness = 4.0; _bone[b].springyPosition = glm::vec3( 0.0, 0.0, 0.0 );
bone[b].orientation.setToIdentity(); _bone[b].springyVelocity = glm::vec3( 0.0, 0.0, 0.0 );
_bone[b].rotation = glm::quat( 0.0f, 0.0f, 0.0f, 0.0f );
_bone[b].yaw = 0.0;
_bone[b].pitch = 0.0;
_bone[b].roll = 0.0;
_bone[b].length = 0.0;
_bone[b].springBodyTightness = 4.0;
_bone[b].orientation.setToIdentity();
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -852,73 +842,73 @@ void Head::initializeSkeleton() {
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// spine and head // spine and head
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bone[ AVATAR_BONE_PELVIS_SPINE ].parent = AVATAR_BONE_NULL; _bone[ AVATAR_BONE_PELVIS_SPINE ].parent = AVATAR_BONE_NULL;
bone[ AVATAR_BONE_MID_SPINE ].parent = AVATAR_BONE_PELVIS_SPINE; _bone[ AVATAR_BONE_MID_SPINE ].parent = AVATAR_BONE_PELVIS_SPINE;
bone[ AVATAR_BONE_CHEST_SPINE ].parent = AVATAR_BONE_MID_SPINE; _bone[ AVATAR_BONE_CHEST_SPINE ].parent = AVATAR_BONE_MID_SPINE;
bone[ AVATAR_BONE_NECK ].parent = AVATAR_BONE_CHEST_SPINE; _bone[ AVATAR_BONE_NECK ].parent = AVATAR_BONE_CHEST_SPINE;
bone[ AVATAR_BONE_HEAD ].parent = AVATAR_BONE_NECK; _bone[ AVATAR_BONE_HEAD ].parent = AVATAR_BONE_NECK;
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// left chest and arm // left chest and arm
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bone[ AVATAR_BONE_LEFT_CHEST ].parent = AVATAR_BONE_MID_SPINE; _bone[ AVATAR_BONE_LEFT_CHEST ].parent = AVATAR_BONE_MID_SPINE;
bone[ AVATAR_BONE_LEFT_SHOULDER ].parent = AVATAR_BONE_LEFT_CHEST; _bone[ AVATAR_BONE_LEFT_SHOULDER ].parent = AVATAR_BONE_LEFT_CHEST;
bone[ AVATAR_BONE_LEFT_UPPER_ARM ].parent = AVATAR_BONE_LEFT_SHOULDER; _bone[ AVATAR_BONE_LEFT_UPPER_ARM ].parent = AVATAR_BONE_LEFT_SHOULDER;
bone[ AVATAR_BONE_LEFT_FOREARM ].parent = AVATAR_BONE_LEFT_UPPER_ARM; _bone[ AVATAR_BONE_LEFT_FOREARM ].parent = AVATAR_BONE_LEFT_UPPER_ARM;
bone[ AVATAR_BONE_LEFT_HAND ].parent = AVATAR_BONE_LEFT_FOREARM; _bone[ AVATAR_BONE_LEFT_HAND ].parent = AVATAR_BONE_LEFT_FOREARM;
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// right chest and arm // right chest and arm
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bone[ AVATAR_BONE_RIGHT_CHEST ].parent = AVATAR_BONE_MID_SPINE; _bone[ AVATAR_BONE_RIGHT_CHEST ].parent = AVATAR_BONE_MID_SPINE;
bone[ AVATAR_BONE_RIGHT_SHOULDER ].parent = AVATAR_BONE_RIGHT_CHEST; _bone[ AVATAR_BONE_RIGHT_SHOULDER ].parent = AVATAR_BONE_RIGHT_CHEST;
bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].parent = AVATAR_BONE_RIGHT_SHOULDER; _bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].parent = AVATAR_BONE_RIGHT_SHOULDER;
bone[ AVATAR_BONE_RIGHT_FOREARM ].parent = AVATAR_BONE_RIGHT_UPPER_ARM; _bone[ AVATAR_BONE_RIGHT_FOREARM ].parent = AVATAR_BONE_RIGHT_UPPER_ARM;
bone[ AVATAR_BONE_RIGHT_HAND ].parent = AVATAR_BONE_RIGHT_FOREARM; _bone[ AVATAR_BONE_RIGHT_HAND ].parent = AVATAR_BONE_RIGHT_FOREARM;
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// left pelvis and leg // left pelvis and leg
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bone[ AVATAR_BONE_LEFT_PELVIS ].parent = AVATAR_BONE_PELVIS_SPINE; _bone[ AVATAR_BONE_LEFT_PELVIS ].parent = AVATAR_BONE_PELVIS_SPINE;
bone[ AVATAR_BONE_LEFT_THIGH ].parent = AVATAR_BONE_LEFT_PELVIS; _bone[ AVATAR_BONE_LEFT_THIGH ].parent = AVATAR_BONE_LEFT_PELVIS;
bone[ AVATAR_BONE_LEFT_SHIN ].parent = AVATAR_BONE_LEFT_THIGH; _bone[ AVATAR_BONE_LEFT_SHIN ].parent = AVATAR_BONE_LEFT_THIGH;
bone[ AVATAR_BONE_LEFT_FOOT ].parent = AVATAR_BONE_LEFT_SHIN; _bone[ AVATAR_BONE_LEFT_FOOT ].parent = AVATAR_BONE_LEFT_SHIN;
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// right pelvis and leg // right pelvis and leg
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bone[ AVATAR_BONE_RIGHT_PELVIS ].parent = AVATAR_BONE_PELVIS_SPINE; _bone[ AVATAR_BONE_RIGHT_PELVIS ].parent = AVATAR_BONE_PELVIS_SPINE;
bone[ AVATAR_BONE_RIGHT_THIGH ].parent = AVATAR_BONE_RIGHT_PELVIS; _bone[ AVATAR_BONE_RIGHT_THIGH ].parent = AVATAR_BONE_RIGHT_PELVIS;
bone[ AVATAR_BONE_RIGHT_SHIN ].parent = AVATAR_BONE_RIGHT_THIGH; _bone[ AVATAR_BONE_RIGHT_SHIN ].parent = AVATAR_BONE_RIGHT_THIGH;
bone[ AVATAR_BONE_RIGHT_FOOT ].parent = AVATAR_BONE_RIGHT_SHIN; _bone[ AVATAR_BONE_RIGHT_FOOT ].parent = AVATAR_BONE_RIGHT_SHIN;
//---------------------------------------------------------- //----------------------------------------------------------
// specify the default pose position // specify the default pose position
//---------------------------------------------------------- //----------------------------------------------------------
bone[ AVATAR_BONE_PELVIS_SPINE ].defaultPosePosition = glm::vec3( 0.0, 0.3, 0.0 ); _bone[ AVATAR_BONE_PELVIS_SPINE ].defaultPosePosition = glm::vec3( 0.0, 0.3, 0.0 );
bone[ AVATAR_BONE_MID_SPINE ].defaultPosePosition = glm::vec3( 0.0, 0.1, 0.0 ); _bone[ AVATAR_BONE_MID_SPINE ].defaultPosePosition = glm::vec3( 0.0, 0.1, 0.0 );
bone[ AVATAR_BONE_CHEST_SPINE ].defaultPosePosition = glm::vec3( 0.0, 0.1, 0.0 ); _bone[ AVATAR_BONE_CHEST_SPINE ].defaultPosePosition = glm::vec3( 0.0, 0.1, 0.0 );
bone[ AVATAR_BONE_NECK ].defaultPosePosition = glm::vec3( 0.0, 0.06, 0.0 ); _bone[ AVATAR_BONE_NECK ].defaultPosePosition = glm::vec3( 0.0, 0.06, 0.0 );
bone[ AVATAR_BONE_HEAD ].defaultPosePosition = glm::vec3( 0.0, 0.06, 0.0 ); _bone[ AVATAR_BONE_HEAD ].defaultPosePosition = glm::vec3( 0.0, 0.06, 0.0 );
bone[ AVATAR_BONE_LEFT_CHEST ].defaultPosePosition = glm::vec3( -0.06, 0.06, 0.0 ); _bone[ AVATAR_BONE_LEFT_CHEST ].defaultPosePosition = glm::vec3( -0.06, 0.06, 0.0 );
bone[ AVATAR_BONE_LEFT_SHOULDER ].defaultPosePosition = glm::vec3( -0.03, 0.0, 0.0 ); _bone[ AVATAR_BONE_LEFT_SHOULDER ].defaultPosePosition = glm::vec3( -0.03, 0.0, 0.0 );
bone[ AVATAR_BONE_LEFT_UPPER_ARM ].defaultPosePosition = glm::vec3( 0.0, -0.12, 0.0 ); _bone[ AVATAR_BONE_LEFT_UPPER_ARM ].defaultPosePosition = glm::vec3( 0.0, -0.12, 0.0 );
bone[ AVATAR_BONE_LEFT_FOREARM ].defaultPosePosition = glm::vec3( 0.0, -0.1, 0.0 ); _bone[ AVATAR_BONE_LEFT_FOREARM ].defaultPosePosition = glm::vec3( 0.0, -0.1, 0.0 );
bone[ AVATAR_BONE_LEFT_HAND ].defaultPosePosition = glm::vec3( 0.0, -0.05, 0.0 ); _bone[ AVATAR_BONE_LEFT_HAND ].defaultPosePosition = glm::vec3( 0.0, -0.05, 0.0 );
bone[ AVATAR_BONE_RIGHT_CHEST ].defaultPosePosition = glm::vec3( 0.06, 0.06, 0.0 ); _bone[ AVATAR_BONE_RIGHT_CHEST ].defaultPosePosition = glm::vec3( 0.06, 0.06, 0.0 );
bone[ AVATAR_BONE_RIGHT_SHOULDER ].defaultPosePosition = glm::vec3( 0.03, 0.0, 0.0 ); _bone[ AVATAR_BONE_RIGHT_SHOULDER ].defaultPosePosition = glm::vec3( 0.03, 0.0, 0.0 );
bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].defaultPosePosition = glm::vec3( 0.0, -0.12, 0.0 ); _bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].defaultPosePosition = glm::vec3( 0.0, -0.12, 0.0 );
bone[ AVATAR_BONE_RIGHT_FOREARM ].defaultPosePosition = glm::vec3( 0.0, -0.1, 0.0 ); _bone[ AVATAR_BONE_RIGHT_FOREARM ].defaultPosePosition = glm::vec3( 0.0, -0.1, 0.0 );
bone[ AVATAR_BONE_RIGHT_HAND ].defaultPosePosition = glm::vec3( 0.0, -0.05, 0.0 ); _bone[ AVATAR_BONE_RIGHT_HAND ].defaultPosePosition = glm::vec3( 0.0, -0.05, 0.0 );
bone[ AVATAR_BONE_LEFT_PELVIS ].defaultPosePosition = glm::vec3( -0.05, 0.0, 0.0 ); _bone[ AVATAR_BONE_LEFT_PELVIS ].defaultPosePosition = glm::vec3( -0.05, 0.0, 0.0 );
bone[ AVATAR_BONE_LEFT_THIGH ].defaultPosePosition = glm::vec3( 0.0, -0.15, 0.0 ); _bone[ AVATAR_BONE_LEFT_THIGH ].defaultPosePosition = glm::vec3( 0.0, -0.15, 0.0 );
bone[ AVATAR_BONE_LEFT_SHIN ].defaultPosePosition = glm::vec3( 0.0, -0.15, 0.0 ); _bone[ AVATAR_BONE_LEFT_SHIN ].defaultPosePosition = glm::vec3( 0.0, -0.15, 0.0 );
bone[ AVATAR_BONE_LEFT_FOOT ].defaultPosePosition = glm::vec3( 0.0, 0.0, 0.04 ); _bone[ AVATAR_BONE_LEFT_FOOT ].defaultPosePosition = glm::vec3( 0.0, 0.0, 0.04 );
bone[ AVATAR_BONE_RIGHT_PELVIS ].defaultPosePosition = glm::vec3( 0.05, 0.0, 0.0 ); _bone[ AVATAR_BONE_RIGHT_PELVIS ].defaultPosePosition = glm::vec3( 0.05, 0.0, 0.0 );
bone[ AVATAR_BONE_RIGHT_THIGH ].defaultPosePosition = glm::vec3( 0.0, -0.15, 0.0 ); _bone[ AVATAR_BONE_RIGHT_THIGH ].defaultPosePosition = glm::vec3( 0.0, -0.15, 0.0 );
bone[ AVATAR_BONE_RIGHT_SHIN ].defaultPosePosition = glm::vec3( 0.0, -0.15, 0.0 ); _bone[ AVATAR_BONE_RIGHT_SHIN ].defaultPosePosition = glm::vec3( 0.0, -0.15, 0.0 );
bone[ AVATAR_BONE_RIGHT_FOOT ].defaultPosePosition = glm::vec3( 0.0, 0.0, 0.04 ); _bone[ AVATAR_BONE_RIGHT_FOOT ].defaultPosePosition = glm::vec3( 0.0, 0.0, 0.04 );
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// calculate bone length // calculate bone length
@ -936,13 +926,13 @@ void Head::initializeSkeleton() {
void Head::calculateBoneLengths() { void Head::calculateBoneLengths() {
for (int b=0; b<NUM_AVATAR_BONES; b++) { for (int b=0; b<NUM_AVATAR_BONES; b++) {
bone[b].length = glm::length( bone[b].defaultPosePosition ); _bone[b].length = glm::length( _bone[b].defaultPosePosition );
} }
avatar.maxArmLength _avatar.maxArmLength
= bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].length = _bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].length
+ bone[ AVATAR_BONE_RIGHT_FOREARM ].length + _bone[ AVATAR_BONE_RIGHT_FOREARM ].length
+ bone[ AVATAR_BONE_RIGHT_HAND ].length; + _bone[ AVATAR_BONE_RIGHT_HAND ].length;
} }
@ -951,54 +941,54 @@ void Head::updateSkeleton() {
//---------------------------------- //----------------------------------
// rotate body... // rotate body...
//---------------------------------- //----------------------------------
avatar.orientation.setToIdentity(); _avatar.orientation.setToIdentity();
avatar.orientation.yaw( _bodyYaw ); _avatar.orientation.yaw( _bodyYaw );
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// calculate positions of all bones by traversing the skeleton tree: // calculate positions of all bones by traversing the skeleton tree:
//------------------------------------------------------------------------ //------------------------------------------------------------------------
for (int b=0; b<NUM_AVATAR_BONES; b++) { for (int b=0; b<NUM_AVATAR_BONES; b++) {
if ( bone[b].parent == AVATAR_BONE_NULL ) { if ( _bone[b].parent == AVATAR_BONE_NULL ) {
bone[b].orientation.set(avatar.orientation); _bone[b].orientation.set( _avatar.orientation );
//printf( "bodyPosition = %f, %f, %f\n", bodyPosition.x, bodyPosition.y, bodyPosition.z ); //printf( "bodyPosition = %f, %f, %f\n", bodyPosition.x, bodyPosition.y, bodyPosition.z );
glm::vec3 ppp = _bodyPosition; glm::vec3 ppp = _bodyPosition;
// ppp.y += 0.2; // ppp.y += 0.2;
bone[b].position = ppp;// + glm::vec3( 0.0f, 1.0f, 0.0f ) * 1.0f; _bone[b].position = ppp;// + glm::vec3( 0.0f, 1.0f, 0.0f ) * 1.0f;
} }
else { else {
bone[b].orientation.set( bone[ bone[b].parent ].orientation ); _bone[b].orientation.set( _bone[ _bone[b].parent ].orientation );
bone[b].position = bone[ bone[b].parent ].position; _bone[b].position = _bone[ _bone[b].parent ].position;
} }
float xx = glm::dot( bone[b].defaultPosePosition, bone[b].orientation.getRight () ); float xx = glm::dot( _bone[b].defaultPosePosition, _bone[b].orientation.getRight () );
float yy = glm::dot( bone[b].defaultPosePosition, bone[b].orientation.getUp () ); float yy = glm::dot( _bone[b].defaultPosePosition, _bone[b].orientation.getUp () );
float zz = -glm::dot( bone[b].defaultPosePosition, bone[b].orientation.getFront () ); float zz = -glm::dot( _bone[b].defaultPosePosition, _bone[b].orientation.getFront () );
glm::vec3 rotatedBoneVector( xx, yy, zz ); glm::vec3 rotatedBoneVector( xx, yy, zz );
bone[b].position += rotatedBoneVector; _bone[b].position += rotatedBoneVector;
} }
} }
void Head::initializeBodySprings() { void Head::initializeBodySprings() {
for (int b=0; b<NUM_AVATAR_BONES; b++) { for (int b=0; b<NUM_AVATAR_BONES; b++) {
bone[b].springyPosition = bone[b].position; _bone[b].springyPosition = _bone[b].position;
bone[b].springyVelocity = glm::vec3( 0.0f, 0.0f, 0.0f ); _bone[b].springyVelocity = glm::vec3( 0.0f, 0.0f, 0.0f );
} }
} }
void Head::updateBodySprings( float deltaTime ) { void Head::updateBodySprings( float deltaTime ) {
for (int b=0; b<NUM_AVATAR_BONES; b++) { for (int b=0; b<NUM_AVATAR_BONES; b++) {
glm::vec3 springVector( bone[b].springyPosition ); glm::vec3 springVector( _bone[b].springyPosition );
if ( bone[b].parent == AVATAR_BONE_NULL ) { if ( _bone[b].parent == AVATAR_BONE_NULL ) {
springVector -= _bodyPosition; springVector -= _bodyPosition;
} }
else { else {
springVector -= bone[ bone[b].parent ].springyPosition; springVector -= _bone[ _bone[b].parent ].springyPosition;
} }
float length = glm::length( springVector ); float length = glm::length( springVector );
@ -1006,64 +996,60 @@ void Head::updateBodySprings( float deltaTime ) {
if ( length > 0.0f ) { if ( length > 0.0f ) {
glm::vec3 springDirection = springVector / length; glm::vec3 springDirection = springVector / length;
float force = ( length - bone[b].length ) * springForce * deltaTime; float force = ( length - _bone[b].length ) * _springForce * deltaTime;
bone[ b ].springyVelocity -= springDirection * force; _bone[ b ].springyVelocity -= springDirection * force;
bone[ bone[b].parent ].springyVelocity += springDirection * force; _bone[ _bone[b].parent ].springyVelocity += springDirection * force;
} }
bone[b].springyVelocity += ( bone[b].position - bone[b].springyPosition ) * bone[b].springBodyTightness * deltaTime; _bone[b].springyVelocity += ( _bone[b].position - _bone[b].springyPosition ) * _bone[b].springBodyTightness * deltaTime;
float decay = 1.0 - springVelocityDecay * deltaTime; float decay = 1.0 - _springVelocityDecay * deltaTime;
if ( decay > 0.0 ) { if ( decay > 0.0 ) {
bone[b].springyVelocity *= decay; _bone[b].springyVelocity *= decay;
} }
else { else {
bone[b].springyVelocity = glm::vec3( 0.0f, 0.0f, 0.0f ); _bone[b].springyVelocity = glm::vec3( 0.0f, 0.0f, 0.0f );
} }
bone[b].springyPosition += bone[b].springyVelocity; _bone[b].springyPosition += _bone[b].springyVelocity;
} }
} }
float Head::getBodyYaw() {
return _bodyYaw;
}
glm::vec3 Head::getHeadLookatDirection() { glm::vec3 Head::getHeadLookatDirection() {
return glm::vec3 return glm::vec3
( (
avatar.orientation.getFront().x, _avatar.orientation.getFront().x,
avatar.orientation.getFront().y, _avatar.orientation.getFront().y,
avatar.orientation.getFront().z _avatar.orientation.getFront().z
); );
} }
glm::vec3 Head::getHeadLookatDirectionUp() { glm::vec3 Head::getHeadLookatDirectionUp() {
return glm::vec3 return glm::vec3
( (
avatar.orientation.getUp().x, _avatar.orientation.getUp().x,
avatar.orientation.getUp().y, _avatar.orientation.getUp().y,
avatar.orientation.getUp().z _avatar.orientation.getUp().z
); );
} }
glm::vec3 Head::getHeadLookatDirectionRight() { glm::vec3 Head::getHeadLookatDirectionRight() {
return glm::vec3 return glm::vec3
( (
avatar.orientation.getRight().x, _avatar.orientation.getRight().x,
avatar.orientation.getRight().y, _avatar.orientation.getRight().y,
avatar.orientation.getRight().z _avatar.orientation.getRight().z
); );
} }
glm::vec3 Head::getHeadPosition() { glm::vec3 Head::getHeadPosition() {
return glm::vec3 return glm::vec3
( (
bone[ AVATAR_BONE_HEAD ].position.x, _bone[ AVATAR_BONE_HEAD ].position.x,
bone[ AVATAR_BONE_HEAD ].position.y, _bone[ AVATAR_BONE_HEAD ].position.y,
bone[ AVATAR_BONE_HEAD ].position.z _bone[ AVATAR_BONE_HEAD ].position.z
); );
} }
@ -1071,26 +1057,26 @@ void Head::updateHandMovement() {
glm::vec3 transformedHandMovement; glm::vec3 transformedHandMovement;
transformedHandMovement transformedHandMovement
= avatar.orientation.getRight() * -movedHandOffset.x = _avatar.orientation.getRight() * -_movedHandOffset.x
+ avatar.orientation.getUp() * -movedHandOffset.y * 0.5f + _avatar.orientation.getUp() * -_movedHandOffset.y * 0.5f
+ avatar.orientation.getFront() * -movedHandOffset.y; + _avatar.orientation.getFront() * -_movedHandOffset.y;
bone[ AVATAR_BONE_RIGHT_HAND ].position += transformedHandMovement; _bone[ AVATAR_BONE_RIGHT_HAND ].position += transformedHandMovement;
//if holding hands, add a pull to the hand... //if holding hands, add a pull to the hand...
if ( usingSprings ) { if ( _usingSprings ) {
if ( closestOtherAvatar != -1 ) { if ( _closestOtherAvatar != -1 ) {
if ( triggeringAction ) { if ( _triggeringAction ) {
/* /*
glm::vec3 handShakePull( DEBUG_otherAvatarListPosition[ closestOtherAvatar ]); glm::vec3 handShakePull( DEBUG_otherAvatarListPosition[ closestOtherAvatar ]);
handShakePull -= bone[ AVATAR_BONE_RIGHT_HAND ].position; handShakePull -= _bone[ AVATAR_BONE_RIGHT_HAND ].position;
handShakePull *= 1.0; handShakePull *= 1.0;
transformedHandMovement += handShakePull; transformedHandMovement += handShakePull;
*/ */
bone[ AVATAR_BONE_RIGHT_HAND ].position = DEBUG_otherAvatarListPosition[ closestOtherAvatar ]; _bone[ AVATAR_BONE_RIGHT_HAND ].position = DEBUG_otherAvatarListPosition[ _closestOtherAvatar ];
} }
} }
} }
@ -1100,8 +1086,8 @@ void Head::updateHandMovement() {
//------------------------------------------------------------------------------- //-------------------------------------------------------------------------------
// determine the arm vector // determine the arm vector
//------------------------------------------------------------------------------- //-------------------------------------------------------------------------------
glm::vec3 armVector = bone[ AVATAR_BONE_RIGHT_HAND ].position; glm::vec3 armVector = _bone[ AVATAR_BONE_RIGHT_HAND ].position;
armVector -= bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; armVector -= _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position;
//------------------------------------------------------------------------------- //-------------------------------------------------------------------------------
@ -1112,52 +1098,56 @@ void Head::updateHandMovement() {
//------------------------------------------------------------------------------- //-------------------------------------------------------------------------------
// if right hand is being dragged beyond maximum arm length... // if right hand is being dragged beyond maximum arm length...
//------------------------------------------------------------------------------- //-------------------------------------------------------------------------------
if ( distance > avatar.maxArmLength ) { if ( distance > _avatar.maxArmLength ) {
//------------------------------------------------------------------------------- //-------------------------------------------------------------------------------
// reset right hand to be constrained to maximum arm length // reset right hand to be constrained to maximum arm length
//------------------------------------------------------------------------------- //-------------------------------------------------------------------------------
bone[ AVATAR_BONE_RIGHT_HAND ].position = bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; _bone[ AVATAR_BONE_RIGHT_HAND ].position = _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position;
glm::vec3 armNormal = armVector / distance; glm::vec3 armNormal = armVector / distance;
armVector = armNormal * avatar.maxArmLength; armVector = armNormal * _avatar.maxArmLength;
distance = avatar.maxArmLength; distance = _avatar.maxArmLength;
glm::vec3 constrainedPosition = bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; glm::vec3 constrainedPosition = _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position;
constrainedPosition += armVector; constrainedPosition += armVector;
bone[ AVATAR_BONE_RIGHT_HAND ].position = constrainedPosition; _bone[ AVATAR_BONE_RIGHT_HAND ].position = constrainedPosition;
} }
/* /*
//------------------------------------------------------------------------------- //-------------------------------------------------------------------------------
// keep arm from going through av body... // keep arm from going through av body...
//------------------------------------------------------------------------------- //-------------------------------------------------------------------------------
glm::vec3 adjustedArmVector = bone[ AVATAR_BONE_RIGHT_HAND ].position; glm::vec3 adjustedArmVector = _bone[ AVATAR_BONE_RIGHT_HAND ].position;
adjustedArmVector -= bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; adjustedArmVector -= _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position;
float rightComponent = glm::dot( adjustedArmVector, avatar.orientation.getRight() ); float rightComponent = glm::dot( adjustedArmVector, avatar.orientation.getRight() );
if ( rightComponent < 0.0 ) if ( rightComponent < 0.0 )
{ {
bone[ AVATAR_BONE_RIGHT_HAND ].position -= avatar.orientation.getRight() * rightComponent; _bone[ AVATAR_BONE_RIGHT_HAND ].position -= avatar.orientation.getRight() * rightComponent;
} }
*/ */
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// set elbow position // set elbow position
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
glm::vec3 newElbowPosition = bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; glm::vec3 newElbowPosition = _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position;
newElbowPosition += armVector * ONE_HALF; newElbowPosition += armVector * ONE_HALF;
glm::vec3 perpendicular = glm::cross( avatar.orientation.getFront(), armVector ); glm::vec3 perpendicular = glm::cross( _avatar.orientation.getFront(), armVector );
newElbowPosition += perpendicular * ( 1.0f - ( avatar.maxArmLength / distance ) ) * ONE_HALF; newElbowPosition += perpendicular * ( 1.0f - ( _avatar.maxArmLength / distance ) ) * ONE_HALF;
bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position = newElbowPosition; _bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position = newElbowPosition;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// set wrist position // set wrist position
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
glm::vec3 vv( bone[ AVATAR_BONE_RIGHT_HAND ].position ); glm::vec3 vv( _bone[ AVATAR_BONE_RIGHT_HAND ].position );
vv -= bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position; vv -= _bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position;
glm::vec3 newWristPosition = bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position; glm::vec3 newWristPosition = _bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position;
newWristPosition += vv * 0.7f; newWristPosition += vv * 0.7f;
bone[ AVATAR_BONE_RIGHT_FOREARM ].position = newWristPosition; _bone[ AVATAR_BONE_RIGHT_FOREARM ].position = newWristPosition;
// Set the vector we send for hand position to other people to be our right hand
setHandPosition(_bone[ AVATAR_BONE_RIGHT_HAND ].position);
} }
@ -1167,17 +1157,17 @@ void Head::renderBody() {
// Render bone positions as spheres // Render bone positions as spheres
//----------------------------------------- //-----------------------------------------
for (int b=0; b<NUM_AVATAR_BONES; b++) { for (int b=0; b<NUM_AVATAR_BONES; b++) {
if ( usingSprings ) { if ( _usingSprings ) {
glColor3fv( lightBlue ); glColor3fv( lightBlue );
glPushMatrix(); glPushMatrix();
glTranslatef( bone[b].springyPosition.x, bone[b].springyPosition.y, bone[b].springyPosition.z ); glTranslatef( _bone[b].springyPosition.x, _bone[b].springyPosition.y, _bone[b].springyPosition.z );
glutSolidSphere( 0.02f, 10.0f, 5.0f ); glutSolidSphere( 0.02f, 10.0f, 5.0f );
glPopMatrix(); glPopMatrix();
} }
else { else {
glColor3fv( skinColor ); glColor3fv( skinColor );
glPushMatrix(); glPushMatrix();
glTranslatef( bone[b].position.x, bone[b].position.y, bone[b].position.z ); glTranslatef( _bone[b].position.x, _bone[b].position.y, _bone[b].position.z );
glutSolidSphere( 0.02f, 10.0f, 5.0f ); glutSolidSphere( 0.02f, 10.0f, 5.0f );
glPopMatrix(); glPopMatrix();
} }
@ -1186,14 +1176,14 @@ void Head::renderBody() {
//----------------------------------------------------- //-----------------------------------------------------
// Render lines connecting the bone positions // Render lines connecting the bone positions
//----------------------------------------------------- //-----------------------------------------------------
if ( usingSprings ) { if ( _usingSprings ) {
glColor3f( 0.4f, 0.5f, 0.6f ); glColor3f( 0.4f, 0.5f, 0.6f );
glLineWidth(3.0); glLineWidth(3.0);
for (int b=1; b<NUM_AVATAR_BONES; b++) { for (int b=1; b<NUM_AVATAR_BONES; b++) {
glBegin( GL_LINE_STRIP ); glBegin( GL_LINE_STRIP );
glVertex3fv( &bone[ bone[ b ].parent ].springyPosition.x ); glVertex3fv( &_bone[ _bone[ b ].parent ].springyPosition.x );
glVertex3fv( &bone[ b ].springyPosition.x ); glVertex3fv( &_bone[ b ].springyPosition.x );
glEnd(); glEnd();
} }
} }
@ -1203,21 +1193,21 @@ void Head::renderBody() {
for (int b=1; b<NUM_AVATAR_BONES; b++) { for (int b=1; b<NUM_AVATAR_BONES; b++) {
glBegin( GL_LINE_STRIP ); glBegin( GL_LINE_STRIP );
glVertex3fv( &bone[ bone[ b ].parent ].position.x ); glVertex3fv( &_bone[ _bone[ b ].parent ].position.x );
glVertex3fv( &bone[ b ].position.x); glVertex3fv( &_bone[ b ].position.x);
glEnd(); glEnd();
} }
} }
if (( usingSprings ) && ( triggeringAction )) { if (( _usingSprings ) && ( _triggeringAction )) {
glColor4f( 1.0, 1.0, 0.5, 0.5 ); glColor4f( 1.0, 1.0, 0.5, 0.5 );
glPushMatrix(); glPushMatrix();
glTranslatef glTranslatef
( (
bone[ AVATAR_BONE_RIGHT_HAND ].springyPosition.x, _bone[ AVATAR_BONE_RIGHT_HAND ].springyPosition.x,
bone[ AVATAR_BONE_RIGHT_HAND ].springyPosition.y, _bone[ AVATAR_BONE_RIGHT_HAND ].springyPosition.y,
bone[ AVATAR_BONE_RIGHT_HAND ].springyPosition.z _bone[ AVATAR_BONE_RIGHT_HAND ].springyPosition.z
); );
glutSolidSphere( 0.03f, 10.0f, 5.0f ); glutSolidSphere( 0.03f, 10.0f, 5.0f );
glPopMatrix(); glPopMatrix();

View file

@ -20,6 +20,11 @@
#include "InterfaceConfig.h" #include "InterfaceConfig.h"
#include "SerialInterface.h" #include "SerialInterface.h"
#include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>
#include <glm/gtx/quaternion.hpp>
enum eyeContactTargets {LEFT_EYE, RIGHT_EYE, MOUTH}; enum eyeContactTargets {LEFT_EYE, RIGHT_EYE, MOUTH};
#define FWD 0 #define FWD 0
@ -80,6 +85,7 @@ struct AvatarBone
glm::vec3 springyPosition; // used for special effects (a 'flexible' variant of position) 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) glm::dvec3 springyVelocity; // used for special effects ( the velocity of the springy position)
float springBodyTightness; // how tightly the springy position tries to stay on the 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 orienttion)
float yaw; // the yaw Euler angle of the bone rotation off the parent 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 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 float roll; // the roll Euler angle of the bone rotation off the parent
@ -97,13 +103,13 @@ struct Avatar
class Head : public AvatarData { class Head : public AvatarData {
public: public:
Head(); Head(bool isMine);
~Head(); ~Head();
Head(const Head &otherHead); Head(const Head &otherHead);
Head* clone() const; Head* clone() const;
void reset(); void reset();
void UpdatePos(float frametime, SerialInterface * serialInterface, int head_mirror, glm::vec3 * gravity); void UpdateGyros(float frametime, SerialInterface * serialInterface, int head_mirror, glm::vec3 * gravity);
void setNoise (float mag) { noise = mag; } void setNoise (float mag) { noise = mag; }
void setPitch(float p) {Pitch = p; } void setPitch(float p) {Pitch = p; }
void setYaw(float y) {Yaw = y; } void setYaw(float y) {Yaw = y; }
@ -124,7 +130,9 @@ class Head : public AvatarData {
float getYaw() {return Yaw;} float getYaw() {return Yaw;}
float getLastMeasuredYaw() {return YawRate;} float getLastMeasuredYaw() {return YawRate;}
float getBodyYaw(); float getBodyYaw() {return _bodyYaw;};
void addBodyYaw(float y) {_bodyYaw += y;};
glm::vec3 getHeadLookatDirection(); glm::vec3 getHeadLookatDirection();
glm::vec3 getHeadLookatDirectionUp(); glm::vec3 getHeadLookatDirectionUp();
glm::vec3 getHeadLookatDirectionRight(); glm::vec3 getHeadLookatDirectionRight();
@ -135,10 +143,10 @@ class Head : public AvatarData {
void setTriggeringAction( bool trigger ); void setTriggeringAction( bool trigger );
void render(int faceToFace, int isMine); void render(int faceToFace);
void renderBody(); void renderBody();
void renderHead( int faceToFace, int isMine ); void renderHead( int faceToFace);
//void renderOrientationDirections( glm::vec3 position, Orientation orientation, float size ); //void renderOrientationDirections( glm::vec3 position, Orientation orientation, float size );
void simulate(float); void simulate(float);
@ -158,9 +166,9 @@ class Head : public AvatarData {
bool getDriveKeys(int key) { return driveKeys[key]; }; bool getDriveKeys(int key) { return driveKeys[key]; };
// Set/Get update the thrust that will move the avatar around // Set/Get update the thrust that will move the avatar around
void setThrust(glm::vec3 newThrust) { avatar.thrust = newThrust; }; void setThrust(glm::vec3 newThrust) { _avatar.thrust = newThrust; };
void addThrust(glm::vec3 newThrust) { avatar.thrust += newThrust; }; void addThrust(glm::vec3 newThrust) { _avatar.thrust += newThrust; };
glm::vec3 getThrust() { return avatar.thrust; }; glm::vec3 getThrust() { return _avatar.thrust; };
// //
// Related to getting transmitter UDP data used to animate the avatar hand // Related to getting transmitter UDP data used to animate the avatar hand
@ -170,6 +178,7 @@ class Head : public AvatarData {
float getTransmitterHz() { return transmitterHz; }; float getTransmitterHz() { return transmitterHz; };
private: private:
bool _isMine;
float noise; float noise;
float Pitch; float Pitch;
float Yaw; float Yaw;
@ -204,37 +213,33 @@ class Head : public AvatarData {
float audioAttack; float audioAttack;
float browAudioLift; float browAudioLift;
bool triggeringAction;
float bodyYawDelta;
float closeEnoughToInteract;
int closestOtherAvatar;
//temporary - placeholder for real other avs //temporary - placeholder for real other avs
glm::vec3 DEBUG_otherAvatarListPosition [ NUM_OTHER_AVATARS ]; glm::vec3 DEBUG_otherAvatarListPosition [ NUM_OTHER_AVATARS ];
float DEBUG_otherAvatarListTimer [ NUM_OTHER_AVATARS ]; float DEBUG_otherAvatarListTimer [ NUM_OTHER_AVATARS ];
bool usingSprings; bool _triggeringAction;
float _bodyYawDelta;
bool handBeingMoved; float _closeEnoughToInteract;
bool previousHandBeingMoved; int _closestOtherAvatar;
glm::vec3 movedHandOffset; bool _usingSprings;
bool _handBeingMoved;
bool _previousHandBeingMoved;
glm::vec3 _movedHandOffset;
float _springVelocityDecay;
float _springForce;
glm::quat _rotation; // the rotation of the avatar body as a whole
AvatarBone _bone[ NUM_AVATAR_BONES ];
AvatarMode _mode;
Avatar _avatar;
int driveKeys[MAX_DRIVE_KEYS]; int driveKeys[MAX_DRIVE_KEYS];
float springVelocityDecay;
float springForce;
int eyeContact; int eyeContact;
eyeContactTargets eyeContactTarget; eyeContactTargets eyeContactTarget;
GLUquadric *sphere; GLUquadric *sphere;
Avatar avatar;
AvatarBone bone[ NUM_AVATAR_BONES ];
AvatarMode mode;
float renderYaw, renderPitch; // Pitch from view frustum when this is own head. float renderYaw, renderPitch; // Pitch from view frustum when this is own head.
@ -244,18 +249,16 @@ class Head : public AvatarData {
timeval transmitterTimer; timeval transmitterTimer;
float transmitterHz; float transmitterHz;
int transmitterPackets; int transmitterPackets;
//------------------------------------------- //-----------------------------
// private methods... // private methods...
//------------------------------------------- //-----------------------------
void initializeAvatar(); void initializeAvatar();
void initializeSkeleton(); void initializeSkeleton();
void updateSkeleton(); void updateSkeleton();
void initializeBodySprings(); void initializeBodySprings();
void updateBodySprings( float deltaTime ); void updateBodySprings( float deltaTime );
void calculateBoneLengths(); void calculateBoneLengths();
void readSensors(); void readSensors();
}; };

View file

@ -103,7 +103,7 @@ Oscilloscope audioScope(256,200,true);
ViewFrustum viewFrustum; // current state of view frustum, perspective, orientation, etc. ViewFrustum viewFrustum; // current state of view frustum, perspective, orientation, etc.
Head myAvatar; // The rendered avatar of oneself Head myAvatar(true); // The rendered avatar of oneself
Camera myCamera; // My view onto the world (sometimes on myself :) Camera myCamera; // My view onto the world (sometimes on myself :)
Camera viewFrustumOffsetCamera; // The camera we use to sometimes show the view frustum from an offset mode Camera viewFrustumOffsetCamera; // The camera we use to sometimes show the view frustum from an offset mode
@ -230,12 +230,7 @@ void displayStats(void)
char stats[200]; char stats[200];
sprintf(stats, "FPS = %3.0f Pkts/s = %d Bytes/s = %d Head(x,y,z)= %4.2f, %4.2f, %4.2f ", sprintf(stats, "FPS = %3.0f Pkts/s = %d Bytes/s = %d Head(x,y,z)= %4.2f, %4.2f, %4.2f ",
FPS, packetsPerSecond, bytesPerSecond, avatarPos.x,avatarPos.y,avatarPos.z); FPS, packetsPerSecond, bytesPerSecond, avatarPos.x,avatarPos.y,avatarPos.z);
drawtext(10, statsVerticalOffset + 49, 0.10f, 0, 1.0, 0, stats); drawtext(10, statsVerticalOffset + 49, 0.10f, 0, 1.0, 0, stats);
if (serialPort.active) {
sprintf(stats, "ADC samples = %d, LED = %d",
serialPort.getNumSamples(), serialPort.getLED());
drawtext(300, statsVerticalOffset + 30, 0.10f, 0, 1.0, 0, stats);
}
std::stringstream voxelStats; std::stringstream voxelStats;
voxelStats << "Voxels Rendered: " << voxels.getVoxelsRendered(); voxelStats << "Voxels Rendered: " << voxels.getVoxelsRendered();
@ -386,7 +381,7 @@ void updateAvatar(float frametime)
float gyroPitchRate = serialPort.getRelativeValue(PITCH_RATE); float gyroPitchRate = serialPort.getRelativeValue(PITCH_RATE);
float gyroYawRate = serialPort.getRelativeValue(YAW_RATE); float gyroYawRate = serialPort.getRelativeValue(YAW_RATE);
myAvatar.UpdatePos(frametime, &serialPort, headMirror, &gravity); myAvatar.UpdateGyros(frametime, &serialPort, headMirror, &gravity);
// //
// Update gyro-based mouse (X,Y on screen) // Update gyro-based mouse (X,Y on screen)
@ -822,7 +817,7 @@ void display(void)
glPushMatrix(); glPushMatrix();
glm::vec3 pos = agentHead->getBodyPosition(); glm::vec3 pos = agentHead->getBodyPosition();
glTranslatef(-pos.x, -pos.y, -pos.z); glTranslatef(-pos.x, -pos.y, -pos.z);
agentHead->render(0, 0); agentHead->render(0);
glPopMatrix(); glPopMatrix();
} }
} }
@ -837,7 +832,7 @@ void display(void)
//Render my own avatar //Render my own avatar
myAvatar.render( true, 1 ); myAvatar.render(true);
} }
glPopMatrix(); glPopMatrix();
@ -1300,7 +1295,7 @@ void *networkReceive(void *args)
AgentList::getInstance()->processBulkAgentData(&senderAddress, AgentList::getInstance()->processBulkAgentData(&senderAddress,
incomingPacket, incomingPacket,
bytesReceived, bytesReceived,
(sizeof(float) * 3) + (sizeof(uint16_t) * 2)); (sizeof(float) * 3) + (sizeof(uint16_t) * 3));
break; break;
default: default:
AgentList::getInstance()->processAgentData(&senderAddress, incomingPacket, bytesReceived); AgentList::getInstance()->processAgentData(&senderAddress, incomingPacket, bytesReceived);
@ -1475,7 +1470,7 @@ void mouseoverFunc( int x, int y)
void attachNewHeadToAgent(Agent *newAgent) { void attachNewHeadToAgent(Agent *newAgent) {
if (newAgent->getLinkedData() == NULL) { if (newAgent->getLinkedData() == NULL) {
newAgent->setLinkedData(new Head()); newAgent->setLinkedData(new Head(false));
} }
} }

View file

@ -43,14 +43,13 @@ AvatarData* AvatarData::clone() const {
return new AvatarData(*this); return new AvatarData(*this);
} }
// transmit data to agents requesting it
// called on me just prior to sending data to others (continuasly called)
int AvatarData::getBroadcastData(unsigned char* destinationBuffer) { int AvatarData::getBroadcastData(unsigned char* destinationBuffer) {
unsigned char* bufferStart = destinationBuffer; unsigned char* bufferStart = destinationBuffer;
// TODO: DRY this up to a shared method // TODO: DRY this up to a shared method
// that can pack any type given the number of bytes // that can pack any type given the number of bytes
// and return the number of bytes to push the pointer // and return the number of bytes to push the pointer
memcpy(destinationBuffer, &_bodyPosition, sizeof(float) * 3); memcpy(destinationBuffer, &_bodyPosition, sizeof(float) * 3);
destinationBuffer += sizeof(float) * 3; destinationBuffer += sizeof(float) * 3;
@ -58,6 +57,11 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) {
destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _bodyPitch); destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _bodyPitch);
destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _bodyRoll); destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _bodyRoll);
memcpy(destinationBuffer, &_handPosition, sizeof(float) * 3);
destinationBuffer += sizeof(float) * 3;
//std::cout << _handPosition.x << ", " << _handPosition.y << ", " << _handPosition.z << "\n";
return destinationBuffer - bufferStart; return destinationBuffer - bufferStart;
} }
@ -73,6 +77,10 @@ void AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) {
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t *)sourceBuffer, &_bodyYaw); sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t *)sourceBuffer, &_bodyYaw);
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t *)sourceBuffer, &_bodyPitch); sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t *)sourceBuffer, &_bodyPitch);
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t *)sourceBuffer, &_bodyRoll); sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t *)sourceBuffer, &_bodyRoll);
memcpy(&_handPosition, sourceBuffer, sizeof(float) * 3);
sourceBuffer += sizeof(float) * 3;
} }
glm::vec3 AvatarData::getBodyPosition() { glm::vec3 AvatarData::getBodyPosition() {
@ -85,6 +93,10 @@ void AvatarData::setBodyPosition(glm::vec3 bodyPosition) {
_bodyPosition = bodyPosition; _bodyPosition = bodyPosition;
} }
void AvatarData::setHandPosition(glm::vec3 handPosition) {
_handPosition = handPosition;
}
float AvatarData::getBodyYaw() { float AvatarData::getBodyYaw() {
return _bodyYaw; return _bodyYaw;
} }

View file

@ -24,6 +24,7 @@ public:
glm::vec3 getBodyPosition(); glm::vec3 getBodyPosition();
void setBodyPosition(glm::vec3 bodyPosition); void setBodyPosition(glm::vec3 bodyPosition);
void setHandPosition(glm::vec3 handPosition);
int getBroadcastData(unsigned char* destinationBuffer); int getBroadcastData(unsigned char* destinationBuffer);
void parseData(unsigned char* sourceBuffer, int numBytes); void parseData(unsigned char* sourceBuffer, int numBytes);
@ -39,6 +40,7 @@ public:
protected: protected:
glm::vec3 _bodyPosition; glm::vec3 _bodyPosition;
glm::vec3 _handPosition;
float _bodyYaw; float _bodyYaw;
float _bodyPitch; float _bodyPitch;

View file

@ -22,7 +22,6 @@ void Orientation::setToIdentity() {
front = glm::vec3( 0.0, 0.0, 1.0 ); front = glm::vec3( 0.0, 0.0, 1.0 );
} }
void Orientation::set( Orientation o ) { void Orientation::set( Orientation o ) {
right = o.right; right = o.right;
up = o.up; up = o.up;
@ -125,7 +124,7 @@ void Orientation::testForOrthogonalAndNormalizedVectors( float epsilon ) {
//---------------------------------------------------------------- //----------------------------------------------------------------
// make sure vectors are orthoginal (or close enough) // make sure vectors are orthogonal (or close enough)
//---------------------------------------------------------------- //----------------------------------------------------------------
glm::vec3 rightCross = glm::cross( up, front ); glm::vec3 rightCross = glm::cross( up, front );
glm::vec3 upCross = glm::cross( front, right ); glm::vec3 upCross = glm::cross( front, right );