vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Scene.h
Go to the documentation of this file.
1 /***************************************************************************
2  Scene.h - description
3  -------------------
4  begin : May 2002
5  copyright : (C) 2002 by Jan Flasar, Ludek Pokluda
6  email : flasar|xpokluda@fi.muni.cz
7  ***************************************************************************/
8 
9 #ifndef SCENE_H
10 #define SCENE_H
11 
12 #include <osg/Node>
13 
14 #include <vrecko/BaseClass.h>
16 
17 #include <vrecko/World.h>
18 #include <vrecko/MTLock.h>
19 
20 #include <helpers/DynamicArray.h>
21 #include <vrecko/SP_CommonDefs.h>
22 
23 namespace vrecko {
24 
25 class SP_SceneInterface;
26 class SP_ObjectInterface;
27 
28 
29 // Flags for CalcNodeBBox:
30 
36 #define CNBB_F_FORCE_AABBOX 0x00000001
37 
39 #define CNBB_F_ONLY_LOCAL_TRANSFORM 0x00000002
40 
43 #define CNBB_F_NO_SELF_TRANSFORM 0x00000004
44 
45 
46 
47 
48 // Flags for Scene::EOIteratorHelper::initIterationFrom()
49 
51 #define EOIH_IF_START_BEGINNING 0x00000001
52 
55 #define EOIH_IF_START_CURRENT 0x00000002
56 
58 #define EOIH_IF_START_NEXT 0x00000004
59 
60 
61 
62 
64  // This structure is both stored and passed to the thread as a parameter,
65  // therefore we must pass also the pointer to this class.
67  HANDLE hThreadHandle;
68 
71 
72 
75  osg::Timer_t lastRequest;
76 
78  unsigned long limitToEO1, limitToEO2;
79 };
80 
81 
82 
83 DWORD WINAPI ScenePSThreadProc(ScenePSThreadInfo *lpParameter);
84 
85 
86 class VRECKO_EXPORT Scene: public BaseClass, public osg::MatrixTransform {
87  public:
88 
89 
110  class VRECKO_EXPORT EOIteratorHelper: public BaseClass {
111 
112 
113  public:
115  ~EOIteratorHelper();
116 
119  bool initIteration();
120 
125  bool initIterationFrom(Scene::EOIteratorHelper *sourceHelper, unsigned long dwInitFlags = EOIH_IF_START_BEGINNING);
126 
130  void endIteration();
131 
145  bool getAndLockNextObject(EnvironmentObject **outObject);
146 
148  bool releaseObject(void);
149 
150  protected:
151  bool bInited;
152 
154 
157 
162 
165 
166 
167 
168  HANDLE hCollisionEvent1, hCollisionEvent2;
170 
171 
172  virtual int processNotification(BaseClass *sender, unsigned long notificationType, void *notificationData);
173  };
174 
175  Scene();
176  ~Scene();
177 // Scene(const Scene& s);
178 
181  void prepareForTermination();
182 
184  void setDescription(const std::string &desc) {description = desc;}
185 
187  const std::string &getDescription(void) {return description;}
188 
189  void update(void);
190 
192  osg::MatrixTransform *getRoot() {return rootNode;}
193 
195  osg::MatrixTransform *getEORoot() {return eoRootNode;}
196 
198  unsigned long getFreeID(unsigned long req_id);
199 
201  int addEnvironmentObject(EnvironmentObject *environment_object, osg::Group *parentNode);
202 
204  inline int addEnvironmentObject(EnvironmentObject *environment_object ) { return addEnvironmentObject(environment_object, eoRootNode); }
205 
207  bool removeEnvironmentObject( unsigned long id );
208 
210  EnvironmentObject * getEnvironmentObject( unsigned long id, bool bReportErrorIfNotFound = true );
211 
215  bool registerEnvironmentObject(EnvironmentObject *environment_object);
216 
219  bool unregisterEnvironmentObject(EnvironmentObject *environment_object);
220 
223  bool unregisterEnvironmentObject(unsigned long id);
224 
225  typedef Sgi::hash_map<unsigned long, EnvironmentObject *> EOMap;
226 
228  inline EOMap &getEOMap(void) {return environment_objects_map;}
229 
231  inline void lockEOMapForRead(void) { eoMapLock.lockRead(); }
232 
234  inline void unlockEOMapForRead(void) { eoMapLock.unlockRead(); }
235 
237  inline void lockEOMapForWrite(void) { eoMapLock.lockWrite(); }
238 
240  inline void unlockEOMapForWrite(void) { eoMapLock.unlockWrite(); }
241 
242 
244  inline bool isLoaded(void) { return _bIsLoaded; }
245 
246 
247  inline void setIsLoaded(bool bNewValue) { _bIsLoaded = bNewValue; }
248 
249 
252  EnvironmentObject *getCollisionObject(EnvironmentObject *eobject);
255  EnvironmentObject **getCollisionObjects(EnvironmentObject *eobject, int &size);
258  EnvironmentObject **getCollisionObjects(esg::OSGAdapter *pOSGAdapter, const osg::Matrix &transf, int &size);
259 
265  EnvironmentObject *getRayIntersection(const osg::Vec3 &origin, const osg::Vec3 &dir);
266 
272  EnvironmentObject *getRayIntersection(const osg::Vec3 &origin, const osg::Vec3 &dir, osg::Vec3 &intersection_point);
273 
279  bool getRayIntersection(EnvironmentObject *eobject, const osg::Vec3 &origin, const osg::Vec3 &dir, osg::Vec3 &intersection_point);
280 
283  void getObjectExtent(EnvironmentObject *eobject, const osg::Vec3 &dir, float &min, float &max);
284 
287  bool separation(esg::Matrix4 *trMat1, std::vector<esg::OSGAdapter *> object1, esg::Matrix4 *trMat2, std::vector<esg::OSGAdapter *> object2, unsigned d1 = UINT_MAX, unsigned d2 = UINT_MAX);
288 
289 
290 
291 
298  bool calcNodeBBox(osg::Node *node, osg::BoundingBox *outBox, osg::Matrix *outTransform, bool *bTransformUsed = NULL, unsigned long dwFlags = 0, osg::Node *subTreeToIgnore = NULL);
299 
310  bool getCollisions(CollisionParams * params, COLLISIONS_INFO_VECTOR ** collisions, unsigned long limitToEO1 = 0, unsigned long limitToEO2 = 0);
311 
312  /* INTERNAL USAGE - set/get scene partitioning interface for scene operations.
313  You should probably use Scene::getCollisions(). */
314  bool addPartitioningSceneInterface(SP_SceneInterface *newInterface, int priority = 0);
315  void removePartitioningSceneInterface(SP_SceneInterface *anInterface);
316  SP_SceneInterface* getPartitioningSceneInterface(int id = PARTITIONING_INTERFACE_DEFAULT);
317 
318  /* INTERNAL USAGE - set/get scene partitioning interface for object operations
319  You should probably use Scene::getCollisions(). */
320  bool addPartitioningObjectInterface(SP_ObjectInterface *newInterface, int priority = 0);
321  void removePartitioningObjectInterface(SP_ObjectInterface *anInterface);
322  SP_ObjectInterface* getPartitioningObjectInterface(int id = PARTITIONING_INTERFACE_DEFAULT);
323 
324 
326  void logHierarchy(const osg::Node *topNode, const char *note = NULL);
327 
328 
329  protected:
331  std::string description;
332 
334 
338  osg::MatrixTransform *rootNode;
340  osg::MatrixTransform *eoRootNode;
341 
342  unsigned long nextFreeID;
343 
346 
347 
348  struct SC_INT_PRIO {
350  int priority;
351  };
353 
354  struct OBJ_INT_PRIO {
356  int priority;
357  };
359 
363  std::vector<ScenePSThreadInfo*> partThreadsInfo;
364 
367 
368  bool calcNodeBBoxHelper(osg::Node *node, osg::BoundingBox *outBox, osg::Matrix *outTransform, bool *bTransformUsed, unsigned long dwFlags, osg::Node *nodeToStopTraversalAt, osg::Node *subTreeToIgnore);
369 
370  friend DWORD WINAPI ScenePSThreadProc(ScenePSThreadInfo *lpParameter);
371 
372  void logHierarchyHelper(int level, const osg::Node *node);
373  void logHierarchyDrawableHelper(int level, const osg::Drawable *dw);
374 };
375 
376 }
377 
378 #endif