Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 27, 2005, 12:22:09 AM (19 years ago)
Author:
bensch
Message:

orxonox.trunk: importer now with subclass PrimitiveModel, taht supports working CONE/CUBE/PLANE/SPHERE/CYLINDER

File:
1 edited

Legend:

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

    r3656 r3657  
    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++;
     
    863833
    864834}
    865 
    866 /**
    867    \brief Builds a Sphere into the Model.
    868    \param size The radius of the Sphere.
    869    \param detail The detail of the Sphere.
    870 */
    871 void Model::sphereModel(float size, unsigned int detail)
    872 {
    873   int vertexCount = 0;
    874   if (detail <= 0)
    875     detail = 1;
    876   //  detail = 2; // make it even
    877   float df = (float)detail;
    878  
    879   // defining the Vertices
    880   for (float i = 0; i < df *2.0; i+=1.0)
    881     {
    882       float vi = i/df *PI;
    883       for (float j = -df / 2.0 +1.0; j < df / 2.0; j+=1.0 *df/(df+1.0))
    884         {
    885           float vj = j/df *PI;
    886           this->addVertex(size * cos(vi) * cos(vj),
    887                           size * sin(vj),
    888                           size * sin(vi) * cos(vj));
    889           this->addVertexTexture(i / (df *2.0), (j-1.0)/(df)+.5);
    890           vertexCount++;
    891         }
    892     }
    893   this->addVertex(0, -size, 0);
    894   this->addVertex(0, size, 0);
    895 
    896   // defining the binding Faces.
    897   unsigned int v1, v2, v3, v4;
    898   for (int i = 0; i <= detail * 2 -1; i++)
    899     {
    900       for (int j = 0; j <= detail; j++)
    901         {
    902          
    903           v1 = i*detail + j;
    904           v4 = i*detail + (j+1);
    905          
    906           if (i == detail*2 -1)
    907             {
    908               v2 = j;
    909               v3 = j+1;
    910             }
    911           else
    912             {
    913               v2 = (i+1)*detail + j;
    914               v3 = (i+1)*detail + (j+1);
    915             }
    916          
    917           if (j == 0)
    918             {
    919               v1 = vertexCount+1;
    920               this->addFace(3, 2, v1, v1, v3, v3, v4, v4);
    921             }
    922           else if (j == detail)
    923             {
    924               v3 = vertexCount+2;
    925               this->addFace(3, 2, v1, v1, v2, v2, v3, v3);
    926             }
    927           else
    928             this->addFace(4, 2, v1, v1, v2, v2, v3, v3, v4, v4);
    929         }
    930     }
    931 }
    932 /**
    933    \brief Creates a Cylinder.
    934 */
    935 void Model::cylinderModel(void)
    936 {
    937   unsigned int detail = 20;
    938   float size = 1.0;
    939 
    940   // check if devision by zero
    941   if (detail <= 3)
    942     detail = 3;
    943   int count = 0;
    944   // defining Points of the Cylinder.
    945   for (float phi = 0.0; phi < 2.0*PI; phi += 2.0*PI/(float)detail)
    946     {
    947       this->addVertex(size*cos(phi), size*sin(phi), -size);
    948       this->addVertex(size*cos(phi), size*sin(phi), size);
    949       count ++;
    950     }
    951   this->addVertex(0, 0, -size);
    952   this->addVertex(0, 0, size);
    953 
    954  
    955   if (count != detail)
    956     PRINTF(1)("calculation error, count should be %d but is %d.\n", detail, count);
    957   vertices->debug();
    958 
    959   // adding Faces
    960   for (int i = 0; i < detail-1; i++)
    961     {
    962       int p1, p2, p3, p4;
    963       p1 = 2*i+1;
    964       p2 = 2*i+2;
    965       if (i <= detail);
    966       p3 = 2*i+4;
    967       p4 = 2*i+3;
    968       // something is wrong here
    969       this->addFace(4, 0, p1, p2, p3, p4);
    970       this->addFace(3, 0, p4, p1, 2*detail+1);
    971       this->addFace(3, 0, p2, p3, 2*detail+2);
    972     }
    973   addFace(4,0, 2*detail-1, 2*detail, 2, 1);
    974   this->addFace(3, 0, 1, 2*detail-1, 2*detail+1);
    975   this->addFace(3, 0, 2*detail, 2, 2*detail+2);
    976 
    977 }
    978 
    979 
    980 void Model::coneModel(float size, unsigned int detail)
    981 {
    982 
    983  
    984 }
Note: See TracChangeset for help on using the changeset viewer.