better camera mouse controls
This commit is contained in:
parent
236deb0453
commit
4a078d7cf7
|
|
@ -12,6 +12,8 @@ namespace RNR
|
|||
{
|
||||
private:
|
||||
QPointF last_position;
|
||||
QPoint grab_position;
|
||||
bool m_grabbed;
|
||||
OgreWidget* widget;
|
||||
bool reset;
|
||||
public:
|
||||
|
|
@ -21,5 +23,7 @@ namespace RNR
|
|||
void mouseEvent(QMouseEvent* e);
|
||||
|
||||
virtual void resetMouse();
|
||||
virtual void grab();
|
||||
virtual void ungrab();
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ namespace RNR
|
|||
{
|
||||
last_position = QPointF();
|
||||
this->widget = widget;
|
||||
m_grabbed = false;
|
||||
}
|
||||
|
||||
void QtInputManager::keyEvent(QKeyEvent* e)
|
||||
|
|
@ -56,10 +57,30 @@ namespace RNR
|
|||
void QtInputManager::resetMouse()
|
||||
{
|
||||
widget->clearFocus();
|
||||
QPoint glob = widget->mapToGlobal(QPoint(widget->width()/2,widget->height()/2));
|
||||
QCursor::setPos(glob);
|
||||
last_position = QPoint(widget->width()/2,widget->height()/2);
|
||||
widget->setFocus();
|
||||
if(!m_grabbed)
|
||||
{
|
||||
QPoint glob = widget->mapToGlobal(QPoint(widget->width()/2,widget->height()/2));
|
||||
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;
|
||||
widget->setFocus();
|
||||
}
|
||||
|
||||
void QtInputManager::grab()
|
||||
{
|
||||
grab_position = widget->mapFromGlobal(QCursor::pos());
|
||||
last_position = grab_position;
|
||||
m_grabbed = true;
|
||||
}
|
||||
|
||||
void QtInputManager::ungrab()
|
||||
{
|
||||
m_grabbed = false;
|
||||
}
|
||||
}
|
||||
|
|
@ -23,6 +23,8 @@ namespace RNR
|
|||
IInputManager();
|
||||
|
||||
virtual void resetMouse() {};
|
||||
virtual void grab() {};
|
||||
virtual void ungrab() {};
|
||||
|
||||
void setWorld(World* world) { m_world = world; world->setInputManager(this); }
|
||||
|
||||
|
|
|
|||
|
|
@ -91,6 +91,10 @@ namespace RNR
|
|||
|
||||
void IInputManager::mouseSecondaryState(bool down)
|
||||
{
|
||||
if(down)
|
||||
grab();
|
||||
else if(!down)
|
||||
ungrab();
|
||||
state.mouse_secondary = down;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue