camera panning via left button drag

actorid
Marc Zinnschlag 11 years ago
parent b9107addc0
commit 07d20a2013

@ -17,7 +17,7 @@ namespace CSVRender
, mCamera(NULL)
, mSceneMgr(NULL), mNavigationMode (NavigationMode_Free), mUpdate (false)
, mKeyForward (false), mKeyBackward (false), mKeyLeft (false), mKeyRight (false)
, mFast (false)
, mFast (false), mDragging (false)
{
setAttribute(Qt::WA_PaintOnScreen);
setAttribute(Qt::WA_NoSystemBackground);
@ -175,6 +175,52 @@ namespace CSVRender
}
}
void SceneWidget::leaveEvent (QEvent *event)
{
mDragging = false;
}
void SceneWidget::mouseMoveEvent (QMouseEvent *event)
{
int factor = mFast ? 4 : 1; /// \todo make this configurable
if (event->buttons() & Qt::LeftButton)
{
if (mDragging)
{
QPoint diff = mOldPos-event->pos();
mOldPos = event->pos();
if (diff.x())
{
Ogre::Vector3 direction = mCamera->getDerivedRight();
/// \todo make mouse sensitivity configurable (the factor 2)
mCamera->move ((factor * direction * diff.x())/2);
mUpdate = true;
}
if (diff.y())
{
Ogre::Vector3 direction = mCamera->getDerivedUp();
/// \todo make mouse sensitivity configurable (the factor 2)
mCamera->move ((factor * -direction * diff.y())/2);
mUpdate = true;
}
}
else
{
mDragging = true;
mOldPos = event->pos();
}
}
}
void SceneWidget::mouseReleaseEvent (QMouseEvent *event)
{
if (event->buttons() & Qt::LeftButton)
mDragging = false;
}
void SceneWidget::focusOutEvent (QFocusEvent *event)
{
mKeyForward = false;

@ -41,6 +41,12 @@ namespace CSVRender
void wheelEvent (QWheelEvent *event);
void leaveEvent (QEvent *event);
void mouseMoveEvent (QMouseEvent *event);
void mouseReleaseEvent (QMouseEvent *event);
void updateOgreWindow();
Ogre::Camera* mCamera;
@ -54,6 +60,8 @@ namespace CSVRender
int mKeyLeft;
int mKeyRight;
bool mFast;
bool mDragging;
QPoint mOldPos;
private slots:

Loading…
Cancel
Save