Showing the changes to interface/src/main.cpp (1 of 9 files). Show all
Unified · Split
| @@ -77,6 +77,7 @@ · 76 unmodified lines | |||
| 77 | #include <SimpleMovingAverage.h> | 77 | #include <SimpleMovingAverage.h> |
| 78 | 78 | ||
| 79 | #include "ViewFrustum.h" | 79 | #include "ViewFrustum.h" |
| 80 | #include "HandControl.h" | ||
| 80 | 81 | ||
| 81 | using namespace std; | 82 | using namespace std; |
| 82 | 83 | ||
| @@ -94,6 +95,8 @@ int HEIGHT = 800; · 11 unmodified lines | |||
| 94 | int fullscreen = 0; | 95 | int fullscreen = 0; |
| 95 | float aspectRatio = 1.0f; | 96 | float aspectRatio = 1.0f; |
| 96 | 97 | ||
| 98 | bool USING_FIRST_PERSON_EFFECT = false; | ||
| 99 | |||
| 97 | bool wantColorRandomizer = true; // for addSphere and load file | 100 | bool wantColorRandomizer = true; // for addSphere and load file |
| 98 | 101 | ||
| 99 | Oscilloscope audioScope(256,200,true); | 102 | Oscilloscope audioScope(256,200,true); |
| @@ -145,6 +148,8 @@ bool lookingInMirror = 0; // Are we currently rendering one's own hea · 45 unmodified lines | |||
| 145 | int displayHeadMouse = 1; // Display sample mouse pointer controlled by head movement | 148 | int displayHeadMouse = 1; // Display sample mouse pointer controlled by head movement |
| 146 | int headMouseX, headMouseY; | 149 | int headMouseX, headMouseY; |
| 147 | 150 | ||
| 151 | HandControl handControl; | ||
| 152 | |||
| 148 | int mouseX = 0; | 153 | int mouseX = 0; |
| 149 | int mouseY = 0; | 154 | int mouseY = 0; |
| 150 | 155 | ||
| @@ -157,78 +162,6 @@ int menuOn = 1; // Whether to show onscreen menu · 6 unmodified lines | |||
| 157 | ChatEntry chatEntry; // chat entry field | 162 | ChatEntry chatEntry; // chat entry field |
| 158 | bool chatEntryOn = false; // Whether to show the chat entry | 163 | bool chatEntryOn = false; // Whether to show the chat entry |
| 159 | 164 | ||
| 160 | struct HandController | ||
| 161 | { | ||
| 162 | bool enabled; | ||
| 163 | int startX; | ||
| 164 | int startY; | ||
| 165 | int x; | ||
| 166 | int y; | ||
| 167 | int lastX; | ||
| 168 | int lastY; | ||
| 169 | int velocityX; | ||
| 170 | int velocityY; | ||
| 171 | float rampUpRate; | ||
| 172 | float rampDownRate; | ||
| 173 | float envelope; | ||
| 174 | }; | ||
| 175 | |||
| 176 | HandController handController; | ||
| 177 | |||
| 178 | void initializeHandController() { | ||
| 179 | handController.enabled = false; | ||
| 180 | handController.startX = WIDTH / 2; | ||
| 181 | handController.startY = HEIGHT / 2; | ||
| 182 | handController.x = 0; | ||
| 183 | handController.y = 0; | ||
| 184 | handController.lastX = 0; | ||
| 185 | handController.lastY = 0; | ||
| 186 | handController.velocityX = 0; | ||
| 187 | handController.velocityY = 0; | ||
| 188 | handController.rampUpRate = 0.05; | ||
| 189 | handController.rampDownRate = 0.02; | ||
| 190 | handController.envelope = 0.0f; | ||
| 191 | } | ||
| 192 | |||
| 193 | void updateHandController( int x, int y ) { | ||
| 194 | handController.lastX = handController.x; | ||
| 195 | handController.lastY = handController.y; | ||
| 196 | handController.x = x; | ||
| 197 | handController.y = y; | ||
| 198 | handController.velocityX = handController.x - handController.lastX; | ||
| 199 | handController.velocityY = handController.y - handController.lastY; | ||
| 200 | |||
| 201 | if (( handController.velocityX != 0 ) | ||
| 202 | || ( handController.velocityY != 0 )) { | ||
| 203 | handController.enabled = true; | ||
| 204 | myAvatar.startHandMovement(); | ||
| 205 | if ( handController.envelope < 1.0 ) { | ||
| 206 | handController.envelope += handController.rampUpRate; | ||
| 207 | if ( handController.envelope >= 1.0 ) { | ||
| 208 | handController.envelope = 1.0; | ||
| 209 | } | ||
| 210 | } | ||
| 211 | } | ||
| 212 | |||
| 213 | if ( ! handController.enabled ) { | ||
| 214 | if ( handController.envelope > 0.0 ) { | ||
| 215 | handController.envelope -= handController.rampDownRate; | ||
| 216 | if ( handController.envelope <= 0.0 ) { | ||
| 217 | handController.startX = WIDTH / 2; | ||
| 218 | handController.startY = HEIGHT / 2; | ||
| 219 | handController.envelope = 0.0; | ||
| 220 | } | ||
| 221 | } | ||
| 222 | } | ||
| 223 | |||
| 224 | if ( handController.envelope > 0.0 ) { | ||
| 225 | float leftRight = ( ( handController.x - handController.startX ) / (float)WIDTH ) * handController.envelope; | ||
| 226 | float downUp = ( ( handController.y - handController.startY ) / (float)HEIGHT ) * handController.envelope; | ||
| 227 | float backFront = 0.0; | ||
| 228 | myAvatar.setHandMovementValues( glm::vec3( leftRight, downUp, backFront ) ); | ||
| 229 | } | ||
| 230 | } | ||
| 231 | |||
| 232 | 165 | ||
| 233 | 166 | ||
| 234 | // | 167 | // |
| @@ -361,7 +294,7 @@ void init(void) · 126 unmodified lines | |||
| 361 | voxels.init(); | 294 | voxels.init(); |
| 362 | voxels.setViewerAvatar(&myAvatar); | 295 | voxels.setViewerAvatar(&myAvatar); |
| 363 | 296 | ||
| 364 | initializeHandController(); | 297 | handControl.setScreenDimensions(WIDTH, HEIGHT); |
| 365 | 298 | ||
| 366 | headMouseX = WIDTH/2; | 299 | headMouseX = WIDTH/2; |
| 367 | headMouseY = HEIGHT/2; | 300 | headMouseY = HEIGHT/2; |
| @@ -777,47 +710,48 @@ void display(void) · 409 unmodified lines | |||
| 777 | myCamera.setTightness ( 100.0f ); | 710 | myCamera.setTightness ( 100.0f ); |
| 778 | } else { | 711 | } else { |
| 779 | 712 | ||
| 780 | // float firstPersonPitch = 20.0f; | 713 | float firstPersonPitch = 20.0f; |
| 781 | // float firstPersonUpShift = 0.1f; | 714 | float firstPersonUpShift = 0.1f; |
| 782 | // float firstPersonDistance = 0.0f; | 715 | float firstPersonDistance = 0.0f; |
| 783 | // float firstPersonT ightness = 100.0f; | 716 | float firstPersonTightness = 100.0f; |
| 784 | 717 | ||
| 785 | float thirdPersonPitch = 0.0f; | 718 | float thirdPersonPitch = 0.0f; |
| 786 | float thirdPersonUpShift = -0.1f; | 719 | float thirdPersonUpShift = -0.1f; |
| 787 | float thirdPersonDistance = 1.f; | 720 | float thirdPersonDistance = 1.f; |
| 788 | float thirdPersonTightness = 8.0f; | 721 | float thirdPersonTightness = 8.0f; |
| 789 | 722 | ||
| 790 | myCamera.setPitch (thirdPersonPitch ); | 723 | if ( USING_FIRST_PERSON_EFFECT ) { |
| 791 | myCamera.setUpShift (thirdPersonUpShift ); | 724 | if ( myAvatar.getSpeed() < 0.02 ) { |
| 792 | myCamera.setDistance (thirdPersonDistance ); | 725 | |
| 793 | myCamera.setTightness(thirdPersonTightness); | 726 | if (myCamera.getMode() != CAMERA_MODE_FIRST_PERSON ) { |
| 794 | 727 | myCamera.setMode(CAMERA_MODE_FIRST_PERSON); | |
| 795 | /* | 728 | } |
| 796 | if ( myAvatar.getSpeed() < 0.02 ) { | 729 | |
| 797 | if (myCamera.getMode() != CAMERA_MODE_FIRST_PERSON ) { | 730 | printf( "myCamera.getModeShift() = %f\n", myCamera.getModeShift()); |
| 798 | myCamera.setMode(CAMERA_MODE_FIRST_PERSON); | 731 | |
| 799 | } | 732 | myCamera.setPitch ( thirdPersonPitch + myCamera.getModeShift() * ( firstPersonPitch - thirdPersonPitch )); |
| 733 | myCamera.setUpShift ( thirdPersonUpShift + myCamera.getModeShift() * ( firstPersonUpShift - thirdPersonUpShift )); | ||
| 734 | myCamera.setDistance ( thirdPersonDistance + myCamera.getModeShift() * ( firstPersonDistance - thirdPersonDistance )); | ||
| 735 | myCamera.setTightness ( thirdPersonTightness + myCamera.getModeShift() * ( firstPersonTightness - thirdPersonTightness )); | ||
| 736 | } else { | ||
| 737 | if (myCamera.getMode() != CAMERA_MODE_THIRD_PERSON ) { | ||
| 738 | myCamera.setMode(CAMERA_MODE_THIRD_PERSON); | ||
| 739 | } | ||
| 800 | 740 | ||
| 801 | printf( "myCamera.getModeShift() = %f\n", myCamera.getModeShift()); | 741 | printf( "myCamera.getModeShift() = %f\n", myCamera.getModeShift()); |
| 802 | 742 | ||
| 803 | myCamera.setPitch ( thirdPersonPitch + myCamera.getModeShift() * ( firstPersonPitch - thirdPersonPitch )); | 743 | myCamera.setPitch ( firstPersonPitch + myCamera.getModeShift() * ( thirdPersonPitch - firstPersonPitch )); |
| 804 | myCamera.setUpShift ( thirdPersonUpShift + myCamera.getModeShift() * ( firstPersonUpShift - thirdPersonUpShift )); | 744 | myCamera.setUpShift ( firstPersonUpShift + myCamera.getModeShift() * ( thirdPersonUpShift - firstPersonUpShift )); |
| 805 | myCamera.setDistance ( thirdPersonDistance + myCamera.getModeShift() * ( firstPersonDistance - thirdPersonDistance )); | 745 | myCamera.setDistance ( firstPersonDistance + myCamera.getModeShift() * ( thirdPersonDistance - firstPersonDistance )); |
| 806 | myCamera.setTightness ( thirdPersonTightness + myCamera.getModeShift() * ( firstPersonTightness - thirdPersonTightness )); | 746 | myCamera.setTightness ( firstPersonTightness + myCamera.getModeShift() * ( thirdPersonTightness - firstPersonTightness )); |
| 807 | } else { | ||
| 808 | if (myCamera.getMode() != CAMERA_MODE_THIRD_PERSON ) { | ||
| 809 | myCamera.setMode(CAMERA_MODE_THIRD_PERSON); | ||
| 810 | } | 747 | } |
| 811 | 748 | } else { | |
| 812 | printf( "myCamera.getModeShift() = %f\n", myCamera.getModeShift()); | 749 | myCamera.setPitch (thirdPersonPitch ); |
| 813 | 750 | myCamera.setUpShift (thirdPersonUpShift ); | |
| 814 | myCamera.setPitch ( firstPersonPitch + myCamera.getModeShift() * ( thirdPersonPitch - firstPersonPitch )); | 751 | myCamera.setDistance (thirdPersonDistance ); |
| 815 | myCamera.setUpShift ( firstPersonUpShift + myCamera.getModeShift() * ( thirdPersonUpShift - firstPersonUpShift )); | 752 | myCamera.setTightness(thirdPersonTightness); |
| 816 | myCamera.setDistance ( firstPersonDistance + myCamera.getModeShift() * ( thirdPersonDistance - firstPersonDistance )); | ||
| 817 | myCamera.setTightness ( firstPersonTightness + myCamera.getModeShift() * ( thirdPersonTightness - firstPersonTightness )); | ||
| 818 | } | 753 | } |
| 819 | */ | 754 | |
| 820 | |||
| 821 | myCamera.setTargetPosition( myAvatar.getHeadPosition() ); | 755 | myCamera.setTargetPosition( myAvatar.getHeadPosition() ); |
| 822 | myCamera.setTargetYaw ( 180.0 - myAvatar.getBodyYaw() ); | 756 | myCamera.setTargetYaw ( 180.0 - myAvatar.getBodyYaw() ); |
| 823 | myCamera.setRoll ( 0.0 ); | 757 | myCamera.setRoll ( 0.0 ); |
| @@ -1466,8 +1400,10 @@ void idle(void) { · 642 unmodified lines | |||
| 1466 | 1400 | ||
| 1467 | float deltaTime = 1.f/FPS; | 1401 | float deltaTime = 1.f/FPS; |
| 1468 | 1402 | ||
| 1469 | // update behaviors for avatar hand movement | 1403 | // update behaviors for avatar hand movement: handControl takes mouse values as input, |
| 1470 | updateHandController( mouseX, mouseY ); | 1404 | // and gives back 3D values modulated for smooth transitioning between interaction modes. |
| 1405 | handControl.update( mouseX, mouseY ); | ||
| 1406 | myAvatar.setHandMovementValues( handControl.getValues() ); | ||
| 1471 | 1407 | ||
| 1472 | // tell my avatar if the mouse is being pressed... | 1408 | // tell my avatar if the mouse is being pressed... |
| 1473 | if ( mousePressed == 1 ) { | 1409 | if ( mousePressed == 1 ) { |
| @@ -1477,9 +1413,9 @@ void idle(void) { · 3 unmodified lines | |||
| 1477 | myAvatar.setMousePressed( false ); | 1413 | myAvatar.setMousePressed( false ); |
| 1478 | } | 1414 | } |
| 1479 | 1415 | ||
| 1480 | // walking triggers the handController to stop | 1416 | // walking triggers the handControl to stop |
| 1481 | if ( myAvatar.getMode() == AVATAR_MODE_WALKING ) { | 1417 | if ( myAvatar.getMode() == AVATAR_MODE_WALKING ) { |
| 1482 | handController.enabled = false; | 1418 | handControl.stop(); |
| 1483 | } | 1419 | } |
| 1484 | 1420 | ||
| 1485 | // | 1421 | // |