From 14d39d174756145377c6af6dba275b9dce40ab46 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Thu, 3 Jan 2019 15:53:37 +1300 Subject: [PATCH] Make mouselook yaw and pitch directly proportional to mouse movement --- .../resources/controllers/keyboardMouse.json | 25 ++++++++----------- interface/src/Application.cpp | 2 ++ interface/src/avatar/MyAvatar.cpp | 6 +++-- interface/src/avatar/MyAvatar.h | 2 ++ .../controllers/src/controllers/Actions.cpp | 17 ++++++++++--- .../controllers/src/controllers/Actions.h | 4 +++ 6 files changed, 35 insertions(+), 21 deletions(-) diff --git a/interface/resources/controllers/keyboardMouse.json b/interface/resources/controllers/keyboardMouse.json index 2ad07911c6..74c11203ef 100644 --- a/interface/resources/controllers/keyboardMouse.json +++ b/interface/resources/controllers/keyboardMouse.json @@ -123,7 +123,16 @@ { "from": { "makeAxis" : ["Keyboard.MouseMoveLeft", "Keyboard.MouseMoveRight"] }, "when": "Keyboard.RightMouseButton", - "to": "Actions.Yaw", + "to": "Actions.DeltaYaw", + "filters": + [ + { "type": "scale", "scale": 0.6 } + ] + }, + + { "from": { "makeAxis" : ["Keyboard.MouseMoveUp", "Keyboard.MouseMoveDown"] }, + "when": "Keyboard.RightMouseButton", + "to": "Actions.DeltaPitch", "filters": [ { "type": "scale", "scale": 0.6 } @@ -144,20 +153,6 @@ { "from": "Keyboard.PgDown", "to": "Actions.VERTICAL_DOWN" }, { "from": "Keyboard.PgUp", "to": "Actions.VERTICAL_UP" }, - { "from": "Keyboard.MouseMoveUp", "when": "Keyboard.RightMouseButton", "to": "Actions.PITCH_UP", - "filters": - [ - { "type": "scale", "scale": 0.6 } - ] - - }, - { "from": "Keyboard.MouseMoveDown", "when": "Keyboard.RightMouseButton", "to": "Actions.PITCH_DOWN", - "filters": - [ - { "type": "scale", "scale": 0.6 } - ] - }, - { "from": "Keyboard.TouchpadDown", "to": "Actions.PITCH_DOWN" }, { "from": "Keyboard.TouchpadUp", "to": "Actions.PITCH_UP" }, diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index a5c1ad6cf0..dfd9873352 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -5970,6 +5970,8 @@ void Application::update(float deltaTime) { if (deltaTime > FLT_EPSILON) { myAvatar->setDriveKey(MyAvatar::PITCH, -1.0f * userInputMapper->getActionState(controller::Action::PITCH)); myAvatar->setDriveKey(MyAvatar::YAW, -1.0f * userInputMapper->getActionState(controller::Action::YAW)); + myAvatar->setDriveKey(MyAvatar::DELTA_PITCH, -1.0f * userInputMapper->getActionState(controller::Action::DELTA_PITCH)); + myAvatar->setDriveKey(MyAvatar::DELTA_YAW, -1.0f * userInputMapper->getActionState(controller::Action::DELTA_YAW)); myAvatar->setDriveKey(MyAvatar::STEP_YAW, -1.0f * userInputMapper->getActionState(controller::Action::STEP_YAW)); } } diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 397817cf60..50e4ad8b9d 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -2696,9 +2696,10 @@ void MyAvatar::updateOrientation(float deltaTime) { _bodyYawDelta = 0.0f; } } - float totalBodyYaw = _bodyYawDelta * deltaTime; + // Rotate directly proportional to delta yaw and delta pitch from right-click mouse movement. + totalBodyYaw += getDriveKey(DELTA_YAW) * _yawSpeed / YAW_SPEED_DEFAULT; // Comfort Mode: If you press any of the left/right rotation drive keys or input, you'll // get an instantaneous 15 degree turn. If you keep holding the key down you'll get another @@ -2766,7 +2767,8 @@ void MyAvatar::updateOrientation(float deltaTime) { head->setBaseRoll(ROLL(euler)); } else { head->setBaseYaw(0.0f); - head->setBasePitch(getHead()->getBasePitch() + getDriveKey(PITCH) * _pitchSpeed * deltaTime); + head->setBasePitch(getHead()->getBasePitch() + getDriveKey(PITCH) * _pitchSpeed * deltaTime + + getDriveKey(DELTA_PITCH) * _pitchSpeed / PITCH_SPEED_DEFAULT); head->setBaseRoll(0.0f); } } diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index b2381366bb..134aca645c 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -264,6 +264,8 @@ public: STEP_YAW, PITCH, ZOOM, + DELTA_YAW, + DELTA_PITCH, MAX_DRIVE_KEYS }; Q_ENUM(DriveKeys) diff --git a/libraries/controllers/src/controllers/Actions.cpp b/libraries/controllers/src/controllers/Actions.cpp index 6923ef4b98..5a396231b6 100644 --- a/libraries/controllers/src/controllers/Actions.cpp +++ b/libraries/controllers/src/controllers/Actions.cpp @@ -52,11 +52,17 @@ namespace controller { * TranslateZnumbernumberMove the user's avatar in the direction of its * z-axis, if the camera isn't in independent or mirror modes. * PitchnumbernumberRotate the user's avatar head and attached camera - * about its negative x-axis (i.e., positive values pitch down), if the camera isn't in HMD, independent, or mirror - * modes. - * YawnumbernumberRotate the user's avatar about its y-axis, if the - * camera isn't in independent or mirror modes. + * about its negative x-axis (i.e., positive values pitch down) at a rate proportional to the control value, if the + * camera isn't in HMD, independent, or mirror modes. + * YawnumbernumberRotate the user's avatar about its y-axis at a rate + * proportional to the control value, if the camera isn't in independent or mirror modes. * RollnumbernumberNo action. + * DeltaPitchnumbernumberRotate the user's avatar head and attached + * camera about its negative x-axis (i.e., positive values pitch down) by an amount proportional to the control value, + * if the camera isn't in HMD, independent, or mirror modes. + * DeltaYawnumbernumberRotate the user's avatar about its y-axis by an + * amount proportional to the control value, if the camera isn't in independent or mirror modes. + * DeltaRollnumbernumberNo action. * StepTranslateXnumbernumberNo action. * StepTranslateYnumbernumberNo action. * StepTranslateZnumbernumberNo action. @@ -318,6 +324,9 @@ namespace controller { makeAxisPair(Action::ROLL, "Roll"), makeAxisPair(Action::PITCH, "Pitch"), makeAxisPair(Action::YAW, "Yaw"), + makeAxisPair(Action::DELTA_YAW, "DeltaYaw"), + makeAxisPair(Action::DELTA_PITCH, "DeltaPitch"), + makeAxisPair(Action::DELTA_ROLL, "DeltaRoll"), makeAxisPair(Action::STEP_YAW, "StepYaw"), makeAxisPair(Action::STEP_PITCH, "StepPitch"), makeAxisPair(Action::STEP_ROLL, "StepRoll"), diff --git a/libraries/controllers/src/controllers/Actions.h b/libraries/controllers/src/controllers/Actions.h index 0c77d63863..a12a3d60a9 100644 --- a/libraries/controllers/src/controllers/Actions.h +++ b/libraries/controllers/src/controllers/Actions.h @@ -27,6 +27,10 @@ enum class Action { ROTATE_Y, YAW = ROTATE_Y, ROTATE_Z, ROLL = ROTATE_Z, + DELTA_PITCH, + DELTA_YAW, + DELTA_ROLL, + STEP_YAW, // FIXME does this have a use case? STEP_PITCH,