Documentation


mainScene.h

Go to the documentation of this file.
00001 
00002 //                            mainScene.h                                     //
00004 
00005 #ifndef MAIN_SCENE_H
00006 #define MAIN_SCENE_H
00007 
00008 #include <X3DTK/kernel.h>
00009 #include <X3DTK/private/X3D_Loader.h>
00010 #include <animal/X3DTK/GL/GLRenderer/myGLRenderer.h>
00011 #include <animal/X3DTK/GL/x3dGLMapBuilder/x3dGLMapBuilder.h>
00012 #include <animal/X3DTK/X3D/groupingNodeCreator.h>
00013 #include <animal/picking.h>
00014 #include <animal/engine/EngineNode.h>
00015 
00016 class MainController;
00017 
00018 namespace animal
00019 {
00020 class KeyEvent;
00021 class MouseEvent;
00022 class Engine;
00023 }
00024 
00025 namespace X3DTK
00026 {
00027 
00028 class MemReleaser;
00029 
00030 namespace GL
00031 {
00032 class Scene;
00033 class MyRenderer;
00034 }
00035 
00036 namespace X3D
00037 {
00038 class Scene;
00039 class X3DGLBuilder;
00040 class EngineNodeCreator;
00041 class EngineLoaderVisitor;
00042 class EngineLoader;
00043 class X3DGLMapBuilder;
00044 class BBoxUpdater;
00045 }
00046 
00048 typedef std::list<animal::Engine*> AnimalEngines;
00049 
00051 typedef std::list< GL::X3DNode *> GLNodeList;
00053 typedef std::map<X3D::X3DNode*, GLNodeList > GLUpdates;
00054 
00058 class MainScene
00059 {
00060 public:
00062     MainScene();
00064     virtual ~MainScene();
00065 
00066     //====================== Manage the main scene
00068     virtual void
00069     load (const char *file, bool fileValidation = false);
00070 
00072     void
00073     load (const char *file, X3D::X3DNode * node, bool fileValidation =false);
00074 
00076     virtual void
00077     draw ();
00078 
00080     void
00081     save (const char *file);
00082 
00084     void
00085     reset();
00086 
00088     virtual void
00089     move (double dt);
00090 
00093     bool
00094     computeBbox ();
00095 
00096     //====================== Manage X3D nodes
00098     bool
00099     pastNode (X3DAbstractNode* node, X3DAbstractNode* parentNode);
00100 
00106     void
00107     deleteNode (X3DAbstractNode* node, X3DAbstractNode* parentNode);
00108 
00113     bool
00114     cutNode (X3DAbstractNode* node, X3DAbstractNode* parentNode);
00115 
00117     template<typename GroupingNode_t>
00118     void newX4DClass()
00119     {
00120         // Define the new creation functions for the new nodes.
00121         groupingNodeCreator.newX4DClass<GroupingNode_t>();
00122 
00123         // (Re-)set the grouping creator of the x3dloader
00124         x3dloader = Singleton<X3D::Loader>::getInstance();//X3DLoader::getInstanceOf<X3D::Loader>();
00125         x3dloader->setComponentCreator(&groupingNodeCreator);
00126     }
00127 
00128 
00129     //====================== Manage engines
00131     void addEngine(animal::Engine* engine);
00133     void removeEngine(animal::Engine* engine);
00135     void clearEngines();
00136 
00137     //====================== Getter
00139     inline X3D::Scene * getX3DScene () const {return x3dscene;}
00140 
00142     inline SFVec3f getBboxMin()const{return min;}
00143 
00145     inline SFVec3f getBboxMax () const { return max; }
00146 
00148     inline MainController * getMainController() const { return mainController; }
00149 
00150     //====================== Setter
00151     inline void setMainController(MainController * MC) { mainController = MC; }
00152 
00153     //====================== Mouse and key board events
00155     void keyPressEvent(animal::KeyEvent *e);
00157     void mouseDoubleClickEvent(animal::MouseEvent * e);
00159     void mouseMoveEvent(animal::MouseEvent * e);
00161     void mousePressEvent(animal::MouseEvent * e);
00163     void mouseReleaseEvent(animal::MouseEvent * e);
00164 
00165 
00166     // ----------  FF: picking -----------------------------
00167     animal::ConstrainedItem* pickPoint( float origin[3], float direction[3], float threshold );
00168     // ----------  end FF: picking -----------------------------
00169     
00171     void setSelectedNode( X3D::X3DBoundedObject * );
00172 
00173 
00174 public:
00175  
00177     void updateGL ();
00178     
00179 private:
00181     void buildGL();
00182 
00185     void releaseNode(X3DAbstractNode* node);
00186 
00188     bool isADescendant(X3DAbstractNode* node1, X3DAbstractNode* node2);
00189 
00190 protected: 
00192     X3D::Scene *x3dscene;
00193 
00195     GL::Scene *glscene;
00196 
00198     SFVec3f min;
00199 
00201     SFVec3f max;
00202     
00203     GLUpdates glUpdates;  
00204 
00205 private: //Attributes
00206     // Creator of x3d nodes
00207     X3DTK::X3D::GroupingNodeCreator groupingNodeCreator;
00208 
00210     X3D::Loader * x3dloader;
00211 
00213     X3D::EngineLoader * engineLoader;
00214 
00215 public:
00217     X3DGLMap x3dGLMap;
00218     
00219 private:
00221     GL::MyRenderer renderer;
00222 
00224     AnimalEngines animalEngines;
00225     
00227     //animal::EngineGroup m_engineRoot;   ///< root of the engine tree.
00228     X3D::EngineNodes allEngineNodes; 
00229     X3D::EngineNodes kinematicEngines; 
00230     X3D::EngineNodes dynamicEngines;   
00231     X3D::EngineNodes collisionEngines; 
00232 
00234     MainController * mainController;
00235     
00237     X3D::X3DBoundedObject * m_selectedNode;
00238     
00240     X3D::BBoxUpdater* bbupdater; // expensive to create
00241 };
00242 
00243 }// X3DTK
00244 
00245 #endif
00246 

Generated on Thu Dec 23 13:52:25 2004 by doxygen 1.3.6