mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-07 03:22:27 +02:00
implement gesture pinch to camera zoom
This commit is contained in:
parent
3b9a8b426f
commit
cd6f9a774d
4 changed files with 44 additions and 1 deletions
|
@ -269,6 +269,8 @@
|
|||
{ "from": "Keyboard.MouseWheelDown", "to": "Actions.LATERAL_LEFT" },
|
||||
{ "from": "Keyboard.MouseWheelLeft", "to": "Actions.BOOM_OUT", "filters": [ { "type": "scale", "scale": 0.02 } ]},
|
||||
{ "from": "Keyboard.MouseWheelRight", "to": "Actions.BOOM_IN", "filters": [ { "type": "scale", "scale": 0.02 } ]},
|
||||
{ "from": "Keyboard.GesturePinchOut", "to": "Actions.BOOM_OUT"},
|
||||
{ "from": "Keyboard.GesturePinchIn", "to": "Actions.BOOM_IN"},
|
||||
|
||||
{ "from": "Keyboard.Space", "to": "Actions.VERTICAL_UP" },
|
||||
{ "from": "Keyboard.R", "to": "Actions.ACTION1" },
|
||||
|
|
|
@ -4871,6 +4871,9 @@ void Application::touchEndEvent(QTouchEvent* event) {
|
|||
}
|
||||
|
||||
void Application::touchGestureEvent(QGestureEvent* event) {
|
||||
if (_keyboardMouseDevice->isActive()) {
|
||||
_keyboardMouseDevice->touchGestureEvent(event);
|
||||
}
|
||||
if (_touchscreenDevice && _touchscreenDevice->isActive()) {
|
||||
_touchscreenDevice->touchGestureEvent(event);
|
||||
}
|
||||
|
@ -6262,7 +6265,7 @@ void Application::update(float deltaTime) {
|
|||
myAvatar->setDriveKey(MyAvatar::TRANSLATE_Z, -1.0f * userInputMapper->getActionState(controller::Action::TRANSLATE_Z));
|
||||
myAvatar->setDriveKey(MyAvatar::TRANSLATE_Y, userInputMapper->getActionState(controller::Action::TRANSLATE_Y));
|
||||
myAvatar->setDriveKey(MyAvatar::TRANSLATE_X, userInputMapper->getActionState(controller::Action::TRANSLATE_X));
|
||||
if (deltaTime > FLT_EPSILON) {
|
||||
if (deltaTime > FLT_EPSILON && userInputMapper->getActionState(controller::Action::TRANSLATE_CAMERA_Z) == 0.0f) {
|
||||
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));
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <QtGui/QKeyEvent>
|
||||
#include <QtGui/QMouseEvent>
|
||||
#include <QtGui/QTouchEvent>
|
||||
#include <QGesture>
|
||||
|
||||
#include <controllers/UserInputMapper.h>
|
||||
#include <PathUtils.h>
|
||||
|
@ -145,6 +146,36 @@ glm::vec2 evalAverageTouchPoints(const QList<QTouchEvent::TouchPoint>& points) {
|
|||
return averagePoint;
|
||||
}
|
||||
|
||||
void KeyboardMouseDevice::touchGestureEvent(const QGestureEvent* event) {
|
||||
QPinchGesture* pinchGesture = (QPinchGesture*) event->gesture(Qt::PinchGesture);
|
||||
|
||||
if (pinchGesture) {
|
||||
switch (pinchGesture->state()) {
|
||||
case Qt::GestureStarted:
|
||||
_lastTotalScaleFactor = pinchGesture->totalScaleFactor();
|
||||
break;
|
||||
|
||||
case Qt::GestureUpdated: {
|
||||
qreal totalScaleFactor = pinchGesture->totalScaleFactor();
|
||||
qreal scaleFactorDelta = totalScaleFactor - _lastTotalScaleFactor;
|
||||
_inputDevice->_axisStateMap[_inputDevice->makeInput(TOUCH_GESTURE_PINCH_POS).getChannel()].value = (float) (scaleFactorDelta > 0 ? scaleFactorDelta : 0.0f);
|
||||
_inputDevice->_axisStateMap[_inputDevice->makeInput(TOUCH_GESTURE_PINCH_NEG).getChannel()].value = (float) (scaleFactorDelta < 0 ? -scaleFactorDelta : 0.0f);
|
||||
_lastTotalScaleFactor = totalScaleFactor;
|
||||
break;
|
||||
}
|
||||
|
||||
case Qt::GestureFinished: {
|
||||
_inputDevice->_axisStateMap[_inputDevice->makeInput(TOUCH_GESTURE_PINCH_POS).getChannel()].value = 0.0f;
|
||||
_inputDevice->_axisStateMap[_inputDevice->makeInput(TOUCH_GESTURE_PINCH_NEG).getChannel()].value = 0.0f;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KeyboardMouseDevice::touchBeginEvent(const QTouchEvent* event) {
|
||||
if (_enableTouch) {
|
||||
_isTouching = event->touchPointStates().testFlag(Qt::TouchPointPressed);
|
||||
|
@ -344,6 +375,8 @@ controller::Input::NamedVector KeyboardMouseDevice::InputDevice::getAvailableInp
|
|||
availableInputs.append(Input::NamedPair(makeInput(TOUCH_AXIS_X_NEG), "TouchpadLeft"));
|
||||
availableInputs.append(Input::NamedPair(makeInput(TOUCH_AXIS_Y_POS), "TouchpadUp"));
|
||||
availableInputs.append(Input::NamedPair(makeInput(TOUCH_AXIS_Y_NEG), "TouchpadDown"));
|
||||
availableInputs.append(Input::NamedPair(makeInput(TOUCH_GESTURE_PINCH_POS), "GesturePinchOut"));
|
||||
availableInputs.append(Input::NamedPair(makeInput(TOUCH_GESTURE_PINCH_NEG), "GesturePinchIn"));
|
||||
});
|
||||
return availableInputs;
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ class QTouchEvent;
|
|||
class QKeyEvent;
|
||||
class QMouseEvent;
|
||||
class QWheelEvent;
|
||||
class QGestureEvent;
|
||||
|
||||
class KeyboardMouseDevice : public InputPlugin {
|
||||
Q_OBJECT
|
||||
|
@ -60,6 +61,8 @@ public:
|
|||
TOUCH_AXIS_X_NEG,
|
||||
TOUCH_AXIS_Y_POS,
|
||||
TOUCH_AXIS_Y_NEG,
|
||||
TOUCH_GESTURE_PINCH_POS,
|
||||
TOUCH_GESTURE_PINCH_NEG,
|
||||
};
|
||||
|
||||
enum TouchButtonChannel {
|
||||
|
@ -81,6 +84,7 @@ public:
|
|||
void mouseReleaseEvent(QMouseEvent* event);
|
||||
void eraseMouseClicked();
|
||||
|
||||
void touchGestureEvent(const QGestureEvent* event);
|
||||
void touchBeginEvent(const QTouchEvent* event);
|
||||
void touchEndEvent(const QTouchEvent* event);
|
||||
void touchUpdateEvent(const QTouchEvent* event);
|
||||
|
@ -121,6 +125,7 @@ protected:
|
|||
QPoint _previousCursor;
|
||||
QPoint _mousePressPos;
|
||||
quint64 _mousePressTime;
|
||||
qreal _lastTotalScaleFactor;
|
||||
bool _clickDeadspotActive;
|
||||
glm::vec2 _lastTouch;
|
||||
std::shared_ptr<InputDevice> _inputDevice { std::make_shared<InputDevice>() };
|
||||
|
|
Loading…
Reference in a new issue