home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 5164 / miletos.7z / scene.h < prev    next >
Encoding:
C/C++ Source or Header  |  2011-04-02  |  6.0 KB  |  192 lines

  1. #ifndef __MILETOS_SCENE_H__
  2. #define __MILETOS_SCENE_H__
  3.  
  4. //
  5. // Libmiletos
  6. //
  7. // Copyright (C) Lauris Kaplinski 2007
  8. //
  9.  
  10. #include <sehle/sehle.h>
  11.  
  12. #include <miletos/types.h>
  13. #include <miletos/miletos.h>
  14.  
  15. #ifdef WIN32
  16. #undef OPAQUE
  17. #undef TRANSPARENT
  18. #endif
  19.  
  20. namespace Miletos {
  21.  
  22. class Camera;
  23.  
  24. class Unknown : public Object {
  25. private:
  26.     // Object implementation
  27.     virtual const Type *objectType (void);
  28.     virtual void build (Thera::Node *pnode, Document *doc, BuildCtx *ctx);
  29.     virtual void release (void);
  30.     virtual void set (const char *attrid, const char *val);
  31.     virtual unsigned int addChild (Thera::Node *cnode, Thera::Node *rnode);
  32. public:
  33.     // Constructor
  34.     Unknown (void) : Object(0) {}
  35.     // Type system
  36.     static const Type *type (void);
  37. };
  38.  
  39. class Text : public Object {
  40. private:
  41.     // Object implementation
  42.     virtual const Type *objectType (void);
  43.     virtual void build (Thera::Node *pnode, Document *doc, BuildCtx *ctx);
  44.     virtual void release (void);
  45.     virtual unsigned int changeAttr (const char *attrid, const char *val) { return 0; }
  46.     virtual void set (const char *attrid, const char *val) {}
  47.     virtual unsigned int changeContent (const char *val) { return 1; }
  48. public:
  49.     // Constructor
  50.     Text (void) : Object(0) {}
  51.     // Type system
  52.     static const Type *type (void);
  53. };
  54.  
  55. class Defs : public Object {
  56. private:
  57.     // Object implementation
  58.     virtual const Type *objectType (void);
  59. public:
  60.     Defs (void) : Object(HAS_CHILDREN) {}
  61.  
  62.     // Type system
  63.     static const Type *type (void);
  64. };
  65.  
  66. // Visibility masks
  67. //
  68. // 1 - opaque geometry
  69. // 2 - transparent geometry
  70. // 4 - shadow maps
  71. // 8 - density maps
  72. //
  73.  
  74. class Item : public Object {
  75. public:
  76.     // Sehle context flags
  77.     static const unsigned int OPAQUE = 1;
  78.     static const unsigned int TRANSPARENT = 2;
  79.     static const unsigned int SHADOW = 4;
  80.     static const unsigned int DENSITY = 8;
  81. private:
  82.     // Object implementation
  83.     virtual const Type *objectType (void);
  84.     // Rendering system
  85.     virtual Sehle::Renderable *show (Sehle::Graph *graph, Sehle::u32 contextmask) = 0;
  86.     virtual Item *trace (const Elea::Line3f *wray, unsigned int mask, float *distance) = 0;
  87. protected:
  88.     Elea::Matrix4x4f _i2p;
  89.     Elea::Matrix4x4f _i2w;
  90.     Elea::Matrix4x4f _w2i;
  91.     Sehle::Graph *graph;
  92.     Sehle::Renderable *renderable;
  93.     // Object implementation
  94.     virtual void build (Thera::Node *pnode, Document *doc, BuildCtx *ctx);
  95.     virtual void release (void);
  96.     virtual void set (const char *attrid, const char *val);
  97.     virtual void write (const char *attrid);
  98.     virtual void update (UpdateCtx *ctx, unsigned int flags);
  99.     // Release references to sehle engine
  100.     virtual void hide (Sehle::RenderableGroup *pgroup) {}
  101.     // Sphere tracing
  102.     virtual Item *trace (const Elea::Line3f *wray, unsigned int mask, const Elea::Matrix4x4f *e2us, float *distance, Elea::Vector3f *uscp) { return NULL; }
  103.     // Constructor
  104.     Item (unsigned int flags) : Object(flags), graph(NULL), renderable(NULL), visibility(0xffffffff), tracemask(0xffffffff), bbox(Elea::Cuboid3fEmpty)  {}
  105. public:
  106.     u32 visibility;
  107.     u32 tracemask;
  108.     Elea::Cuboid3f bbox;
  109.     // Access
  110.     const Elea::Cuboid3f& getBBox (void) { return bbox; }
  111.     const Elea::Matrix4x4f& getI2P (void) const { return _i2p; }
  112.     void setI2P (const Elea::Matrix4x4f *pi2p);
  113.     Elea::Matrix4x4f getI2W (void) const;
  114.     void setI2W (const Elea::Matrix4x4f *pi2w);
  115.     const Elea::Matrix4x4f& getW2I (void) const { return _w2i; }
  116.     // Get child to parent transform for given child
  117.     virtual void getC2P (Elea::Matrix4x4f *c2p, Miletos::Item *child);
  118.     // Render system management
  119.     Sehle::Renderable *invokeShow (Sehle::Graph *graph, Sehle::u32 contextmask);
  120.     void invokeHide (Sehle::RenderableGroup *pgroup);
  121.     // Trace returns if there will be hit along ray between 0-infinity
  122.     Item *invokeTrace (const Elea::Line3f *wray, unsigned int mask, float *distance);
  123.     // e2us - transformation from world-space ellipsoid to unit sphere (no translation)
  124.     // uscp - collision point in unit sphere coordinates
  125.     Item *invokeTrace (const Elea::Line3f *wray, unsigned int mask, const Elea::Matrix4x4f *e2us, float *distance, Elea::Vector3f *uscp);
  126.     // Type system
  127.     static const Type *type (void);
  128. };
  129.  
  130. class Group : public Item {
  131. private:
  132. protected:
  133.     // Object implementation
  134.     virtual const Type *objectType (void);
  135.     virtual void build (Thera::Node *pnode, Document *doc, BuildCtx *ctx);
  136.     virtual void release (void);
  137.     virtual void set (const char *attrid, const char *val);
  138.     virtual void update (UpdateCtx *ctx, unsigned int flags);
  139.     virtual void modified (unsigned int flags);
  140.     virtual Object *childAdded (Thera::Node *cnode, Thera::Node *rnode);
  141.     virtual unsigned int removeChild (Thera::Node *cnode, Thera::Node *rnode);
  142.     // Item implementation
  143.     virtual Sehle::Renderable *show (Sehle::Graph *graph, Sehle::u32 contextmask);
  144.     virtual void hide (Sehle::RenderableGroup *pgroup);
  145.     virtual Item *trace (const Elea::Line3f *ray, unsigned int mask, float *distance);
  146. public:
  147.     // Constructor
  148.     Group (void) : Item(HAS_CHILDREN) {}
  149.     // Type system
  150.     static const Type *type (void);
  151. };
  152.  
  153. class Scene : public Object {
  154. private:
  155.     Sehle::RenderableGroup *rgroup;
  156.  
  157.     void updateChildData (Thera::Node *removed);
  158. protected:
  159.     // Object implementation
  160.     virtual const Type *objectType (void);
  161.     virtual void build (Thera::Node *pnode, Document *doc, BuildCtx *ctx);
  162.     virtual void release (void);
  163.     virtual void set (const char *attrid, const char *val);
  164.     virtual void write (const char *attrid);
  165.     virtual Object *childAdded (Thera::Node *cnode, Thera::Node *rnode);
  166.     virtual unsigned int removeChild (Thera::Node *cnode, Thera::Node *rnode);
  167.     virtual void update (UpdateCtx *ctx, unsigned int flags);
  168.     virtual void modified (unsigned int flags);
  169. public:
  170.     Elea::Color4f ambient;
  171.     u32 ncameras;
  172.     Camera **cameras;
  173.  
  174.     // Constructor
  175.     Scene (void) : Object(HAS_CHILDREN), rgroup(NULL), ambient(Elea::Color4fWhite), ncameras(0), cameras(NULL) {}
  176.     // Type system
  177.     static const Type *type (void);
  178.  
  179.     // Access
  180.     void show (Sehle::Graph *graph);
  181.     void hide (void);
  182.     Item *trace (const Elea::Line3f *ray, unsigned int mask, float *distance);
  183.     Item *trace (const Elea::Line3f *wray, unsigned int mask, const Elea::Matrix4x4f *e2us, float *distance, Elea::Vector3f *uscp);
  184.  
  185.     void setAmbient (const Elea::Color4f& color);
  186. };
  187.  
  188. } // Namespace Miletos
  189.  
  190. #endif
  191.  
  192.