History

Merge remote-tracking branch 'upstream/master'

Philip Rosedale committed 13 years ago

Commit dec7e592 parents a89b011 d7d435113 files · +642 −208Browse files

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

Unified · Split

interface/src/main.cpp+38−9
@@ -102,6 +102,13 @@ int screenHeight = 800; · 101 unmodified lines
102102 int fullscreen = 0;
103103 float aspectRatio = 1.0f;
104104
105+bool USING_MOUSE_VIEW_SHIFT = false;
106+float MOUSE_VIEW_SHIFT_RATE = 40.0f;
107+float MOUSE_VIEW_SHIFT_YAW_MARGIN = (float)(WIDTH * 0.2f);
108+float MOUSE_VIEW_SHIFT_PITCH_MARGIN = (float)(HEIGHT * 0.2f);
109+float MOUSE_VIEW_SHIFT_YAW_LIMIT = 45.0;
110+float MOUSE_VIEW_SHIFT_PITCH_LIMIT = 30.0;
111+
105112 //CameraMode defaultCameraMode = CAMERA_MODE_FIRST_PERSON;
106113 CameraMode defaultCameraMode = CAMERA_MODE_THIRD_PERSON;
107114
@@ -206,7 +213,6 @@ double elapsedTime; · 98 unmodified lines
206213 timeval applicationStartupTime;
207214 bool justStarted = true;
208215
209−
210216 // Every second, check the frame rates and other stuff
211217 void Timer(int extra) {
212218 gettimeofday(&timerEnd, NULL);
@@ -370,9 +376,7 @@ void sendVoxelEditMessage(PACKET_HEADER header, VoxelDetail& detail) { · 157 unmodified lines
370376 }
371377 }
372378
373−//
374379 // Using gyro data, update both view frustum and avatar head position
375−//
376380 void updateAvatar(float deltaTime) {
377381
378382 // Update my avatar's head position from gyros
@@ -409,7 +413,34 @@ void updateAvatar(float deltaTime) { · 30 unmodified lines
409413 const float RENDER_PITCH_MULTIPLY = 4.f;
410414 myAvatar.setRenderPitch((1.f - renderPitchSpring * deltaTime) * myAvatar.getRenderPitch() +
411415 renderPitchSpring * deltaTime * -myAvatar.getHeadPitch() * RENDER_PITCH_MULTIPLY);
412−
416+ }
417+
418+
419+ if (USING_MOUSE_VIEW_SHIFT)
420+ {
421+ //make it so that when your mouse hits the edge of the screen, the camera shifts
422+ float rightBoundary = (float)WIDTH - MOUSE_VIEW_SHIFT_YAW_MARGIN;
423+ float bottomBoundary = (float)HEIGHT - MOUSE_VIEW_SHIFT_PITCH_MARGIN;
424+
425+ if (mouseX > rightBoundary) {
426+ float f = (mouseX - rightBoundary) / ( (float)WIDTH - rightBoundary);
427+ mouseViewShiftYaw += MOUSE_VIEW_SHIFT_RATE * f * deltaTime;
428+ if (mouseViewShiftYaw > MOUSE_VIEW_SHIFT_YAW_LIMIT) { mouseViewShiftYaw = MOUSE_VIEW_SHIFT_YAW_LIMIT; }
429+ } else if (mouseX < MOUSE_VIEW_SHIFT_YAW_MARGIN) {
430+ float f = 1.0 - (mouseX / MOUSE_VIEW_SHIFT_YAW_MARGIN);
431+ mouseViewShiftYaw -= MOUSE_VIEW_SHIFT_RATE * f * deltaTime;
432+ if (mouseViewShiftYaw < -MOUSE_VIEW_SHIFT_YAW_LIMIT) { mouseViewShiftYaw = -MOUSE_VIEW_SHIFT_YAW_LIMIT; }
433+ }
434+ if (mouseY < MOUSE_VIEW_SHIFT_PITCH_MARGIN) {
435+ float f = 1.0 - (mouseY / MOUSE_VIEW_SHIFT_PITCH_MARGIN);
436+ mouseViewShiftPitch += MOUSE_VIEW_SHIFT_RATE * f * deltaTime;
437+ if ( mouseViewShiftPitch > MOUSE_VIEW_SHIFT_PITCH_LIMIT ) { mouseViewShiftPitch = MOUSE_VIEW_SHIFT_PITCH_LIMIT; }
438+ }
439+ else if (mouseY > bottomBoundary) {
440+ float f = (mouseY - bottomBoundary) / ((float)HEIGHT - bottomBoundary);
441+ mouseViewShiftPitch -= MOUSE_VIEW_SHIFT_RATE * f * deltaTime;
442+ if (mouseViewShiftPitch < -MOUSE_VIEW_SHIFT_PITCH_LIMIT) { mouseViewShiftPitch = -MOUSE_VIEW_SHIFT_PITCH_LIMIT; }
443+ }
413444 }
414445
415446 if (OculusManager::isConnected()) {
@@ -1032,7 +1063,7 @@ void display(void) · 616 unmodified lines
10321063 myCamera.setDistance (1.5f);
10331064 myCamera.setTightness (8.0f);
10341065 myCamera.setTargetPosition(myAvatar.getHeadPosition());
1035− myCamera.setTargetRotation(myAvatar.getBodyYaw(), 0.0f, 0.0f);
1066+ myCamera.setTargetRotation(myAvatar.getBodyYaw() - mouseViewShiftYaw, mouseViewShiftPitch, 0.0f);
10361067 }
10371068
10381069 // important...
@@ -1540,9 +1571,6 @@ void specialkey(int k, int x, int y) { · 501 unmodified lines
15401571 if (glutGetModifiers() == GLUT_ACTIVE_SHIFT) myAvatar.setDriveKeys(RIGHT, 1);
15411572 else myAvatar.setDriveKeys(ROT_RIGHT, 1);
15421573 }
1543−#ifndef _WIN32
1544− audio.setWalkingState(true);
1545−#endif
15461574 }
15471575 }
15481576
@@ -1800,6 +1828,8 @@ void idle(void) { · 251 unmodified lines
18001828 // walking triggers the handControl to stop
18011829 if (myAvatar.getMode() == AVATAR_MODE_WALKING) {
18021830 handControl.stop();
1831+ mouseViewShiftYaw *= 0.9;
1832+ mouseViewShiftPitch *= 0.9;
18031833 }
18041834
18051835 // Read serial port interface devices
@@ -1836,7 +1866,6 @@ void idle(void) { · 30 unmodified lines
18361866 glutPostRedisplay();
18371867 lastTimeIdle = check;
18381868 }
1839−
18401869 }
18411870
18421871 void reshape(int width, int height) {