Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 7, 2005, 3:54:49 PM (20 years ago)
Author:
chris
Message:

orxonox/branches/levelloader: Merged trunk into branch… still not working though…

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/levelloader/src/lib/graphics/importer/model.cc

    r3605 r3746  
    3434{
    3535  this->initialize();
    36 }
    37 
    38 /**
    39    \brief Creates a 3D-Model of Primitive-Type type
    40 
    41    if you want to just display a Cube/Sphere/Cylinder/... without any material.
    42    
    43    \todo implement Cube/Sphere/Cylinder/...
    44 */
    45 Model::Model(PRIMITIVE type)
    46 {
    47   this->initialize();
    48 
    49   switch (type)
    50     {
    51     default:
    52     case CUBE:
    53       this->cubeModel();
    54       break;
    55     case SPHERE:
    56       this->sphereModel();
    57       break;
    58     case CYLINDER:
    59       this->cylinderModel();
    60       break;
    61 
    62     }
    63   this->importToGL ();
    64 
    65   this->cleanup();
    6636}
    6737
     
    492462
    493463      tmpElem->vertexNumber = va_arg (itemlist, int) -1;
    494       if (type >= 2)
     464      if (type & TEXCOORD)
    495465        tmpElem->texCoordNumber = va_arg (itemlist, int) -1;
    496       if (type == 1 || type ==3)
     466      if (type & NORMAL)
    497467        tmpElem->normalNumber = va_arg(itemlist, int) -1;
    498468      this->currentGroup->currentFace->vertexCount++;
     
    797767void Model::cubeModel(void)
    798768{
    799   this->addVertex ("-0.5 -0.5 0.5");
    800   this->addVertex ("0.5 -0.5 0.5");
    801   this->addVertex ("-0.5 0.5 0.5");
    802   this->addVertex ("0.5 0.5 0.5");
    803   this->addVertex ("-0.5 0.5 -0.5");
    804   this->addVertex ("0.5 0.5 -0.5");
    805   this->addVertex ("-0.5 -0.5 -0.5");
    806   this->addVertex ("0.5 -0.5 -0.5");
    807 
    808   this->addVertexTexture ("0.0 0.0");
    809   this->addVertexTexture ("1.0 0.0");
    810   this->addVertexTexture ("0.0 1.0");
    811   this->addVertexTexture ("1.0 1.0");
    812   this->addVertexTexture ("0.0 2.0");
    813   this->addVertexTexture ("1.0 2.0");
    814   this->addVertexTexture ("0.0 3.0");
    815   this->addVertexTexture ("1.0 3.0");
    816   this->addVertexTexture ("0.0 4.0");
    817   this->addVertexTexture ("1.0 4.0");
    818   this->addVertexTexture ("2.0 0.0");
    819   this->addVertexTexture ("2.0 1.0");
    820   this->addVertexTexture ("-1.0 0.0");
    821   this->addVertexTexture ("-1.0 1.0");
    822 
    823   this->addVertexNormal ("0.0 0.0 1.0");
    824   this->addVertexNormal ("0.0 0.0 1.0");
    825   this->addVertexNormal ("0.0 0.0 1.0");
    826   this->addVertexNormal ("0.0 0.0 1.0");
    827   this->addVertexNormal ("0.0 1.0 0.0");
    828   this->addVertexNormal ("0.0 1.0 0.0");
    829   this->addVertexNormal ("0.0 1.0 0.0");
    830   this->addVertexNormal ("0.0 1.0 0.0");
    831   this->addVertexNormal ("0.0 0.0 -1.0");
    832   this->addVertexNormal ("0.0 0.0 -1.0");
    833   this->addVertexNormal ("0.0 0.0 -1.0");
    834   this->addVertexNormal ("0.0 0.0 -1.0");
    835   this->addVertexNormal ("0.0 -1.0 0.0");
    836   this->addVertexNormal ("0.0 -1.0 0.0");
    837   this->addVertexNormal ("0.0 -1.0 0.0");
    838   this->addVertexNormal ("0.0 -1.0 0.0");
    839   this->addVertexNormal ("1.0 0.0 0.0");
    840   this->addVertexNormal ("1.0 0.0 0.0");
    841   this->addVertexNormal ("1.0 0.0 0.0");
    842   this->addVertexNormal ("1.0 0.0 0.0");
    843   this->addVertexNormal ("-1.0 0.0 0.0");
    844   this->addVertexNormal ("-1.0 0.0 0.0");
    845   this->addVertexNormal ("-1.0 0.0 0.0");
    846   this->addVertexNormal ("-1.0 0.0 0.0");
     769  this->addVertex (-0.5, -0.5, 0.5);
     770  this->addVertex (0.5, -0.5, 0.5);
     771  this->addVertex (-0.5, 0.5, 0.5);
     772  this->addVertex (0.5, 0.5, 0.5);
     773  this->addVertex (-0.5, 0.5, -0.5);
     774  this->addVertex (0.5, 0.5, -0.5);
     775  this->addVertex (-0.5, -0.5, -0.5);
     776  this->addVertex (0.5, -0.5, -0.5);
     777
     778  this->addVertexTexture (0.0, 0.0);
     779  this->addVertexTexture (1.0, 0.0);
     780  this->addVertexTexture (0.0, 1.0);
     781  this->addVertexTexture (1.0, 1.0);
     782  this->addVertexTexture (0.0, 2.0);
     783  this->addVertexTexture (1.0, 2.0);
     784  this->addVertexTexture (0.0, 3.0);
     785  this->addVertexTexture (1.0, 3.0);
     786  this->addVertexTexture (0.0, 4.0);
     787  this->addVertexTexture (1.0, 4.0);
     788  this->addVertexTexture (2.0, 0.0);
     789  this->addVertexTexture (2.0, 1.0);
     790  this->addVertexTexture (-1.0, 0.0);
     791  this->addVertexTexture (-1.0, 1.0);
     792
     793  this->addVertexNormal (0.0, 0.0, 1.0);
     794  this->addVertexNormal (0.0, 0.0, 1.0);
     795  this->addVertexNormal (0.0, 0.0, 1.0);
     796  this->addVertexNormal (0.0, 0.0, 1.0);
     797  this->addVertexNormal (0.0, 1.0, 0.0);
     798  this->addVertexNormal (0.0, 1.0, 0.0);
     799  this->addVertexNormal (0.0, 1.0, 0.0);
     800  this->addVertexNormal (0.0, 1.0, 0.0);
     801  this->addVertexNormal (0.0, 0.0, -1.0);
     802  this->addVertexNormal (0.0, 0.0, -1.0);
     803  this->addVertexNormal (0.0, 0.0, -1.0);
     804  this->addVertexNormal (0.0, 0.0, -1.0);
     805  this->addVertexNormal (0.0, -1.0, 0.0);
     806  this->addVertexNormal (0.0, -1.0, 0.0);
     807  this->addVertexNormal (0.0, -1.0, 0.0);
     808  this->addVertexNormal (0.0, -1.0, 0.0);
     809  this->addVertexNormal (1.0, 0.0, 0.0);
     810  this->addVertexNormal (1.0, 0.0, 0.0);
     811  this->addVertexNormal (1.0, 0.0, 0.0);
     812  this->addVertexNormal (1.0, 0.0, 0.0);
     813  this->addVertexNormal (-1.0, 0.0, 0.0);
     814  this->addVertexNormal (-1.0, 0.0, 0.0);
     815  this->addVertexNormal (-1.0, 0.0, 0.0);
     816  this->addVertexNormal (-1.0, 0.0, 0.0);
    847817
    848818  /* normaleLess-testingMode
     
    855825  */
    856826
    857   this->addFace ("1/1/1 2/2/2 4/4/3 3/3/4");
    858   this->addFace ("3/3/5 4/4/6 6/6/7 5/5/8");
    859   this->addFace ("5/5/9 6/6/10 8/8/11 7/7/12");
    860   this->addFace ("7/7/13 8/8/14 2/10/15 1/9/16");
    861   this->addFace ("2/2/17 8/11/18 6/12/19 4/4/20");
    862   this->addFace ("7/13/21 1/1/22 3/3/23 5/14/24");
    863 
    864 }
    865 
    866 /**
    867    \brief Builds a Sphere into the Model
    868 */
    869 void Model::sphereModel()
    870 {
    871   int detail = 30;
    872   if (detail <= 0) detail = 1;
    873   float df = (float)detail;
    874   for (float i = 0.0; i < df/2; i+=1.0)
    875     {
    876       for (float j = 0.0; j < df; j+=1.0)
    877       {
    878         float vz = i/df *2.0*PI - PI/2.0;
    879         this->addVertex(cos(j/df*2.0*PI) * cos(vz) ,
    880                         sin(j/df*2.0*PI) * cos(vz),
    881                         sin(vz));
    882         //if (j==0.0)
    883         //printf ("%f %f\n", vz, sin (vz));
    884         if (i==0.0)
    885           PRINTF(0)("%f, %f\n", j/df*2.0*PI, cos(j/df*PI));
    886       }
    887     }
    888   vertices->debug();
    889   for (int i = 0; i < detail/2; i++)
    890     for (int j = 1; j < detail; j++)
    891       {
    892         unsigned int v1,v2,v3,v4;
    893         v1 = i*detail +j;
    894 
    895         /*      if (j+1 == detail)
    896           {
    897             v2 = i*detail +1;
    898             v3 = i*detail+detail + 1;
    899           }
    900           else*/
    901           {
    902             v2 = i*detail +j+1;
    903             v3 = i*detail+detail + j+1;
    904           }
    905         v4 = i*detail+detail + j;
    906         //printf("%i %i %i %i\n", v1, v2, v3, v4);
    907         this->addFace(4, 0, v1, v2, v3, v4);
    908       }
    909 }
    910 
    911 /**
    912    \brief Creates a Cylinder.
    913 */
    914 void Model::cylinderModel(void)
    915 {
    916   unsigned int detail = 20;
    917   float size = 1.0;
    918 
    919   // check if devision by zero
    920   if (detail <= 3)
    921     detail = 3;
    922   int count = 0;
    923   // defining Points of the Cylinder.
    924   for (float phi = 0.0; phi < 2.0*PI; phi += 2.0*PI/(float)detail)
    925     {
    926       this->addVertex(size*cos(phi), size*sin(phi), -size);
    927       this->addVertex(size*cos(phi), size*sin(phi), size);
    928       count ++;
    929     }
    930   this->addVertex(0, 0, -size);
    931   this->addVertex(0, 0, size);
    932 
    933  
    934   if (count != detail)
    935     PRINTF(1)("calculation error, count should be %d but is %d.\n", detail, count);
    936   vertices->debug();
    937 
    938   // adding Faces
    939   for (int i = 0; i < detail-1; i++)
    940     {
    941       int p1, p2, p3, p4;
    942       p1 = 2*i+1;
    943       p2 = 2*i+2;
    944       if (i <= detail);
    945       p3 = 2*i+4;
    946       p4 = 2*i+3;
    947       // something is wrong here
    948       this->addFace(4, 0, p1, p2, p3, p4);
    949       this->addFace(3, 0, p4, p1, 2*detail+1);
    950       this->addFace(3, 0, p2, p3, 2*detail+2);
    951     }
    952   addFace(4,0, 2*detail-1, 2*detail, 2, 1);
    953   this->addFace(3, 0, 1, 2*detail-1, 2*detail+1);
    954   this->addFace(3, 0, 2*detail, 2, 2*detail+2);
    955 
    956 }
     827  this->addFace (4, 3, 1,1,1, 2,2,2, 4,4,3, 3,3,4);
     828  this->addFace (4, 3, 3,3,5, 4,4,6, 6,6,7, 5,5,8);
     829  this->addFace (4, 3, 5,5,9, 6,6,10, 8,8,11, 7,7,12);
     830  this->addFace (4, 3, 7,7,13, 8,8,14, 2,10,15, 1,9,16);
     831  this->addFace (4, 3, 2,2,17, 8,11,18, 6,12,19, 4,4,20);
     832  this->addFace (4, 3, 7,13,21, 1,1,22, 3,3,23, 5,14,24);
     833
     834}
Note: See TracChangeset for help on using the changeset viewer.