consolidated some code in Head.cpp

This commit is contained in:
Jeffrey Ventrella 2013-04-16 20:35:50 -07:00
parent e825764304
commit 1fb8d0b268
3 changed files with 82 additions and 21 deletions

View file

@ -48,6 +48,26 @@ unsigned int iris_texture_height = 256;
Head::Head() { Head::Head() {
initializeAvatar(); initializeAvatar();
avatar.velocity = glm::vec3( 0.0, 0.0, 0.0 );
avatar.thrust = glm::vec3( 0.0, 0.0, 0.0 );
avatar.orientation.setToIdentity();
closestOtherAvatar = 0;
_bodyYaw = -90.0;
_bodyPitch = 0.0;
_bodyRoll = 0.0;
bodyYawDelta = 0.0;
triggeringAction = false;
mode = AVATAR_MODE_STANDING;
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;
@ -121,6 +141,25 @@ Head::Head() {
Head::Head(const Head &otherHead) { Head::Head(const Head &otherHead) {
initializeAvatar(); initializeAvatar();
avatar.velocity = otherHead.avatar.velocity;
avatar.thrust = otherHead.avatar.thrust;
avatar.orientation.set( otherHead.avatar.orientation );
closestOtherAvatar = otherHead.closestOtherAvatar;
_bodyYaw = otherHead._bodyYaw;
_bodyPitch = otherHead._bodyPitch;
_bodyRoll = otherHead._bodyRoll;
bodyYawDelta = otherHead.bodyYawDelta;
triggeringAction = otherHead.triggeringAction;
mode = otherHead.mode;
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];
@ -298,14 +337,14 @@ void Head::simulate(float deltaTime) {
//------------------------ //------------------------
// update avatar skeleton // update avatar skeleton
//------------------------ //------------------------
updateAvatarSkeleton(); updateSkeleton();
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// 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 ){
initializeAvatarSprings(); initializeBodySprings();
usingSprings = true; usingSprings = true;
//printf( "just started moving hand\n" ); //printf( "just started moving hand\n" );
} }
@ -319,7 +358,7 @@ void Head::simulate(float deltaTime) {
if ( handBeingMoved ) { if ( handBeingMoved ) {
updateHandMovement(); updateHandMovement();
updateAvatarSprings( deltaTime ); updateBodySprings( deltaTime );
} }
previousHandBeingMoved = handBeingMoved; previousHandBeingMoved = handBeingMoved;
@ -508,6 +547,8 @@ void Head::simulate(float deltaTime) {
void Head::render(int faceToFace, int isMine) { void Head::render(int faceToFace, int isMine) {
/*
//--------------------------------------------------- //---------------------------------------------------
// show avatar position // show avatar position
//--------------------------------------------------- //---------------------------------------------------
@ -516,7 +557,8 @@ void Head::render(int faceToFace, int isMine) {
glScalef( 0.03, 0.03, 0.03 ); glScalef( 0.03, 0.03, 0.03 );
glutSolidSphere( 1, 10, 10 ); glutSolidSphere( 1, 10, 10 );
glPopMatrix(); glPopMatrix();
*/
//--------------------------------------------------- //---------------------------------------------------
// show avatar orientation // show avatar orientation
//--------------------------------------------------- //---------------------------------------------------
@ -768,6 +810,7 @@ AvatarMode Head::getMode() {
void Head::initializeAvatar() { void Head::initializeAvatar() {
/*
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(); avatar.orientation.setToIdentity();
@ -783,7 +826,16 @@ void Head::initializeAvatar() {
triggeringAction = false; triggeringAction = false;
mode = AVATAR_MODE_STANDING; mode = AVATAR_MODE_STANDING;
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].position = glm::vec3( 0.0, 0.0, 0.0 );
bone[b].springyPosition = glm::vec3( 0.0, 0.0, 0.0 ); bone[b].springyPosition = glm::vec3( 0.0, 0.0, 0.0 );
@ -875,10 +927,12 @@ void Head::initializeAvatar() {
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// generate world positions // generate world positions
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
updateAvatarSkeleton(); updateSkeleton();
} }
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 );
@ -892,7 +946,7 @@ void Head::calculateBoneLengths() {
void Head::updateAvatarSkeleton() { void Head::updateSkeleton() {
//---------------------------------- //----------------------------------
// rotate body... // rotate body...
//---------------------------------- //----------------------------------
@ -927,7 +981,7 @@ void Head::updateAvatarSkeleton() {
} }
void Head::initializeAvatarSprings() { 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 );
@ -935,7 +989,7 @@ void Head::initializeAvatarSprings() {
} }
void Head::updateAvatarSprings( 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 );

View file

@ -210,6 +210,8 @@ class Head : public AvatarData {
float closeEnoughToInteract; float closeEnoughToInteract;
int closestOtherAvatar; int closestOtherAvatar;
//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 ];
@ -233,14 +235,7 @@ class Head : public AvatarData {
AvatarBone bone[ NUM_AVATAR_BONES ]; AvatarBone bone[ NUM_AVATAR_BONES ];
AvatarMode mode; AvatarMode mode;
void initializeAvatar();
void updateAvatarSkeleton();
void initializeAvatarSprings();
void updateAvatarSprings( float deltaTime );
void calculateBoneLengths();
void readSensors();
float renderYaw, renderPitch; // Pitch from view frustum when this is own head. float renderYaw, renderPitch; // Pitch from view frustum when this is own head.
// //
@ -250,6 +245,18 @@ class Head : public AvatarData {
float transmitterHz; float transmitterHz;
int transmitterPackets; int transmitterPackets;
//-------------------------------------------
// private methods...
//-------------------------------------------
void initializeAvatar();
void initializeSkeleton();
void updateSkeleton();
void initializeBodySprings();
void updateBodySprings( float deltaTime );
void calculateBoneLengths();
void readSensors();
}; };
#endif #endif

View file

@ -9,7 +9,7 @@
#include <SharedUtil.h> #include <SharedUtil.h>
static bool testingForNormalizationAndOrthogonality = false; static bool testingForNormalizationAndOrthogonality = true;
Orientation::Orientation() { Orientation::Orientation() {
right = glm::vec3( 1.0, 0.0, 0.0 ); right = glm::vec3( 1.0, 0.0, 0.0 );
@ -94,9 +94,9 @@ void Orientation::setRightUpFront( const glm::vec3 &r, const glm::vec3 &u, const
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Orientation::testForOrthogonalAndNormalizedVectors( float epsilon ) { void Orientation::testForOrthogonalAndNormalizedVectors( float epsilon ) {
//---------------------------------------------------------------- //------------------------------------------------------------------
// make sure vectors are normalized (or close to length 1) // make sure vectors are normalized (or close enough to length 1.0)
//---------------------------------------------------------------- //------------------------------------------------------------------
float rightLength = glm::length( right ); float rightLength = glm::length( right );
float upLength = glm::length( up ); float upLength = glm::length( up );
float frontLength = glm::length( front ); float frontLength = glm::length( front );