#include #include struct v3d { float x,y,z; v3d() x(0), y(0), z(0) {} v3d(ax, ay, az) x(ax), y(ay), z(az) {} v3d(v3d a) { x=a.x; y=a.y; z=a.z; } } struct Tri { v3d points[3]; Tri() {} Tri(a,b,c) { points[0]=a; points[1]=b; points[2]=c; } Tri(Tri a) { points[0]=a.points[0]; points[1]=a.points[1]; points[2]=a.points[2]; } }; class Object { public: v3d location; std::vector triangles; std::string name; } std::ostream& operator<<(std::ostream &out, v3d &p) { out << "("; out << p.x << ","; out << p.y << ","; out << p.z << ")"; return out; } std::istream& operator<<(std::ostream &in, v3d &p) { std::string c; in >> c; sscanf(c, "(%f,%f,%f)", &p.x, &p.y, &p.z); return in; } void main() { std::vector objects; int i; // Load mesh data std::ifstream in(filename.c_str(), std::ios::in); int count; in >> count; objects.resize(count); for (i = 0; i < count; i++) { in >> objects[i].location; in >> count; objects[i].triangles.resize(count); for (int j = 0; j < objects[i].triangles.size(); j++) { in >> objects[i].triangles[j].points[0]; in.ingore(1); // skip a space in >> objects[i].triangles[j].points[1]; in.ingore(1); // skip a space in >> objects[i].triangles[j].points[2]; } } //stats cout << "There are " << objects.size() << " objects in the scene:" << std::endl; for (i = 0; i < objects.size(); i++) { cout << "Object " << i << " centered at " << objects[i].location; cout << " contains " << objects[i].triangles.size << " triangles" << std::endl; } }