00001 #include "shapes.h" 00002 00007 #include <math/vector3.h> 00008 #include <math/matrix4.h> 00009 00010 #include <cstdio> 00011 #include <iostream> 00012 using namespace std; 00013 00015 00016 GltShapes::GltShapes() 00017 { 00018 reserve(3); // Conserve memory 00019 } 00020 00021 GltShapes::~GltShapes() 00022 { 00023 } 00024 00025 void 00026 GltShapes::draw() const 00027 { 00028 if (!visible()) 00029 return; 00030 00031 glPushMatrix(); 00032 00033 glColor(); 00034 transformation().glMultMatrix(); 00035 00036 for (uint32 i=0; i<size(); i++) 00037 if ((*this)[i].get()) 00038 (*this)[i]->draw(); 00039 00040 glPopMatrix(); 00041 } 00042 00043 void 00044 GltShapes::boundingBox(BoundingBox &box) const 00045 { 00046 box.reset(); 00047 00048 for (uint32 i=0; i<size(); i++) 00049 if ((*this)[i].get()) 00050 { 00051 BoundingBox tmp; 00052 (*this)[i]->boundingBox(tmp); 00053 box += tmp; 00054 } 00055 } 00056 00057 string GltShapes::description() const 00058 { 00059 char buffer[1024]; 00060 sprintf(buffer,"Shape container with %d elements.",int(size())); 00061 return buffer; 00062 } 00063 00064 bool 00065 GltShapes::povrayExport(ostream &os) const 00066 { 00067 os << "union { " << endl; 00068 00069 for (uint32 i=0; i<size(); i++) 00070 (*this)[i]->povrayExport(os); 00071 00072 transformation().writePov(os) << endl; 00073 os << "}" << endl; 00074 00075 return true; 00076 } 00077 00078 void 00079 GltShapes::flushExpired() 00080 { 00081 for (uint32 i=0; i<size(); ) 00082 { 00083 if ((*this)[i]->expired()) 00084 erase(begin()+i); 00085 else 00086 { 00087 (*this)[i]->flushExpired(); 00088 i++; 00089 } 00090 } 00091 }