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