load map/obj

This commit is contained in:
Joachim Rey 2025-10-09 21:33:37 +02:00
parent 6b454d46ad
commit 8383fc1edf
18 changed files with 305 additions and 43 deletions

51
src/object/object.cpp Normal file
View file

@ -0,0 +1,51 @@
#include <fstream>
#include <iostream>
#include "object.h"
void Object::load(std::string file, std::string txtpos) {
std::string line;
std::ifstream ifile;
ifile.open (file);
bool first = true;
if (ifile.is_open()) {
while ( getline (ifile,line) ) {
if (first) {
if (line != "OBJECT") {
std::cerr << "File " << file << " does not contain OBJECT signature (" << line << ")." << std::endl;
return;
}
first = false;
} else if (line == "" ) {
return;
} else {
this->plns.push_back(new Plane(line));
}
}
ifile.close();
} else {
std::cerr << "Could not open file " << file << std::endl;
return;
}
this->pts = new Point(txtpos);
}
std::vector<Plane*> Object::getSides() { return this->plns; }
bool Object::isContained() { return true; };
std::ostream & operator<<(std::ostream& os, Object& o){
return o.print(os);
}
std::ostream& Object::print(std::ostream& os) {
os << " - Object " << this << std::endl;
for (Plane* i: this->getSides()) {
os << (*i);
}
return os;
}