1 /**************************************************************************/
2 /*  Copyright 2009 Tim Day                                                */
3 /*                                                                        */
4 /*  This file is part of Fracplanet                                       */
5 /*                                                                        */
6 /*  Fracplanet is free software: you can redistribute it and/or modify    */
7 /*  it under the terms of the GNU General Public License as published by  */
8 /*  the Free Software Foundation, either version 3 of the License, or     */
9 /*  (at your option) any later version.                                   */
10 /*                                                                        */
11 /*  Fracplanet is distributed in the hope that it will be useful,         */
12 /*  but WITHOUT ANY WARRANTY; without even the implied warranty of        */
13 /*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         */
14 /*  GNU General Public License for more details.                          */
15 /*                                                                        */
16 /*  You should have received a copy of the GNU General Public License     */
17 /*  along with Fracplanet.  If not, see <http://www.gnu.org/licenses/>.   */
18 /**************************************************************************/
19 
20 /*! \file
21   \brief Interface for class TriangleMeshViewer.
22 */
23 
24 #ifndef _triangle_mesh_viewer_h_
25 #define _triangle_mesh_viewer_h_
26 
27 #include "common.h"
28 #include "parameters_render.h"
29 #include "qtcommon.h"
30 #include "random.h"
31 #include "triangle_mesh.h"
32 #include "triangle_mesh_viewer_display.h"
33 
34 //! A class to display a triangle mesh.
35 /*! Wraps a TriangleMeshViewerDisplay with some controls.
36   \todo Add better controls.
37 */
38 class TriangleMeshViewer : public QWidget
39 {
40  private:
41 
42   Q_OBJECT;
43 
44  public:
45 
46   //! Constructor.
47   TriangleMeshViewer(QWidget* parent,const ParametersRender* param,const std::vector<const TriangleMesh*>& m,bool verbose);
48 
49   //! Destructor
50   ~TriangleMeshViewer();
51 
52   //! Used to set message in statusbar
53   void notify(const std::string&);
54 
55   //! Sets the TriangleMesh to be displayed.
56   void set_mesh(const std::vector<const TriangleMesh*>& m);
57 
58  public slots:
59 
60   void fly();
61   void unfly();
62 
63   void set_tilt(int v);
64   void set_spinrate(int v);
65 
66  private:
67 
68   //! Control logging
69   const bool _verbose;
70 
71   //! Pointer to the rendering parameters.
72   const ParametersRender* parameters;
73 
74   //! The actual rendering area.
75   TriangleMeshViewerDisplay* display;
76 
77   //! Real time for computing how much to advance animation
78   boost::scoped_ptr<QTime> clock;
79 
80   //! Record time last tick
81   int last_t;
82 
83   //! Label and box around the elevation slider.
84   QGroupBox* tilt_box;
85 
86   //! Slider controlling tilt
87   QSlider* tilt_slider;
88 
89   //! Container for fly and reset buttons
90   QWidget* button_box;
91 
92   //! Label and box arond the spin-rate slider.
93   QGroupBox* spinrate_box;
94 
95   //! Spin rate slider.
96   QSlider* spinrate_slider;
97 
98   //! Display fly velocity, render info
99   QStatusBar* statusbar;
100 
101   //! Last notified message
102   std::string notify_message;
103 
104   //@{
105   //! Parameter of camera position.
106   XYZ camera_position;
107   XYZ camera_forward;
108   XYZ camera_up;
109   float camera_velocity;
110   float camera_yaw_rate;
111   float camera_pitch_rate;
112   float camera_roll_rate;
113   //@}
114 
115   //@{
116   //! Parameters of object
117   float object_tilt;
118   float object_rotation;
119   float object_spinrate;
120   //@}
121 
122   //@{
123   //! Key state
124   bool keypressed_arrow_left;
125   bool keypressed_arrow_right;
126   bool keypressed_arrow_up;
127   bool keypressed_arrow_down;
128   bool keypressed_mouse_left;
129   bool keypressed_mouse_right;
130   //@}
131 
132   //! Whether in fly mode
133   bool fly_mode;
134 
135   //! Interested in some key presses
136   void keyPressEvent(QKeyEvent* e);
137 
138   //! Interested in some key state
139   void keyReleaseEvent(QKeyEvent* e);
140 
141   //! Interested in mouse clicks for steering
142   void mousePressEvent(QMouseEvent* e);
143 
144   //! Interested in some button state
145   void mouseReleaseEvent(QMouseEvent* e);
146 
147   //! Interested in mouse position for steering
148   void mouseMoveEvent(QMouseEvent* e);
149 
150   //! Interested in wheel for speed
151   void wheelEvent(QWheelEvent* e);
152 
153  private slots:
154 
155   void tick();
156 
157   void reset();
158 };
159 
160 #endif
161