vee_scene.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 /* COPYRIGHT
00004  *
00005  * This file is part of the Visual Effects Engine - VEE
00006  *
00007  * Read the "VEE-LICENSE" file for the license.
00008  *
00009  * Authors & Copyright:   
00010  *
00011  * Tommi Ilmonen, Tuukka Heikura, Marko Myllymaa and 
00012  * Janne Kontkanen 2001-2004
00013  *
00014  * Additional copyrights: Tekes 2003-2004
00015  *
00016  * firstname.lastname@hut.fi
00017  *
00018  */
00019 
00020 #ifndef VEE_SCENE_H
00021 #define VEE_SCENE_H
00022 
00023 #include <vee_bounding_box.h>
00024 #include <vee_object.h>
00025 #include <vee_object_store.h>
00026 #include <vee_force_object.h>
00027 #include <vee_gravity.h>
00028 #include <vee_time.h>
00029 
00030 #include <iostream>
00031 #include <sys/time.h>
00032 
00033 // #include <vector>
00034 
00035 
00036 
00066 #define VEE_SB_CHILDREN 8
00067 #define VEE_SB_SPLITS 2
00068 // #define VEE_SB_SQUARES VEE_SB_SPLITS * VEE_SB_SPLITS
00069 
00070 class VEE_SceneBox
00071 {
00072 public:
00073 
00074   // typedef std::vector<VEE_Object *>::iterator iterator;
00075   typedef VEE_PointerStoreSet<VEE_Object> ObjectStore;
00076   typedef ObjectStore::iterator iterator;
00077 
00078   VEE_SceneBox();
00079   VEE_SceneBox(VEE_SceneBox *parent, 
00080          const VEE_Vector3 &low,
00081          const VEE_Vector3 &high);
00082 
00083   virtual ~VEE_SceneBox();
00084 
00085   void init(VEE_SceneBox *parent, 
00086       const VEE_Vector3 &low,
00087       const VEE_Vector3 &high);
00088 
00089   void setArea(const VEE_Vector3 &low,
00090          const VEE_Vector3 &high)
00091   { m_bbox.low() = low; m_bbox.high() = high; }
00092 
00093   bool addObject(VEE_Object *);
00094   bool addNewObject(VEE_Object *);
00095   bool addObject(VEE_ForceObject *);
00096   bool addNewForce(VEE_ForceObject *);
00097   void addChildObject(VEE_Object *);
00098   void removeChildObject(VEE_Object *);
00099 
00100   void addForceHere(VEE_ForceObject *o, 
00101         const VEE_BoundingBox *bbox, 
00102         const VEE_SceneBox * caller = 0);
00103   void addForceSomewhere(VEE_ForceObject *o, 
00104        const VEE_BoundingBox *bbox, 
00105        const VEE_SceneBox * caller = 0);
00106   void forgetForce(VEE_ForceObject *o);
00107 
00108   void updateScene(int frame);
00109   void updateScene() { updateScene(m_frame); }
00110 
00111   void getObjects(ObjectStore * target);
00112   void getForces(std::set<VEE_ForceObject *> * target);
00113 
00114   uint totalChildren();
00115   uint totalForces();
00116 
00117   void update(uint splitTreshold, 
00118         uint collapseTreshold, 
00119         int allowRecursionLevels);
00120   void update(uint splitTreshold, 
00121         uint collapseTreshold, 
00122         int allowRecursionLevels,
00123         float dt);
00124 
00125   bool updateTree(uint splitTreshold, 
00126       uint collapseTreshold, 
00127       int allowRecursionLevels = 10);
00128 
00129   void updateR(float dt);
00130 
00131   bool trySplit(uint treshold, int allowRecursionLevels);
00132   bool tryCollapse(uint treshold);
00133 
00134   void refreshTimeLastUpdate();
00135   void incrementFrame() { m_frame++; }
00136 
00138   bool isSplit() const { return m_children != 0; }
00139 
00140   bool write(std::ostream * s = 0);
00141 
00142   void getForce(VEE_ForceType forceType,
00143     const VEE_Object *object,
00144     VEE_Vector3 *force, 
00145     const VEE_Vector3 &velocity,
00146     const VEE_Vector3 &location);
00147   uint getForces(VEE_ForceType forceType,
00148      const VEE_Object *object,
00149      VEE_Vector3 *force,
00150      uint n,
00151      const VEE_Vector3 *velocity,
00152      const VEE_Vector3 *location);
00153   uint getForcesDown(VEE_ForceType forceType,
00154          const VEE_Object *object,
00155          VEE_Vector3 *force,
00156          uint n,
00157          const VEE_Vector3 *velocity,
00158          const VEE_Vector3 *location);
00159   uint getForcesNR(VEE_ForceType forceType,
00160        const VEE_Object *object,
00161        VEE_Vector3 *force,
00162        uint n,
00163        const VEE_Vector3 *velocity,
00164        const VEE_Vector3 *location);
00165     
00166   VEE_SceneBox *parent() { return m_parent; }
00167   VEE_SceneBox *children() { return m_children; }
00168   VEE_SceneBox *child(uint k) { return &m_children[k]; }
00169   // VEE_Object *&object(uint k) { return m_objects[k]; }
00170   uint numObjects() { return m_objects.size(); }
00171   uint numForceObjects() { return m_forces.size(); }
00172   VEE_BoundingBox & boundingBox() { return m_bbox; }
00173   const VEE_BoundingBox & boundingBox() const { return m_bbox; }
00174 
00175   uint numChildBoxes();
00176 
00177 #ifndef VEE_FAST
00178   static long count() { return m_count; }
00179 #endif
00180 
00181   iterator begin() { return m_objects.begin(); }
00182   iterator end() { return m_objects.end(); }
00183   static VEE_Object * getObject(iterator & it) { return (*it); }
00184 
00185 protected:
00186 
00187   VEE_SceneBox &getChild(uint x, uint y, uint z)
00188   { return m_children[x * 4 + y * 2 + z]; }
00189 
00190   bool updateSceneLocation(VEE_Object *);
00191   bool updateForceSceneLocation(VEE_ForceObject *);
00192   void updateVelocities(float dt);
00193   void tryToSendForcesDown();
00194 
00195   // std::vector<VEE_Object *>      m_objects;
00196   ObjectStore                    m_objects;
00197   
00198   typedef VEE_PointerStoreSet<VEE_ForceObject> ForceStore;
00199 
00200   // VEE_PointerStoreList<VEE_ForceObject> m_forces;
00201   // VEE_PointerStoreHash<VEE_ForceObject> m_forces;
00202   ForceStore                     m_forces;
00203   // std::vector<VEE_Polygon *>     m_polygonObjects;
00204 
00205   VEE_SceneBox *m_parent;
00206   VEE_SceneBox *m_children;
00207 
00208   VEE_BoundingBox m_bbox;
00209 
00210   int m_frame;
00211 
00212 private:
00214   VEE_SceneBox(const VEE_SceneBox &) {}
00215 
00216 #ifndef VEE_FAST
00217   static long m_count;
00218 #endif
00219 
00220   VEE_Time m_tvLast;
00221 };
00222 
00223 #endif

Generated on Mon Mar 12 21:09:01 2007 for VEE - The Visual Effects Engine by  doxygen 1.4.6