From 06f8990d42cab394477466ac525cdbc796eb8e58 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Fri, 19 Apr 2013 14:52:06 -0700 Subject: [PATCH] removed avatar structure from Head class (leftover from the start of the prototyping phase) --- interface/src/Head.cpp | 131 ++++++++++++++++------------------------- interface/src/Head.h | 29 +++------ 2 files changed, 58 insertions(+), 102 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 442c5eefba..7cf053d0a0 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -47,9 +47,9 @@ unsigned int iris_texture_height = 256; Head::Head(bool isMine) { - _avatar.orientation.setToIdentity(); - _avatar.velocity = glm::vec3( 0.0, 0.0, 0.0 ); - _avatar.thrust = glm::vec3( 0.0, 0.0, 0.0 ); + _orientation.setToIdentity(); + _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 ); _closestOtherAvatar = 0; _bodyYaw = -90.0; @@ -134,9 +134,9 @@ Head::Head(bool isMine) { Head::Head(const Head &otherHead) { - _avatar.orientation.set( otherHead._avatar.orientation ); - _avatar.velocity = otherHead._avatar.velocity; - _avatar.thrust = otherHead._avatar.thrust; + _orientation.set( otherHead._orientation ); + _velocity = otherHead._velocity; + _thrust = otherHead._thrust; _rotation = otherHead._rotation; _closestOtherAvatar = otherHead._closestOtherAvatar; _bodyYaw = otherHead._bodyYaw; @@ -314,7 +314,7 @@ void Head::simulate(float deltaTime) { float distance = glm::length( v ); - if ( distance < _avatar.maxArmLength ) { + if ( distance < _maxArmLength ) { if ( distance < closestDistance ) { closestDistance = distance; _closestOtherAvatar = o; @@ -348,31 +348,31 @@ void Head::simulate(float deltaTime) { //------------------------------------------------- // this handles the avatar being driven around... //------------------------------------------------- - _avatar.thrust = glm::vec3( 0.0, 0.0, 0.0 ); + _thrust = glm::vec3( 0.0, 0.0, 0.0 ); if (_driveKeys[FWD]) { - glm::vec3 front( _avatar.orientation.getFront().x, _avatar.orientation.getFront().y, _avatar.orientation.getFront().z ); - _avatar.thrust += front * THRUST_MAG; + glm::vec3 front( _orientation.getFront().x, _orientation.getFront().y, _orientation.getFront().z ); + _thrust += front * THRUST_MAG; } if (_driveKeys[BACK]) { - glm::vec3 front( _avatar.orientation.getFront().x, _avatar.orientation.getFront().y, _avatar.orientation.getFront().z ); - _avatar.thrust -= front * THRUST_MAG; + glm::vec3 front( _orientation.getFront().x, _orientation.getFront().y, _orientation.getFront().z ); + _thrust -= front * THRUST_MAG; } if (_driveKeys[RIGHT]) { - glm::vec3 right( _avatar.orientation.getRight().x, _avatar.orientation.getRight().y, _avatar.orientation.getRight().z ); - _avatar.thrust += right * THRUST_MAG; + glm::vec3 right( _orientation.getRight().x, _orientation.getRight().y, _orientation.getRight().z ); + _thrust += right * THRUST_MAG; } if (_driveKeys[LEFT]) { - glm::vec3 right( _avatar.orientation.getRight().x, _avatar.orientation.getRight().y, _avatar.orientation.getRight().z ); - _avatar.thrust -= right * THRUST_MAG; + glm::vec3 right( _orientation.getRight().x, _orientation.getRight().y, _orientation.getRight().z ); + _thrust -= right * THRUST_MAG; } if (_driveKeys[UP]) { - glm::vec3 up( _avatar.orientation.getUp().x, _avatar.orientation.getUp().y, _avatar.orientation.getUp().z ); - _avatar.thrust += up * THRUST_MAG; + glm::vec3 up( _orientation.getUp().x, _orientation.getUp().y, _orientation.getUp().z ); + _thrust += up * THRUST_MAG; } if (_driveKeys[DOWN]) { - glm::vec3 up( _avatar.orientation.getUp().x, _avatar.orientation.getUp().y, _avatar.orientation.getUp().z ); - _avatar.thrust -= up * THRUST_MAG; + glm::vec3 up( _orientation.getUp().x, _orientation.getUp().y, _orientation.getUp().z ); + _thrust -= up * THRUST_MAG; } if (_driveKeys[ROT_RIGHT]) { _bodyYawDelta -= YAW_MAG * deltaTime; @@ -384,7 +384,7 @@ void Head::simulate(float deltaTime) { //---------------------------------------------------------- - float translationalSpeed = glm::length( _avatar.velocity ); + float translationalSpeed = glm::length( _velocity ); float rotationalSpeed = fabs( _bodyYawDelta ); if ( translationalSpeed + rotationalSpeed > 0.2 ) { @@ -416,18 +416,18 @@ void Head::simulate(float deltaTime) { //---------------------------------------------------------- // add thrust to velocity //---------------------------------------------------------- - _avatar.velocity += glm::dvec3(_avatar.thrust * deltaTime); + _velocity += glm::dvec3(_thrust * deltaTime); //---------------------------------------------------------- // update position by velocity //---------------------------------------------------------- - _bodyPosition += (glm::vec3)_avatar.velocity * deltaTime; + _bodyPosition += (glm::vec3)_velocity * deltaTime; //---------------------------------------------------------- // decay velocity //---------------------------------------------------------- const float LIN_VEL_DECAY = 5.0; - _avatar.velocity *= ( 1.0 - LIN_VEL_DECAY * deltaTime ); + _velocity *= ( 1.0 - LIN_VEL_DECAY * deltaTime ); if (!_noise) { // Decay back toward center @@ -546,7 +546,7 @@ void Head::updateBigSphereCollisionTest( float deltaTime ) { float amp = 1.0 - (distanceToBigSphereCenter / combinedRadius); glm::vec3 collisionForce = vectorFromJointToBigSphere * amp; _bone[b].springyVelocity += collisionForce * 8.0f * deltaTime; - _avatar.velocity += collisionForce * 18.0f * deltaTime; + _velocity += collisionForce * 18.0f * deltaTime; } } } @@ -567,15 +567,15 @@ void Head::updateBigSphereCollisionTest( float deltaTime ) { //---------------------------------------------------------- // add gravity to velocity //---------------------------------------------------------- - _avatar.velocity += glm::dvec3( 0.0, -1.0, 0.0 ) * 0.05; + _velocity += glm::dvec3( 0.0, -1.0, 0.0 ) * 0.05; //---------------------------------------------------------- // ground collisions //---------------------------------------------------------- if ( _bodyPosition.y < 0.0 ) { _bodyPosition.y = 0.0; - if ( _avatar.velocity.y < 0.0 ) { - _avatar.velocity.y *= -0.7; + if ( _velocity.y < 0.0 ) { + _velocity.y *= -0.7; } } } @@ -658,35 +658,6 @@ void Head::render(int faceToFace) { } } - - -//this has been moved to Utils.cpp -/* -void Head::renderOrientationDirections( glm::vec3 position, Orientation orientation, float size ) { - glm::vec3 pRight = position + orientation.right * size; - glm::vec3 pUp = position + orientation.up * size; - glm::vec3 pFront = position + orientation.front * size; - - glColor3f( 1.0f, 0.0f, 0.0f ); - glBegin( GL_LINE_STRIP ); - glVertex3f( position.x, position.y, position.z ); - glVertex3f( pRight.x, pRight.y, pRight.z ); - glEnd(); - - glColor3f( 0.0f, 1.0f, 0.0f ); - glBegin( GL_LINE_STRIP ); - glVertex3f( position.x, position.y, position.z ); - glVertex3f( pUp.x, pUp.y, pUp.z ); - glEnd(); - - glColor3f( 0.0f, 0.0f, 1.0f ); - glBegin( GL_LINE_STRIP ); - glVertex3f( position.x, position.y, position.z ); - glVertex3f( pFront.x, pFront.y, pFront.z ); - glEnd(); -} -*/ - void Head::renderHead(int faceToFace) { @@ -986,7 +957,7 @@ void Head::calculateBoneLengths() { _bone[b].length = glm::length( _bone[b].defaultPosePosition ); } - _avatar.maxArmLength + _maxArmLength = _bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].length + _bone[ AVATAR_BONE_RIGHT_FOREARM ].length + _bone[ AVATAR_BONE_RIGHT_HAND ].length; @@ -996,13 +967,13 @@ void Head::updateSkeleton() { //---------------------------------- // rotate body... //---------------------------------- - _avatar.orientation.setToIdentity(); - _avatar.orientation.yaw( _bodyYaw ); + _orientation.setToIdentity(); + _orientation.yaw( _bodyYaw ); //test! - make sure this does what expected: st rotation to be identity PLUS _bodyYaw - //_rotation = glm::angleAxis( _bodyYaw, _avatar.orientation.up ); + //_rotation = glm::angleAxis( _bodyYaw, _orientation.up ); - //glm::quat yaw_rotation = glm::angleAxis( _bodyYaw, _avatar.orientation.up ); + //glm::quat yaw_rotation = glm::angleAxis( _bodyYaw, _orientation.up ); //------------------------------------------------------------------------ @@ -1010,7 +981,7 @@ void Head::updateSkeleton() { //------------------------------------------------------------------------ for (int b=0; b _avatar.maxArmLength ) { + if ( distance > _maxArmLength ) { //------------------------------------------------------------------------------- // reset right hand to be constrained to maximum arm length //------------------------------------------------------------------------------- _bone[ AVATAR_BONE_RIGHT_HAND ].position = _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; glm::vec3 armNormal = armVector / distance; - armVector = armNormal * _avatar.maxArmLength; - distance = _avatar.maxArmLength; + armVector = armNormal * _maxArmLength; + distance = _maxArmLength; glm::vec3 constrainedPosition = _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; constrainedPosition += armVector; _bone[ AVATAR_BONE_RIGHT_HAND ].position = constrainedPosition; @@ -1200,9 +1171,9 @@ void Head::updateHandMovement() { //----------------------------------------------------------------------------- glm::vec3 newElbowPosition = _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; newElbowPosition += armVector * ONE_HALF; - glm::vec3 perpendicular = glm::cross( _avatar.orientation.getFront(), armVector ); + glm::vec3 perpendicular = glm::cross( _orientation.getFront(), armVector ); - newElbowPosition += perpendicular * ( 1.0f - ( _avatar.maxArmLength / distance ) ) * ONE_HALF; + newElbowPosition += perpendicular * ( 1.0f - ( _maxArmLength / distance ) ) * ONE_HALF; _bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position = newElbowPosition; //----------------------------------------------------------------------------- diff --git a/interface/src/Head.h b/interface/src/Head.h index 554ab3eafe..9ab60f2e73 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -22,16 +22,6 @@ #include #include //looks like we might not need this - -// Note to self: -// modes I might need to implement for avatar -// -// walking usingSprings - ramping down -// bumping into sphere usingSprings is on -// moving hand usingSprings is on -// stuck to another hand usingSprings is on - - enum eyeContactTargets {LEFT_EYE, RIGHT_EYE, MOUTH}; #define FWD 0 @@ -101,14 +91,6 @@ struct AvatarBone float radius; // used for detecting collisions for certain physical effects }; -struct Avatar -{ - glm::dvec3 velocity; - glm::vec3 thrust; - float maxArmLength; - Orientation orientation; -}; - class Head : public AvatarData { public: Head(bool isMine); @@ -176,9 +158,9 @@ class Head : public AvatarData { bool getDriveKeys(int key) { return _driveKeys[key]; }; // Set/Get update the thrust that will move the avatar around - void setThrust(glm::vec3 newThrust) { _avatar.thrust = newThrust; }; - void addThrust(glm::vec3 newThrust) { _avatar.thrust += newThrust; }; - glm::vec3 getThrust() { return _avatar.thrust; }; + void setThrust(glm::vec3 newThrust) { _thrust = newThrust; }; + void addThrust(glm::vec3 newThrust) { _thrust += newThrust; }; + glm::vec3 getThrust() { return _thrust; }; // // Related to getting transmitter UDP data used to animate the avatar hand @@ -237,7 +219,10 @@ class Head : public AvatarData { glm::quat _rotation; // the rotation of the avatar body as a whole AvatarBone _bone[ NUM_AVATAR_BONES ]; AvatarMode _mode; - Avatar _avatar; + glm::dvec3 _velocity; + glm::vec3 _thrust; + float _maxArmLength; + Orientation _orientation; int _driveKeys[MAX_DRIVE_KEYS]; int _eyeContact; eyeContactTargets _eyeContactTarget;