3d-render/src/object/object.cpp

52 lines
1.1 KiB
C++
Raw Normal View History

2025-10-09 21:33:37 +02:00
#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;
}