cleaned up logic for body springs mode and moving hand mode

This commit is contained in:
Jeffrey Ventrella 2013-04-19 14:34:01 -07:00
parent d962230556
commit 9a93ab7d7c
3 changed files with 99 additions and 102 deletions

View file

@ -33,7 +33,7 @@ float MouthWidthChoices[3] = {0.5, 0.77, 0.3};
float browWidth = 0.8; float browWidth = 0.8;
float browThickness = 0.16; float browThickness = 0.16;
bool usingBigSphereCollisionTest = false; bool usingBigSphereCollisionTest = true;
const float DECAY = 0.1; const float DECAY = 0.1;
const float THRUST_MAG = 10.0; const float THRUST_MAG = 10.0;
@ -104,10 +104,8 @@ Head::Head(bool isMine) {
_lastLoudness = 0.0; _lastLoudness = 0.0;
_browAudioLift = 0.0; _browAudioLift = 0.0;
_noise = 0; _noise = 0;
_handBeingMoved = false;
_previousHandBeingMoved = false;
_movedHandOffset = glm::vec3( 0.0, 0.0, 0.0 ); _movedHandOffset = glm::vec3( 0.0, 0.0, 0.0 );
_usingSprings = false; _usingBodySprings = false;
_springForce = 6.0f; _springForce = 6.0f;
_springVelocityDecay = 16.0f; _springVelocityDecay = 16.0f;
@ -338,32 +336,15 @@ void Head::simulate(float deltaTime) {
//------------------------ //------------------------
updateSkeleton(); updateSkeleton();
//------------------------------------------------------------------------ //------------------------------------------------------------
// reset hand and elbow position according to hand movement // reset hand and arm positions according to hand movement
//------------------------------------------------------------------------ //------------------------------------------------------------
if ( _handBeingMoved ){ if (_usingBodySprings) {
if (! _previousHandBeingMoved ){
initializeBodySprings();
_usingSprings = true;
//printLog( "just started moving hand\n" );
}
}
else {
if ( _previousHandBeingMoved ){
_usingSprings = false;
//printLog( "just stopped moving hand\n" );
}
}
if ( _handBeingMoved ) {
updateHandMovement(); updateHandMovement();
updateBodySprings( deltaTime ); updateBodySprings( deltaTime );
} }
_previousHandBeingMoved = _handBeingMoved;
_handBeingMoved = false;
if ( _isMine ) { // driving the avatar around should only apply is this is my avatar (as opposed to an avatar being driven remotely) if ( _isMine ) { // driving the avatar around should only apply if this is my avatar (as opposed to an avatar being driven remotely)
//------------------------------------------------- //-------------------------------------------------
// this handles the avatar being driven around... // this handles the avatar being driven around...
//------------------------------------------------- //-------------------------------------------------
@ -411,7 +392,7 @@ void Head::simulate(float deltaTime) {
} }
else else
{ {
_mode = AVATAR_MODE_COMMUNICATING; _mode = AVATAR_MODE_INTERACTING;
} }
//---------------------------------------------------------- //----------------------------------------------------------
@ -571,6 +552,18 @@ void Head::updateBigSphereCollisionTest( float deltaTime ) {
} }
if ( jointCollision ) { if ( jointCollision ) {
if (!_usingBodySprings) {
_usingBodySprings = true;
initializeBodySprings();
}
/*
else {
if (_usingSprings) {
_usingSprings = false;
}
}
*/
//---------------------------------------------------------- //----------------------------------------------------------
// add gravity to velocity // add gravity to velocity
//---------------------------------------------------------- //----------------------------------------------------------
@ -648,7 +641,7 @@ void Head::render(int faceToFace) {
glPopMatrix(); glPopMatrix();
} }
if ( _usingSprings ) { if (_usingBodySprings) {
if ( _closestOtherAvatar != -1 ) { if ( _closestOtherAvatar != -1 ) {
glm::vec3 v1( _bone[ AVATAR_BONE_RIGHT_HAND ].position ); glm::vec3 v1( _bone[ AVATAR_BONE_RIGHT_HAND ].position );
@ -704,7 +697,7 @@ void Head::renderHead(int faceToFace) {
glPushMatrix(); glPushMatrix();
if (_usingSprings) { if (_usingBodySprings) {
glTranslatef glTranslatef
( (
_bone[ AVATAR_BONE_HEAD ].springyPosition.x, _bone[ AVATAR_BONE_HEAD ].springyPosition.x,
@ -862,10 +855,19 @@ void Head::renderHead(int faceToFace) {
} }
void Head::startHandMovement() {
void Head::setHandMovement( glm::vec3 handOffset ) { if (!_usingBodySprings) {
_handBeingMoved = true; initializeBodySprings();
_usingBodySprings = true;
}
}
void Head::stopHandMovement() {
_usingBodySprings = false;
}
void Head::setHandMovementValues( glm::vec3 handOffset ) {
_movedHandOffset = handOffset; _movedHandOffset = handOffset;
} }
@ -873,7 +875,6 @@ AvatarMode Head::getMode() {
return _mode; return _mode;
} }
void Head::initializeSkeleton() { void Head::initializeSkeleton() {
for (int b=0; b<NUM_AVATAR_BONES; b++) { for (int b=0; b<NUM_AVATAR_BONES; b++) {
@ -1133,7 +1134,7 @@ void Head::updateHandMovement() {
_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 ( _usingBodySprings ) {
if ( _closestOtherAvatar != -1 ) { if ( _closestOtherAvatar != -1 ) {
if ( _triggeringAction ) { if ( _triggeringAction ) {
@ -1225,7 +1226,7 @@ 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 ( _usingBodySprings ) {
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 );
@ -1244,7 +1245,7 @@ void Head::renderBody() {
//----------------------------------------------------- //-----------------------------------------------------
// Render lines connecting the bone positions // Render lines connecting the bone positions
//----------------------------------------------------- //-----------------------------------------------------
if ( _usingSprings ) { if ( _usingBodySprings ) {
glColor3f( 0.4f, 0.5f, 0.6f ); glColor3f( 0.4f, 0.5f, 0.6f );
glLineWidth(3.0); glLineWidth(3.0);
@ -1272,7 +1273,7 @@ void Head::renderBody() {
} }
if (( _usingSprings ) && ( _triggeringAction )) { if (( _usingBodySprings ) && ( _triggeringAction )) {
glColor4f( 1.0, 1.0, 0.5, 0.5 ); glColor4f( 1.0, 1.0, 0.5, 0.5 );
glPushMatrix(); glPushMatrix();
glTranslatef glTranslatef

View file

@ -22,6 +22,16 @@
#include <glm/gtc/quaternion.hpp> #include <glm/gtc/quaternion.hpp>
#include <glm/gtx/quaternion.hpp> //looks like we might not need this #include <glm/gtx/quaternion.hpp> //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}; enum eyeContactTargets {LEFT_EYE, RIGHT_EYE, MOUTH};
#define FWD 0 #define FWD 0
@ -40,7 +50,7 @@ enum AvatarMode
{ {
AVATAR_MODE_STANDING = 0, AVATAR_MODE_STANDING = 0,
AVATAR_MODE_WALKING, AVATAR_MODE_WALKING,
AVATAR_MODE_COMMUNICATING, AVATAR_MODE_INTERACTING,
NUM_AVATAR_MODES NUM_AVATAR_MODES
}; };
@ -149,7 +159,9 @@ class Head : public AvatarData {
void simulate(float); void simulate(float);
void setHandMovement( glm::vec3 movement ); void startHandMovement();
void stopHandMovement();
void setHandMovementValues( glm::vec3 movement );
void updateHandMovement(); void updateHandMovement();
float getLoudness() {return _loudness;}; float getLoudness() {return _loudness;};
@ -218,9 +230,7 @@ class Head : public AvatarData {
float _bodyYawDelta; float _bodyYawDelta;
float _closeEnoughToInteract; float _closeEnoughToInteract;
int _closestOtherAvatar; int _closestOtherAvatar;
bool _usingSprings; bool _usingBodySprings;
bool _handBeingMoved;
bool _previousHandBeingMoved;
glm::vec3 _movedHandOffset; glm::vec3 _movedHandOffset;
float _springVelocityDecay; float _springVelocityDecay;
float _springForce; float _springForce;

View file

@ -177,7 +177,7 @@ int mousePressed = 0; // true if mouse has been pressed (clear when finished)
Menu menu; // main menu Menu menu; // main menu
int menuOn = 1; // Whether to show onscreen menu int menuOn = 1; // Whether to show onscreen menu
struct HandMovement struct HandController
{ {
bool enabled; bool enabled;
int startX; int startX;
@ -193,59 +193,61 @@ struct HandMovement
float envelope; float envelope;
}; };
HandMovement handMovement; HandController handController;
void initializeHandMovement() { void initializeHandController() {
handMovement.enabled = false; handController.enabled = false;
handMovement.startX = WIDTH / 2; handController.startX = WIDTH / 2;
handMovement.startY = HEIGHT / 2; handController.startY = HEIGHT / 2;
handMovement.x = 0; handController.x = 0;
handMovement.y = 0; handController.y = 0;
handMovement.lastX = 0; handController.lastX = 0;
handMovement.lastY = 0; handController.lastY = 0;
handMovement.velocityX = 0; handController.velocityX = 0;
handMovement.velocityY = 0; handController.velocityY = 0;
handMovement.rampUpRate = 0.05; handController.rampUpRate = 0.05;
handMovement.rampDownRate = 0.02; handController.rampDownRate = 0.02;
handMovement.envelope = 0.0f; handController.envelope = 0.0f;
} }
void updateHandMovement( int x, int y ) { void updateHandController( int x, int y ) {
handMovement.lastX = handMovement.x; handController.lastX = handController.x;
handMovement.lastY = handMovement.y; handController.lastY = handController.y;
handMovement.x = x; handController.x = x;
handMovement.y = y; handController.y = y;
handMovement.velocityX = handMovement.x - handMovement.lastX; handController.velocityX = handController.x - handController.lastX;
handMovement.velocityY = handMovement.y - handMovement.lastY; handController.velocityY = handController.y - handController.lastY;
if (( handMovement.velocityX != 0 ) if (( handController.velocityX != 0 )
|| ( handMovement.velocityY != 0 )) { || ( handController.velocityY != 0 )) {
handMovement.enabled = true; handController.enabled = true;
if ( handMovement.envelope < 1.0 ) { myAvatar.startHandMovement();
handMovement.envelope += handMovement.rampUpRate; if ( handController.envelope < 1.0 ) {
if ( handMovement.envelope >= 1.0 ) { handController.envelope += handController.rampUpRate;
handMovement.envelope = 1.0; if ( handController.envelope >= 1.0 ) {
handController.envelope = 1.0;
} }
} }
} }
if ( ! handMovement.enabled ) { if ( ! handController.enabled ) {
if ( handMovement.envelope > 0.0 ) { if ( handController.envelope > 0.0 ) {
handMovement.envelope -= handMovement.rampDownRate; handController.envelope -= handController.rampDownRate;
if ( handMovement.envelope <= 0.0 ) { if ( handController.envelope <= 0.0 ) {
handMovement.startX = WIDTH / 2; handController.startX = WIDTH / 2;
handMovement.startY = HEIGHT / 2; handController.startY = HEIGHT / 2;
handMovement.envelope = 0.0; handController.envelope = 0.0;
myAvatar.stopHandMovement();
} }
} }
} }
if ( handMovement.envelope > 0.0 ) { if ( handController.envelope > 0.0 ) {
float leftRight = ( ( handMovement.x - handMovement.startX ) / (float)WIDTH ) * handMovement.envelope; float leftRight = ( ( handController.x - handController.startX ) / (float)WIDTH ) * handController.envelope;
float downUp = ( ( handMovement.y - handMovement.startY ) / (float)HEIGHT ) * handMovement.envelope; float downUp = ( ( handController.y - handController.startY ) / (float)HEIGHT ) * handController.envelope;
float backFront = 0.0; float backFront = 0.0;
myAvatar.setHandMovement( glm::vec3( leftRight, downUp, backFront ) ); myAvatar.setHandMovementValues( glm::vec3( leftRight, downUp, backFront ) );
} }
} }
@ -378,7 +380,7 @@ void init(void)
voxels.setViewerHead(&myAvatar); voxels.setViewerHead(&myAvatar);
myAvatar.setRenderYaw(startYaw); myAvatar.setRenderYaw(startYaw);
initializeHandMovement(); initializeHandController();
headMouseX = WIDTH/2; headMouseX = WIDTH/2;
headMouseY = HEIGHT/2; headMouseY = HEIGHT/2;
@ -444,22 +446,6 @@ void reset_sensors()
} }
} }
/*
void updateAvatarHand(float deltaTime) {
// If mouse is being dragged, send current force to the hand controller
if (mousePressed == 1)
{
// NOTE--PER: Need to re-implement when ready for new avatar hand movements
const float MOUSE_HAND_FORCE = 1.5;
float dx = mouseX - mouseStartX;
float dy = mouseY - mouseStartY;
glm::vec3 vel(dx*MOUSE_HAND_FORCE, -dy*MOUSE_HAND_FORCE*(WIDTH/HEIGHT), 0);
//myAvatar.hand->addVelocity(vel*deltaTime);
}
}
*/
// //
// Using gyro data, update both view frustum and avatar head position // Using gyro data, update both view frustum and avatar head position
// //
@ -1416,7 +1402,7 @@ void idle(void) {
float deltaTime = 1.f/FPS; float deltaTime = 1.f/FPS;
// update behaviors for avatar hand movement // update behaviors for avatar hand movement
updateHandMovement( mouseX, mouseY ); updateHandController( mouseX, mouseY );
// when the mouse is being pressed, an 'action' is being // when the mouse is being pressed, an 'action' is being
// triggered in the avatar. The action is context-based. // triggered in the avatar. The action is context-based.
@ -1427,9 +1413,9 @@ void idle(void) {
myAvatar.setTriggeringAction( false ); myAvatar.setTriggeringAction( false );
} }
// walking triggers the handMovement to stop // walking triggers the handController to stop
if ( myAvatar.getMode() == AVATAR_MODE_WALKING ) { if ( myAvatar.getMode() == AVATAR_MODE_WALKING ) {
handMovement.enabled = false; handController.enabled = false;
} }
// //