home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Amiga / Jeux / demos / crystalPPC.lha / polyset.h < prev    next >
C/C++ Source or Header  |  1998-01-15  |  4KB  |  115 lines

  1. #ifndef POLYSET_H
  2. #define POLYSET_H
  3.  
  4. #ifndef MATH3D_H
  5. #include "math3d.h"
  6. #endif
  7.  
  8. #ifndef SCRIPT_H
  9. #include "script.h"
  10. #endif
  11.  
  12. #ifndef VERTEX_H
  13. #include "vertex.h"
  14. #endif
  15.  
  16. #ifndef CSOBJECT_H
  17. #include "csobject.h"
  18. #endif
  19.  
  20. class Polygon3D;
  21. class Sector;
  22. class World;
  23. class Camera;
  24. class ViewPolygon;
  25. class Textures;
  26.  
  27. // A PolygonSet class is a set of polygons (amazing, isn't it :-)
  28. // A PolygonSet describes a set of polygons that form a convex and
  29. // (probably) closed hull. All polygons in a set share vertices
  30. // from the same pool.
  31. //
  32. // Every polygon in the set has a visible and an invisible face;
  33. // if the vertices of the polygon are ordered clockwise then the
  34. // polygon is visible. Using this feature it is possible to define
  35. // two kinds of PolygonSets: in one kind the polygons are oriented
  36. // such that they are visible from within the hull. In other words,
  37. // the polygons form a sort of container or room where the camera
  38. // can be located. We call this kind of PolygonSet a Sector (a
  39. // subclass of PolygonSet). In another kind the polygons are
  40. // oriented such that they are visible from the outside. We call
  41. // this kind of PolygonSet a Thing (another subclass of PolygonSet).
  42. //
  43. // Things and Sectors have many similarities. That's why the
  44. // PolygonSet class was created: to exploit these similarities.
  45. // However, there are some important differences between Things and
  46. // Sectors:
  47. //    - Currently, only things can move. This means that the object
  48. //      space coordinates of a Sector are ALWAYS equal to the world
  49. //      space coordinates. It would be possible to allow moveable
  50. //      Sectors but I don't how this should be integrated into an
  51. //      easy model of the world.
  52. //    - Polygons in things don't support filtering, transparency,
  53. //      and portals although this could be added. It would give
  54. //      some nice effects. But for this feature to be really useful
  55. //      we would need to have good support for space warping via
  56. //      portals.
  57.  
  58. class PolygonSet : public CsObject
  59. {
  60. protected:
  61.   PolygonSet* next;    // PolygonSets are linked either in a World object or in
  62.               // another PolygonSet (Thing in Sector for example).
  63.  
  64.   Vertex* vertices;    // Table of vertices used by polygons in set
  65.   int num_vertices;
  66.   int max_vertices;
  67.  
  68.   Polygon3D** polygon;    // Table of ptr to polygons forming the outside of the set
  69.   int num_polygon;    // Number used
  70.   int max_polygon;    // Max supported
  71.  
  72.   Sector* sector;    // Sector where this polyset belongs (pointer to this if it is a sector).
  73.  
  74. public:
  75.   PolygonSet (char* name, int type, int max_v, int max_p);
  76.   ~PolygonSet ();
  77.  
  78.   void set_max (int max_v, int max_p);
  79.  
  80.   void set_vertex (int idx, Vector3 v) { set_vertex (idx, v.x, v.y, v.z); }
  81.   void set_vertex (int idx, float x, float y, float z);
  82.   Vertex& vtex (int idx) { return vertices[idx]; }
  83.  
  84.   void add_polygon (Polygon3D* poly);
  85.   Polygon3D* new_polygon (char* name, int max, Textures* textures, int texnr);
  86.   Polygon3D* new_polygon (char* name, int max, Textures* textures, char* tex_name);
  87.   int get_num_polygon () { return num_polygon; }
  88.   Polygon3D* get_polygon (int idx) { return polygon[idx]; }
  89.   Polygon3D* get_polygon (char* name);
  90.  
  91.   // Intersect world-space segment with polygons of this set. Return
  92.   // polygon it intersects with (or NULL) and the intersection point
  93.   // in world coordinates.
  94.   Polygon3D* intersect_segment (Vector3& start, Vector3& end, Vector3& isect);
  95.  
  96.   // Return FALSE if none of the vertices of this sector is in front
  97.   // of the camera.
  98.   int transform_world2cam (Matrix3& m_w2c, Matrix3& m_c2w, Vector3& v_w2c);
  99.  
  100.   void dump ();
  101.   PolygonSet* get_next () { return next; }
  102.   void set_next (PolygonSet* next) { PolygonSet::next = next; }
  103.   void set_sector (Sector* sector) { PolygonSet::sector = sector; }
  104.  
  105.   void save (FILE* fp, int indent, Textures* textures, char* setname);
  106.   void load (World* w, char** buf, Textures* textures, char* setname);
  107.  
  108.   Polygon3D* select_polygon (Camera* c, ViewPolygon* view, int xx, int yy);
  109.   Vertex* select_vertex (Camera* c, ViewPolygon* view, int xx, int yy);
  110.   void edit_draw_vertices ();
  111.   void edit_split_poly (Camera* c, Textures* textures);
  112. };
  113.  
  114. #endif /*POLYSET_H*/
  115.