00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 #ifndef VRS_SG_GAMENAVIGATION_H
00092 #define VRS_SG_GAMENAVIGATION_H
00093
00094 #include <vrs/vector.h>
00095 #include <vrs/sg/navigation.h>
00096 #include <vrs/sg/inputevent.h>
00097
00098 namespace VRS {
00099
00100 class DirectionInterpolator;
00101 class KeyEvent;
00102 class LookAt;
00103 class TimeEvent;
00104
00127 class VRS_CORE_API GameNavigation : public Navigation {
00128
00129 public:
00130
00131 GameNavigation(
00132 LookAt* target = NULL,
00133 InputEvent::Button button = InputEvent::MouseButton1,
00134 InputEvent::Modifier must_modifier = InputEvent::NoModifier,
00135 InputEvent::Modifier must_not_modifier = InputEvent::NoModifier,
00136 const Vector& onGroundPlane = Vector::origin,
00137 double minHeight = 0.01,
00138 double refHeight = 1.0,
00139 double walkSpeed = 0.1,
00140 double runSpeed = 0.3,
00141 double verticalTime = 2.0,
00142 double horizontalAccelerationTime = 0.3,
00143 double verticalAccelerationTime = 0.3
00144 );
00207 double getSensitivity() const;
00209 void setSensitivity(double sensitivity = 0.05);
00213 Vector getGroundPlaneVector() const;
00215 void setGroundPlaneVector(const Vector& onGroundPlane);
00217
00218 double getMinHeight() const;
00220 void setMinHeight(double height);
00222
00223 double getReferenceHeight() const;
00225 void setReferenceHeight(double height);
00227
00228 double getWalkSpeed() const;
00230 void setWalkSpeed(double s);
00232
00233 double getRunSpeed() const;
00235 void setRunSpeed(double s);
00237
00238 double getVerticalTime() const;
00240 void setVerticalTime(double time);
00242
00243 double getHorizontalAccelerationTime() const;
00245 void setHorizontalAccelerationTime(double acceleration);
00247
00248 double getVerticalAccelerationTime() const;
00250 void setVerticalAccelerationTime(double acceleration);
00252
00253 bool isRunning() const;
00259 void setKeyTimeout(unsigned int t);
00268 void setKeys(unsigned int front, unsigned int back, unsigned int left, unsigned int right,
00269 unsigned int up, unsigned int down, unsigned int toggleSpeed, unsigned int turnAround);
00271
00272 void enableKeys();
00273 void disableKeys();
00277 void enableMouseButtonAcceleration(InputEvent::Button button = InputEvent::MouseButton3);
00280 void disableMouseButtonAcceleration();
00283 double getHorizontalScaling() const;
00284 double getVerticalScaling() const;
00285 void setScaling(double horizontal = 1.0, double vertical = 1.0);
00296 virtual BehaviorNode::InvalidationHint dragStart(int x, int y, ButtonEvent*);
00297 virtual BehaviorNode::InvalidationHint dragMotion(int x, int y, MotionEvent*);
00298 virtual BehaviorNode::InvalidationHint dragEnd(int x, int y, ButtonEvent*);
00299 virtual BehaviorNode::InvalidationHint handle(Event*);
00302 virtual ~GameNavigation();
00303
00304 VRS_TYPEINFO(GameNavigation, Manipulator);
00305
00306 private:
00307
00308 BehaviorNode::InvalidationHint onTimer(TimeEvent* e);
00309 BehaviorNode::InvalidationHint onKey(KeyEvent* key);
00310 BehaviorNode::InvalidationHint turnAround();
00311 void rotate();
00312
00313
00314
00315 double walkSpeed_;
00316 double runSpeed_;
00317 double verticalTime_;
00318
00319 double minHeight_;
00320 double refHeight_;
00321
00322 double horizontalAccelerationTime_;
00323 double verticalAccelerationTime_;
00324
00325 double horizontalScaling_;
00326 double verticalScaling_;
00327
00328 double sensitivity_;
00329
00330 Vector onGroundPlane_;
00331
00332 int keyTimeout_;
00333
00334
00335 unsigned int frontKey_;
00336 unsigned int backKey_;
00337 unsigned int rightKey_;
00338 unsigned int leftKey_;
00339 unsigned int upKey_;
00340 unsigned int downKey_;
00341 unsigned int runKey_;
00342 unsigned int turnAroundKey_;
00343 bool enableKeys_;
00344
00345
00346 bool running_;
00347
00348 bool forwardPressed_;
00349 bool backwardPressed_;
00350 bool leftPressed_;
00351 bool rightPressed_;
00352 bool upPressed_;
00353 bool downPressed_;
00354
00355 double currentForwardSpeed_;
00356 double currentSidewardSpeed_;
00357 double verticalSpeedAmount_;
00358
00359
00360 int forwardTimeout_;
00361 int sidewardTimeout_;
00362 int upDownTimeout_;
00363
00364
00365 int lastX_;
00366 int lastY_;
00367 double dx_;
00368 double dy_;
00369 int turnAroundSteps_;
00370
00371 SO<DirectionInterpolator> interpol_;
00372
00373 static const double MaxAltitude;
00374
00375 InputEvent::Button mouseButtonAccelerationButton_;
00376 bool enableMouseButtonAcceleration_;
00377 bool accelerationButtonPressed_;
00378
00379 double elapsedTime_;
00380 };
00381
00382 inline double GameNavigation::getSensitivity() const { return sensitivity_; }
00383 inline Vector GameNavigation::getGroundPlaneVector() const { return onGroundPlane_; }
00384 inline double GameNavigation::getMinHeight() const { return minHeight_; }
00385 inline double GameNavigation::getReferenceHeight() const { return refHeight_; }
00386 inline double GameNavigation::getWalkSpeed() const { return walkSpeed_; }
00387 inline double GameNavigation::getRunSpeed() const { return runSpeed_; }
00388 inline double GameNavigation::getVerticalTime() const { return verticalTime_; }
00389 inline double GameNavigation::getHorizontalAccelerationTime() const { return horizontalAccelerationTime_; }
00390 inline double GameNavigation::getVerticalAccelerationTime() const { return verticalAccelerationTime_; }
00391 inline bool GameNavigation::isRunning() const { return running_; }
00392 inline double GameNavigation::getHorizontalScaling() const { return horizontalScaling_; }
00393 inline double GameNavigation::getVerticalScaling() const { return verticalScaling_; }
00394
00395 }
00396
00397 #endif // VRS_SG_GAMENAVIGATION_H