fixed a bug in menu clicking

This commit is contained in:
Jeffrey Ventrella 2013-05-09 14:37:13 -07:00
parent 03a24266eb
commit 3ba93397bd
4 changed files with 65 additions and 49 deletions

View file

@ -488,11 +488,10 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) {
_avatarTouch.setYourHandPosition(_interactingOther->_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].springyPosition); _avatarTouch.setYourHandPosition(_interactingOther->_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].springyPosition);
_avatarTouch.setYourHandState (_interactingOther->_handState); _avatarTouch.setYourHandState (_interactingOther->_handState);
_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position = if ( _avatarTouch.getAbleToReachOtherAvatar()) {
_interactingOther->_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].springyPosition; _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position =
_interactingOther->_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].springyPosition;
//_handHoldingPosition }
} }
}//if (_isMine) }//if (_isMine)
@ -512,10 +511,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) {
} }
_avatarTouch.setMyHandState(_handState); _avatarTouch.setMyHandState(_handState);
_avatarTouch.setMyHandPosition(_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].springyPosition);
if (_handState == 1) {
_avatarTouch.setMyHandPosition(_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].springyPosition);
}
} }
} }

View file

@ -16,13 +16,14 @@ const float THREAD_RADIUS = 0.012;
AvatarTouch::AvatarTouch() { AvatarTouch::AvatarTouch() {
_myHandPosition = glm::vec3(0.0f, 0.0f, 0.0f); _myHandPosition = glm::vec3(0.0f, 0.0f, 0.0f);
_yourHandPosition = glm::vec3(0.0f, 0.0f, 0.0f); _yourHandPosition = glm::vec3(0.0f, 0.0f, 0.0f);
_myBodyPosition = glm::vec3(0.0f, 0.0f, 0.0f); _myBodyPosition = glm::vec3(0.0f, 0.0f, 0.0f);
_yourBodyPosition = glm::vec3(0.0f, 0.0f, 0.0f); _yourBodyPosition = glm::vec3(0.0f, 0.0f, 0.0f);
_myHandState = 0; _vectorBetweenHands = glm::vec3(0.0f, 0.0f, 0.0f);
_yourHandState = 0; _myHandState = 0;
_reachableRadius = 0.0f; _yourHandState = 0;
_reachableRadius = 0.0f;
_canReachToOtherAvatar = false; _canReachToOtherAvatar = false;
_handsCloseEnoughToGrasp = false; _handsCloseEnoughToGrasp = false;
@ -60,15 +61,17 @@ void AvatarTouch::setReachableRadius(float r) {
_reachableRadius = r; _reachableRadius = r;
} }
void AvatarTouch::render(glm::vec3 cameraPosition) { void AvatarTouch::render(glm::vec3 cameraPosition) {
if (_canReachToOtherAvatar) { if (_canReachToOtherAvatar) {
glColor4f(0.3, 0.4, 0.5, 0.5); glColor4f(0.3, 0.4, 0.5, 0.5);
glm::vec3 p(_yourBodyPosition); glm::vec3 p(_yourBodyPosition);
p.y = 0.0005f; p.y = 0.0005f;
renderCircle(p, _reachableRadius, glm::vec3(0.0f, 1.0f, 0.0f), 30); renderCircle(p, _reachableRadius, glm::vec3(0.0f, 1.0f, 0.0f), 30);
renderBeamBetweenHands();
// if your hand is grasping, show it... // if your hand is grasping, show it...
if (_yourHandState == 1) { if (_yourHandState == 1) {
glPushMatrix(); glPushMatrix();
@ -78,28 +81,7 @@ if (_canReachToOtherAvatar) {
glColor4f(1.0, 1.0, 0.2, 0.1); glutSolidSphere(0.030f, 10.0f, 10.0f); glColor4f(1.0, 1.0, 0.2, 0.1); glutSolidSphere(0.030f, 10.0f, 10.0f);
glPopMatrix(); glPopMatrix();
} }
}
//show beam
glm::vec3 v1(_myHandPosition);
glm::vec3 v2(_yourHandPosition);
if (_handsCloseEnoughToGrasp) {
glLineWidth(2.0);
glColor4f(0.7f, 0.4f, 0.1f, 0.3);
glBegin(GL_LINE_STRIP);
glVertex3f(v1.x, v1.y, v1.z);
glVertex3f(v2.x, v2.y, v2.z);
glEnd();
glColor4f(1.0f, 1.0f, 0.0f, 0.8);
for (int p=0; p<NUM_POINTS; p++) {
glBegin(GL_POINTS);
glVertex3f(_point[p].x, _point[p].y, _point[p].z);
glEnd();
}
}
}
// if my hand is grasping, show it... // if my hand is grasping, show it...
if (_myHandState == 1) { if (_myHandState == 1) {
@ -114,24 +96,54 @@ if (_canReachToOtherAvatar) {
void AvatarTouch::simulate (float deltaTime) { void AvatarTouch::simulate (float deltaTime) {
glm::vec3 v = _yourBodyPosition - _myBodyPosition; _vectorBetweenHands = _yourBodyPosition - _myBodyPosition;
float distance = glm::length(_vectorBetweenHands);
float distance = glm::length(v);
if (distance < _reachableRadius) { if (distance < _reachableRadius) {
_canReachToOtherAvatar = true; _canReachToOtherAvatar = true;
generateBeamBetweenHands();
} else { } else {
_canReachToOtherAvatar = false; _canReachToOtherAvatar = false;
} }
/*
}
void AvatarTouch::generateBeamBetweenHands() {
for (int p=0; p<NUM_POINTS; p++) { for (int p=0; p<NUM_POINTS; p++) {
_point[p] = _myHandPosition + v * ((float)p / (float)NUM_POINTS); _point[p] = _myHandPosition + _vectorBetweenHands * ((float)p / (float)NUM_POINTS);
_point[p].x += randFloatInRange(-THREAD_RADIUS, THREAD_RADIUS); _point[p].x += randFloatInRange(-THREAD_RADIUS, THREAD_RADIUS);
_point[p].y += randFloatInRange(-THREAD_RADIUS, THREAD_RADIUS); _point[p].y += randFloatInRange(-THREAD_RADIUS, THREAD_RADIUS);
_point[p].z += randFloatInRange(-THREAD_RADIUS, THREAD_RADIUS); _point[p].z += randFloatInRange(-THREAD_RADIUS, THREAD_RADIUS);
} }
*/ }
}
void AvatarTouch::renderBeamBetweenHands() {
glm::vec3 v1(_myHandPosition);
glm::vec3 v2(_yourHandPosition);
glLineWidth(2.0);
glColor4f(0.7f, 0.4f, 0.1f, 0.3);
glBegin(GL_LINE_STRIP);
glVertex3f(v1.x, v1.y, v1.z);
glVertex3f(v2.x, v2.y, v2.z);
glEnd();
glColor4f(1.0f, 1.0f, 0.0f, 0.8);
for (int p=0; p<NUM_POINTS; p++) {
glBegin(GL_POINTS);
glVertex3f(_point[p].x, _point[p].y, _point[p].z);
glEnd();
}
}

View file

@ -43,11 +43,15 @@ private:
glm::vec3 _yourBodyPosition; glm::vec3 _yourBodyPosition;
glm::vec3 _myHandPosition; glm::vec3 _myHandPosition;
glm::vec3 _yourHandPosition; glm::vec3 _yourHandPosition;
glm::vec3 _vectorBetweenHands;
int _myHandState; int _myHandState;
int _yourHandState; int _yourHandState;
bool _canReachToOtherAvatar; bool _canReachToOtherAvatar;
bool _handsCloseEnoughToGrasp; bool _handsCloseEnoughToGrasp;
float _reachableRadius; float _reachableRadius;
void generateBeamBetweenHands();
void renderBeamBetweenHands();
}; };
#endif #endif

View file

@ -1887,7 +1887,11 @@ glm::vec3 getGravity(glm::vec3 pos) {
} }
void mouseFunc(int button, int state, int x, int y) { void mouseFunc(int button, int state, int x, int y) {
if ( !menu.mouseClick(x, y)) { // if a menu item was not clicked or unclicked...
//catch mouse actiond on the menu
bool menuClickedOrUnclicked = menu.mouseClick(x, y);
if (!menuClickedOrUnclicked) {
if ( button == GLUT_LEFT_BUTTON ) { if ( button == GLUT_LEFT_BUTTON ) {
mouseX = x; mouseX = x;
mouseY = y; mouseY = y;