vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BlockUpdater.h
Go to the documentation of this file.
1 #ifndef _BLOCKUPDATER
2 #define _BLOCKUPDATER 1
3 
4 /*
5 #include <vrecko/Ability.h>
6 #include <vrecko/EnvironmentObject.h>
7 #include <vrecko/World.h>
8 #include "../ObjectUtils/Animator.h"
9 #include <vector>
10 #include <list>
11 #include <string>
12 #include <time.h>
13 #include "model.h"
14 #include "subblock.h"
15 #include "ModelManager.h"
16 #include <iostream>
17 #include <sstream>
18 #include <fstream>
19 
20 #include <xercesc/parsers/XercesDOMParser.hpp>
21 #include <xercesc/dom/DOM.hpp>
22 #include <xercesc/sax/HandlerBase.hpp>
23 #include <xercesc/util/XMLString.hpp>
24 #include <xercesc/util/PlatformUtils.hpp>
25 
26 #include <xercesc/dom/DOMWriter.hpp>
27 #include <xercesc/framework/StdOutFormatTarget.hpp>
28 #include <xercesc/framework/LocalFileFormatTarget.hpp>
29 */
30 
31 using namespace vrecko;
32 using namespace std;
33 using namespace xercesc_2_7;
34 
35 #define SHOWVEC3(v) "(" << v.x() << ", " << v.y() << ", " << v.z() << ")"
36 
37 namespace ArtificialWorld
38 {
42  noneSet = 0,
48  bothSet = 3
49  };
50 
53  public:
56  objectCenterDir = osg::Vec3(0.0f, 0.0f, 0.0f);
57  objectCenterPoint = osg::Vec3(0.0f, 0.0f, 0.0f);
58  };
59 
61  void SetObjectCenterDir(osg::Vec3 newCenterDir){
62  objectCenterDir = newCenterDir;
67  };
68 
70  void SetObjectCenterPoint(osg::Vec3 newCenterPoint){
71  objectCenterPoint = newCenterPoint;
76  };
77 
79  osg::Vec3 GetObjectCenterDir(void){return objectCenterDir;};
81  osg::Vec3 GetObjectCenterPoint(void){return objectCenterPoint;};
83  BlockAttributesSetEnum WhatIsSet(void){return set;};
84 
85  private:
87  osg::Vec3 objectCenterDir;
89  osg::Vec3 objectCenterPoint;
92  };
93 
95  class BlockUpdater: public Ability
96  {
97  public:
98  BlockUpdater();
99  ~BlockUpdater();
100 
102  virtual void update(void);
104  virtual void preInitialize(void);
106  virtual void postInitialize(void);
107 
109  virtual bool loadXMLParameters(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *parametersNode);
111  bool LoadXMLParametersFromFile(string filename);
112 
114  void SetParentEO(EnvironmentObject *newParentEO);
115 
117  void Hide();
119  void Show();
121  void HideSubBlocks();
123  void ShowSubBlocks();
125  bool IsVisible();
126 
128  string GetBlockType(void){ return myBlockType; };
130  vector<SubBlock*> GetSubBlocks(void){ return subBlocks; };
132  vector<BlockUpdater*> GetSubBlocksUpdaters(void){ return subBlocksUpdaters; };
134  vector<Model*> GetModels(void){ return models; };
136  osg::Vec4 GetBoundingSphere(void){ return boundingSphere; };
138  osg::Vec3* GetBoundingBox(void){ return boundingBox; };
140  BlockAttributes* GetAttributes(void){ return attributes; };
142  list<Model*> getVisibleModels(osg::Vec3 position);
143 
144  XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* getDOMDocument() { return xmlDocument; }
145 
146  private:
148  void init(void);
149 
151  void updatescene(unsigned long distance);
153  void updatescene(osg::Vec3 position);
154 
156  void UpdateModels(unsigned long distance);
158  void UpdateSubBlocks();
159 
160 
161  // QCHANGE: od nacteni se v pameti udrzuje parser a nacteny XML document.
162  // Tato abilita to nepotrebuje, ale je to pro budouci rozsiritelnost a pro moznost dotazu z jinych abilit,
163  // ktere treba budou zpracovavat XML tagy, ktere BlockUpdater ignoruje (napriklad CarSim, ktery potrebuje nacist
164  // informace o silnicich)
165  XERCES_CPP_NAMESPACE_QUALIFIER XercesDOMParser* xmlParser;
166  XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* xmlDocument;
167 
168 
170  list<Model*> currentlyVisibleModels;
172  vector<SubBlock*> subBlocks;
174  vector<BlockUpdater*> subBlocksUpdaters;
175 
177  osg::Vec3 lastViewerPosition;
179  EnvironmentObject *owner;
181  EnvironmentObject *parentEO;
182 
184  vector<Model*> models;
185 
187  list<Model*> getVisibleModels(unsigned long distance);
188 
190  void RemoveLoadedModels(list<Model*> *toRemove);
191 
193  void AddModels(list<Model*> *toAdd);
194 
196  bool isNoSubblocks;
197 
199  string myBlockType;
201  osg::Vec4 boundingSphere;
203  osg::Vec3 boundingBox[2];
205  BlockAttributes* attributes;
206 
207  public:
209  osg::Vec3 GetCurrentWorldPosition(void){ return owner->getWorldPosition(); };
211  };
212 }
213 #endif
214