Mistakenly use FLT_MIN as the largest negative number possible, where we should be using -FLT_MAX.
55 lines
1.3 KiB
C++
55 lines
1.3 KiB
C++
#include <iostream>
|
|
#include <string>
|
|
#include <fstream>
|
|
#include <sstream>
|
|
#include <vector>
|
|
#include "model.h"
|
|
|
|
Model::Model(const char *filename) : verts_(), faces_() {
|
|
std::ifstream in;
|
|
in.open (filename, std::ifstream::in);
|
|
if (in.fail()) return;
|
|
std::string line;
|
|
while (!in.eof()) {
|
|
std::getline(in, line);
|
|
std::istringstream iss(line.c_str());
|
|
char trash;
|
|
if (!line.compare(0, 2, "v ")) {
|
|
iss >> trash;
|
|
Vec3f v;
|
|
for (int i=0;i<3;i++) iss >> v[i];
|
|
verts_.push_back(v);
|
|
} else if (!line.compare(0, 2, "f ")) {
|
|
std::vector<int> f;
|
|
int itrash, idx;
|
|
iss >> trash;
|
|
while (iss >> idx >> trash >> itrash >> trash >> itrash) {
|
|
idx--; // in wavefront obj all indices start at 1, not zero
|
|
f.push_back(idx);
|
|
}
|
|
faces_.push_back(f);
|
|
}
|
|
}
|
|
std::cerr << "# v# " << verts_.size() << " f# " << faces_.size() << std::endl;
|
|
}
|
|
|
|
Model::~Model() {
|
|
}
|
|
|
|
int Model::nverts() {
|
|
return (int)verts_.size();
|
|
}
|
|
|
|
int Model::nfaces() {
|
|
return (int)faces_.size();
|
|
}
|
|
|
|
std::vector<int> Model::face(int idx) {
|
|
return faces_[idx];
|
|
}
|
|
|
|
Vec3f Model::vert(int i) {
|
|
return verts_[i];
|
|
}
|
|
|