1 /*
2  Copyright (C) 2010-2014 Kristian Duske
3 
4  This file is part of TrenchBroom.
5 
6  TrenchBroom is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  TrenchBroom is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with TrenchBroom. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef TrenchBroom_FlyModeHelper
21 #define TrenchBroom_FlyModeHelper
22 
23 #include "VecMath.h"
24 
25 #include <iostream>
26 
27 #include <wx/thread.h>
28 #include <wx/wx.h>
29 
30 namespace TrenchBroom {
31     namespace Renderer {
32         class Camera;
33     }
34 
35     namespace View {
36         class FlyModeHelper : public wxThread {
37         private:
38             wxWindow* m_window;
39             Renderer::Camera& m_camera;
40 
41             wxCriticalSection m_critical;
42             bool m_forward;
43             bool m_backward;
44             bool m_left;
45             bool m_right;
46 
47             bool m_enabled;
48 
49             wxPoint m_originalMousePos;
50             wxPoint m_lastMousePos;
51             wxPoint m_currentMouseDelta;
52             bool m_ignoreMotionEvents;
53 
54             wxLongLong m_lastPollTime;
55 
56             class CameraEvent;
57         public:
58             FlyModeHelper(wxWindow* window, Renderer::Camera& camera);
59             ~FlyModeHelper();
60 
61             void enable();
62             void disable();
63             bool enabled() const;
64             bool cancel();
65         private:
66             void lockMouse();
67             void unlockMouse();
68         public:
69             bool keyDown(wxKeyEvent& event);
70             bool keyUp(wxKeyEvent& event);
71         public:
72             void motion(wxMouseEvent& event);
73         private:
74             void resetMouse();
75             wxPoint windowCenter() const;
76         private:
77             ExitCode Entry();
78             Vec3f moveDelta();
79             Vec2f lookDelta();
80             Vec2f lookSpeed() const;
81             float moveSpeed() const;
82         };
83     }
84 }
85 
86 #endif /* defined(TrenchBroom_FlyModeHelper) */
87