Umasoft
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Engine.h
1 //
2 // Engine.h
3 //
4 // Copyright (c) 2001-2011 Virtual Terrain Project
5 // Free for all uses, see license.txt for details.
6 //
7 
8 #ifndef VTENGINEH
9 #define VTENGINEH
10 
11 #include "vtdata/vtString.h"
12 #include "Event.h"
13 
14 class vtWindow;
15 
22 
29 {
30 public:
31  vtEnabledBase() { m_bEnabled = true; }
32 
33  virtual void SetEnabled(bool bOn) { m_bEnabled = bOn; }
34  bool GetEnabled() { return m_bEnabled; }
35 
36 protected:
37  bool m_bEnabled;
38 };
39 
40 typedef osg::ref_ptr<class vtEngine> vtEnginePtr;
41 
54 class vtEngine : public vtEnabledBase, public osg::Referenced
55 {
56 public:
57  vtEngine();
58 
64  osg::Referenced *GetTarget(uint which = 0);
66  void AddTarget(osg::Referenced *ptr) { m_Targets.Append(ptr); }
68  void SetTarget(osg::Referenced *ptr) { m_Targets.SetAt(0, ptr); }
70  void RemoveTarget(osg::Referenced *ptr);
71 
73  uint NumTargets() { return m_Targets.GetSize(); }
74 
75  void setName(const char *str) { m_strName = str; }
76  const char *getName() { return m_strName; }
77 
79  virtual void OnMouse(vtMouseEvent &event);
80 
82  virtual void OnKey(int key, int flags);
83 
85  virtual void OnWindowSize(int width, int height);
86 
90  virtual void Eval();
91 
92  // an engine may be associate with a window
93  void SetWindow(vtWindow *pWin) { m_pWindow = pWin; }
94  vtWindow *GetWindow() { return m_pWindow; }
95 
96  // Engine tree methods
97  void AddChild(vtEngine *pEngine) { m_Children.push_back(pEngine); }
98  void RemoveChild(vtEngine *pEngine);
99  vtEngine *GetChild(uint i) { return m_Children[i].get(); }
100  uint NumChildren() { return m_Children.size(); }
101 
102  void AddChildrenToList(vtArray<vtEngine*> &list, bool bEnabledOnly);
103 
104 protected:
105  vtArray<osg::Referenced*> m_Targets;
106  std::vector<vtEnginePtr> m_Children;
107  vtString m_strName;
108  vtWindow *m_pWindow;
109 
110 protected:
111  ~vtEngine() {}
112 };
113 
114 
115 class vtEngineArray : public vtArray<vtEngine*>
116 {
117 public:
118  vtEngineArray(vtEngine *pTop, bool bEnabledOnly = true)
119  {
120  if (pTop)
121  pTop->AddChildrenToList(*this, bEnabledOnly);
122  }
123 };
124 
125 
133 class vtLastMouse : public vtEngine
134 {
135 public:
136  vtLastMouse();
137 
138  void OnMouse(vtMouseEvent &event);
139 
140  void GetNormalizedMouseCoords(float &mx, float &my);
141 
144 
147 
149  int m_flags;
150 
151 protected:
152  virtual ~vtLastMouse() {}
153 };
154 
160 {
161 public:
162  vtSimpleBillboardEngine(float fAngleOffset = 0.0f);
163  virtual ~vtSimpleBillboardEngine() {}
164 
165  void SetPitch(bool bFlag) { m_bPitch = bFlag; }
166 
167  void Eval();
168 
169  bool m_bPitch;
170  float m_fAngleOffset;
171 };
172  // Group eng
174 
175 #endif // VTENGINEH
176