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