Modifying QFirstPersonCameraController (keybinds)
-
0
Just started using QT and I've ran into what is probably a very simple problem. I'm making a 3D scene where you're supposed to move the camera through space using WASD + mouse for rotation. The existing QFirstPersonCameraController worked great except for the key binds. I decided to make my own camera class inheriting from QAbstractCameraController to change this and potentially other things later on.
I've essentially just copied the code from QFirstPersonCamera but I can't wrap my mind around how the keyboard movement works. How does the InputState work? Where are the keybinds set up for the tAxisValues? I feel really lost and couldn't find anything when trying to search for it.
customcamera.h:
#ifndef CUSTOMCAMERA_H #define CUSTOMCAMERA_H #include <Qt3DExtras/qabstractcameracontroller.h> namespace Qt3DExtras { class CustomCamera : public QAbstractCameraController { Q_OBJECT public: explicit CustomCamera(Qt3DCore::QNode* parent = nullptr); ~CustomCamera(); private: void moveCamera(const InputState &state, float dt) override; }; } #endif // CUSTOMCAMERA_Hcustomcamera.cpp:
#include "customcamera.h" #include <Qt3DRender/QCamera> QT_BEGIN_NAMESPACE namespace Qt3DExtras { CustomCamera::CustomCamera(Qt3DCore::QNode *parent) : QAbstractCameraController(parent) { } CustomCamera::~CustomCamera() { } void CustomCamera::moveCamera(const QAbstractCameraController::InputState &state, float dt) { Qt3DRender::QCamera *theCamera = camera(); if (theCamera == nullptr) return; theCamera->translate(QVector3D(state.txAxisValue * linearSpeed(), state.tyAxisValue * linearSpeed(), state.tzAxisValue * linearSpeed()) * dt); if (state.leftMouseButtonActive) { float theLookSpeed = lookSpeed(); if (state.shiftKeyActive) { theLookSpeed *= 0.2f; } const QVector3D upVector(0.0f, 1.0f, 0.0f); theCamera->pan(state.rxAxisValue * theLookSpeed * dt, upVector); theCamera->tilt(state.ryAxisValue * theLookSpeed * dt); } } } // Qt3DExtras QT_END_NAMESPACEI was thinking that maybe I could just use normal key press events or whatever you would use for holding down buttons but shouldn't the code related to moving the camera go inside the moveCamera() function? Also unsure how I continuously call such a function while a button is held down.
Any help appreciated!