From 020c21d1d6d1b1cf801796521e69531b01926bd5 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Wed, 10 Apr 2013 16:52:48 -0700 Subject: [PATCH 1/2] removed Vector3D class and fixed bug in avatar springs --- interface/src/Head.cpp | 84 +++++------ interface/src/Head.h | 6 +- interface/src/Orientation.cpp | 258 +++++++--------------------------- interface/src/Orientation.h | 27 ++-- 4 files changed, 114 insertions(+), 261 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 03bb37f7cd..3e9597faa5 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -89,6 +89,10 @@ Head::Head() movedHandOffset = glm::vec3( 0.0, 0.0, 0.0 ); sphere = NULL; + + springForce = 6.0f; + springToBodyTightness = 2.0f; + springVelocityDecay = 5.0f; hand = new Hand(glm::vec3(skinColor[0], skinColor[1], skinColor[2])); @@ -279,6 +283,12 @@ void Head::setLeanSideways(float dist){ void Head::simulate(float deltaTime) { updateAvatarSkeleton(); + + //------------------------------------------------------------------------ + // update springy behavior: + //------------------------------------------------------------------------ + updateAvatarSprings( deltaTime ); + /* glm::vec3 forward @@ -303,32 +313,32 @@ void Head::simulate(float deltaTime) //notice that the z values from avatar.orientation are flipped to accommodate different coordinate system if (driveKeys[FWD]) { - glm::vec3 front( avatar.orientation.getFront().getX(), avatar.orientation.getFront().getY(), -avatar.orientation.getFront().getZ() ); + glm::vec3 front( avatar.orientation.getFront().x, avatar.orientation.getFront().y, -avatar.orientation.getFront().z ); avatar.thrust += front * THRUST_MAG; } if (driveKeys[BACK]) { - glm::vec3 front( avatar.orientation.getFront().getX(), avatar.orientation.getFront().getY(), -avatar.orientation.getFront().getZ() ); + glm::vec3 front( avatar.orientation.getFront().x, avatar.orientation.getFront().y, -avatar.orientation.getFront().z ); avatar.thrust -= front * THRUST_MAG; } if (driveKeys[RIGHT]) { - glm::vec3 right( avatar.orientation.getRight().getX(), avatar.orientation.getRight().getY(), -avatar.orientation.getRight().getZ() ); + glm::vec3 right( avatar.orientation.getRight().x, avatar.orientation.getRight().y, -avatar.orientation.getRight().z ); avatar.thrust += right * THRUST_MAG; } if (driveKeys[LEFT]) { - glm::vec3 right( avatar.orientation.getRight().getX(), avatar.orientation.getRight().getY(), -avatar.orientation.getRight().getZ() ); + glm::vec3 right( avatar.orientation.getRight().x, avatar.orientation.getRight().y, -avatar.orientation.getRight().z ); avatar.thrust -= right * THRUST_MAG; } if (driveKeys[UP]) { - glm::vec3 up( avatar.orientation.getUp().getX(), avatar.orientation.getUp().getY(), -avatar.orientation.getUp().getZ() ); + glm::vec3 up( avatar.orientation.getUp().x, avatar.orientation.getUp().y, -avatar.orientation.getUp().z ); avatar.thrust += up * THRUST_MAG; } if (driveKeys[DOWN]) { - glm::vec3 up( avatar.orientation.getUp().getX(), avatar.orientation.getUp().getY(), -avatar.orientation.getUp().getZ() ); + glm::vec3 up( avatar.orientation.getUp().x, avatar.orientation.getUp().y, -avatar.orientation.getUp().z ); avatar.thrust -= up * THRUST_MAG; } @@ -851,12 +861,6 @@ void Head::updateAvatarSkeleton() avatar.bone[b].position += rotatedBoneVector; } - - //------------------------------------------------------------------------ - // update springy behavior: - //------------------------------------------------------------------------ - updateAvatarSprings(); - //------------------------------------------------------------------------ // reset hand and elbow position according to hand movement //------------------------------------------------------------------------ @@ -866,6 +870,7 @@ void Head::updateAvatarSkeleton() handBeingMoved = false; } + /* glm::dvec3 v( avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position ); v -= avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position; @@ -874,53 +879,50 @@ void Head::updateAvatarSkeleton() { avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position += v * 0.2; } + */ } -//------------------------------ -void Head::updateAvatarSprings() +//----------------------------------------------- +void Head::updateAvatarSprings( float deltaTime ) { - //printf( "listing bone parent springyPosition:\n" ); - for (int b=0; b 0.0f ) - { - glm::vec3 springDirection = springVector / length; - - float force = ( length - avatar.bone[b].length ) * 0.01; - - avatar.bone[ b ].springyVelocity -= springDirection * force; - avatar.bone[ avatar.bone[b].parent ].springyVelocity += springDirection * force; - } - - avatar.bone[b].springyVelocity += ( avatar.bone[b].position - avatar.bone[b].springyPosition ) * 0.01f; - avatar.bone[b].springyVelocity *= 0.8; - avatar.bone[b].springyPosition += avatar.bone[b].springyVelocity; } + + float length = glm::length( springVector ); + + if ( length > 0.0f ) + { + glm::vec3 springDirection = springVector / length; + + float force = ( length - avatar.bone[b].length ) * springForce * deltaTime; + + avatar.bone[ b ].springyVelocity -= springDirection * force; + avatar.bone[ avatar.bone[b].parent ].springyVelocity += springDirection * force; + } + + avatar.bone[b].springyVelocity += ( avatar.bone[b].position - avatar.bone[b].springyPosition ) * springToBodyTightness * deltaTime; + avatar.bone[b].springyVelocity *= 0.8; + + avatar.bone[b].springyVelocity *= ( 1.0 - springVelocityDecay * deltaTime ); + + avatar.bone[b].springyPosition += avatar.bone[b].springyVelocity; } } diff --git a/interface/src/Head.h b/interface/src/Head.h index cdcdb36dfd..8772e283f6 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -243,6 +243,10 @@ class Head : public AgentData { //glm::vec3 movedHandPosition; int driveKeys[MAX_DRIVE_KEYS]; + + float springVelocityDecay; + float springForce; + float springToBodyTightness; int eyeContact; eyeContactTargets eyeContactTarget; @@ -252,7 +256,7 @@ class Head : public AgentData { void initializeAvatar(); void updateAvatarSkeleton(); - void updateAvatarSprings(); + void updateAvatarSprings( float deltaTime ); void calculateBoneLengths(); void readSensors(); diff --git a/interface/src/Orientation.cpp b/interface/src/Orientation.cpp index 63ea77f4dd..7c37951359 100755 --- a/interface/src/Orientation.cpp +++ b/interface/src/Orientation.cpp @@ -1,232 +1,82 @@ -//----------------------------------------------------------- -// -// Created by Jeffrey Ventrella and added as a utility -// class for High Fidelity Code base, April 2013 -// -//----------------------------------------------------------- - #include "Orientation.h" -#include "Vector3D.h" #include "Util.h" //------------------------ Orientation::Orientation() { - right.setXYZ ( 1.0, 0.0, 0.0 ); - up.setXYZ ( 0.0, 1.0, 0.0 ); - front.setXYZ ( 0.0, 0.0, 1.0 ); + right = glm::vec3( 1.0, 0.0, 0.0 ); + up = glm::vec3( 0.0, 1.0, 0.0 ); + front = glm::vec3( 0.0, 0.0, 1.0 ); } - -//-------------------------------- +//------------------------------- void Orientation::setToIdentity() { - right.setXYZ ( 1.0, 0.0, 0.0 ); - up.setXYZ ( 0.0, 1.0, 0.0 ); - front.setXYZ ( 0.0, 0.0, 1.0 ); + right = glm::vec3( 1.0, 0.0, 0.0 ); + up = glm::vec3( 0.0, 1.0, 0.0 ); + front = glm::vec3( 0.0, 0.0, 1.0 ); } - //------------------------------------ void Orientation::set( Orientation o ) { - right.set ( o.getRight() ); - up.set ( o.getUp () ); - front.set ( o.getFront() ); + right = o.getRight(); + up = o.getUp(); + front = o.getFront(); } - -//----------------------------------------------------------------------------------------- -void Orientation::forceAxisInDirection( int whichAxis, const Vector3D &direction, double forceAmount ) -{ - Vector3D diff; - - if ( whichAxis == ORIENTATION_RIGHT_AXIS ) - { - diff.setToDifference( direction, right ); - right.addScaled( diff, forceAmount ); - right.normalize(); - up.setToCross( front, right ); - up.normalize(); - front.setToCross( right, up ); - } - else if ( whichAxis == ORIENTATION_UP_AXIS ) - { - diff.setToDifference( direction, up ); - up.addScaled( diff, forceAmount ); - up.normalize(); - front.setToCross( right, up ); - front.normalize(); - right.setToCross( up, front ); - } - else if ( whichAxis == ORIENTATION_FRONT_AXIS ) - { - diff.setToDifference( direction, front ); - front.addScaled( diff, forceAmount ); - front.normalize(); - right.setToCross( up, front ); - right.normalize(); - up.setToCross( front, right ); - } -} - - -//------------------------------------------------------------------------------------------------------ -void Orientation::forceFrontInDirection( const Vector3D &direction, const Vector3D &upDirection, double forceAmount ) -{ - Vector3D diff; - diff.setToDifference( direction, front ); - front.addScaled( diff, forceAmount ); - front.normalize(); - right.setToCross( upDirection, front ); - right.normalize(); - up.setToCross( front, right ); -} - - - - //--------------------------------------- -void Orientation::yaw( double angle ) +void Orientation::yaw( float angle ) +{ + float r = angle * PI_OVER_180; + float s = sin( r ); + float c = cos( r ); + + glm::vec3 cosineFront = front * c; + glm::vec3 cosineRight = right * c; + glm::vec3 sineFront = front * s; + glm::vec3 sineRight = right * s; + + front = cosineFront + sineRight; + right = cosineRight - sineFront; +} + +//--------------------------------------- +void Orientation::pitch( float angle ) +{ + float r = angle * PI_OVER_180; + float s = sin( r ); + float c = cos( r ); + + glm::vec3 cosineUp = up * c; + glm::vec3 cosineFront = front * c; + glm::vec3 sineUp = up * s; + glm::vec3 sineFront = front * s; + + up = cosineUp + sineFront; + front = cosineFront - sineUp; +} + +//--------------------------------------- +void Orientation::roll( float angle ) { double r = angle * PI_OVER_180; double s = sin( r ); double c = cos( r ); - Vector3D cosineFront; - Vector3D cosineRight; - Vector3D sineFront; - Vector3D sineRight; + glm::vec3 cosineUp = up * c; + glm::vec3 cosineRight = right * c; + glm::vec3 sineUp = up * s; + glm::vec3 sineRight = right * s; - cosineFront.setToScaled ( front, c ); - cosineRight.setToScaled ( right, c ); - sineFront.setToScaled ( front, s ); - sineRight.setToScaled ( right, s ); - - front.set( cosineFront ); - front.add( sineRight ); - - right.set( cosineRight ); - right.subtract( sineFront ); + up = cosineUp + sineRight; + right = cosineRight - sineUp; } - -//--------------------------------------- -void Orientation::pitch( double angle ) +//--------------------------------------------------------------------------------------------- +void Orientation::setRightUpFront( const glm::vec3 &r, const glm::vec3 &u, const glm::vec3 &f ) { - double r = angle * PI_OVER_180; - double s = sin( r ); - double c = cos( r ); - - Vector3D cosineUp; - Vector3D cosineFront; - Vector3D sineUp; - Vector3D sineFront; - - cosineUp.setToScaled ( up, c ); - cosineFront.setToScaled ( front, c ); - sineUp.setToScaled ( up, s ); - sineFront.setToScaled ( front, s ); - - up.set( cosineUp ); - up.add( sineFront ); - - front.set( cosineFront ); - front.subtract( sineUp ); + right = r; + up = u; + front = f; } - - -//--------------------------------------- -void Orientation::roll( double angle ) -{ - double r = angle * PI_OVER_180; - double s = sin( r ); - double c = cos( r ); - - Vector3D cosineUp; - Vector3D cosineRight; - Vector3D sineUp; - Vector3D sineRight; - - cosineUp.setToScaled ( up, c ); - cosineRight.setToScaled ( right, c ); - sineUp.setToScaled ( up, s ); - sineRight.setToScaled ( right, s ); - - up.set( cosineUp ); - up.add( sineRight ); - - right.set( cosineRight ); - right.subtract( sineUp ); -} - - -Vector3D Orientation::getRight () { return right; } -Vector3D Orientation::getUp () { return up; } -Vector3D Orientation::getFront () { return front; } - - -//----------------------------------------------------------------------------- -void Orientation::setRightUpFront( const Vector3D &r, const Vector3D &u, const Vector3D &f ) -{ - //verifyValidOrientation(); - - right.set (r); - up.set (u); - front.set (f); -} - - -//----------------------------------------------------------------------------- -void Orientation::verifyValidOrientation() -{ - assert( right.getMagnitude () < 1.0 + CENTIMETER ); - assert( right.getMagnitude () > 1.0 - CENTIMETER ); - assert( up.getMagnitude () < 1.0 + CENTIMETER ); - assert( up.getMagnitude () > 1.0 - CENTIMETER ); - assert( front.getMagnitude () < 1.0 + CENTIMETER ); - assert( front.getMagnitude () > 1.0 - CENTIMETER ); - - if ( right.getMagnitude() > 1.0 + CENTIMETER ) - { - printf( "oops: the magnitude of the 'right' part of the orientation is %f!\n", right.getMagnitude() ); - } - else if ( right.getMagnitude() < 1.0 - CENTIMETER ) - { - printf( "oops: the magnitude of the 'right' part of the orientation is %f!\n", right.getMagnitude() ); - } - - - if ( up.getMagnitude() > 1.0 + CENTIMETER ) - { - printf( "oops: the magnitude of the 'up' part of the orientation is %f!\n", up.getMagnitude() ); - } - else if ( up.getMagnitude() < 1.0 - CENTIMETER ) - { - printf( "oops: the magnitude of the 'up' part of the orientation is %f!\n", up.getMagnitude() ); - } - - - if ( front.getMagnitude() > 1.0 + CENTIMETER ) - { - printf( "oops: the magnitude of the 'front' part of the orientation is %f!\n", front.getMagnitude() ); - } - else if ( front.getMagnitude() < 1.0 - CENTIMETER ) - { - printf( "oops: the magnitude of the 'front' part of the orientation is %f!\n", front.getMagnitude() ); - } - - if (( right.dotWith ( up ) > CENTIMETER ) - || ( right.dotWith ( up ) < -CENTIMETER )) { printf( "oops: the 'right' and 'up' parts of the orientation are not perpendicular! The dot is: %f\n", right.dotWith ( up ) ); } - - if (( right.dotWith ( front ) > CENTIMETER ) - || ( right.dotWith ( front ) < -CENTIMETER )) { printf( "oops: the 'right' and 'front' parts of the orientation are not perpendicular! The dot is: %f\n", right.dotWith ( front ) ); } - - if (( up.dotWith ( front ) > CENTIMETER ) - || ( up.dotWith ( front ) < -CENTIMETER )) { printf( "oops: the 'up' and 'front' parts of the orientation are not perpendicular! The dot is: %f\n", up.dotWith ( front ) ); } - -} - - - - diff --git a/interface/src/Orientation.h b/interface/src/Orientation.h index f9f6744fc2..77771b785c 100755 --- a/interface/src/Orientation.h +++ b/interface/src/Orientation.h @@ -9,7 +9,7 @@ #define __interface__orientation__ #include // with this work? "Math.h" -#include "Vector3D.h" +#include enum Axis { @@ -22,30 +22,27 @@ class Orientation { private: - Vector3D right; - Vector3D up; - Vector3D front; + glm::vec3 right; + glm::vec3 up; + glm::vec3 front; - void verifyValidOrientation(); + //void verifyValidOrientation(); public: Orientation(); - void yaw ( double ); - void pitch ( double ); - void roll ( double ); + void yaw ( float ); + void pitch ( float ); + void roll ( float ); void set( Orientation ); void setToIdentity(); - void forceFrontInDirection( const Vector3D &, const Vector3D &, double ); - void forceAxisInDirection( int, const Vector3D &, double ); - - Vector3D getRight(); - Vector3D getUp(); - Vector3D getFront(); + glm::vec3 getRight() { return right; } + glm::vec3 getUp() { return up; } + glm::vec3 getFront() { return front; } - void setRightUpFront( const Vector3D &, const Vector3D &, const Vector3D & ); + void setRightUpFront( const glm::vec3 &, const glm::vec3 &, const glm::vec3 & ); }; From 6270659cdc396ea7a60de344bce38c2ecd31552e Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 10 Apr 2013 16:56:15 -0700 Subject: [PATCH 2/2] inline declaration and initialization for menu --- interface/src/MenuColumn.cpp | 2 +- interface/src/MenuColumn.h | 2 +- interface/src/main.cpp | 5 ++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/interface/src/MenuColumn.cpp b/interface/src/MenuColumn.cpp index 8d160cb280..98fa8a1d85 100644 --- a/interface/src/MenuColumn.cpp +++ b/interface/src/MenuColumn.cpp @@ -108,7 +108,7 @@ int MenuColumn::getLeftPosition() { return leftPosition; } -int MenuColumn::addRow(const char * rowName, MenuRowCallback callback) { +int MenuColumn::addRow(const char* rowName, MenuRowCallback callback) { MenuRow* row; row = new MenuRow(rowName, callback); rows.push_back(*row); diff --git a/interface/src/MenuColumn.h b/interface/src/MenuColumn.h index b84f483678..71c42eed7f 100644 --- a/interface/src/MenuColumn.h +++ b/interface/src/MenuColumn.h @@ -26,7 +26,7 @@ public: int getLeftPosition(); void render(int yOffset, int menuHeight, int lineHeight); void renderMouseOver(int yOffset); - int addRow(const char * rowName, MenuRowCallback callback); + int addRow(const char* rowName, MenuRowCallback callback); private: char columnName[MAX_COLUMN_NAME]; int columnWidth; diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 35c52b6e95..c7497feabb 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -897,13 +897,12 @@ int setMirror(int state) { } void initMenu() { - MenuColumn *menuColumnOptions, *menuColumnTools; - menuColumnOptions = menu.addColumn("Options"); + MenuColumn *menuColumnOptions = menu.addColumn("Options"); menuColumnOptions->addRow("Head", setHead); menuColumnOptions->addRow("Field", setField); menuColumnOptions->addRow("Noise", setNoise); menuColumnOptions->addRow("Mirror", setMirror); - menuColumnTools = menu.addColumn("Tools"); + MenuColumn *menuColumnTools = menu.addColumn("Tools"); menuColumnTools->addRow("Stats", setStats); menuColumnTools->addRow("Menu", setMenu); }