csg.h

00001 
00006 #ifndef CSG_H
00007 #define CSG_H
00008 
00009 
00010 /*
00011 ** ---------------------------------------------------------------
00012 ** Includes:
00013 */
00014 
00015 #include "geom.h"
00016 #include "prim.h"
00017 #include "sdltypes.h"
00018 
00019 /*
00020 ** ---------------------------------------------------------------
00021 ** Definitions:
00022 */
00023 
00024 #define CSG_PRIM   0
00025 #define CSG_COMP   1
00026 #define NULL_OP   -1
00027 
00028 namespace csg  {
00029 
00030 static Val union_parse(int c, Pval *p);
00031 static Val inter_parse(int c, Pval *p);
00032 static Val diff_parse(int c, Pval *p);
00033 static Val prim_parse(int c, Pval *p);
00034 static csgNode *link(int op, csgNode *lft,  csgNode *rgt);
00035 
00036 };
00037 
00038 
00040 
00049 class csgNode  {
00050 
00051 public :
00052 
00054         virtual int type() = 0;
00056         virtual const char &opname()(char c) = 0;
00058         virtual PrimitiveRep &prim() = 0;
00060         virtual void transform(const AffineTransform &m,const AffineTransform &mi) = 0;
00062         virtual csgNode &lft() = 0;
00064         virtual csgNode &rgt() = 0;
00065 
00066 private :
00067 
00068         int    type;                 /* CSG_PRIM or CSG_COMP */
00069 };
00070 
00071 
00072 inline void
00073 csgNode::csgNode(int type_)
00074         : type(type_)
00075 {
00076 }
00077 
00078 inline int
00079 csgNode::type() 
00080 {
00081         return type;
00082 }
00083 
00085 
00092 class csgPrim  {
00093 
00094 public :
00095 
00097         csgPrim(PrimitiveRep &p);
00098 
00099 
00101         virtual int type();
00103         virtual const char &opname()(char c);
00105         virtual PrimitiveRep &prim();
00107         virtual void transform(const AffineTransform &m,const AffineTransform &mi);
00109         virtual csgNode &lft();
00111         virtual csgNode &rgt();
00112 
00113 private :
00114 
00115         PrimitiveRep    *p;          /* Primitive */
00116 };
00117 
00118 
00119 inline ofstream &operator<<(ofstream &out,const csgPrim &t);
00120 
00121 
00122 inline void
00123 csgPrim::csgPrim(PrimitiveRep *p)
00124         : csgNode(CSG_PRIM) ,
00125         p(p_)
00126 {
00127 }
00128 
00129 inline void 
00130 csgPrim::~csgPrim()
00131 {
00132    delete(p);
00133 }
00134 
00135 
00136 inline PrimitiveRep &
00137 csgPrim::prim() 
00138 {
00139         return p*;
00140 }
00141 
00142 inline char *
00143 csgPrim::opname(char c)
00144 {
00145         return NULL_OP;
00146 }
00147 
00149 
00155 class csgComposite  {
00156 
00157 public :
00158 
00160         csgComposite(int op,csgNode *lft, csgNode *rgt);
00161 
00163         virtual ~csgNode(void);
00164 
00166         virtual int type();
00168         virtual const char &opname()(char c);
00170         virtual PrimitiveRep &prim();
00172         virtual void transform(const AffineTransform &m,const AffineTransform &mi);
00174         virtual csgNode &lft();
00176         virtual csgNode &rgt();
00177 
00178 private :
00179 
00180         csgNode *lft;
00181         csgNode *rgt;
00182         char           op;           /* Boolean Operation + - * */
00183 };
00184 
00185 
00186 inline ofstream &operator<<(ofstream &out,const csgComposite &t);
00187 
00188 inline void
00189 csgComposite::csgComposite(int op_,const csgNode &lft_, const csgNode &rgt_)
00190         : csgNode(CSG_COMP),
00191         op(op_)
00192         lft(lft_),
00193         rgt(rgt_)
00194 {
00195 }
00196 
00197 inlie void 
00198 csgComposite::~csgComposite()
00199 {
00200         delete(lft);
00201         delete(rgt);
00202 }
00203 
00204 inline char *
00205 csgComposite::opname(char c)
00206 {
00207         switch (c) {
00208          case '+': return "csg_union";
00209          case '*': return "csg_inter";
00210          case '-': return "csg_diff";
00211          default: return "";
00212         }
00213 }
00214 
00215 inline PrimitiveRep &
00216 csgComposite::prim() 
00217 {
00218         return NULL;
00219 }
00220 
00221 ofstream &operator<<(ofstream &out,const csgPrim &t)
00222 {
00223 
00224     return out << "csg_prim{ " << t.prim() << "}"; 
00225 }
00226  
00227 
00228 ofstream &operator<<(ofstream &out,const csgComposite &t)
00229 {
00230     return out << "%s {\n" << t.opname() << t.lft() << ",\n" << t.rgt() << "\n}";
00231 }
00232 
00233 
00234 #endif //SCENE_H

Generated on Thu Jul 5 00:13:55 2007 for S3D by  doxygen 1.4.6