]> git.tdb.fi Git - r2c2.git/blob - source/designer/cameracontroller.h
Don't crash if a train has no router
[r2c2.git] / source / designer / cameracontroller.h
1 #ifndef CAMERACONTROLLER_H_
2 #define CAMERACONTROLLER_H_
3
4 #include <msp/graphics/window.h>
5 #include <msp/gl/camera.h>
6 #include <msp/input/keyboard.h>
7 #include <msp/input/mouse.h>
8 #include "3d/view.h"
9
10 /**
11 Moves the camera based on keyboard and mouse events.  Controls are as follows:
12
13 Arrow keys  - pan
14 Home        - view all
15 Insert      - view from top down
16 Wheel       - adjust viewing distance
17 RMB         - rotate
18 MMB         - pan
19 Shift + RMB - pan
20 Shift + MMB - rotate
21 Ctrl + RMB  - adjust viewing distance
22 Ctrl + MMB  - adjust viewing distance
23 */
24 class CameraController
25 {
26 private:
27         enum DragMode
28         {
29                 NONE,
30                 PAN,
31                 ROTATE,
32                 DISTANCE
33         };
34
35         R2C2::View3D &view;
36         Msp::Input::Keyboard &keyboard;
37         Msp::Input::Mouse &mouse;
38         Msp::GL::Camera &camera;
39         int move_x;
40         int move_y;
41         int pointer_x;
42         int pointer_y;
43         bool shift_pressed;
44         bool ctrl_pressed;
45         DragMode drag_mode;
46
47 public:
48         CameraController(R2C2::View3D &, Msp::Input::Keyboard &, Msp::Input::Mouse &);
49
50         void top_down();
51         void set_look_direction(const Msp::GL::Vector3 &);
52         void view_all();
53
54         void move(float, float);
55         void adjust_distance(float);
56         void rotate(const R2C2::Angle &);
57         void pitch(const R2C2::Angle &);
58
59         void tick(float);
60 private:
61         void button_press(unsigned);
62         void button_release(unsigned);
63         void axis_motion(unsigned, float, float);
64         void key_press(unsigned);
65         void key_release(unsigned);
66
67 public:
68         /** Return the focus point, i.e. where the look ray intersects with ground. */
69         Msp::GL::Vector3 get_focus() const;
70
71         /** Return distance from the focus point. */
72         float get_distance() const;
73
74         /** Return the viewport height at focus distance. */
75         float get_view_scale() const;
76 };
77
78 #endif