vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ShootingSimulation.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vrecko/Ability.h>
6 #include <vrecko/Logger.h>
7 #include <vrecko/Message.h>
8 #include <vrecko/Scene.h>
9 #include <vrecko/World.h>
10 
11 #include <osgText/Font>
12 
13 using namespace vrecko;
14 
15 namespace APShootingSimulation
16 {
17 
21 enum GameStates {
22  PREPARE_NEW_GAME, // before starting a new game => after initializing of the app or after the last level
23  PREPARE_NEXT_LEVEL, // prepare state for next level
24  WAITING_FOR_START, // waiting for pressing 'start' button
25  COUNTDOWN, // after pressing 'start' button
26  RUNNING_LEVEL // during playing levels
27 };
28 
38 };
39 
52 {
53 public:
54 
59  virtual ~ShootingSimulation() {};
60 
64  virtual bool initialize(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *parameters = NULL);
65 
69  virtual void update(void);
70 
78  osg::ref_ptr<vrecko::EnvironmentObject> resolveIntersections(osg::Vec3 &vector,
79  osg::Vec3 &position,
80  std::vector<osg::Node*> **nodePath = NULL);
81 
82 protected:
83 
91  bool addObject(osg::ref_ptr<vrecko::EnvironmentObject> &obj, const std::string& geoPath);
92 
96  void setCrosshairPos();
97 
103  void moveTarget(osg::Vec3 currentTargetPos);
104 
108  void testAndHandleHit();
109 
111  DECLARE_INPUT(Start, MessageBool);
112  DECLARE_INPUT(Mouse, MessageVec2);
113  DECLARE_INPUT(Trigger, MessageBool);
114  DECLARE_INPUT(Sensor_Transformation, MessageSensorTransformation);
115 
116 private:
117  // string of start buttons for 'startText'
118  static const std::string START_BUTTONS;
119 
120  // paths to models
121  static const std::string PATH_WALL;
122  static const std::string PATH_CROSSHAIR;
123  static const std::string PATH_TARGET;
124 
125  #define NUM_TARGETS 3
126  static const std::string PATH_TARGET_DAMAGED[];
127 
128  // Environment objects
129  osg::ref_ptr<vrecko::EnvironmentObject> wall;
130  osg::ref_ptr<vrecko::EnvironmentObject> target;
131  osg::ref_ptr<vrecko::EnvironmentObject> crosshair;
132  osg::ref_ptr<vrecko::EnvironmentObject> damagedTargets[NUM_TARGETS];
133 
134  // index of damagedTarget currently in use
135  unsigned int dmgTargetIndex;
136  // current start position of the target
137  unsigned int targetPosIndex;
138 
139  // osg vectors for aiming
140  osg::Vec2 _mouse2DVector;
141  osg::Vec3 _aimVector;
142  osg::Vec3 _standingPosition;
143  osg::Vec3 _opti3DVector0;
144  osg::Vec3 _opti3DVector1;
145 
146  static const float CROSSHAIR_DIFF;
147  static const float DEFAULT_Z_GRID;
148  float screenZGrid;
149 
150  // target appearance setup
151  static const int NUM_TARGETS_POS;
152  static const float X_TARGETS[];
153  static const float Y_TARGETS[];
154 
155  static const float MIN_X;
156  static const float MAX_X;
157  static const float MIN_Y;
158  static const float MAX_Y;
159 
160  static const float TARGET_INITIAL_SPEED;
161  static const float TARGET_SPEED_INCREASE_VALUE;
162  float _targetSpeed;
163 
164  // state of game
165  GameStates gameState;
166  // current target move direction
167  MoveDirections moveDirection;
168  unsigned int level;
169  static const int MAX_LEVEL;
170 
171  // score variables
172  std::string scoreString;
173  int score;
174 
175  // text variables
176  osg::ref_ptr<osgText::Text> startText;
177  osg::ref_ptr<osg::Geode> startTextGeode;
178  osg::ref_ptr<osgText::Text> scoreText;
179  osg::ref_ptr<osg::Geode> scoreTextGeode;
180  osg::ref_ptr<osgText::Font> textFont;
181 
182  // timing
183  std::string timeString;
184  int timeToEnd;
185  static const int STARTING_TIME;
186 
187  osg::Timer_t beginningTime;
188  osg::Timer_t currentTime;
189  osg::Timer_t startOfMove;
190  osg::Timer_t previousTick;
191 
192  double movingTime;
193  static const double MOVE_UP_SPEED;
194  static const double MOVE_DOWN_SPEED;
195 };
196 
197 }
198