Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

ISModeler.H

Go to the documentation of this file.
00001 
00010 #ifndef MODELER_H
00011 #define MODELER_H
00012 
00013 #define TWOPI 6.2831853
00014 
00015 #include "ISMesh.H"
00016 #include "DrawObj.H"
00017 
00018 #define OUTSIDE_GLUE_CORE
00019 #include <config/config.H>
00020 
00021 
00022 class BRUSHICON_OUTLINE_OBJ : public DrawObj {
00023  public:
00024   
00025   BRUSHICON_OUTLINE_OBJ() : DrawObj("BRUSHICON_OUTLINE") {
00026     setSelectable(false);
00027   }
00028   virtual ~BRUSHICON_OUTLINE_OBJ() {}
00029 
00030   
00031   void draw() {
00032     glDisable(GL_LIGHTING);
00033     glDisable(GL_TEXTURE_2D);
00034     
00035     glColor3f(1.,1.,1.);
00036     glLineWidth(1);
00037     
00038     glBegin(GL_LINE_STRIP);
00039     glVertex3d(0,0,-1.85);
00040     glVertex3d(0.15,0.1,-1.75);
00041     glVertex3d(0.1,0.06,-1.0);
00042     glVertex3d(0.5,0.1,-0.75);
00043     glVertex3d(0.5,0.1,-0.25);
00044     glVertex3d(0.5,0,0);
00045     glVertex3d(-0.5,0,0);
00046     glVertex3d(-0.5,0.1,-0.25);
00047     glVertex3d(-0.5,0.1,-0.75);
00048     glVertex3d(-0.1,0.06,-1.0);
00049     glVertex3d(-0.15,0.1,-1.75);
00050     glVertex3d(0,0,-1.85);
00051     glEnd();
00052     
00053     glBegin(GL_LINE_STRIP);
00054     glVertex3d(0,0,-1.85);
00055     glVertex3d(0.15,-0.1,-1.75);
00056     glVertex3d(0.1,-0.06,-1.0);
00057     glVertex3d(0.5,-0.1,-0.75);
00058     glVertex3d(0.5,-0.1,-0.25);
00059     glVertex3d(0.5,0,0);
00060     glVertex3d(-0.5,0,0);
00061     glVertex3d(-0.5,-0.1,-0.25);
00062     glVertex3d(-0.5,-0.1,-0.75);
00063     glVertex3d(-0.1,-0.06,-1.0);
00064     glVertex3d(-0.15,-0.1,-1.75);
00065     glVertex3d(0,0,-1.85);
00066     glEnd();
00067     
00068     glBegin(GL_LINES);
00069     glVertex3d(0.15,-0.1,-1.75);
00070     glVertex3d(0.15,0.1,-1.75);
00071     glVertex3d(-0.15,-0.1,-1.75);
00072     glVertex3d(-0.15,0.1,-1.75);
00073     glVertex3d(0.1,-0.06,-1.0);
00074     glVertex3d(0.1,0.06,-1.0);
00075     glVertex3d(-0.1,-0.06,-1.0);
00076     glVertex3d(-0.1,0.06,-1.0);
00077     glVertex3d(0.5,-0.1,-0.25);
00078     glVertex3d(0.5,0.1,-0.25);
00079     glVertex3d(-0.5,-0.1,-0.25);
00080     glVertex3d(-0.5,0.1,-0.25);
00081     glEnd();
00082   }
00083 };
00084 
00085 
00086 
00087 class ISMODELER
00088 {
00089  public:
00090 
00091   static ISMesh* TETRA() {
00092     ISMesh *m = new ISMesh("TETRA");
00093     double r = 0.433012701892;
00094     m->addVertex(Wpt(-0.5,-r,-r));
00095     m->addVertex(Wpt(0.0,-r,r));
00096     m->addVertex(Wpt(0.5,-r,-r));
00097     m->addVertex(Wpt(0.0,r,0.0));
00098     m->addFace(1,0,2);
00099     m->addFace(1,2,3);
00100     m->addFace(3,2,0);
00101     m->addFace(3,0,1);
00102     return m;
00103   }
00104 
00105   static ISMesh* PYRAMID() {
00106     ISMesh *m = new ISMesh("PYRAMID");
00107     ISVertex *v;
00108     v = m->addVertex(Wpt(-0.5,0.5,0.5));
00109     v->setTexCoords(1.0,0.0);
00110     v = m->addVertex(Wpt(-0.5,0.5,-0.5));
00111     v->setTexCoords(0.0,0.0);
00112     v = m->addVertex(Wpt(0.5,0.5,-0.5));
00113     v->setTexCoords(1.0,0.0);
00114     v = m->addVertex(Wpt(0.5,0.5,0.5));
00115     v->setTexCoords(0.0,0.0);
00116     v = m->addVertex(Wpt(0,-0.5,0));
00117     v->setTexCoords(0.5,1.0);
00118     m->addFace(2,1,0);
00119     m->addFace(0,3,2);
00120     m->addFace(1,4,0);
00121     m->addFace(2,4,1);
00122     m->addFace(3,4,2);
00123     m->addFace(0,4,3);
00132     return m;
00133   }
00134 
00135   static ISMesh* Z_PYRAMID() {
00136     ISMesh *m = new ISMesh("Z_PYRAMID");
00137     ISVertex *v;
00138     v = m->addVertex(Wpt(0.5,-0.5,-0.5));
00139     v->setTexCoords(1.0,0.0);
00140     v = m->addVertex(Wpt(-0.5,-0.5,-0.5));
00141     v->setTexCoords(0.0,0.0);
00142     v = m->addVertex(Wpt(-0.5,0.5,-0.5));
00143     v->setTexCoords(1.0,0.0);
00144     v = m->addVertex(Wpt(0.5,0.5,-0.5));
00145     v->setTexCoords(0.0,0.0);
00146     v = m->addVertex(Wpt(0,0,0.5));
00147     v->setTexCoords(0.5,1.0);
00148     m->addFace(0,1,2);
00149     m->addFace(2,3,0);
00150     m->addFace(0,4,1);
00151     m->addFace(1,4,2);
00152     m->addFace(2,4,3);
00153     m->addFace(3,4,0);
00154     return m;
00155   }
00156 
00157 
00158   static ISMesh* SPLAT(Wvec normal) {
00159 
00160     normal = normal.normalize();
00161     Wvec perp = cross(normal,Wvec(1,0,0)).normalize();
00162     if (perp.length() == 0.0)
00163       perp = cross(normal,Wvec(0,1,0)).normalize();
00164     
00165     ISMesh *mesh = new ISMesh("SPLATmesh");
00166     ISVertex *v_center = mesh->addVertex(Wpt(0,0,0));
00167     v_center->setTexCoords(0.5,0.5);
00168     ISVertex *v_last = NULL;
00169     ISVertex *v_first = NULL;
00170     
00171     int nverts = CONFIGval("SPLAT_NVERTS",8,false);
00172     for (double angle=0.; angle<TWOPI; angle += TWOPI/(double)nverts) {
00173       Wtransf m = Wtransf::rotation(normal, angle);
00174       Wpt p = Origin + (0.6 + 0.4*rand()/RAND_MAX)*perp;
00175       Wpt pnew = m*p;
00176       
00177       ISVertex *v_new = mesh->addVertex(pnew);
00178       v_new->setTexCoords((cos(angle)*(pnew - Origin).length() + 1)/2.0, 
00179               (sin(angle)*(pnew - Origin).length() + 1)/2.0);
00180 
00181       if (v_last != NULL)
00182     mesh->addFace(v_last,v_center,v_new);
00183       else
00184     v_first = v_new;
00185       
00186       v_last = v_new;
00187     }
00188     mesh->addFace(v_last,v_center,v_first);
00189     
00190     return mesh;
00191   }
00192 
00193 
00194   static DrawObj* BRUSHICON_OUTLINE() {
00195     return new BRUSHICON_OUTLINE_OBJ();
00196   }
00197 
00198 
00199   static ISMesh* BRUSHICON() {
00200     ISMesh *m = new ISMesh("BRUSHICON");
00201 
00202     // normals...
00203     //Wvec up(0.0,1.0,0.0);
00204     //Wvec down(0.0,-1.0,0.0);
00205     //Wvec forward(0.0,0.0,1.0);
00206 
00207     ISVertex *v;
00208 
00209     v = new ISVertex(Wpt( -0.5,0,0));
00210     v->setMesh(m);
00211     v->setTexCoords(0.0,0.0);
00212     m->addVertex(v);
00213     v = new ISVertex(Wpt(0.5,0,0));
00214     v->setMesh(m);
00215     v->setTexCoords(1.0,0.0);
00216     m->addVertex(v);
00217     v = new ISVertex(Wpt(-0.5,0.1,-0.25));
00218     v->setMesh(m);
00219     v->setTexCoords(0.0,0.25);
00220     m->addVertex(v);
00221     v = new ISVertex(Wpt(0.5,0.1,-0.25));
00222     v->setMesh(m);
00223     v->setTexCoords(1.0,0.25);
00224     m->addVertex(v);
00225     v = new ISVertex(Wpt(-0.5,0.1,-0.75));
00226     v->setMesh(m);
00227     v->setTexCoords(0.0,0.75);
00228     m->addVertex(v);
00229     v = new ISVertex(Wpt(0.5,0.1,-0.75));
00230     v->setMesh(m);
00231     v->setTexCoords(1.0,0.75);
00232     m->addVertex(v);
00233     v = new ISVertex(Wpt(-0.1,0.06,-1.0));
00234     v->setMesh(m);
00235     v->setTexCoords(0.4,1.0);
00236     m->addVertex(v);
00237     v = new ISVertex(Wpt(0.1,0.06,-1.0));
00238     v->setMesh(m);
00239     v->setTexCoords(0.6,1.0);
00240     m->addVertex(v);
00241     v = new ISVertex(Wpt(-0.15,0.1,-1.75));
00242     v->setMesh(m);
00243     v->setTexCoords(0.35,1.75);
00244     m->addVertex(v);
00245     v = new ISVertex(Wpt(0.15,0.1,-1.75));
00246     v->setMesh(m);
00247     v->setTexCoords(0.65,1.75);
00248     m->addVertex(v);
00249     v = new ISVertex(Wpt(0,0,-1.85));
00250     v->setMesh(m);
00251     v->setTexCoords(0.5,1.85);
00252     m->addVertex(v);
00253     
00254 
00255     v = new ISVertex(Wpt(-0.5,-0.1,-0.25));
00256     v->setMesh(m);
00257     v->setTexCoords(0.0,0.25);
00258     m->addVertex(v);
00259     v = new ISVertex(Wpt(0.5,-0.1,-0.25));
00260     v->setMesh(m);
00261     v->setTexCoords(1.0,0.25);
00262     m->addVertex(v);
00263     v = new ISVertex(Wpt(-0.5,-0.1,-0.75));
00264     v->setMesh(m);
00265     v->setTexCoords(0.0,0.75);
00266     m->addVertex(v);
00267     v = new ISVertex(Wpt(0.5,-0.1,-0.75));
00268     v->setMesh(m);
00269     v->setTexCoords(1.0,0.75);
00270     m->addVertex(v);
00271     v = new ISVertex(Wpt(-0.1,-0.06,-1.0));
00272     v->setMesh(m);
00273     v->setTexCoords(0.4,1.0);
00274     m->addVertex(v);
00275     v = new ISVertex(Wpt(0.1,-0.06,-1.0));
00276     v->setMesh(m);
00277     v->setTexCoords(0.6,1.0);
00278     m->addVertex(v);
00279     v = new ISVertex(Wpt(-0.15,-0.1,-1.75));
00280     v->setMesh(m);
00281     v->setTexCoords(0.35,1.75);
00282     m->addVertex(v);
00283     v = new ISVertex(Wpt(0.15,-0.1,-1.75));
00284     v->setMesh(m);
00285     v->setTexCoords(0.65,1.75);
00286     m->addVertex(v);
00287     
00288     // top
00289     m->addFace(0,1,2);
00290     m->addFace(1,3,2);
00291 
00292     m->addFace(2,3,4);
00293     m->addFace(3,5,4);
00294 
00295     m->addFace(4,5,6);
00296     m->addFace(5,7,6);
00297 
00298     m->addFace(6,7,8);
00299     m->addFace(7,9,8);
00300 
00301     m->addFace(8,9,10);
00302 
00303     // bottom
00304     m->addFace(0,12,1);
00305     m->addFace(11,12,0);
00306 
00307     m->addFace(11,14,12);
00308     m->addFace(13,14,11);
00309 
00310     m->addFace(13,16,14);
00311     m->addFace(15,16,13);
00312 
00313     m->addFace(15,18,16);
00314     m->addFace(17,18,15);
00315 
00316     m->addFace(18,17,10);
00317 
00318     // one side
00319     m->addFace(11,0,2);
00320 
00321     m->addFace(11,2,4);
00322     m->addFace(4,13,11);
00323 
00324     m->addFace(13,4,6);
00325     m->addFace(6,15,13);
00326 
00327     m->addFace(15,6,8);
00328     m->addFace(8,17,15);
00329 
00330     m->addFace(17,8,10);
00331 
00332     // the other side
00333     m->addFace(3,1,12);
00334 
00335     m->addFace(3,12,14);
00336     m->addFace(14,5,3);
00337 
00338     m->addFace(5,14,16);
00339     m->addFace(16,7,5);
00340 
00341     m->addFace(7,16,18);
00342     m->addFace(18,9,7);
00343 
00344     m->addFace(9,18,10);
00345 
00346     //m->setUseVertexNormals(1);
00347 
00348     return m;
00349   }
00350 
00351 
00352 
00353   // some of the faces in this sphere may be facing the wrong way..
00354   static ISMesh* SPHERE(int numSides=10, int numVertLines=7) {
00355     ISMesh *m = new ISMesh("SPHERE");
00356     
00357     Wpt_list baseRing, newRing, lastRing;
00358     
00359     int _numSides = 10;
00360     int _numVertLines = 7;
00361     double angle;
00362     for (angle=0; angle<6.2831853; angle += 6.2831853/_numSides) {
00363       baseRing += Wpt(cos(angle),sin(angle),0);
00364     }
00365 
00366     ARRAY<ISVertex*> _lastVerts;
00367     ARRAY<ISVertex*> newVerts;
00368     
00369     double ringSpacing = 1.0 / ((double)_numVertLines+1.0);
00370     double z;
00371     z = 0.5 - ringSpacing;
00372     Wtransf xform = Wtransf::translation(Wvec(0,0,z)) *
00373       Wtransf::scaling(sqrt(0.25 - z*z));
00374     newRing = xform*baseRing;
00375     
00376     // add the top of the sphere
00377     ISVertex *topV = m->addVertex(Wpt(0,0,0.49));
00378     int j;
00379     for (j=0;j<newRing.num();j++) {
00380       //cerr << "adding " << newRing[j] << endl;
00381       newVerts += m->addVertex(newRing[j]);
00382     }
00383     for (j=0;j<newRing.num()-1;j++) {
00384       m->addFace(newVerts[j],newVerts[j+1],topV);
00385     }
00386     m->addFace(newVerts[j],newVerts[0],topV);
00387     
00388     _lastVerts.clear();
00389     for (j=0;j<newVerts.num();j++)
00390       _lastVerts += newVerts[j];
00391     
00392     // add sides to the sphere
00393     int s;
00394     for (s=1;s<_numVertLines;s++) {
00395       z = 0.5 - ringSpacing*(s+1);
00396       Wtransf xform = Wtransf::translation(Wvec(0,0,z)) *
00397         Wtransf::scaling(sqrt(0.25 - z*z));
00398       newRing = xform*baseRing;
00399       newVerts.clear();
00400       for (j=0;j<newRing.num();j++) {
00401         newVerts += m->addVertex(newRing[j]);
00402         //cerr << "adding " << newRing[j] << endl;
00403       }
00404       
00405       for (j=0;j<newVerts.num()-1;j++) {
00406         m->addFace(_lastVerts[j],_lastVerts[j+1],newVerts[j]);
00407         m->addFace(newVerts[j],_lastVerts[j+1],newVerts[j+1]);
00408       }
00409       m->addFace(_lastVerts[j],_lastVerts[0],newVerts[j]);
00410       m->addFace(newVerts[j],_lastVerts[0],newVerts[0]);
00411 
00412 
00413       _lastVerts.clear();
00414       for (j=0;j<newVerts.num();j++)
00415         _lastVerts += newVerts[j];
00416     }
00417 
00418     // add the bottom of the sphere
00419     ISVertex *botV = m->addVertex(Wpt(0,0,-0.49));
00420     for (j=0;j<_lastVerts.num()-1;j++) {
00421       m->addFace(_lastVerts[j],_lastVerts[j+1],botV);
00422     }
00423     m->addFace(_lastVerts[j],_lastVerts[0],botV);
00424 
00425     
00426     return m;
00427   }
00428 
00429   static ISMesh* CLOSEDCHOPSTICKS() {
00430     ISMesh *m = new ISMesh("CLOSEDCHOPSTICKS");
00431     double r = 1.8;
00432     double faceScale=0.25;
00433     double spacing=0.0;
00434     
00435     Wtransf rotr=Wtransf::rotation(Wvec(0,-1,0),-20*(M_PI/180));
00436 
00437     //left one
00438     m->addVertex(rotr*Wpt(-0.866*faceScale-spacing,-0.5*faceScale,-r));
00439     m->addVertex(rotr*Wpt(-spacing,1*faceScale,-r));
00440     m->addVertex(rotr*Wpt(0.866*faceScale-spacing,-0.5*faceScale,-r));
00441     m->addVertex(rotr*Wpt(-spacing,0.0,0.0));
00442     m->addFace(0,1,2);
00443     m->addFace(2,1,3);
00444     m->addFace(2,3,0);
00445     m->addFace(0,3,1);
00446 
00447     Wtransf rotl=Wtransf::rotation(Wvec(0,-1,0),20*(M_PI/180));
00448     //right one
00449     m->addVertex(rotl*Wpt(-0.866*faceScale+spacing,-0.5*faceScale,-r));
00450     m->addVertex(rotl*Wpt(+spacing,1*faceScale,-r));
00451     m->addVertex(rotl*Wpt(0.866*faceScale+spacing,-0.5*faceScale,-r));
00452     m->addVertex(rotl*Wpt(+spacing,0.0,0.0));
00453     m->addFace(4,5,6);
00454     m->addFace(6,5,7);
00455     m->addFace(6,7,4);
00456     m->addFace(4,7,5);
00457     return m;
00458   }
00459 
00460   static ISMesh* OPENCHOPSTICKS() {
00461     ISMesh *m = new ISMesh("OPENCHOPSTICKS");
00462     double r = 1.8;
00463     double faceScale=0.25;
00464     double spacing=0.2;
00465     
00466     Wtransf rotr=Wtransf::rotation(Wvec(0,-1,0),0*(M_PI/180));
00467 
00468     //left one
00469     m->addVertex(rotr*Wpt(-0.866*faceScale-spacing,-0.5*faceScale,-r));
00470     m->addVertex(rotr*Wpt(-spacing,1*faceScale,-r));
00471     m->addVertex(rotr*Wpt(0.866*faceScale-spacing,-0.5*faceScale,-r));
00472     m->addVertex(rotr*Wpt(-spacing,0.0,0.0));
00473     m->addFace(0,1,2);
00474     m->addFace(2,1,3);
00475     m->addFace(2,3,0);
00476     m->addFace(0,3,1);
00477 
00478     Wtransf rotl=Wtransf::rotation(Wvec(0,-1,0),0*(M_PI/180));
00479     //right one
00480     m->addVertex(rotl*Wpt(-0.866*faceScale+spacing,-0.5*faceScale,-r));
00481     m->addVertex(rotl*Wpt(+spacing,1*faceScale,-r));
00482     m->addVertex(rotl*Wpt(0.866*faceScale+spacing,-0.5*faceScale,-r));
00483     m->addVertex(rotl*Wpt(+spacing,0.0,0.0));
00484     m->addFace(4,5,6);
00485     m->addFace(6,5,7);
00486     m->addFace(6,7,4);
00487     m->addFace(4,7,5);
00488     return m;
00489   }
00490 
00491 };
00492 
00493 
00494 
00495 
00496 #endif

Generated on Thu Jul 8 15:19:28 2004 for inspace by doxygen 1.3.4