Skip to content

Commit 94896f9

Browse files
committed
Add idle rotation
1 parent 7f7fb06 commit 94896f9

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

src/Renderer/OpenGL/OpenGLRendererWidget.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,27 @@ void OpenGLRendererWidget::paintGL()
8585

8686
float aspect = (float)w / h;
8787

88+
// Idle Rotation
89+
if (_rotating) {
90+
// Increment yaw angle
91+
_camAngle.y += 0.005f; // faster or slower
92+
93+
// Keep angle bounded to prevent float precision issues over time
94+
if (_camAngle.y > 6.283185f) _camAngle.y -= 6.283185f;
95+
96+
// Recalculate camera position
97+
_camPos.x = _camDist * sin(_camAngle.x) * cos(_camAngle.y);
98+
_camPos.y = _camDist * cos(_camAngle.x);
99+
_camPos.z = _camDist * sin(_camAngle.x) * sin(_camAngle.y);
100+
101+
// Repaint continuously
102+
update();
103+
}
104+
88105
_volumeRenderer.render(defaultFramebufferObject(), _camPos, _camAngle, aspect);
89106
}
90107

108+
91109
void OpenGLRendererWidget::cleanup()
92110
{
93111
_isInitialized = false;
@@ -115,6 +133,7 @@ bool OpenGLRendererWidget::eventFilter(QObject* target, QEvent* event)
115133
_previousMousePos = mousePos;
116134

117135
_mousePressed = true;
136+
_rotating = false; // FIXME: improve interaction with roation
118137
break;
119138
}
120139
case QEvent::MouseMove:

src/Renderer/OpenGL/OpenGLRendererWidget.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class OpenGLRendererWidget : public QOpenGLWidget, QOpenGLFunctions_4_2_Core
2929
void setColormap(const QImage& colormap);
3030
void setCursorPoint(mv::Vector3f cursorPoint);
3131

32+
3233
public:
3334
bool eventFilter(QObject* target, QEvent* event);
3435

@@ -49,4 +50,7 @@ class OpenGLRendererWidget : public QOpenGLWidget, QOpenGLFunctions_4_2_Core
4950
bool _mousePressed = false;
5051

5152
bool _isInitialized = false;
53+
54+
// for rotation
55+
bool _rotating = true;
5256
};

0 commit comments

Comments
 (0)