Skip to content

Commit

Permalink
add enum for CameraMotionMode
Browse files Browse the repository at this point in the history
  • Loading branch information
kkimurak committed Aug 23, 2020
1 parent 382c3f8 commit 0ee7196
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
7 changes: 6 additions & 1 deletion include/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ Copyright (C) 2011, Parsian Robotic Center (eew.aut.ac.ir/~parsian/grsim)
#include <QGLWidget>
#include <QString>

enum CameraMotionMode {
ROTATE_VIEW_POINT = 1,
MOVE_POSITION_FREELY = 2,
MOVE_POSITION_LR = 4,
};

class CGraphics
{
Expand Down Expand Up @@ -61,7 +66,7 @@ class CGraphics
dReal renderDepth();
void setRenderDepth(dReal depth);
void setViewpoint (dReal x,dReal y,dReal z,dReal h,dReal p,dReal r);
void cameraMotion (int mode, int deltax, int deltay);
void cameraMotion (CameraMotionMode mode, int deltax, int deltay);
void lookAt(dReal x,dReal y,dReal z);
void getCameraForward(dReal& x,dReal& y,dReal& z);
void getCameraRight(dReal& x,dReal& y,dReal& z);
Expand Down
6 changes: 3 additions & 3 deletions src/glwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,13 @@ void GLWidget::mouseMoveEvent(QMouseEvent *event)
int dy = -(event->y() - lastPos.y());
if (event->buttons() & Qt::LeftButton) {
if (ctrl)
ssl->g->cameraMotion(4,dx,dy);
ssl->g->cameraMotion(CameraMotionMode::MOVE_POSITION_FREELY,dx,dy);
else
ssl->g->cameraMotion(1,dx,dy);
ssl->g->cameraMotion(CameraMotionMode::ROTATE_VIEW_POINT,dx,dy);
}
else if (event->buttons() & Qt::MidButton)
{
ssl->g->cameraMotion(2,dx,dy);
ssl->g->cameraMotion(CameraMotionMode::MOVE_POSITION_LR,dx,dy);
}
lastPos = event->pos();
update3DCursor(event->x(),event->y());
Expand Down
8 changes: 4 additions & 4 deletions src/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,22 +181,22 @@ void CGraphics::wrapCameraAngles()
}
}

void CGraphics::cameraMotion (int mode, int deltax, int deltay)
void CGraphics::cameraMotion (CameraMotionMode mode, int deltax, int deltay)
{
if (graphicDisabled) return;
dReal side = 0.01f * dReal(deltax);
dReal fwd = (mode==4) ? (0.01f * dReal(deltay)) : 0.0f;
dReal fwd = (mode==CameraMotionMode::ROTATE_VIEW_POINT) ? (0.01f * dReal(deltay)) : 0.0f;
dReal s = (dReal) sin (view_hpr[0]*M_PI/180.0f);
dReal c = (dReal) cos (view_hpr[0]*M_PI/180.0f);

if (mode==1) {
if (mode==CameraMotionMode::ROTATE_VIEW_POINT) {
view_hpr[0] += dReal (deltax) * 0.5f;
view_hpr[1] += dReal (deltay) * 0.5f;
}
else {
view_xyz[0] += -s*side + c*fwd;
view_xyz[1] += c*side + s*fwd;
if (mode==2 || mode==5) view_xyz[2] += 0.01f * dReal(deltay);
if (mode==CameraMotionMode::MOVE_POSITION_FREELY) view_xyz[2] += 0.01f * dReal(deltay);
}
wrapCameraAngles();
}
Expand Down

0 comments on commit 0ee7196

Please sign in to comment.