vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CameraPath.h
Go to the documentation of this file.
1 #ifndef _CAMERA_PATH_H
2 #define _CAMERA_PATH_H
3 
4 #include <vrecko/ReaderWriter.h>
5 
6 #include <vrecko/Ability.h>
8 #include <vrecko/Scene.h>
10 #include <vrecko/Logger.h>
11 
12 #include <helpers/XercesXMLUtils.h>
13 #include <xercesc/parsers/XercesDOMParser.hpp>
14 #include <xercesc/dom/DOM.hpp>
15 #include <xercesc/sax/HandlerBase.hpp>
16 #include <xercesc/util/XMLString.hpp>
17 #include <xercesc/util/PlatformUtils.hpp>
18 
19 #include <osg/Group>
20 #include <osg/Geode>
21 #include <osg/Geometry>
22 #include <osg/Shape>
23 #include <osg/ShapeDrawable>
24 #include <osg/PositionAttitudeTransform>
25 #include <osg/LineWidth>
26 #include <osg/LightModel>
27 #include <osg/ShadeModel>
28 #include <osg/PolygonMode>
29 
30 #include <osg/Timer>
31 #include <vector>
32 
33 using namespace vrecko;
34 using namespace vrecko;
35 
36 namespace APCameraMovement {
37 
38 #define CONTROL_POINT_RADIUS 1.0
39 #define CONTROL_POINT_COLOR osg::Vec4(1.0, 0.0, 0.0, 0.5)
40 
41 #define VECTOR_POINT_RADIUS 1.0
42 #define VECTOR_POINT_COLOR osg::Vec4(0.0, 0.0, 1.0, 0.5)
43 
44 #define CONTROL_LINE_WIDTH 1.0
45 #define CONTROL_LINE_COLOR osg::Vec4(0.0, 0.0, 1.0, 1.0)
46 
47 #define PATH_LINE_WIDTH 1.0
48 #define PATH_LINE_COLOR osg::Vec4(1.0, 0.0, 0.0, 1.0)
49 
50 #define DEFAULT_VECPW osg::Vec3(CONTROL_POINT_RADIUS*3, 0.0, 0.0)
51 #define DEFAULT_VECCPW osg::Vec3(-(CONTROL_POINT_RADIUS*3), 0.0, 0.0)
52 #define DEFAULT_CDIR osg::Quat(0.0, 0.0, 0.0, 1.0)
53 
54 #define TOP_VECTOR osg::Vec3(0.0, 1.0, 0.0)
55 #define DIR_VECTOR osg::Vec3(0.0, 0.0, 1.0)
56 
57 #define STEP 0.01
58 #define MULT 6
59 #define SPEED 2
60 
61  struct ControlPoint {
62  osg::Vec3 position;
63  osg::Vec3 vectorPathWise;
65  osg::Quat cameraRotation;
66 
67  double totalPathLength; // total length from first to this point
68  double pathLength; // length of the curve [i-1;i]
69  unsigned int pathIndex; // index where the curve [i-1;i] ends
70  };
71 
72  class CameraPath : public Ability {
73  public:
74  CameraPath();
75  ~CameraPath();
76 
77  // called as the first initialization method, before loadXMLParameters
78  virtual void preInitialize();
79 
80  // called as the last initialization method, after loadXMLParameters
81  virtual void postInitialize();
82 
83  // loads XML parameters from given node
84  virtual bool loadXMLParameters(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *pParametersNode);
85 
86  // processes an event
87 // void processEvent(const std::string &strInputName, void *pValue);
88 
89  // ability update method
90  virtual void update();
91 
92  // visualisies the path incl. points
93  void draw();
94 
95  void setDirty(bool d) { dirty = d; }
96  std::vector<ControlPoint>* getControlPoints() { return &controlPoints; }
97 
98  void addPoint(osg::Vec3 pos, osg::Vec3 vecPW = DEFAULT_VECPW, osg::Vec3 vecCPW = DEFAULT_VECCPW, osg::Quat cDir = DEFAULT_CDIR) {
99  ControlPoint p;
100  p.position = pos;
101  p.vectorPathWise = vecPW;
102  p.vectorCounterPathWise = vecCPW;
103  p.cameraRotation = cDir;
104  controlPoints.push_back(p);
105  }
106 
107  inline bool animating() { return isAnimating; }
108 
109  bool startAnimation();
110  bool stopAnimation();
111  bool updateActTime();
112  float convertActTimeToActPos();
113  bool updateAnimation(float fActPos);
114 
115  private:
116 
117  // control points defining the path
118  std::vector<ControlPoint> controlPoints;
119 
120  // the path vertices to be drawn as line strip
121  std::vector<osg::Vec3> pathPoints;
122 
123  // pointer to parent enviroment object
124  EnvironmentObject* pEOOwner;
125 
126  bool dirty;
127  bool isAnimating;
128  osg::Timer_t lastTimerTick;
129 
130  // actual position of camera when animating (relative distance on the curve)
131  float fActTime;
132 
133  // computes the path
134  void computePath();
135 
136  // pointer to avatar view
137  World::AvatarView *avView;
138 
139 
140 
141 
142  // parameters corresponding to macros above
143  float controlPointRadius; // sphere radius of a main control point
144  osg::Vec4 controlPointColor; // color of a main control point
145 
146  float vectorPointRadius; // sphere radius of a point defining a vector
147  osg::Vec4 vectorPointColor; // color of a point defining a vector
148 
149  float controlLineWidth; // width of a line showing the vectors
150  osg::Vec4 controlLineColor; // color of a line showing the vectors
151 
152  float pathLineWidth; // width of a line showing the path
153  osg::Vec4 pathLineColor; // color of a line showing the path
154 
155  float speed; // speed of the camera (float per second)
156  float step; // a step of one ferguson curve (how many pieces there are between two control points)
157 
158  bool freeLook; // defines whether user can rotate with camera while moving
159 
160 
161  DECLARE_INPUT(Trigger, MessageVoid);
162  };
163 
164 }
165 
166 #endif
167