#include "OffObject.h" #include #include "vgl.h" #include #include #include #include using namespace std; OffObject::OffObject(string name) { SetName(name); SetType(GL_TRIANGLES); } void OffObject::SetName(string name) { if (name == "" ) { fileName = "offs/teapot.off"; } else { fileName = name; } } void OffObject::Init() { LoadFile(fileName); return; } void EatComment(ifstream & inFile) { bool comment = true; char peek; string junk; while (comment and inFile) { inFile.get(peek); if (peek =='#') { getline(inFile, junk); } else { inFile.unget(); comment = false; } } return; } void FindExtreme(vec3 & min,vec3 & max, vec3 point){ int i; for(i=0;i<3;i++) { min[i] = std::min(min[i],point[i]); max[i] = std::max(max[i], point[i]); } return; } void OffObject::LoadFile(string name){ Vertex v; int vertices, polys; int i,j; ifstream file; string junk; vec3 min, max; GLushort a,b,c; int pts; file.open(fileName.c_str()); if (!file) { cerr << " Unable to open " << fileName << endl; return; } // read in the header, should be OFF, getline(file, junk); EatComment(file); file >> vertices >> polys ; getline(file, junk); // set everything to be red. v.color = color; for(i=0;i> v.position; points.push_back(v); if (i == 0) { min = v.position; max = v.position; } else { FindExtreme(min, max, v.position); } // for now ignore anything else. getline(file, junk); } // normalize the object between -.5 and .5 in all dimensions. max -= min; GLfloat norm = std::max(max.x, max.y); norm = std::max(norm, max.z); vec3 move = vec3(-0.5); for(i=0;i> pts; file >> a >> b >> c; if (file) { index.push_back(a); index.push_back(b); index.push_back(c); for(j=4; j<= pts; j++){ b = c; file >> c; if (file) { index.push_back(a); index.push_back(b); index.push_back(c); } else { cout << "Attempt to read past end of file " << endl; } } } else { cout << "Attempt to read past end of file " << endl; } getline(file,junk); } file.close(); return; } void OffObject::DisplaySetup() { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); return; }