00001 #ifndef BODY_JOT_H
00002 #define BODY_JOT_H
00003
00004 #include "disp/bbox.H"
00005 #include "disp/ref_img_client.H"
00006 #include "mlib/point3i.H"
00007 #include "mlib/points.H"
00008 #include "net/data_item.H"
00009 #include "std/support.H"
00010 #include "mod.H"
00011
00012 #define CMVEC2 mlib::CXYvec
00013 #define MVEC2 mlib::XYvec
00014
00015 class VIEWptr;
00016 #define CVIEWptr const VIEWptr
00017
00018 class TEXTURE;
00019
00020 class GEOM;
00021
00022 #define CFACElist const FACElist
00023 class FACElist : public ARRAY<mlib::Point3i> {
00024 public:
00025 FACElist(int num=16) : ARRAY<mlib::Point3i>(num) {}
00026 };
00027
00028 #define CBODYptr const BODYptr
00029 MAKE_PTR_BASEC(BODY);
00030 class BODY : public REFcounter,
00031 public DATA_ITEM,
00032 public RefImageClient {
00033 private:
00034 static mlib::CXYpt_list _dummy;
00035 protected:
00036 int _tris;
00037 BBOX _bb;
00038 mlib::EDGElist _edges;
00039
00040 virtual BODYptr create_cube() {return 0;}
00041 virtual BODYptr create_cone() {return 0;}
00042 virtual BODYptr create_cylinder() {return 0;}
00043 virtual BODYptr create_sphere() {return 0;}
00044
00045 virtual BODYptr create_torus (double ) {return 0;}
00046 virtual BODYptr create_trunc_cone(double ) {return 0;}
00047 virtual BODYptr create_revolve (mlib::CWpt_list &,
00048 BODYptr &)
00049 {return 0;}
00050 virtual BODYptr create_extrusion(mlib::CWpt_list &,
00051 BODYptr &)
00052 {return 0;}
00053 virtual BODYptr create_extrusion(mlib::CWpt_list &,
00054 mlib::CWpt_list &,
00055 BODYptr &)
00056 {return 0;}
00057 virtual BODYptr create_trunc_pyr(CMVEC2 &,
00058 CMVEC2 &)
00059 {return 0;}
00060 static BODY *_factory;
00061 static str_ptr _base_name;
00062 static TAGlist _body_tags;
00063 public:
00064 BODY() : _tris(0) {}
00065 virtual ~BODY() {}
00066
00067 virtual CTAGlist&tags() const { return _body_tags; }
00068
00069 virtual BODYptr copy(int y=1) const = 0;
00070 virtual double nearest(mlib::CWtransf&,mlib::CWpt&,double )
00071 {return HUGE;}
00072 virtual int intersect(RAYhit &r, mlib::CWtransf &xf,
00073 mlib::Wpt &near, mlib::Wvec &n,
00074 double &d, double &d2d,
00075 mlib::XYpt &uvc) const = 0;
00076
00077 int intersect(RAYhit &r, mlib::CWtransf &xf) const {
00078 mlib::Wpt p;
00079 mlib::Wvec n;
00080 double d=0, d2d=0;
00081 mlib::XYpt xy;
00082 return intersect(r, xf, p, n, d, d2d, xy);
00083 }
00084 int intersect(RAYhit &r) const {
00085 mlib::Wtransf xf;
00086 return intersect(r, xf);
00087 }
00088
00089 virtual void transform(mlib::CWtransf &xform, CMOD&) = 0;
00090 virtual BODY *subtract (BODYptr &subtractor) = 0;
00091 virtual BODY *intersect(BODYptr &intersector)= 0;
00092 virtual BODY *combine (BODYptr &unionor )= 0;
00093
00094 virtual mlib::CEDGElist &body_edges() = 0;
00095
00096 virtual mlib::CWpt_list &vertices() = 0;
00097 virtual void set_vertices(mlib::CWpt_list &) = 0;
00098
00099
00100
00101 virtual void triangulate(mlib::Wpt_list &verts, FACElist &faces) {
00102 verts.clear(); faces.clear();
00103 }
00104 virtual void changed() = 0;
00105
00106 virtual void set_geom(GEOM*) {}
00107
00108
00109 virtual int uv_able () const {return false;}
00110 virtual int can_set_uv () const {return false;}
00111 virtual void set_texcoords(mlib::CXYpt_list &) {}
00112 virtual mlib::CXYpt_list &get_texcoords() { return _dummy;}
00113
00114
00115 static BODYptr cube() {return _factory->create_cube();}
00116 static BODYptr cone() {return _factory->create_cone();}
00117 static BODYptr cylinder() {return _factory->create_cylinder();}
00118 static BODYptr sphere() {return _factory->create_sphere();}
00119
00120 static BODYptr torus (double radius)
00121 {return _factory->create_torus(radius);}
00122 static BODYptr trunc_cone(double radius)
00123 {return _factory->create_trunc_cone(radius);}
00124 static BODYptr revolve (mlib::CWpt_list &profile, BODYptr &ob)
00125 {return _factory->create_revolve(profile, ob);}
00126 static BODYptr extrusion (mlib::CWpt_list &profile, BODYptr &ob)
00127 {return _factory->create_extrusion(profile, ob);}
00128 static BODYptr extrusion (mlib::CWpt_list &profile, mlib::CWpt_list &path,
00129 BODYptr &ob)
00130 {return _factory->create_extrusion(profile, path, ob);}
00131 static BODYptr trunc_pyr (CMVEC2 &taper, CMVEC2 &shear)
00132 {return _factory->create_trunc_pyr(taper, shear);}
00133 virtual BODYptr body_copy(int y = 1) {return copy(y);}
00134 static int set_factory(BODY *b) {_factory = b; return _factory != 0;}
00135
00136 virtual CBBOX &get_bb() = 0;
00137 bool bb_valid() const { return _bb.valid();}
00138
00139
00140
00141 static str_ptr base_name() {return _base_name;}
00142
00143 virtual DATA_ITEM *dup() const = 0;
00144
00145 DEFINE_RTTI_METHODS2("BODY", DATA_ITEM, CDATA_ITEM*);
00146 };
00147 #endif