MorphoGraphX
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CameraPath.hpp
1 #ifndef CAMERAPATH_HPP
2 #define CAMERAPATH_HPP
3 
4 #include <Config.hpp>
5 
6 #include <Misc.hpp>
7 
8 #include <QObject>
9 #include <QTimer>
10 #include <QPointer>
11 #include <QList>
12 
13 class MGXCamera;
14 
15 class CameraPath : public QObject {
16  Q_OBJECT
17 public:
19  ~CameraPath();
20  void addFrame(MGXCamera* camera, float time = 1.0);
21  void addRotation(const mgx::Point3f& axis, double angle, float time = 2.0);
22 
23  void animatePath(MGXCamera* camera, float dt);
24 
25 protected slots:
26  void nextFrame();
27 
28 signals:
29  void endPath();
30  void frameUpdated();
31 
32 protected:
33  struct Action : public QObject {
34  Action(float t, QObject* parent = 0)
35  : QObject(parent)
36  , time(t)
37  {
38  }
39 
40  // Returns true when the end is reached
41  virtual bool startInterpolation(MGXCamera* camera) = 0;
42  virtual bool interpolateFrame(MGXCamera* camera, float t) = 0;
43  float time;
44  };
45 
46  struct ToPosition : public Action {
47  ToPosition(const mgx::Point3f& c, const mgx::Point3f& p, const mgx::Point3f& d, float z, float t, QObject* parent = 0)
48  : Action(t, parent)
49  , center(c)
50  , position(p)
51  , direction(d)
52  , zoom(z)
53  {
54  }
55 
56  virtual bool startInterpolation(MGXCamera* camera);
57  virtual bool interpolateFrame(MGXCamera* camera, float t);
58  mgx::Point3f center;
59  mgx::Point3f position;
60  mgx::Point3f direction;
61  float zoom;
62 
63  // Quaternions for camera orientation
64  mgx::Quaternion oq1, oq2;
65  // Quaternions for camera position
66  mgx::Quaternion pq1, pq2;
67  };
68 
69  struct Rotation : public Action {
70  Rotation(const mgx::Point3f& c, const mgx::Point3f& ax, float an, float t, QObject* parent = 0)
71  : Action(t, parent)
72  , center(c)
73  , axis(ax)
74  , angle(an)
75  {
76  }
77  virtual bool startInterpolation(MGXCamera*) {
78  return true;
79  }
80  virtual bool interpolateFrame(MGXCamera*, float) {
81  return true;
82  }
83  mgx::Point3f center;
84  mgx::Point3f axis;
85  double angle;
86  };
87 
88  QList<QPointer<Action> > frames;
89  MGXCamera* camera;
90  float dt;
91  float current_time;
92  int current_index;
93  QTimer* timer;
94 };
95 
96 #endif // CAMERAPATH_HPP
Definition: CameraPath.hpp:46
Definition: MorphoViewer.hpp:51
Misc.
Definition: CameraPath.hpp:33
QObject(QObject *parent=0)
Definition: CameraPath.hpp:69
Definition: CameraPath.hpp:15