diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 3c23cf32cd..c5364c0029 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -3,7 +3,7 @@ // interface // // Created by Philip Rosedale on 9/11/12. -// adapted by Jeffrey Ventrella +// adapted by Jeffrey Ventrella // Copyright (c) 2012 Physical, Inc.. All rights reserved. // @@ -47,7 +47,7 @@ Avatar::Avatar(bool isMine) { _velocity = glm::vec3( 0.0, 0.0, 0.0 ); _thrust = glm::vec3( 0.0, 0.0, 0.0 ); - _rotation = glm::quat( 0.0f, 0.0f, 0.0f, 0.0f ); + _rotation = glm::quat( 0.0f, 0.0f, 0.0f, 0.0f ); _bodyYaw = -90.0; _bodyPitch = 0.0; _bodyRoll = 0.0; @@ -59,13 +59,13 @@ Avatar::Avatar(bool isMine) { //_transmitterTimer = 0; _transmitterHz = 0.0; _transmitterPackets = 0; - + initializeSkeleton(); _TEST_bigSphereRadius = 0.3f; _TEST_bigSpherePosition = glm::vec3( 0.0f, _TEST_bigSphereRadius, 2.0f ); - for (int i = 0; i < MAX_DRIVE_KEYS; i++) _driveKeys[i] = false; + for (int i = 0; i < MAX_DRIVE_KEYS; i++) _driveKeys[i] = false; _head.pupilSize = 0.10; _head.interPupilDistance = 0.6; @@ -84,13 +84,13 @@ Avatar::Avatar(bool isMine) { _head.mouthHeight = 0.2; _head.eyeballPitch[0] = 0; _head.eyeballPitch[1] = 0; - _head.eyeballScaleX = 1.2; - _head.eyeballScaleY = 1.5; + _head.eyeballScaleX = 1.2; + _head.eyeballScaleY = 1.5; _head.eyeballScaleZ = 1.0; _head.eyeballYaw[0] = 0; _head.eyeballYaw[1] = 0; _head.pitchTarget = 0; - _head.yawTarget = 0; + _head.yawTarget = 0; _head.noiseEnvelope = 1.0; _head.pupilConverge = 10.0; _head.leanForward = 0.0; @@ -129,7 +129,7 @@ Avatar::Avatar(bool isMine) { Avatar::Avatar(const Avatar &otherAvatar) { - + _velocity = otherAvatar._velocity; _thrust = otherAvatar._thrust; _rotation = otherAvatar._rotation; @@ -152,15 +152,15 @@ Avatar::Avatar(const Avatar &otherAvatar) { _movedHandOffset = otherAvatar._movedHandOffset; _usingBodySprings = otherAvatar._usingBodySprings; _springForce = otherAvatar._springForce; - _springVelocityDecay = otherAvatar._springVelocityDecay; + _springVelocityDecay = otherAvatar._springVelocityDecay; _orientation.set( otherAvatar._orientation ); - + _sphere = NULL; - + initializeSkeleton(); for (int i = 0; i < MAX_DRIVE_KEYS; i++) _driveKeys[i] = otherAvatar._driveKeys[i]; - + _head.pupilSize = otherAvatar._head.pupilSize; _head.interPupilDistance = otherAvatar._head.interPupilDistance; _head.interBrowDistance = otherAvatar._head.interBrowDistance; @@ -223,7 +223,7 @@ void Avatar::reset() { } -//this pertains to moving the head with the glasses +//this pertains to moving the head with the glasses void Avatar::UpdateGyros(float frametime, SerialInterface * serialInterface, glm::vec3 * gravity) // Using serial data, update avatar/render position and angles { @@ -232,14 +232,14 @@ void Avatar::UpdateGyros(float frametime, SerialInterface * serialInterface, glm float measured_pitch_rate = serialInterface->getRelativeValue(HEAD_PITCH_RATE); _head.yawRate = serialInterface->getRelativeValue(HEAD_YAW_RATE); float measured_lateral_accel = serialInterface->getRelativeValue(ACCEL_X) - - ROLL_ACCEL_COUPLING*serialInterface->getRelativeValue(HEAD_ROLL_RATE); + ROLL_ACCEL_COUPLING*serialInterface->getRelativeValue(HEAD_ROLL_RATE); float measured_fwd_accel = serialInterface->getRelativeValue(ACCEL_Z) - - PITCH_ACCEL_COUPLING*serialInterface->getRelativeValue(HEAD_PITCH_RATE); + PITCH_ACCEL_COUPLING*serialInterface->getRelativeValue(HEAD_PITCH_RATE); float measured_roll_rate = serialInterface->getRelativeValue(HEAD_ROLL_RATE); - - //printLog("Pitch Rate: %d ACCEL_Z: %d\n", serialInterface->getRelativeValue(PITCH_RATE), + + //printLog("Pitch Rate: %d ACCEL_Z: %d\n", serialInterface->getRelativeValue(PITCH_RATE), // serialInterface->getRelativeValue(ACCEL_Z)); - //printLog("Pitch Rate: %d ACCEL_X: %d\n", serialInterface->getRelativeValue(PITCH_RATE), + //printLog("Pitch Rate: %d ACCEL_X: %d\n", serialInterface->getRelativeValue(PITCH_RATE), // serialInterface->getRelativeValue(ACCEL_Z)); //printLog("Pitch: %f\n", Pitch); @@ -251,12 +251,12 @@ void Avatar::UpdateGyros(float frametime, SerialInterface * serialInterface, glm const float MIN_PITCH = -45; const float MAX_YAW = 85; const float MIN_YAW = -85; - + if ((_headPitch < MAX_PITCH) && (_headPitch > MIN_PITCH)) addHeadPitch(measured_pitch_rate * -HEAD_ROTATION_SCALE * frametime); addHeadRoll(measured_roll_rate * HEAD_ROLL_SCALE * frametime); - + if ((_headYaw < MAX_YAW) && (_headYaw > MIN_YAW)) addHeadYaw(_head.yawRate * HEAD_ROTATION_SCALE * frametime); @@ -264,7 +264,7 @@ void Avatar::UpdateGyros(float frametime, SerialInterface * serialInterface, glm } void Avatar::addLean(float x, float z) { - // Add Body lean as impulse + // Add Body lean as impulse _head.leanSideways += x; _head.leanForward += z; } @@ -283,72 +283,70 @@ void Avatar::setMousePressed( bool d ) { } void Avatar::simulate(float deltaTime) { - + // update avatar skeleton updateSkeleton(); // reset hand and arm positions according to hand movement updateHandMovement( deltaTime ); - + if ( !_interactingOtherIsNearby ) { //initialize _handHolding _handHolding.position = _bone[ AVATAR_BONE_RIGHT_HAND ].position; _handHolding.velocity = glm::vec3( 0.0, 0.0, 0.0 ); } - + _interactingOtherIsNearby = false; // if the avatar being simulated is mine, then loop through - // all the other avatars to get information about them... - //------------------------------------------------------------- - if ( _isMine ) { - _nearOtherAvatar = false; + // all the other avatars for potential interactions... + if ( _isMine ) + { float closestDistance = 10000.0f; - AgentList* agentList = AgentList::getInstance(); + AgentList * agentList = AgentList::getInstance(); - //_numOtherAvatars = 0; - for(AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { + if ((*agent).getLinkedData() != NULL && (*agent).getType() == AGENT_TYPE_AVATAR) { - Head *otherAvatar = (Head *)(*agent).getLinkedData(); + Avatar *otherAvatar = (Avatar *)(*agent).getLinkedData(); - // check for collisions with other avatars and respond + // check for collisions with other avatars and respond updateAvatarCollisionDetectionAndResponse ( - otherAvatar->getBonePosition( AVATAR_BONE_PELVIS_SPINE ), - 0.2, - 0.2, - otherAvatar->getBodyUpDirection(), - deltaTime - ); + otherAvatar->getBonePosition( AVATAR_BONE_PELVIS_SPINE ), + 0.2, + 0.2, + otherAvatar->getBodyUpDirection(), + deltaTime + ); - // test other avatar hand position for proximity + // test other avatar hand position for proximity glm::vec3 v( _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position ); v -= otherAvatar->getBonePosition( AVATAR_BONE_RIGHT_HAND ); float distance = glm::length( v ); if ( distance < _maxArmLength ) { - + //if ( distance < closestDistance ) { // perhaps I don't need this if we want to allow multi-avatar interactions { closestDistance = distance; _interactingOther = otherAvatar; _interactingOtherIsNearby = true; - // if I am holding hands with another avatar, a force is applied + // if I am holding hands with another avatar, a force is applied if (( _handState == 1 ) || ( _interactingOther->_handState == 1 )) { glm::vec3 vectorToOtherHand = _interactingOther->_handPosition - _handHolding.position; glm::vec3 vectorToMyHand = _bone[ AVATAR_BONE_RIGHT_HAND ].position - _handHolding.position; _handHolding.velocity *= 0.7; - _handHolding.velocity += ( vectorToOtherHand + vectorToMyHand ) * _handHolding.force * deltaTime; + _handHolding.velocity += ( vectorToOtherHand + vectorToMyHand ) * _handHolding.force * deltaTime; _handHolding.position += _handHolding.velocity; - _bone[ AVATAR_BONE_RIGHT_HAND ].position = _handHolding.position; - } + _bone[ AVATAR_BONE_RIGHT_HAND ].position = _handHolding.position; + } } } } @@ -361,22 +359,22 @@ void Avatar::simulate(float deltaTime) { updateArmIKAndConstraints( deltaTime ); - + if (!_interactingOtherIsNearby) { _interactingOther = NULL; } - + if ( usingBigSphereCollisionTest ) { - + // test for avatar collision response (using a big sphere :) updateAvatarCollisionDetectionAndResponse ( - _TEST_bigSpherePosition, - _TEST_bigSphereRadius, - _TEST_bigSphereRadius, - glm::vec3( 0.0, 1.0, 0.0 ), - deltaTime - ); + _TEST_bigSpherePosition, + _TEST_bigSphereRadius, + _TEST_bigSphereRadius, + glm::vec3( 0.0, 1.0, 0.0 ), + deltaTime + ); } if ( AVATAR_GRAVITY ) { @@ -385,20 +383,20 @@ void Avatar::simulate(float deltaTime) { } else { if ( _position.y < _bone[ AVATAR_BONE_RIGHT_FOOT ].radius ) { - _position.y = _bone[ AVATAR_BONE_RIGHT_FOOT ].radius; + _position.y = _bone[ AVATAR_BONE_RIGHT_FOOT ].radius; _velocity.y = 0.0; - } + } } } // update body springs updateBodySprings( deltaTime ); - - // driving the avatar around should only apply if this is my avatar (as opposed to an avatar being driven remotely) + + // driving the avatar around should only apply if this is my avatar (as opposed to an avatar being driven remotely) if ( _isMine ) { - + _thrust = glm::vec3( 0.0, 0.0, 0.0 ); - + if (_driveKeys[FWD]) { glm::vec3 front( _orientation.getFront().x, _orientation.getFront().y, _orientation.getFront().z ); _thrust += front * THRUST_MAG; @@ -423,14 +421,14 @@ void Avatar::simulate(float deltaTime) { glm::vec3 up( _orientation.getUp().x, _orientation.getUp().y, _orientation.getUp().z ); _thrust -= up * THRUST_MAG; } - if (_driveKeys[ROT_RIGHT]) { + if (_driveKeys[ROT_RIGHT]) { _bodyYawDelta -= YAW_MAG * deltaTime; } - if (_driveKeys[ROT_LEFT]) { + if (_driveKeys[ROT_LEFT]) { _bodyYawDelta += YAW_MAG * deltaTime; } } - + float translationalSpeed = glm::length( _velocity ); float rotationalSpeed = fabs( _bodyYawDelta ); if ( translationalSpeed + rotationalSpeed > 0.2 ) @@ -441,21 +439,21 @@ void Avatar::simulate(float deltaTime) { { _mode = AVATAR_MODE_INTERACTING; } - + // update body yaw by body yaw delta if (_isMine) { - _bodyYaw += _bodyYawDelta * deltaTime; + _bodyYaw += _bodyYawDelta * deltaTime; } - + // decay body yaw delta _bodyYawDelta *= (1.0 - TEST_YAW_DECAY * deltaTime); - + // add thrust to velocity _velocity += glm::dvec3(_thrust * deltaTime); - + // update position by velocity _position += (glm::vec3)_velocity * deltaTime; - + // decay velocity _velocity *= ( 1.0 - LIN_VEL_DECAY * deltaTime ); @@ -464,13 +462,13 @@ void Avatar::simulate(float deltaTime) { // if (!_head.noise) { - // Decay back toward center + // Decay back toward center _headPitch *= (1.0f - DECAY * 2 * deltaTime); _headYaw *= (1.0f - DECAY * 2 * deltaTime); _headRoll *= (1.0f - DECAY * 2 * deltaTime); } else { - // Move toward new target + // Move toward new target _headPitch += (_head.pitchTarget - _headPitch) * 10 * deltaTime; // (1.f - DECAY*deltaTime)*Pitch + ; _headYaw += (_head.yawTarget - _headYaw ) * 10 * deltaTime; // (1.f - DECAY*deltaTime); _headRoll *= 1.f - (DECAY * deltaTime); @@ -479,7 +477,7 @@ void Avatar::simulate(float deltaTime) { _head.leanForward *= (1.f - DECAY * 30 * deltaTime); _head.leanSideways *= (1.f - DECAY * 30 * deltaTime); - // Update where the avatar's eyes are + // Update where the avatar's eyes are // // First, decide if we are making eye contact or not if (randFloat() < 0.005) { @@ -497,7 +495,7 @@ void Avatar::simulate(float deltaTime) { const float DEGREES_BETWEEN_VIEWER_EYES = 3; const float DEGREES_TO_VIEWER_MOUTH = 7; - + if (_head.eyeContact) { // Should we pick a new eye contact target? if (randFloat() < 0.01) { @@ -519,7 +517,7 @@ void Avatar::simulate(float deltaTime) { _head.eyeballYaw[0] = _head.eyeballYaw[1] = -_headYaw + eye_target_yaw_adjust; } - + if (_head.noise) { _headPitch += (randFloat() - 0.5) * 0.2 * _head.noiseEnvelope; @@ -531,14 +529,14 @@ void Avatar::simulate(float deltaTime) { if (!_head.eyeContact) { if (randFloat() < 0.01) _head.eyeballPitch[0] = _head.eyeballPitch[1] = (randFloat() - 0.5) * 20; if (randFloat() < 0.01) _head.eyeballYaw[0] = _head.eyeballYaw[1] = (randFloat()- 0.5) * 10; - } - + } + if ((randFloat() < 0.005) && (fabs(_head.pitchTarget - _headPitch) < 1.0) && (fabs(_head.yawTarget - _headYaw) < 1.0)) { SetNewHeadTarget((randFloat()-0.5) * 20.0, (randFloat()-0.5) * 45.0); } - + if (0) { - + // Pick new target _head.pitchTarget = (randFloat() - 0.5) * 45; _head.yawTarget = (randFloat() - 0.5) * 22; @@ -554,10 +552,10 @@ void Avatar::simulate(float deltaTime) { // Update audio trailing average for rendering facial animations const float AUDIO_AVERAGING_SECS = 0.05; _head.averageLoudness = (1.f - deltaTime / AUDIO_AVERAGING_SECS) * _head.averageLoudness + - (deltaTime / AUDIO_AVERAGING_SECS) * _audioLoudness; + (deltaTime / AUDIO_AVERAGING_SECS) * _audioLoudness; } - - + + float Avatar::getGirth() { return COLLISION_BODY_RADIUS; } @@ -565,38 +563,38 @@ float Avatar::getGirth() { float Avatar::getHeight() { return COLLISION_HEIGHT; } - - + + glm::vec3 Avatar::getBodyUpDirection() { return _orientation.getUp(); } - + // This is a workspace for testing avatar body collision detection and response void Avatar::updateAvatarCollisionDetectionAndResponse ( glm::vec3 collisionPosition, float collisionGirth, float collisionHeight, glm::vec3 collisionUpVector, float deltaTime ) { - + float myBodyApproximateBoundingRadius = 1.0f; glm::vec3 vectorFromMyBodyToBigSphere(_position - collisionPosition); bool jointCollision = false; - + float distanceToBigSphere = glm::length(vectorFromMyBodyToBigSphere); if ( distanceToBigSphere < myBodyApproximateBoundingRadius + collisionGirth ) { - for (int b=0; b 0.0) + if (distanceToBigSphereCenter > 0.0) { glm::vec3 directionVector = vectorFromJointToBigSphereCenter / distanceToBigSphereCenter; - float penetration = 1.0 - (distanceToBigSphereCenter / combinedRadius); - glm::vec3 collisionForce = vectorFromJointToBigSphereCenter * penetration; - + float penetration = 1.0 - (distanceToBigSphereCenter / combinedRadius); + glm::vec3 collisionForce = vectorFromJointToBigSphereCenter * penetration; + _bone[b].springyVelocity += collisionForce * 30.0f * deltaTime; _velocity += collisionForce * 100.0f * deltaTime; _bone[b].springyPosition = collisionPosition + directionVector * combinedRadius; @@ -608,43 +606,43 @@ void Avatar::updateAvatarCollisionDetectionAndResponse if (!_usingBodySprings) { _usingBodySprings = true; initializeBodySprings(); - } - } + } + } } } void Avatar::render(bool lookingInMirror) { - + // show avatar position glColor4f( 0.5f, 0.5f, 0.5f, 0.6 ); glPushMatrix(); - glTranslatef(_position.x, _position.y, _position.z); - glScalef( 0.03, 0.03, 0.03 ); - glutSolidSphere( 1, 10, 10 ); + glTranslatef(_position.x, _position.y, _position.z); + glScalef( 0.03, 0.03, 0.03 ); + glutSolidSphere( 1, 10, 10 ); glPopMatrix(); if ( usingBigSphereCollisionTest ) { - - // show TEST big sphere + + // show TEST big sphere glColor4f( 0.5f, 0.6f, 0.8f, 0.7 ); glPushMatrix(); - glTranslatef(_TEST_bigSpherePosition.x, _TEST_bigSpherePosition.y, _TEST_bigSpherePosition.z); - glScalef( _TEST_bigSphereRadius, _TEST_bigSphereRadius, _TEST_bigSphereRadius ); - glutSolidSphere( 1, 20, 20 ); + glTranslatef(_TEST_bigSpherePosition.x, _TEST_bigSpherePosition.y, _TEST_bigSpherePosition.z); + glScalef( _TEST_bigSphereRadius, _TEST_bigSphereRadius, _TEST_bigSphereRadius ); + glutSolidSphere( 1, 20, 20 ); glPopMatrix(); - } - + } + // render body renderBody(); - + // render head renderHead(lookingInMirror); // if this is my avatar, then render my interactions with the other avatar if ( _isMine ) { - if ( _interactingOtherIsNearby ) { - + if ( _interactingOtherIsNearby ) { + glm::vec3 v1( _bone[ AVATAR_BONE_RIGHT_HAND ].position ); glm::vec3 v2( _interactingOther->_handPosition ); @@ -658,10 +656,10 @@ void Avatar::render(bool lookingInMirror) { } } - + void Avatar::renderHead(bool lookingInMirror) { int side = 0; - + glEnable(GL_DEPTH_TEST); glEnable(GL_RESCALE_NORMAL); @@ -682,7 +680,7 @@ void Avatar::renderHead(bool lookingInMirror) { } glScalef( 0.03, 0.03, 0.03 ); - + if (lookingInMirror) { glRotatef(_bodyYaw - _headYaw, 0, 1, 0); glRotatef(_bodyPitch + _headPitch, 1, 0, 0); @@ -697,22 +695,22 @@ void Avatar::renderHead(bool lookingInMirror) { glColor3fv(skinColor); glutSolidSphere(1, 30, 30); - + // Ears glPushMatrix(); - glTranslatef(1.0, 0, 0); - for(side = 0; side < 2; side++) { - glPushMatrix(); - glScalef(0.3, 0.65, .65); - glutSolidSphere(0.5, 30, 30); - glPopMatrix(); - glTranslatef(-2.0, 0, 0); - } + glTranslatef(1.0, 0, 0); + for(side = 0; side < 2; side++) { + glPushMatrix(); + glScalef(0.3, 0.65, .65); + glutSolidSphere(0.5, 30, 30); + glPopMatrix(); + glTranslatef(-2.0, 0, 0); + } glPopMatrix(); - - - // Update audio attack data for facial animation (eyebrows and mouth) - _head.audioAttack = 0.9 * _head.audioAttack + 0.1 * fabs(_audioLoudness - _head.lastLoudness); + + + // Update audio attack data for facial animation (eyebrows and mouth) + _head.audioAttack = 0.9 * _head.audioAttack + 0.1 * fabs(_audioLoudness - _head.lastLoudness); _head.lastLoudness = _audioLoudness; @@ -721,43 +719,43 @@ void Avatar::renderHead(bool lookingInMirror) { _head.browAudioLift += sqrt(_head.audioAttack) / 1000.0; _head.browAudioLift *= .90; - + // Render Eyebrows glPushMatrix(); - glTranslatef(-_head.interBrowDistance / 2.0,0.4,0.45); - for(side = 0; side < 2; side++) { - glColor3fv(browColor); - glPushMatrix(); - glTranslatef(0, 0.35 + _head.browAudioLift, 0); - glRotatef(_head.eyebrowPitch[side]/2.0, 1, 0, 0); - glRotatef(_head.eyebrowRoll[side]/2.0, 0, 0, 1); - glScalef(browWidth, browThickness, 1); - glutSolidCube(0.5); - glPopMatrix(); - glTranslatef(_head.interBrowDistance, 0, 0); - } + glTranslatef(-_head.interBrowDistance / 2.0,0.4,0.45); + for(side = 0; side < 2; side++) { + glColor3fv(browColor); + glPushMatrix(); + glTranslatef(0, 0.35 + _head.browAudioLift, 0); + glRotatef(_head.eyebrowPitch[side]/2.0, 1, 0, 0); + glRotatef(_head.eyebrowRoll[side]/2.0, 0, 0, 1); + glScalef(browWidth, browThickness, 1); + glutSolidCube(0.5); + glPopMatrix(); + glTranslatef(_head.interBrowDistance, 0, 0); + } glPopMatrix(); // Mouth glPushMatrix(); - glTranslatef(0,-0.35,0.75); - glColor3f(0,0,0); - glRotatef(_head.mouthPitch, 1, 0, 0); - glRotatef(_head.mouthYaw, 0, 0, 1); - glScalef(_head.mouthWidth*(.7 + sqrt(_head.averageLoudness)/60.0), _head.mouthHeight*(1.0 + sqrt(_head.averageLoudness)/30.0), 1); - glutSolidCube(0.5); + glTranslatef(0,-0.35,0.75); + glColor3f(0,0,0); + glRotatef(_head.mouthPitch, 1, 0, 0); + glRotatef(_head.mouthYaw, 0, 0, 1); + glScalef(_head.mouthWidth*(.7 + sqrt(_head.averageLoudness)/60.0), _head.mouthHeight*(1.0 + sqrt(_head.averageLoudness)/30.0), 1); + glutSolidCube(0.5); glPopMatrix(); glTranslatef(0, 1.0, 0); - + glTranslatef(-_head.interPupilDistance/2.0,-0.68,0.7); // Right Eye glRotatef(-10, 1, 0, 0); glColor3fv(eyeColor); - glPushMatrix(); + glPushMatrix(); { glTranslatef(_head.interPupilDistance/10.0, 0, 0.05); glRotatef(20, 0, 0, 1); @@ -775,7 +773,7 @@ void Avatar::renderHead(bool lookingInMirror) { gluQuadricOrientation(_sphere, GLU_OUTSIDE); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, iris_texture_width, iris_texture_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, &iris_texture[0]); } - + glPushMatrix(); { glRotatef(_head.eyeballPitch[1], 1, 0, 0); @@ -788,12 +786,12 @@ void Avatar::renderHead(bool lookingInMirror) { gluSphere(_sphere, _head.pupilSize, 15, 15); glDisable(GL_TEXTURE_2D); } - + glPopMatrix(); // Left Eye glColor3fv(eyeColor); glTranslatef(_head.interPupilDistance, 0, 0); - glPushMatrix(); + glPushMatrix(); { glTranslatef(-_head.interPupilDistance/10.0, 0, .05); glRotatef(-20, 0, 0, 1); @@ -809,20 +807,20 @@ void Avatar::renderHead(bool lookingInMirror) { glTranslatef(0, 0, .35); glRotatef(-75, 1, 0, 0); glScalef(1.0, 0.4, 1.0); - + glEnable(GL_TEXTURE_2D); gluSphere(_sphere, _head.pupilSize, 15, 15); glDisable(GL_TEXTURE_2D); } glPopMatrix(); - - + + glPopMatrix(); - } - -void Avatar::startHandMovement() { +} +void Avatar::startHandMovement() { + if (!_usingBodySprings) { initializeBodySprings(); _usingBodySprings = true; @@ -830,9 +828,9 @@ void Avatar::startHandMovement() { } void Avatar::stopHandMovement() { -//_usingBodySprings = false; + //_usingBodySprings = false; } - + void Avatar::setHandMovementValues( glm::vec3 handOffset ) { _movedHandOffset = handOffset; } @@ -842,7 +840,7 @@ AvatarMode Avatar::getMode() { } void Avatar::initializeSkeleton() { - + for (int b=0; b 0.0f ) { @@ -1023,16 +1021,16 @@ void Avatar::updateBodySprings( float deltaTime ) { } _bone[b].springyVelocity += ( _bone[b].position - _bone[b].springyPosition ) * _bone[b].springBodyTightness * deltaTime; - + float decay = 1.0 - _springVelocityDecay * deltaTime; if ( decay > 0.0 ) { _bone[b].springyVelocity *= decay; } 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; } } @@ -1040,32 +1038,32 @@ void Avatar::updateBodySprings( float deltaTime ) { glm::vec3 Avatar::getHeadLookatDirection() { return glm::vec3 ( - _orientation.getFront().x, - _orientation.getFront().y, - _orientation.getFront().z - ); + _orientation.getFront().x, + _orientation.getFront().y, + _orientation.getFront().z + ); } glm::vec3 Avatar::getHeadLookatDirectionUp() { return glm::vec3 ( - _orientation.getUp().x, - _orientation.getUp().y, - _orientation.getUp().z - ); + _orientation.getUp().x, + _orientation.getUp().y, + _orientation.getUp().z + ); } glm::vec3 Avatar::getHeadLookatDirectionRight() { return glm::vec3 ( - _orientation.getRight().x, - _orientation.getRight().y, - _orientation.getRight().z - ); + _orientation.getRight().x, + _orientation.getRight().y, + _orientation.getRight().z + ); } glm::vec3 Avatar::getHeadPosition() { - + if ( _usingBodySprings ) { return _bone[ AVATAR_BONE_HEAD ].springyPosition; } @@ -1082,8 +1080,8 @@ glm::vec3 Avatar::getBonePosition( AvatarBoneID b ) { void Avatar::updateHandMovement( float deltaTime ) { glm::vec3 transformedHandMovement; - - transformedHandMovement + + transformedHandMovement = _orientation.getRight() * _movedHandOffset.x + _orientation.getUp() * -_movedHandOffset.y * 0.5f + _orientation.getFront() * -_movedHandOffset.y; @@ -1097,11 +1095,11 @@ void Avatar::updateHandMovement( float deltaTime ) { void Avatar::updateArmIKAndConstraints( float deltaTime ) { - + // determine the arm vector glm::vec3 armVector = _bone[ AVATAR_BONE_RIGHT_HAND ].position; armVector -= _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; - + // test to see if right hand is being dragged beyond maximum arm length float distance = glm::length( armVector ); @@ -1116,15 +1114,15 @@ void Avatar::updateArmIKAndConstraints( float deltaTime ) { constrainedPosition += armVector; _bone[ AVATAR_BONE_RIGHT_HAND ].position = constrainedPosition; } - - // set elbow position + + // set elbow position glm::vec3 newElbowPosition = _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; newElbowPosition += armVector * ONE_HALF; glm::vec3 perpendicular = glm::cross( _orientation.getFront(), armVector ); newElbowPosition += perpendicular * ( 1.0f - ( _maxArmLength / distance ) ) * ONE_HALF; _bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position = newElbowPosition; - - // set wrist position + + // set wrist position glm::vec3 vv( _bone[ AVATAR_BONE_RIGHT_HAND ].position ); vv -= _bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position; glm::vec3 newWristPosition = _bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position; @@ -1136,35 +1134,35 @@ void Avatar::updateArmIKAndConstraints( float deltaTime ) { void Avatar::renderBody() { - + // Render bone positions as spheres for (int b=0; bANG_VEL_THRESHOLD?gyrX*angVelScale:0, + fabs(gyrZ*angVelScale)>ANG_VEL_THRESHOLD?gyrZ*angVelScale:0, + fabs(-gyrY*angVelScale)>ANG_VEL_THRESHOLD?-gyrY*angVelScale:0); + + // Add linear forces to the hand + //const float LINEAR_VEL_SENSITIVITY = 50.0; + const float LINEAR_VEL_SENSITIVITY = 5.0; + float linVelScale = LINEAR_VEL_SENSITIVITY*(1.0f/getTransmitterHz()); + glm::vec3 linVel(linX*linVelScale, linZ*linVelScale, -linY*linVelScale); + addVelocity(linVel); + */ - addAngularVelocity(fabs(gyrX*angVelScale)>ANG_VEL_THRESHOLD?gyrX*angVelScale:0, - fabs(gyrZ*angVelScale)>ANG_VEL_THRESHOLD?gyrZ*angVelScale:0, - fabs(-gyrY*angVelScale)>ANG_VEL_THRESHOLD?-gyrY*angVelScale:0); - - // Add linear forces to the hand - //const float LINEAR_VEL_SENSITIVITY = 50.0; - const float LINEAR_VEL_SENSITIVITY = 5.0; - float linVelScale = LINEAR_VEL_SENSITIVITY*(1.0f/getTransmitterHz()); - glm::vec3 linVel(linX*linVelScale, linZ*linVelScale, -linY*linVelScale); - addVelocity(linVel); - */ - -} - +} \ No newline at end of file diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 4ae1334262..131ff26c93 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -914,7 +914,7 @@ void display(void) agent != agentList->end(); agent++) { if ((*agent).getLinkedData() != NULL && (*agent).getType() == AGENT_TYPE_AVATAR) { - Head *avatar = (Head *)(*agent).getLinkedData(); + Avatar *avatar = (Avatar *)(*agent).getLinkedData(); avatar->render(0); } } @@ -1500,7 +1500,7 @@ void idle(void) { AgentList * agentList = AgentList::getInstance(); for(AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { if ((*agent).getLinkedData() != NULL) { - Head *avatar = (Head *)(*agent).getLinkedData(); + Avatar *avatar = (Avatar *)(*agent).getLinkedData(); avatar->simulate(deltaTime); } }