mirror of
https://github.com/overte-org/overte.git
synced 2025-04-25 18:16:08 +02:00
added mouse view shift behaviors
This commit is contained in:
parent
847bfbdadd
commit
e4c84e7b74
1 changed files with 39 additions and 3 deletions
|
@ -97,11 +97,20 @@ int packetsPerSecond = 0;
|
|||
int bytesPerSecond = 0;
|
||||
int bytesCount = 0;
|
||||
|
||||
float mouseViewShiftYaw = 0.0f;
|
||||
float mouseViewShiftPitch = 0.0f;
|
||||
|
||||
int WIDTH = 1200; // Window size
|
||||
int HEIGHT = 800;
|
||||
int fullscreen = 0;
|
||||
float aspectRatio = 1.0f;
|
||||
|
||||
float MOUSE_VIEW_SHIFT_RATE = 40.0f;
|
||||
float MOUSE_VIEW_SHIFT_YAW_MARGIN = (float)(WIDTH * 0.2f);
|
||||
float MOUSE_VIEW_SHIFT_PITCH_MARGIN = (float)(HEIGHT * 0.2f);
|
||||
float MOUSE_VIEW_SHIFT_YAW_LIMIT = 45.0;
|
||||
float MOUSE_VIEW_SHIFT_PITCH_LIMIT = 30.0;
|
||||
|
||||
//CameraMode defaultCameraMode = CAMERA_MODE_FIRST_PERSON;
|
||||
CameraMode defaultCameraMode = CAMERA_MODE_THIRD_PERSON;
|
||||
|
||||
|
@ -408,9 +417,34 @@ void updateAvatar(float deltaTime) {
|
|||
const float RENDER_PITCH_MULTIPLY = 4.f;
|
||||
myAvatar.setRenderPitch((1.f - renderPitchSpring * deltaTime) * myAvatar.getRenderPitch() +
|
||||
renderPitchSpring * deltaTime * -myAvatar.getHeadPitch() * RENDER_PITCH_MULTIPLY);
|
||||
|
||||
}
|
||||
|
||||
|
||||
//make it so that when your mouse hits the edge of the screen, the camera shifts
|
||||
float rightBoundary = (float)WIDTH - MOUSE_VIEW_SHIFT_YAW_MARGIN;
|
||||
float bottomBoundary = (float)HEIGHT - MOUSE_VIEW_SHIFT_PITCH_MARGIN;
|
||||
|
||||
if (mouseX > rightBoundary) {
|
||||
float f = (mouseX - rightBoundary) / ( (float)WIDTH - rightBoundary);
|
||||
mouseViewShiftYaw += MOUSE_VIEW_SHIFT_RATE * f * deltaTime;
|
||||
if (mouseViewShiftYaw > MOUSE_VIEW_SHIFT_YAW_LIMIT) { mouseViewShiftYaw = MOUSE_VIEW_SHIFT_YAW_LIMIT; }
|
||||
} else if (mouseX < MOUSE_VIEW_SHIFT_YAW_MARGIN) {
|
||||
float f = 1.0 - (mouseX / MOUSE_VIEW_SHIFT_YAW_MARGIN);
|
||||
mouseViewShiftYaw -= MOUSE_VIEW_SHIFT_RATE * f * deltaTime;
|
||||
if (mouseViewShiftYaw < -MOUSE_VIEW_SHIFT_YAW_LIMIT) { mouseViewShiftYaw = -MOUSE_VIEW_SHIFT_YAW_LIMIT; }
|
||||
}
|
||||
if (mouseY < MOUSE_VIEW_SHIFT_PITCH_MARGIN) {
|
||||
float f = 1.0 - (mouseY / MOUSE_VIEW_SHIFT_PITCH_MARGIN);
|
||||
mouseViewShiftPitch += MOUSE_VIEW_SHIFT_RATE * f * deltaTime;
|
||||
if ( mouseViewShiftPitch > MOUSE_VIEW_SHIFT_PITCH_LIMIT ) { mouseViewShiftPitch = MOUSE_VIEW_SHIFT_PITCH_LIMIT; }
|
||||
}
|
||||
else if (mouseY > bottomBoundary) {
|
||||
float f = (mouseY - bottomBoundary) / ((float)HEIGHT - bottomBoundary);
|
||||
mouseViewShiftPitch -= MOUSE_VIEW_SHIFT_RATE * f * deltaTime;
|
||||
if (mouseViewShiftPitch < -MOUSE_VIEW_SHIFT_PITCH_LIMIT) { mouseViewShiftPitch = -MOUSE_VIEW_SHIFT_PITCH_LIMIT; }
|
||||
}
|
||||
|
||||
|
||||
if (OculusManager::isConnected()) {
|
||||
float yaw, pitch, roll;
|
||||
OculusManager::getEulerAngles(yaw, pitch, roll);
|
||||
|
@ -1023,7 +1057,7 @@ void display(void)
|
|||
-myAvatar.getHeadPitch(),
|
||||
myAvatar.getHeadRoll());
|
||||
} else {
|
||||
myCamera.setTargetRotation(myAvatar.getAbsoluteHeadYaw(), myAvatar.getAbsoluteHeadPitch(), 0.0f);
|
||||
myCamera.setTargetRotation(myAvatar.getAbsoluteHeadYaw()- mouseViewShiftYaw, myAvatar.getAbsoluteHeadPitch() + mouseViewShiftPitch, 0.0f);
|
||||
}
|
||||
} else if (myCamera.getMode() == CAMERA_MODE_THIRD_PERSON) {
|
||||
myAvatar.setDisplayingHead(true);
|
||||
|
@ -1031,7 +1065,7 @@ void display(void)
|
|||
myCamera.setDistance (1.5f);
|
||||
myCamera.setTightness (8.0f);
|
||||
myCamera.setTargetPosition(myAvatar.getHeadPosition());
|
||||
myCamera.setTargetRotation(myAvatar.getBodyYaw(), 0.0f, 0.0f);
|
||||
myCamera.setTargetRotation(myAvatar.getBodyYaw() - mouseViewShiftYaw, mouseViewShiftPitch, 0.0f);
|
||||
}
|
||||
|
||||
// important...
|
||||
|
@ -1788,6 +1822,8 @@ void idle(void) {
|
|||
// walking triggers the handControl to stop
|
||||
if (myAvatar.getMode() == AVATAR_MODE_WALKING) {
|
||||
handControl.stop();
|
||||
mouseViewShiftYaw *= 0.9;
|
||||
mouseViewShiftPitch *= 0.9;
|
||||
}
|
||||
|
||||
// Read serial port interface devices
|
||||
|
|
Loading…
Reference in a new issue