History

Merge remote-tracking branch 'upstream/master'

Philip Rosedale committed 13 years ago

Commit 99957f32 parents 996a879 69cf6e39 files · +340 −184Browse files

Showing the changes to interface/src/main.cpp (1 of 9 files). Show all

Unified · Split

interface/src/main.cpp+44−108
@@ -77,6 +77,7 @@ · 76 unmodified lines
7777 #include <SimpleMovingAverage.h>
7878
7979 #include "ViewFrustum.h"
80+#include "HandControl.h"
8081
8182 using namespace std;
8283
@@ -94,6 +95,8 @@ int HEIGHT = 800; · 11 unmodified lines
9495 int fullscreen = 0;
9596 float aspectRatio = 1.0f;
9697
98+bool USING_FIRST_PERSON_EFFECT = false;
99+
97100 bool wantColorRandomizer = true; // for addSphere and load file
98101
99102 Oscilloscope audioScope(256,200,true);
@@ -145,6 +148,8 @@ bool lookingInMirror = 0; // Are we currently rendering one's own hea · 45 unmodified lines
145148 int displayHeadMouse = 1; // Display sample mouse pointer controlled by head movement
146149 int headMouseX, headMouseY;
147150
151+HandControl handControl;
152+
148153 int mouseX = 0;
149154 int mouseY = 0;
150155
@@ -157,78 +162,6 @@ int menuOn = 1; // Whether to show onscreen menu · 6 unmodified lines
157162 ChatEntry chatEntry; // chat entry field
158163 bool chatEntryOn = false; // Whether to show the chat entry
159164
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−
232165
233166
234167 //
@@ -361,7 +294,7 @@ void init(void) · 126 unmodified lines
361294 voxels.init();
362295 voxels.setViewerAvatar(&myAvatar);
363296
364− initializeHandController();
297+ handControl.setScreenDimensions(WIDTH, HEIGHT);
365298
366299 headMouseX = WIDTH/2;
367300 headMouseY = HEIGHT/2;
@@ -777,47 +710,48 @@ void display(void) · 409 unmodified lines
777710 myCamera.setTightness ( 100.0f );
778711 } else {
779712
780−// float firstPersonPitch = 20.0f;
781−// float firstPersonUpShift = 0.1f;
782−// float firstPersonDistance = 0.0f;
783−// float firstPersonT ightness = 100.0f;
713+ float firstPersonPitch = 20.0f;
714+ float firstPersonUpShift = 0.1f;
715+ float firstPersonDistance = 0.0f;
716+ float firstPersonTightness = 100.0f;
784717
785718 float thirdPersonPitch = 0.0f;
786719 float thirdPersonUpShift = -0.1f;
787720 float thirdPersonDistance = 1.f;
788721 float thirdPersonTightness = 8.0f;
789722
790− myCamera.setPitch (thirdPersonPitch );
791− myCamera.setUpShift (thirdPersonUpShift );
792− myCamera.setDistance (thirdPersonDistance );
793− myCamera.setTightness(thirdPersonTightness);
794−
795− /*
796− if ( myAvatar.getSpeed() < 0.02 ) {
797− if (myCamera.getMode() != CAMERA_MODE_FIRST_PERSON ) {
798− myCamera.setMode(CAMERA_MODE_FIRST_PERSON);
799− }
723+ if ( USING_FIRST_PERSON_EFFECT ) {
724+ if ( myAvatar.getSpeed() < 0.02 ) {
725+
726+ if (myCamera.getMode() != CAMERA_MODE_FIRST_PERSON ) {
727+ myCamera.setMode(CAMERA_MODE_FIRST_PERSON);
728+ }
729+
730+ printf( "myCamera.getModeShift() = %f\n", myCamera.getModeShift());
731+
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+ }
800740
801− printf( "myCamera.getModeShift() = %f\n", myCamera.getModeShift());
741+ printf( "myCamera.getModeShift() = %f\n", myCamera.getModeShift());
802742
803− myCamera.setPitch ( thirdPersonPitch + myCamera.getModeShift() * ( firstPersonPitch - thirdPersonPitch ));
804− myCamera.setUpShift ( thirdPersonUpShift + myCamera.getModeShift() * ( firstPersonUpShift - thirdPersonUpShift ));
805− myCamera.setDistance ( thirdPersonDistance + myCamera.getModeShift() * ( firstPersonDistance - thirdPersonDistance ));
806− myCamera.setTightness ( thirdPersonTightness + myCamera.getModeShift() * ( firstPersonTightness - thirdPersonTightness ));
807− } else {
808− if (myCamera.getMode() != CAMERA_MODE_THIRD_PERSON ) {
809− myCamera.setMode(CAMERA_MODE_THIRD_PERSON);
743+ myCamera.setPitch ( firstPersonPitch + myCamera.getModeShift() * ( thirdPersonPitch - firstPersonPitch ));
744+ myCamera.setUpShift ( firstPersonUpShift + myCamera.getModeShift() * ( thirdPersonUpShift - firstPersonUpShift ));
745+ myCamera.setDistance ( firstPersonDistance + myCamera.getModeShift() * ( thirdPersonDistance - firstPersonDistance ));
746+ myCamera.setTightness ( firstPersonTightness + myCamera.getModeShift() * ( thirdPersonTightness - firstPersonTightness ));
810747 }
811−
812− printf( "myCamera.getModeShift() = %f\n", myCamera.getModeShift());
813−
814− myCamera.setPitch ( firstPersonPitch + myCamera.getModeShift() * ( thirdPersonPitch - firstPersonPitch ));
815− myCamera.setUpShift ( firstPersonUpShift + myCamera.getModeShift() * ( thirdPersonUpShift - firstPersonUpShift ));
816− myCamera.setDistance ( firstPersonDistance + myCamera.getModeShift() * ( thirdPersonDistance - firstPersonDistance ));
817− myCamera.setTightness ( firstPersonTightness + myCamera.getModeShift() * ( thirdPersonTightness - firstPersonTightness ));
748+ } else {
749+ myCamera.setPitch (thirdPersonPitch );
750+ myCamera.setUpShift (thirdPersonUpShift );
751+ myCamera.setDistance (thirdPersonDistance );
752+ myCamera.setTightness(thirdPersonTightness);
818753 }
819− */
820−
754+
821755 myCamera.setTargetPosition( myAvatar.getHeadPosition() );
822756 myCamera.setTargetYaw ( 180.0 - myAvatar.getBodyYaw() );
823757 myCamera.setRoll ( 0.0 );
@@ -1466,8 +1400,10 @@ void idle(void) { · 642 unmodified lines
14661400
14671401 float deltaTime = 1.f/FPS;
14681402
1469− // update behaviors for avatar hand movement
1470− updateHandController( mouseX, mouseY );
1403+ // update behaviors for avatar hand movement: handControl takes mouse values as input,
1404+ // and gives back 3D values modulated for smooth transitioning between interaction modes.
1405+ handControl.update( mouseX, mouseY );
1406+ myAvatar.setHandMovementValues( handControl.getValues() );
14711407
14721408 // tell my avatar if the mouse is being pressed...
14731409 if ( mousePressed == 1 ) {
@@ -1477,9 +1413,9 @@ void idle(void) { · 3 unmodified lines
14771413 myAvatar.setMousePressed( false );
14781414 }
14791415
1480− // walking triggers the handController to stop
1416+ // walking triggers the handControl to stop
14811417 if ( myAvatar.getMode() == AVATAR_MODE_WALKING ) {
1482− handController.enabled = false;
1418+ handControl.stop();
14831419 }
14841420
14851421 //