From dfaf752d730c105e74e05c606ea2061911b395ee Mon Sep 17 00:00:00 2001 From: Riku Avelar Date: Wed, 30 Nov 2016 16:55:47 -0500 Subject: [PATCH] Animation Controls --- mainwindow.ui | 44 +++++++++++++++++++++++++++++++++++-- src/viewer/simpleViewer.cpp | 18 +++++++-------- src/viewer/simpleViewer.h | 5 +++-- src/window/mainwindow.cpp | 4 ++++ src/window/mainwindow.h | 1 + 5 files changed, 59 insertions(+), 13 deletions(-) diff --git a/mainwindow.ui b/mainwindow.ui index 329e3be..b4402cf 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -30,7 +30,7 @@ - + @@ -56,9 +56,10 @@ QFrame::Raised + speedSlider - + 6 @@ -212,6 +213,45 @@ + + + + 0 + + + 100 + + + 1 + + + 10 + + + Qt::Horizontal + + + QSlider::TicksBelow + + + 10 + + + + + + + + 10 + 75 + true + + + + + + + diff --git a/src/viewer/simpleViewer.cpp b/src/viewer/simpleViewer.cpp index 7aeccc7..8ae1c90 100644 --- a/src/viewer/simpleViewer.cpp +++ b/src/viewer/simpleViewer.cpp @@ -881,17 +881,13 @@ void Viewer::changeColor(QColor c){ } void Viewer::animate(){ - clock_t time = clock(); - double dt = time - startTime; - frame += dt * 0.006 * frame_mult; // 60fps - startTime = time; - update(); + clock_t time = clock(); + double dt = time - startTime; + frame += dt * 0.006 * frame_mult; // 60fps + startTime = time; + update(); } -void Viewer::startAniumation(){} - -void Viewer::stopAnimation(){} - void Viewer::rotateSelectedObjXCCW() { rotateSelected(RotateDirection::X_CCW); } @@ -911,6 +907,10 @@ void Viewer::rotateSelectedObjZCW() { rotateSelected(RotateDirection::Z_CW); } +void Viewer::animationSpeedChange(int val) { + frame_mult = fmax(double(val) / 10, 0.05); +} + void Viewer::rotateSelected(RotateDirection dir) { if(selectedObj.shape == nullptr || selectedObj.shape->getParent() == nullptr) return; diff --git a/src/viewer/simpleViewer.h b/src/viewer/simpleViewer.h index c32d442..ea61947 100644 --- a/src/viewer/simpleViewer.h +++ b/src/viewer/simpleViewer.h @@ -81,6 +81,7 @@ public slots: void rotateSelectedObjYCW(); void rotateSelectedObjZCCW(); void rotateSelectedObjZCW(); + void animationSpeedChange(int); signals: int shapeSelected(int); @@ -107,8 +108,8 @@ private: PickedGeom pickGeom(int, int); void animate(); - void startAniumation(); - void stopAnimation(); +// void startAnimation(); +// void stopAnimation(); void drawUi(); diff --git a/src/window/mainwindow.cpp b/src/window/mainwindow.cpp index 62ba704..90e4b98 100644 --- a/src/window/mainwindow.cpp +++ b/src/window/mainwindow.cpp @@ -75,6 +75,10 @@ void MainWindow::addViewer(Viewer* viewer) connect(ui->cw_y, SIGNAL(clicked(bool)), viewer, SLOT(rotateSelectedObjYCW())); connect(ui->ccw_z, SIGNAL(clicked(bool)), viewer, SLOT(rotateSelectedObjZCCW())); connect(ui->cw_z, SIGNAL(clicked(bool)), viewer, SLOT(rotateSelectedObjZCW())); + + connect(ui->speedSlider, SIGNAL(valueChanged(int)), viewer, SLOT(animationSpeedChange(int))); + connect(ui->play_button, SIGNAL(clicked(bool)), viewer, SLOT(toggleAnimation())); + } void MainWindow::onColorPickerActivate(){ diff --git a/src/window/mainwindow.h b/src/window/mainwindow.h index b21499c..4a44b33 100644 --- a/src/window/mainwindow.h +++ b/src/window/mainwindow.h @@ -23,6 +23,7 @@ public: public slots: void onColorPickerActivate(); +// void onToggleAnimationText(); //void onTextureToggle(); private: