GteCameraRig.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #pragma once
9 
10 #include <Graphics/GteCamera.h>
12 #include <map>
13 
14 namespace gte
15 {
16 
18 {
19 public:
20  // Construction. The camera rig is designed for moving the camera around
21  // in a world coordinate system. This object is used in the sample 3D
22  // applications.
23  virtual ~CameraRig();
24  CameraRig();
25  CameraRig(std::shared_ptr<Camera> const& camera, float translationSpeed, float rotationSpeed);
26 
27  // Member access. The functions are for deferred construction after
28  // a default construction of a camera rig.
29  void Set(std::shared_ptr<Camera> const& camera, float translationSpeed, float rotationSpeed);
30 
31  // TODO: The camera vectors are the world axes? (INVARIANT)
32  void ComputeWorldAxes();
33 
34  inline std::shared_ptr<Camera> const& GetCamera() const;
35  inline void SetTranslationSpeed(float translationSpeed);
36  inline float GetTranslationSpeed() const;
37  inline void SetRotationSpeed(float rotationSpeed);
38  inline float GetRotationSpeed() const;
39 
40  // Control of camera motion. If the camera moves, subscribers to the
41  // pvw-matrix update will have the system memory and GPU memory of the
42  // constant buffers updated. Only one motion may be active at a single
43  // time. When a motion is active, a call to Move() will execute that
44  // motion.
45 
46  // The motion is controlled directly by calling SetDirect*().
47  inline void SetDirectMoveForward();
48  inline void SetDirectMoveBackward();
49  inline void SetDirectMoveUp();
50  inline void SetDirectMoveDown();
51  inline void SetDirectMoveRight();
52  inline void SetDirectMoveLeft();
53  inline void SetDirectTurnRight();
54  inline void SetDirectTurnLeft();
55  inline void SetDirectLookUp();
56  inline void SetDirectLookDown();
57  inline void SetDirectRollClockwise();
58  inline void SetDirectRollCounterclockwise();
59 
60  // The motion is controlled indirectly. TheRegister* calls map the
61  // 'trigger' to the function specified by the *-suffix. If trigger >= 0,
62  // the function is added to a map. If trigger < 0 in the Register*
63  // function, the corresponding function is removed from the map. A call
64  // to PushMotion(trigger) will set the active motion if the trigger
65  // is currently mapped; the Boolean return is 'true' iff the trigger is
66  // mapped. A call to PopMotion(trigger) will disable the motion if the
67  // trigger is currently mapped; the Boolean return it 'true' iff the
68  // trigger is currently mapped.
69  inline void RegisterMoveForward(int trigger);
70  inline void RegisterMoveBackward(int trigger);
71  inline void RegisterMoveUp(int trigger);
72  inline void RegisterMoveDown(int trigger);
73  inline void RegisterMoveRight(int trigger);
74  inline void RegisterMoveLeft(int trigger);
75  inline void RegisterTurnRight(int trigger);
76  inline void RegisterTurnLeft(int trigger);
77  inline void RegisterLookUp(int trigger);
78  inline void RegisterLookDown(int trigger);
79  inline void RegisterRollClockwise(int trigger);
80  inline void RegisterRollCounterclockwise(int trigger);
81  bool PushMotion(int trigger);
82  bool PopMotion(int trigger);
83 
84  bool Move();
85  void ClearMotions();
86 
87 protected:
88  // Camera motion. These are called based on the state set in the
89  // public interface.
90  enum { MAX_ACTIVE_MOTIONS = 12 };
91  virtual void MoveForward();
92  virtual void MoveBackward();
93  virtual void MoveUp();
94  virtual void MoveDown();
95  virtual void MoveRight();
96  virtual void MoveLeft();
97  virtual void TurnRight();
98  virtual void TurnLeft();
99  virtual void LookUp();
100  virtual void LookDown();
101  virtual void RollClockwise();
102  virtual void RollCounterclockwise();
103 
104  typedef void(CameraRig::*MoveFunction)(void);
105  void Register(int trigger, MoveFunction function);
106 
107  bool SetActive(MoveFunction function);
108  bool SetInactive(MoveFunction function);
109 
110  std::shared_ptr<Camera> mCamera;
111  float mTranslationSpeed, mRotationSpeed;
112 
113  // Maintain the world coordinate system.
114  Vector4<float> mWorldAxis[3];
115 
116  // Move via direct or indirect triggers.
117  MoveFunction mMotion;
118  std::map<int, MoveFunction> mIndirectMap;
120  std::array<MoveFunction, MAX_ACTIVE_MOTIONS> mActiveMotions;
121 };
122 
123 
124 inline std::shared_ptr<Camera> const& CameraRig::GetCamera() const
125 {
126  return mCamera;
127 }
128 
129 inline void CameraRig::SetTranslationSpeed(float translationSpeed)
130 {
131  mTranslationSpeed = translationSpeed;
132 }
133 
134 inline float CameraRig::GetTranslationSpeed() const
135 {
136  return mTranslationSpeed;
137 }
138 
139 inline void CameraRig::SetRotationSpeed(float rotationSpeed)
140 {
141  mRotationSpeed = rotationSpeed;
142 }
143 
144 inline float CameraRig::GetRotationSpeed() const
145 {
146  return mRotationSpeed;
147 }
148 
150 {
151  mMotion = &CameraRig::MoveForward;
152 }
153 
155 {
156  mMotion = &CameraRig::MoveBackward;
157 }
158 
160 {
161  mMotion = &CameraRig::MoveUp;
162 }
163 
165 {
166  mMotion = &CameraRig::MoveDown;
167 }
168 
170 {
171  mMotion = &CameraRig::MoveRight;
172 }
173 
175 {
176  mMotion = &CameraRig::MoveLeft;
177 }
178 
180 {
181  mMotion = &CameraRig::TurnRight;
182 }
183 
185 {
186  mMotion = &CameraRig::TurnLeft;
187 }
188 
190 {
191  mMotion = &CameraRig::LookUp;
192 }
193 
195 {
196  mMotion = &CameraRig::LookDown;
197 }
198 
200 {
201  mMotion = &CameraRig::RollClockwise;
202 }
203 
205 {
207 }
208 
209 inline void CameraRig::RegisterMoveForward(int trigger)
210 {
211  Register(trigger, &CameraRig::MoveForward);
212 }
213 
214 inline void CameraRig::RegisterMoveBackward(int trigger)
215 {
216  Register(trigger, &CameraRig::MoveBackward);
217 }
218 
219 inline void CameraRig::RegisterMoveUp(int trigger)
220 {
221  Register(trigger, &CameraRig::MoveUp);
222 }
223 
224 inline void CameraRig::RegisterMoveDown(int trigger)
225 {
226  Register(trigger, &CameraRig::MoveDown);
227 }
228 
229 inline void CameraRig::RegisterMoveRight(int trigger)
230 {
231  Register(trigger, &CameraRig::MoveRight);
232 }
233 
234 inline void CameraRig::RegisterMoveLeft(int trigger)
235 {
236  Register(trigger, &CameraRig::MoveLeft);
237 }
238 
239 inline void CameraRig::RegisterTurnRight(int trigger)
240 {
241  Register(trigger, &CameraRig::TurnRight);
242 }
243 
244 inline void CameraRig::RegisterTurnLeft(int trigger)
245 {
246  Register(trigger, &CameraRig::TurnLeft);
247 }
248 
249 inline void CameraRig::RegisterLookUp(int trigger)
250 {
251  Register(trigger, &CameraRig::LookUp);
252 }
253 
254 inline void CameraRig::RegisterLookDown(int trigger)
255 {
256  Register(trigger, &CameraRig::LookDown);
257 }
258 
259 inline void CameraRig::RegisterRollClockwise(int trigger)
260 {
261  Register(trigger, &CameraRig::RollClockwise);
262 }
263 
265 {
266  Register(trigger, &CameraRig::RollCounterclockwise);
267 }
268 
269 }
void SetDirectLookUp()
Definition: GteCameraRig.h:189
void RegisterMoveBackward(int trigger)
Definition: GteCameraRig.h:214
void RegisterMoveUp(int trigger)
Definition: GteCameraRig.h:219
void RegisterTurnRight(int trigger)
Definition: GteCameraRig.h:239
void SetDirectMoveDown()
Definition: GteCameraRig.h:164
void RegisterMoveLeft(int trigger)
Definition: GteCameraRig.h:234
void SetDirectMoveUp()
Definition: GteCameraRig.h:159
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
void RegisterLookDown(int trigger)
Definition: GteCameraRig.h:254
virtual void TurnRight()
MoveFunction mMotion
Definition: GteCameraRig.h:117
void RegisterLookUp(int trigger)
Definition: GteCameraRig.h:249
float GetTranslationSpeed() const
Definition: GteCameraRig.h:134
void RegisterTurnLeft(int trigger)
Definition: GteCameraRig.h:244
virtual void RollClockwise()
void SetDirectMoveBackward()
Definition: GteCameraRig.h:154
virtual void RollCounterclockwise()
virtual void MoveRight()
virtual void LookUp()
virtual void TurnLeft()
virtual void MoveUp()
void SetDirectTurnRight()
Definition: GteCameraRig.h:179
void SetDirectMoveLeft()
Definition: GteCameraRig.h:174
void RegisterRollCounterclockwise(int trigger)
Definition: GteCameraRig.h:264
void RegisterMoveForward(int trigger)
Definition: GteCameraRig.h:209
virtual void MoveForward()
void RegisterRollClockwise(int trigger)
Definition: GteCameraRig.h:259
void RegisterMoveRight(int trigger)
Definition: GteCameraRig.h:229
void RegisterMoveDown(int trigger)
Definition: GteCameraRig.h:224
void SetDirectMoveForward()
Definition: GteCameraRig.h:149
virtual void MoveBackward()
void SetTranslationSpeed(float translationSpeed)
Definition: GteCameraRig.h:129
void SetDirectMoveRight()
Definition: GteCameraRig.h:169
void SetDirectTurnLeft()
Definition: GteCameraRig.h:184
virtual void LookDown()
float GetRotationSpeed() const
Definition: GteCameraRig.h:144
std::array< MoveFunction, MAX_ACTIVE_MOTIONS > mActiveMotions
Definition: GteCameraRig.h:120
std::shared_ptr< Camera > const & GetCamera() const
Definition: GteCameraRig.h:124
void SetDirectRollClockwise()
Definition: GteCameraRig.h:199
void SetRotationSpeed(float rotationSpeed)
Definition: GteCameraRig.h:139
std::shared_ptr< Camera > mCamera
Definition: GteCameraRig.h:110
virtual void MoveLeft()
virtual void MoveDown()
void SetDirectRollCounterclockwise()
Definition: GteCameraRig.h:204
#define GTE_IMPEXP
Definition: GTEngineDEF.h:63
float mTranslationSpeed
Definition: GteCameraRig.h:111
void SetDirectLookDown()
Definition: GteCameraRig.h:194
std::map< int, MoveFunction > mIndirectMap
Definition: GteCameraRig.h:118


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:59