better camera mouse controls

This commit is contained in:
floralrainfall 2023-07-21 04:31:37 -04:00
parent 236deb0453
commit 4a078d7cf7
4 changed files with 35 additions and 4 deletions

View File

@ -12,6 +12,8 @@ namespace RNR
{ {
private: private:
QPointF last_position; QPointF last_position;
QPoint grab_position;
bool m_grabbed;
OgreWidget* widget; OgreWidget* widget;
bool reset; bool reset;
public: public:
@ -21,5 +23,7 @@ namespace RNR
void mouseEvent(QMouseEvent* e); void mouseEvent(QMouseEvent* e);
virtual void resetMouse(); virtual void resetMouse();
virtual void grab();
virtual void ungrab();
}; };
} }

View File

@ -7,6 +7,7 @@ namespace RNR
{ {
last_position = QPointF(); last_position = QPointF();
this->widget = widget; this->widget = widget;
m_grabbed = false;
} }
void QtInputManager::keyEvent(QKeyEvent* e) void QtInputManager::keyEvent(QKeyEvent* e)
@ -56,10 +57,30 @@ namespace RNR
void QtInputManager::resetMouse() void QtInputManager::resetMouse()
{ {
widget->clearFocus(); widget->clearFocus();
QPoint glob = widget->mapToGlobal(QPoint(widget->width()/2,widget->height()/2)); if(!m_grabbed)
QCursor::setPos(glob); {
last_position = QPoint(widget->width()/2,widget->height()/2); QPoint glob = widget->mapToGlobal(QPoint(widget->width()/2,widget->height()/2));
widget->setFocus(); QCursor::setPos(glob);
last_position = QPoint(widget->width()/2,widget->height()/2);
}
else
{
QCursor::setPos(widget->mapToGlobal(grab_position));
last_position = grab_position;
}
reset = true; reset = true;
widget->setFocus();
}
void QtInputManager::grab()
{
grab_position = widget->mapFromGlobal(QCursor::pos());
last_position = grab_position;
m_grabbed = true;
}
void QtInputManager::ungrab()
{
m_grabbed = false;
} }
} }

View File

@ -23,6 +23,8 @@ namespace RNR
IInputManager(); IInputManager();
virtual void resetMouse() {}; virtual void resetMouse() {};
virtual void grab() {};
virtual void ungrab() {};
void setWorld(World* world) { m_world = world; world->setInputManager(this); } void setWorld(World* world) { m_world = world; world->setInputManager(this); }

View File

@ -91,6 +91,10 @@ namespace RNR
void IInputManager::mouseSecondaryState(bool down) void IInputManager::mouseSecondaryState(bool down)
{ {
if(down)
grab();
else if(!down)
ungrab();
state.mouse_secondary = down; state.mouse_secondary = down;
} }