vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Camera.h
Go to the documentation of this file.
1 #ifndef _CAMERA_H_
2 #define _CAMERA_H_
3 
5 
6 #include <vrecko/PluginManager.h>
7 #include <vrecko/World.h>
9 #include <vrecko/Scene.h>
10 
11 //XML parameters
12 #include <helpers/XercesXMLUtils.h>
13 #include <vrecko/ReaderWriter.h>
14 #include <xercesc/parsers/XercesDOMParser.hpp>
15 
16 #include <osg/Group>
17 #include <osg/Geode>
18 #include <osg/Geometry>
19 #include <osg/Shape>
20 #include <osg/ShapeDrawable>
21 #include <osg/Timer>
22 
23 #include <iostream>
24 #include <fstream>
25 #include <sstream>
26 #include <vector>
27 #include <cmath>
28 
29 namespace APCameraPath {
30 
31 #define SHOW_VIEW_LINE false
32 #define PATH_POINT_RADIUS 0.5
33 
34 #define SHOW_LINES_WHILE_ANIMATING false
35 
36 #define ANIMATION_TIME 10 //s
37 #define DYNAMIC_SPEED false
38 #define TRANSPARENCY 1.0 //0.0 is invisible, 1.0 is non-transparent
39 
40 #define AUTO_RUN false;
41 
42 
43 typedef unsigned int _uint;
44 
46 {
49 };
50 
52 {
53  public:
54  Camera();
55  virtual ~Camera() {};
56  void update(void);
57  virtual bool initialize(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *parameters = NULL) { bool bRet = ControllableAbility::initialize(); Init(); UpdatePath(); return bRet; };
58 
59  protected:
60 
61  enum state
62  {
66  } m_eState;
67  enum animate
68  {
71  } m_eAnimate;
72 
73  vrecko::World::AvatarView avView; //Used for storing actual view position before animation
74 
76  vrecko::EnvironmentObject* m_pEOPathPoints; //EO for path control points
78  vrecko::EnvironmentObject* m_pEOCursor; //EO for 3D pointers
79  vrecko::EnvironmentObject* m_pEOCamera; //EO for Camera model for 3rd person view
80 
82  bool b3rdCamera;
83 
84  unsigned int m_numOfViewPts;
85 
86  std::vector<ControlPoint> m_ControlPoints;
87 
88  std::vector<osg::Vec3> m_ActPathLine; //Used for storing actual path line for animating
89  std::vector<osg::Vec3> m_ActViewLine; //------------||--------- view line -----||------
90 
91  //XML Parameters
92  float fPointRadius;
95  int iSpeed;
100  bool bAutoRun;
102 
103  virtual void fillDefaultInfo();
104  virtual bool activate();
105  virtual void deactivate();
106  virtual void menuItemClicked(const char* itemID);
107  bool loadXMLParameters(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *pParametersNode);
108 
109  std::vector<osg::Vec3> PathCtrlPts;
110  std::vector<osg::Vec3> ViewCtrlPts;
111 
113  // FUNCTIONS
115 
118  void ComputePath(std::vector<ControlPoint> &ControlPoints, osg::Vec3Array* Path, osg::Vec3Array* View);
122  void ComputeSpline(const std::vector<osg::Vec3> &PointList, osg::Vec3Array* arrayToStorePoints,
123  bool bDynamicSpeed, const std::vector<double>* LengthsOfParts);
127  std::vector<double> ArcLength(osg::Vec3Array* PointList, int PointsOnPart = 100);
128 
129  void DrawSpline(vrecko::EnvironmentObject* pCurveOwner, osg::Vec3Array* PointSet, osg::Vec4 colorOfLine);
133  void CreateCurs2ViewPts();
137  void DrawVecCursor(vrecko::EnvironmentObject* pCursorOwner, double dVecLength,
138  const osg::Matrix &rotationMatrix, osg::Vec3 &position);
142  vrecko::EnvironmentObject* DrawPoint(osg::Vec3 position, float pointRadius, osg::Vec4 pointColor);
146  void UpdatePath();
150  void InitAnimation(osg::Vec3Array* path, osg::Vec3Array* view);
151  void Animate();
155  osg::Matrix Orient2Vec(osg::Vec3 Vector);
159  bool makeMenu();
163  bool makeMovementMenu();
167  bool FindPoint(double dDistance, osg::Vec3Array* PointList, osg::Vec3Array* newControlPoints);
171  void Clear();
172 
173  void Init();
175  void AddPathPoint(osg::Vec3 position);
176  void AddViewPoint(osg::Vec3 position);
177  void DeletePoint(unsigned long ID);
178 
179  void start1stAnimation();
181  void SaveAnimation(const char* FileName);
182  bool LoadAnimation(const char* FileName,std::vector<osg::Vec3> &newPathControlPoints,
183  std::vector<osg::Vec3> &newViewControlPoints);
185 
186  //----------------------------------------------------------------------
187  // Simple Object Movement Part
188  //----------------------------------------------------------------------
189 
190  osg::Vec3 firstPointerPos; // pointer position when activate
191  osg::Vec3 firstObjectPos; // object position when activated
192  unsigned long movingObjectID; // ID of the object that is being handled. If this is 0, the ability is not activated
194 
195  void issueRequests(bool bStopIfNoSelection);
196  bool objectTransformationFromPointer(vrecko::EnvironmentObject *eo, osg::Matrix *outTrans);
197  void UpdateMove();
198  bool ActivateMove();
199  void DeactivateMove();
200 };
201 
203 //Catmull-rom splines
204 inline float F1(float t) { return (2*pow(t,2)-pow(t,3)-t); }
205 inline float F2(float t) { return (3*pow(t,3)-(5*pow(t,2))+2); }
206 inline float F3(float t) { return (4*pow(t,2)-(3*pow(t,3))+t); }
207 inline float F4(float t) { return (pow(t,3)-pow(t,2)); }
209 }
210 
211 #endif
212