home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / 3DTOSHI2.ZIP / mpg3d / source / G3dgem.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-17  |  4.0 KB  |  150 lines

  1.  
  2. // g3dgem.cpp
  3. //
  4. // Copyright (c) 1996 by Toshiaki Tsuji, all rights reserved.
  5.  
  6. #include "stdgfx.h"
  7. #include "g3dgem.h"
  8.  
  9. struct GEMFACETYPE
  10.   {
  11.     INT Num;
  12.     INT PointList[16];
  13.   }; // End of GEMFACETYPE
  14.  
  15. G3DGEMTOOL::G3DGEMTOOL () : G3DFILETOOL ()
  16.   {
  17.   } // End of Constructor for G3DGEMTOOL
  18.   
  19. G3DGEMTOOL::~G3DGEMTOOL ()
  20.   {
  21.   } // End of Destructor for G3DGEMTOOL
  22.   
  23. BOOLEAN G3DGEMTOOL::LoadPoints ( FILEHANDLE f, G3DPOLYHEDRON *Object,
  24.                                  LONG NumPoints, double Scale )
  25.   {
  26.     LONG i;
  27.     float x,y,z;
  28.     FLPVECTOR3D *PointList;
  29.     GEOMETRYDATA *GeometryData;
  30.     
  31.     Object->CreateGeometryPoints(NumPoints);
  32.     
  33.     GeometryData = Object->GetGeometryData ();
  34.     PointList = GeometryData->FLPLocalPoints;
  35.  
  36.     if (PointList==NULL)
  37.       return FAILURE;
  38.           
  39.     for (i=0;i<NumPoints;i++)
  40.       {
  41.         fscanf ( f, "%f %f %f\n", &x, &y, &z );
  42.         PointList[i].x = (float)(x*Scale);
  43.         PointList[i].y = (float)(y*Scale);
  44.         PointList[i].z = (float)(z*Scale);
  45.       } // End for
  46.       
  47.     return SUCCESS;  
  48.   } // End of LoadPoints for G3DGEMTOOL                                 
  49.                                  
  50. BOOLEAN G3DGEMTOOL::LoadFaces ( FILEHANDLE f, G3DPOLYHEDRON *Object,
  51.                                 LONG NumFaces )
  52.   {
  53.     LONG i;
  54.     G3DPOLY *PolyList;
  55.     GEOMETRYDATA *GeometryData;
  56.     LONG NewFaceNum;
  57.  
  58.     GEMFACETYPE *Faces;
  59.     Faces = new GEMFACETYPE [NumFaces];
  60.     if (Faces==NULL)
  61.       return FAILURE;
  62.       
  63.     NewFaceNum = 0;
  64.     INT j;
  65.     for (i=0;i<NumFaces;i++)
  66.       {
  67.         fscanf ( f, "%d ", &(Faces[i].Num) );
  68.  
  69.         for (j=0;j<Faces[i].Num-1;j++)
  70.           {
  71.             fscanf ( f, "%d ", &(Faces[i].PointList[j]) );
  72.           } // End for
  73.         fscanf ( f, "%d\n", &(Faces[i].PointList[j]) );
  74.         NewFaceNum += 1 + Faces[i].Num - 3;
  75.       } // End for
  76.       
  77.     Object->CreateGeometryPolys ( NewFaceNum );
  78.       
  79.     GeometryData = Object->GetGeometryData ();
  80.     PolyList = GeometryData->Polys;
  81.       
  82.     if (PolyList==NULL)  
  83.       {
  84.         delete Faces;
  85.         return FAILURE;
  86.       } // End if  
  87.       
  88.     for (i=0;i<NumFaces;i++)
  89.       {
  90.         for (j=2;j<Faces[i].Num;j++)
  91.           {
  92.             PolyList->Points[0] = Faces[i].PointList[0] - 1;
  93.             PolyList->Points[1] = Faces[i].PointList[j-1] - 1;
  94.             PolyList->Points[2] = Faces[i].PointList[j] - 1;
  95.             PolyList->TexCoords[0].x = (float)0; PolyList->TexCoords[0].y = (float)0;
  96.             PolyList->TexCoords[1].x = (float)0; PolyList->TexCoords[1].y = (float)0;
  97.             PolyList->TexCoords[2].x = (float)0; PolyList->TexCoords[2].y = (float)0;
  98.             PolyList++;
  99.           } // End for
  100.       } // End for
  101.  
  102.     delete Faces;
  103.     Faces = NULL;
  104.     return SUCCESS;      
  105.   } // End of LoadFaces for G3DGEMTOOL                                
  106.                                 
  107. BOOLEAN G3DGEMTOOL::Load ( FILEHANDLE f, LINKEDLIST<G3DOBJECT*> *ObjectList,
  108.                            BOOLEAN ClockWise, double Scale )
  109.   {
  110.     INT NumPoints,NumFaces,Total;
  111.     
  112.     fscanf ( f, "%d %d %d\n", &NumPoints, &NumFaces, &Total );
  113.     
  114.     G3DPOLYHEDRON *Object = new G3DPOLYHEDRON ();
  115.     if (Object==NULL)
  116.       return FAILURE;
  117.  
  118.     Object->TextureMapped = FALSE;  
  119.     if (LoadPoints ( f, Object, NumPoints, Scale )==FAILURE)
  120.       {
  121.         delete Object;
  122.         return FAILURE;
  123.       } // End if
  124.       
  125.     if (LoadFaces ( f, Object, NumFaces )==FAILURE)
  126.       {
  127.         delete Object;
  128.         return FAILURE;
  129.       } // End if
  130.     
  131.     Object->ClockWised = ClockWise;
  132.     ObjectList->AddObject ( Object );  
  133.     return SUCCESS;
  134.   } // End of Load for G3DGEMTOOL
  135.   
  136. BOOLEAN G3DGEMTOOL::Save ( FILEHANDLE f, LINKEDLIST<G3DOBJECT*> *ObjectList,
  137.                            BOOLEAN ClockWise, double Scale )
  138.   {
  139.     if (f)
  140.       {}
  141.     if (ObjectList)
  142.       {}
  143.     if (ClockWise)
  144.       {}
  145.     if (Scale)
  146.       {}
  147.     return FAILURE;          
  148.   } // End of Save for G3DGEMTOOL 
  149.  
  150.