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

ascshape.cc

Go to the documentation of this file.
00001 #include "ascshape.hh"
00002 #include "register.hh"
00003 
00004 #include "stringhash.hh"
00005 #include "asc.hh"
00006 
00007 namespace anoid {
00008     namespace plugin {
00009 
00010         using namespace std;
00011         using namespace config;
00012 
00013         struct AscData {
00014             DtShapeRef shape;
00015             GLuint display;
00016         };
00017 
00018         string_map<AscData *> loaded;
00019 
00020         void AscShape::init(Configuration &c) {
00021             if (c.hasElement("filename")) {
00022                 string s = c.getString("filename");
00023                 AscData* data;
00024                 data = loaded[s.c_str()];
00025                 if (data == NULL) {
00026                     data = new AscData;
00027                     data->display = glGenLists(1);
00028 
00029                     ASC loader(s);
00030 
00031                     glNewList(data->display, GL_COMPILE);           
00032                     glBegin(GL_TRIANGLES);                  
00033 
00034                     data->shape = dtNewComplexShape();
00035 
00036                     for (vector<Triangle>::iterator i = loader.triangles.begin(); i!=loader.triangles.end(); ++i) {
00037                         Triangle &t = *i;
00038 
00039                         // display list
00040                         glNormal3f(t.normal.getX(), t.normal.getY(), t.normal.getZ());
00041                         glVertex3f(loader.vertices[t.A]->getX(),loader.vertices[t.A]->getY(),loader.vertices[t.A]->getZ()); 
00042                         glVertex3f(loader.vertices[t.B]->getX(),loader.vertices[t.B]->getY(),loader.vertices[t.B]->getZ()); 
00043                         glVertex3f(loader.vertices[t.C]->getX(),loader.vertices[t.C]->getY(),loader.vertices[t.C]->getZ()); 
00044 
00045                         // collision detection
00046                         dtBegin(DT_SIMPLEX);
00047                         dtVertex(loader.vertices[t.A]->getX(),loader.vertices[t.A]->getY(),loader.vertices[t.A]->getZ());   
00048                         dtVertex(loader.vertices[t.B]->getX(),loader.vertices[t.B]->getY(),loader.vertices[t.B]->getZ());   
00049                         dtVertex(loader.vertices[t.C]->getX(),loader.vertices[t.C]->getY(),loader.vertices[t.C]->getZ());   
00050                         dtEnd();
00051                     }
00052 
00053                     dtEndComplexShape();
00054 
00055                     glEnd();
00056                     glEndList();
00057 
00058                     loaded[s.c_str()] = data;
00059                 }
00060 
00061                 dtCreateObject(parent, data->shape);
00062                 display = data->display;
00063             } else {
00064                 cerr << "No filename given for AscShape" << endl;
00066             }
00067 
00068             Shape::init(c);
00069         }
00070 
00071         void AscShape::redraw() {
00072             glCallList(display);
00073             Shape::redraw();
00074         }
00075 
00076         Register(AscShape)
00077 
00078     };
00079 };

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