Umasoft
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
NavEngines.h
1 //
2 // NavEngines.h
3 //
4 // Navigation Engines, generally for moving the camera with mouse input.
5 //
6 // Copyright (c) 2001-2006 Virtual Terrain Project
7 // Free for all uses, see license.txt for details.
8 //
9 
10 #ifndef NAVENGINESH
11 #define NAVENGINESH
12 
13 #include "vtdata/HeightField.h"
14 #include "Engine.h"
15 #include "Event.h"
16 
22 
24 
34 class vtFlyer : public vtLastMouse
35 {
36 public:
37  vtFlyer(float fSpeed = 1.0f, bool bAllowRoll = false);
38 
41  void SetSpeed(float fSpeed) { m_fSpeed = fSpeed; }
44  float GetSpeed() { return m_fSpeed; }
45 
46  void SetAlwaysMove(bool bMove);
47  void SetMultiplier(float fMult) { m_fMult = fMult; }
48 
49  void Eval();
50 
51  enum DOF { DOF_X = 0, DOF_Y, DOF_Z, DOF_PITCH, DOF_YAW, DOF_ROLL };
52  void SetDOF(DOF dof, bool bTrue) { m_bDOF[dof] = bTrue; }
53  bool GetDOF(DOF dof) { return m_bDOF[dof]; }
54 
56  float GetCurrentSpeed() { return m_fCurrentSpeed; }
57 
58 protected:
59  void DoKeyNavigation();
60 
61  float m_fSpeed; // max units per frame of movement
62  float m_fMult; // multiply speed by this factor
63  bool m_bDOF[6]; // six degrees of freedom
64  bool m_bAlwaysMove;
65  float m_fCurrentSpeed; // current speed (most recent frame)
66 
67 protected:
68  ~vtFlyer() {}
69 };
70 
80 class vtOrthoFlyer : public vtFlyer
81 {
82 public:
83  vtOrthoFlyer(float fSpeed);
84  void Eval();
85 };
86 
91 class vtTerrainFlyer : public vtFlyer
92 {
93 public:
94  vtTerrainFlyer(float fSpeed, bool bAllowRoll = false);
95 
97  void SetHeightField(vtHeightField3d *pHF) { m_pHeightField = pHF; }
98 
99  // If true, exaggerate the speed of the view by height above ground
100  void SetExag(bool bDo) { m_bExag = bDo; }
101  bool GetExag() { return m_bExag; }
102 
103  // override
104  void Eval();
105 
106 protected:
107  vtHeightField3d *m_pHeightField;
108  bool m_bExag; // exaggerate speed based on height
109 
110 protected:
111  ~vtTerrainFlyer() {}
112 };
113 
114 
127 {
128 public:
129  vtPanoFlyer(float fSpeed);
130 
131  void Eval();
132 
133 protected:
134  float m_Velocity;
135 };
136 
137 
138 class vtTin3d;
139 
144 class vtTinFlyer : public vtLastMouse
145 {
146 public:
147  vtTinFlyer(float fSpeed);
148 
149  void SetSpeed(float fSpeed) { m_fSpeed = fSpeed; }
150  float GetSpeed() { return m_fSpeed; }
151 
153  void SetTin(vtTin3d *pTin);
154 
155  // implementation override
156  void Eval();
157 
158 protected:
159  float m_fSpeed; // max units per frame of movement
160  vtTin3d *m_pTin;
161  float m_fPitch;
162 };
163 
164 
165 class vtHeightConstrain;
166 
171 class VFlyer : public vtTerrainFlyer
172 {
173 public:
174  VFlyer(float scale);
175 
176  void SetVerticalVelocity(float velocity);
177 
181  void SetGravity(float grav) { m_fGravity = grav; }
182 
186  void SetGroundTester(vtHeightConstrain *pEng) { m_pConstrain = pEng; }
187 
191  void SetDamping(float damp) { m_fDamping = damp; }
192 
193  void Eval(); // overrides
194 
195 protected:
196  FPoint3 m_Velocity;
197  float m_last_time;
198  float m_fGravity;
199  float m_fDamping;
200  vtHeightConstrain *m_pConstrain;
201 };
202 
203 
210 {
211 public:
212  QuakeFlyer(float scale);
213  void Eval();
214 
215  // override
216  void OnKey(int key, int flags);
217 
218 protected:
219  IPoint2 m_LastMousePt;
220  float m_flastmovex, m_flastmovey;
221  short m_sWrap;
222  bool m_bNavEnable;
223 };
224 
225 
230 {
231 public:
232  vtHeightConstrain(float fMinHeight);
233 
235  void SetHeightField(vtHeightField3d *pHF) { m_pHF = pHF; }
236 
238  void SetMinGroundOffset(float fMeters) { m_fMinGroundOffset = fMeters; }
239 
241  float GetMinGroundOffset() { return m_fMinGroundOffset; }
242 
244  void SetUseCulture(bool set) { m_bUseCulture = set; }
245 
247  bool GetUseCulture() { return m_bUseCulture; }
248 
250  void SetMaintain(bool bMaintain) { m_bMaintain = bMaintain; }
251  bool GetMaintain() { return m_bMaintain; }
252 
254  void SetMaintainHeight(float fHeight) { m_fMaintainHeight = fHeight; }
255 
256  bool IsVerticallyMobile();
257 
258  void Eval();
259 
260 protected:
261  bool m_bMaintain;
262  float m_fMaintainHeight;
263  vtHeightField3d *m_pHF;
264  float m_fMinGroundOffset;
265  bool m_bUseCulture;
266  bool m_bOnGround;
267 
268 protected:
269  ~vtHeightConstrain() {}
270 };
271 
272 
274 
285 class vtTrackball : public vtLastMouse
286 {
287 public:
288  vtTrackball(float fRadius);
289 
290  void SetRadius(float fRadius);
291  float GetRadius() const;
292 
293  void SetPivotPoint(const FPoint3 &pos) { m_Pivot = pos; }
294  FPoint3 GetPivotPoint() const { return m_Pivot; }
295 
296  void SetRotateButton(int button, int modifier = 0, bool bExact = true);
297  void SetZoomButton(int button, int modifier = 0, bool bExact = true);
298  void SetTranslateButton(int button, int modifier = 0, bool bExact = true);
299 
300  void SetZoomScale(float s);
301  void SetRotScale(float s);
302  void SetTransScale(float s);
303 
304  void SetDirection(float fTheta, float fPhi);
305  void MoveDirection(float fTheta, float fPhi);
306 
307  void SetTrans(const FPoint3 &trans) { m_Trans = trans; }
308  void Translate(const FPoint3 &trans) { m_Trans += trans; }
309  FPoint3 GetTrans() const { return m_Trans; }
310 
311  void GetState(FPoint3 *state);
312  void SetState(const FPoint3 *state);
313 
314  void OnMouse(vtMouseEvent &event);
315  void Eval();
316 
317  void LimitPos(const FPoint3 &min, const FPoint3 &max);
318  void LimitTrans(const FPoint3 &min, const FPoint3 &max);
319 
320 protected:
321  bool _IsRotate();
322  bool _IsZoom();
323  bool _IsTranslate();
324  void _ApplyLimits();
325 
326  FPoint3 m_Pos, m_Start, m_Trans, m_Pivot;
327  bool m_bRotate;
328  bool m_bZoom;
329  bool m_bTrans;
330 
331  IPoint2 m_MouseStart;
332  float m_fZoomScale;
333  float m_fRotScale;
334  float m_fTransScale;
335 
336  int m_rotate_button;
337  int m_rotate_modifier;
338  bool m_rotate_exact;
339  int m_zoom_button;
340  int m_zoom_modifier;
341  bool m_zoom_exact;
342  int m_trans_button;
343  int m_trans_modifier;
344  bool m_trans_exact;
345 
346  // Limits
347  FPoint3 m_pos_min, m_pos_max;
348  FPoint3 m_trans_min, m_trans_max;
349 
350 protected:
351  ~vtTrackball() {}
352 };
353  // Group nav
355 
356 #endif
357