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