Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

3dsshape.cc

Go to the documentation of this file.
00001 #include "3dsshape.hh"
00002 #include "dlc_register.h"
00003 
00004 #include "stringhash.hh"
00005 #include "3ds.hh"
00006 
00007 struct 3dsData {
00008     DtShapeRef shape;
00009     GLuint display;
00010 };
00011 
00012 string_map<3dsData *> loaded;
00013 
00014 void o3dsShape::init(oConfiguration &c) {
00015     if (c.hasElement("filename")) {
00016         string s = c.getString("filename")
00017         
00018         3dsData* data;
00019         data = loaded[s.c_str()];
00020         if (data == NULL) {
00021             data = new 3dsData;
00022             data->display = glGenLists(1);
00023             
00024             3ds loader(s);
00025 
00026             glNewList(data->display, GL_COMPILE);           
00027             glBegin(GL_TRIANGLES);                  
00028 
00029             data->shape = dtNewComplexShape();
00030 
00031             cout << "number of objects: " << loader.numOfObjects << endl;
00032             for(int i=0; i<loader.numOfObjects; i++) {
00033                 if(loader.pObject.size() <= 0) break;
00034                 
00035                 t3DObject *pObject = &loader.pObject[i];
00036                 if(pObject->bHasTexture) {
00037                     glEnable(GL_TEXTURE_2D);
00038                     glColor3ub(255, 255, 255);
00039                     glBindTexture(GL_TEXTURE_2D, texture[pObject->materialID]);
00040                 } else {
00041                     glDisable(GL_TEXTURE_2D);
00042                 }
00043                 
00044                 for(int j = 0; j < pObject->numOfFaces; j++) {
00045                     //what about all the inbetween calls
00046                     dtBegin(DT_SIMPLEX);
00047                     for(int whichVertex = 0; whichVertex < 3; whichVertex++) {
00048                         int index = pObject->pFaces[j].vertIndex[whichVertex];
00049                         glNormal3f(pObject->pNormals[ index ].x, pObject->pNormals[ index ].y, pObject->pNormals[ index ].z);                   
00050                         if(pObject->bHasTexture) {
00051                             if(pObject->pTexVerts) {
00052                                 glTexCoord2f(pObject->pTexVerts[ index ].x, pObject->pTexVerts[ index ].y);
00053                             }
00054                         } else {
00055                             BYTE *pColor = loader.pMaterials[pObject->materialID].color;
00056                             glColor3ub(pColor[0], pColor[1], pColor[2]);
00057                         }
00058                         glVertex3f(pObject->pVerts[ index ].x, pObject->pVerts[ index ].y, pObject->pVerts[ index ].z);             
00059                         dtVertex(pObject->pVerts[ index ].x, pObject->pVerts[ index ].y, pObject->pVerts[ index ].z);               
00060                     }
00061                     dtEnd();
00062                 }
00063                 glEnd();
00064             }
00065             
00066             //          //fixme one could easily clear this up to use the same structures as the asc-loader
00067             //          //that is our own
00068             //          for (vector<Triangle>::iterator i = loader.triangles.begin(); i!=loader.triangles.end(); ++i) {
00069             //              Triangle &t = *i;
00070             //
00071             //              // display list
00072             //              glNormal3f(t.normal.getX(), t.normal.getY(), t.normal.getZ());
00073             //              glVertex3f(loader.vertices[t.A]->getX(),loader.vertices[t.A]->getY(),loader.vertices[t.A]->getZ()); 
00074             //              glVertex3f(loader.vertices[t.B]->getX(),loader.vertices[t.B]->getY(),loader.vertices[t.B]->getZ()); 
00075             //              glVertex3f(loader.vertices[t.C]->getX(),loader.vertices[t.C]->getY(),loader.vertices[t.C]->getZ()); 
00076             //
00077             //              // collision detection
00078             //              dtBegin(DT_SIMPLEX);
00079             //              dtVertex(loader.vertices[t.A]->getX(),loader.vertices[t.A]->getY(),loader.vertices[t.A]->getZ());   
00080             //              dtVertex(loader.vertices[t.B]->getX(),loader.vertices[t.B]->getY(),loader.vertices[t.B]->getZ());   
00081             //              dtVertex(loader.vertices[t.C]->getX(),loader.vertices[t.C]->getY(),loader.vertices[t.C]->getZ());   
00082             //              dtEnd();
00083             //          }
00084             //
00085             dtEndComplexShape();
00086             
00087             glEnd();
00088             glEndList();
00089 
00090             loaded[s.c_str()] = data;
00091         }
00092 
00093         dtCreateObject(parent, data->shape);
00094         display = data->display;
00095     } else {
00096         cerr << "No filename given for 3dshape" << endl;
00098     }
00099 
00100     Shape::init(xml);
00101 }
00102 
00103 void o3dsShape::redraw() {
00104     glCallList(display);
00105     Shape::redraw();
00106 }
00107 
00108 DLC_Register_Macro(o3dsShape)

Anoid NG © Michael Westergaard, Martin Stig Stissing, Ronni Michael Laursen, and Kristian Bisgaard Lassen