navigator_tool.hpp
Go to the documentation of this file.
1 /*
2 ** TP CPE Lyon
3 ** Copyright (C) 2014 Damien Rohmer
4 **
5 ** This program is free software: you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation, either version 3 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
14 **
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 
20 #pragma once
21 
22 
23 #ifndef NAVIGATOR_TOOL_HPP
24 #define NAVIGATOR_TOOL_HPP
25 
26 #include "trackball.hpp"
27 #include "../lib3d/vec3.hpp"
28 
29 #include <vector>
30 
31 namespace cpe
32 {
33 
46  {
47  public:
48 
49  // ********************************************* //
50  // ********************************************* //
51  // CONSTRUCTORS
52  // ********************************************* //
53  // ********************************************* //
54 
57 
58 
59  // ********************************************* //
60  // ********************************************* //
61  // Screen parameters
62  // ********************************************* //
63  // ********************************************* //
64 
66  unsigned int& screen_size_x();
68  unsigned int screen_size_x() const;
69 
71  unsigned int& screen_size_y();
73  unsigned int screen_size_y() const;
74 
75 
76  // ********************************************* //
77  // ********************************************* //
78  // Camera manipulation
79  // ********************************************* //
80  // ********************************************* //
81 
83  double& dist_cam();
85  float dist_cam() const;
86 
88  void go_forward(float dL);
90  void go_right (float dL);
92  void go_up (float dL);
93 
94 
96  void trackball_rotate(const int& x,const int&y);
98  void trackball_zoom(const int& y);
99 
100 
101  // ********************************************* //
102  // ********************************************* //
103  // Mouse record
104  // ********************************************* //
105  // ********************************************* //
106 
108  int& x_previous();
110  const int& x_previous() const;
111 
113  int& y_previous();
115  const int& y_previous() const;
116 
118  bool& left_button();
120  bool left_button() const;
121 
123  bool& right_button();
125  bool right_button() const;
126 
127 
128 
129 
130  // ********************************************* //
131  // ********************************************* //
132  // Projection parameters
133  // ********************************************* //
134  // ********************************************* //
135 
148  std::vector<double> projection_param() const;
149 
150 
151  // ********************************************* //
152  // ********************************************* //
153  // Camera orientation
154  // ********************************************* //
155  // ********************************************* //
156 
158  matrix3 camera_orientation() const;
160  vec3 camera_translation() const;
161 
163  vec3 camera_position() const;
164 
165 
166  // ********************************************* //
167  // ********************************************* //
168  // FPS
169  // ********************************************* //
170  // ********************************************* //
171 
173  void increase_frame_number();
174 
176  unsigned int time() const;
178  unsigned int& time();
179 
181  double update_fps();
183  double delta_time();
184 
186  double fps();
187 
188  // ********************************************* //
189  // ********************************************* //
190  // Picking
191  // ********************************************* //
192  // ********************************************* //
196  std::pair<vec3,vec3> ray_world_space_cam1(const int& x_screen,const int& y_screen) const;
197 
198 
199  private:
200 
201 
202  // ********************************************* //
203  // ********************************************* //
204  // Internal Camera Parameters
205  // ********************************************* //
206  // ********************************************* //
207 
213  double dist;
214 
216  double fov;
218  double znear;
220  double zfar;
221 
222  // ********************************************* //
223  // ********************************************* //
224  // Window and mouse parameters
225  // ********************************************* //
226  // ********************************************* //
227 
229  unsigned int x_size;
231  unsigned int y_size;
232 
237 
238 
243 
244  // ********************************************* //
245  // ********************************************* //
246  // Time parameter
247  // ********************************************* //
248  // ********************************************* //
249 
251  double current_fps;
253  unsigned int current_time;
255  unsigned int old_time;
257  unsigned int frame;
258 
259  };
260 }
261 
262 #endif
vec3 tr
internal camera world space translation
Definition: navigator_tool.hpp:211
void trackball_zoom(const int &y)
camera zoom using on-screen coordinates
Definition: navigator_tool.cpp:100
vec3 camera_position() const
get the current position of the camera
Definition: navigator_tool.cpp:139
vec3 camera_translation() const
get the camera absolute translation
Definition: navigator_tool.cpp:135
void go_up(float dL)
move the camera up by a distance dL
Definition: navigator_tool.cpp:61
(Dirty) Container class for camera, mouse and fps manipulation
Definition: navigator_tool.hpp:45
bool & right_button()
is right button clicked
Definition: navigator_tool.cpp:77
void increase_frame_number()
increase the frame number by 1
Definition: navigator_tool.cpp:148
double current_fps
internal storage of current fps
Definition: navigator_tool.hpp:251
double & dist_cam()
zoom factor
Definition: navigator_tool.cpp:46
int mouse_y_previous
internal storage of previous clicked position of the mouse (y)
Definition: navigator_tool.hpp:236
matrix3 camera_orientation() const
get the camera orientation (matrix of the quaternion)
Definition: navigator_tool.cpp:131
int & y_previous()
previous position of the mouse in screen y-coordinate
Definition: navigator_tool.cpp:70
unsigned int & screen_size_y()
Window size y.
Definition: navigator_tool.cpp:43
double znear
internal camera Znear storage
Definition: navigator_tool.hpp:218
unsigned int & screen_size_x()
Window size x.
Definition: navigator_tool.cpp:40
void trackball_rotate(const int &x, const int &y)
camera rotation using on-screen coordinates
Definition: navigator_tool.cpp:80
unsigned int frame
internal storage of current frame number
Definition: navigator_tool.hpp:257
Matrix 3x3.
Definition: matrix3.hpp:36
double dist
internal zoom magnitude (z-translation in local coordinate frame)
Definition: navigator_tool.hpp:213
double update_fps()
update the fps counter and set frame to 0
Definition: navigator_tool.cpp:153
double fov
internal camera FOV storage
Definition: navigator_tool.hpp:216
unsigned int y_size
internal storage of window height
Definition: navigator_tool.hpp:231
unsigned int current_time
internal storage of current time
Definition: navigator_tool.hpp:253
bool is_right_button
internal storage when right button is clicked
Definition: navigator_tool.hpp:242
std::pair< vec3, vec3 > ray_world_space_cam1(const int &x_screen, const int &y_screen) const
give the (x,y) coordinate in screen space and return the center and the ray pointed in world space ...
Definition: navigator_tool.cpp:170
A container class to deal with a trackball, use ArcBall paradigm.
Definition: trackball.hpp:34
bool is_left_button
internal storage when left button is clicked
Definition: navigator_tool.hpp:240
double zfar
internal camera Zfar storage
Definition: navigator_tool.hpp:220
bool & left_button()
is left button clicked
Definition: navigator_tool.cpp:74
double fps()
get the current fps
Definition: navigator_tool.cpp:165
unsigned int time() const
get the current elapsed time
Definition: navigator_tool.cpp:150
double delta_time()
elapsed time since old_time record
Definition: navigator_tool.cpp:160
void go_forward(float dL)
move the camera forward by a distance dL
Definition: navigator_tool.cpp:49
Vectors/Points 3D.
Definition: vec3.hpp:36
int mouse_x_previous
internal storage of previous clicked position of the mouse (x)
Definition: navigator_tool.hpp:234
void go_right(float dL)
move the camera to the right by a distance dL
Definition: navigator_tool.cpp:55
int & x_previous()
previous position of the mouse in screen x-coordinate
Definition: navigator_tool.cpp:67
std::vector< double > projection_param() const
Projection camera parameters: left/top/znear/zfar/aspect.
Definition: navigator_tool.cpp:116
trackball track
internal rotation quaternion controled using ArcBall
Definition: navigator_tool.hpp:209
unsigned int x_size
internal storage of window width
Definition: navigator_tool.hpp:229
navigator_tool()
empty constructor
Definition: navigator_tool.cpp:30
unsigned int old_time
internal storage of previously recorded time
Definition: navigator_tool.hpp:255