Home | History | Annotate | Download | only in opengl
      1 // This file is part of Eigen, a lightweight C++ template library
      2 // for linear algebra.
      3 //
      4 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud (at) inria.fr>
      5 //
      6 // This Source Code Form is subject to the terms of the Mozilla
      7 // Public License v. 2.0. If a copy of the MPL was not distributed
      8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
      9 
     10 #ifndef EIGEN_QUATERNION_DEMO_H
     11 #define EIGEN_QUATERNION_DEMO_H
     12 
     13 #include "gpuhelper.h"
     14 #include "camera.h"
     15 #include "trackball.h"
     16 #include <map>
     17 #include <QTimer>
     18 #include <QtGui/QApplication>
     19 #include <QtOpenGL/QGLWidget>
     20 #include <QtGui/QMainWindow>
     21 
     22 class RenderingWidget : public QGLWidget
     23 {
     24   Q_OBJECT
     25 
     26     typedef std::map<float,Frame> TimeLine;
     27     TimeLine m_timeline;
     28     Frame lerpFrame(float t);
     29 
     30     Frame mInitFrame;
     31     bool mAnimate;
     32     float m_alpha;
     33 
     34     enum TrackMode {
     35       TM_NO_TRACK=0, TM_ROTATE_AROUND, TM_ZOOM,
     36       TM_LOCAL_ROTATE, TM_FLY_Z, TM_FLY_PAN
     37     };
     38 
     39     enum NavMode {
     40       NavTurnAround,
     41       NavFly
     42     };
     43 
     44     enum LerpMode {
     45       LerpQuaternion,
     46       LerpEulerAngles
     47     };
     48 
     49     enum RotationMode {
     50       RotationStable,
     51       RotationStandard
     52     };
     53 
     54     Camera mCamera;
     55     TrackMode mCurrentTrackingMode;
     56     NavMode mNavMode;
     57     LerpMode mLerpMode;
     58     RotationMode mRotationMode;
     59     Vector2i mMouseCoords;
     60     Trackball mTrackball;
     61 
     62     QTimer m_timer;
     63 
     64     void setupCamera();
     65 
     66     std::vector<Vector3f> mVertices;
     67     std::vector<Vector3f> mNormals;
     68     std::vector<int> mIndices;
     69 
     70   protected slots:
     71 
     72     virtual void animate(void);
     73     virtual void drawScene(void);
     74 
     75     virtual void grabFrame(void);
     76     virtual void stopAnimation();
     77 
     78     virtual void setNavMode(int);
     79     virtual void setLerpMode(int);
     80     virtual void setRotationMode(int);
     81     virtual void resetCamera();
     82 
     83   protected:
     84 
     85     virtual void initializeGL();
     86     virtual void resizeGL(int width, int height);
     87     virtual void paintGL();
     88 
     89     //--------------------------------------------------------------------------------
     90     virtual void mousePressEvent(QMouseEvent * e);
     91     virtual void mouseReleaseEvent(QMouseEvent * e);
     92     virtual void mouseMoveEvent(QMouseEvent * e);
     93     virtual void keyPressEvent(QKeyEvent * e);
     94     //--------------------------------------------------------------------------------
     95 
     96   public:
     97     EIGEN_MAKE_ALIGNED_OPERATOR_NEW
     98 
     99     RenderingWidget();
    100     ~RenderingWidget() { }
    101 
    102     QWidget* createNavigationControlWidget();
    103 };
    104 
    105 class QuaternionDemo : public QMainWindow
    106 {
    107   Q_OBJECT
    108   public:
    109     QuaternionDemo();
    110   protected:
    111     RenderingWidget* mRenderingWidget;
    112 };
    113 
    114 #endif // EIGEN_QUATERNION_DEMO_H
    115