本文整理汇总了C++中BoundBox::extend方法的典型用法代码示例。如果您正苦于以下问题:C++ BoundBox::extend方法的具体用法?C++ BoundBox::extend怎么用?C++ BoundBox::extend使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BoundBox
的用法示例。
在下文中一共展示了BoundBox::extend方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadFile
bool Object::loadFile(const std::string &path) {
using namespace std;
using namespace std::chrono;
const time_point loadStartTime = high_resolution_clock::now();
ifstream ifs(path.c_str(), ifstream::in);
if (!ifs.is_open()) {
std::cerr << "File \"" << path << "\" could not be loaded." << std::endl;
return false;
}
BoundBox boundBox;
string line;
vector<string> tokens;
string mtlPath;
string mtlName;
while (ifs.good()) {
tokens.clear();
getline(ifs, line);
istringstream iss(line);
copy(istream_iterator<string>(iss), istream_iterator<string>(), back_inserter(tokens));
if (tokens.size() == 0 || tokens[0].size() == 0 || tokens[0][0] == '#')
continue;
if (tokens[0] == "v") {
if (tokens.size() != 4) {
cerr << path << ": Vertex command does not have correct number of components\n";
continue;
}
const Vector3f vertex(FromString<float>(tokens[1]),
FromString<float>(tokens[2]),
FromString<float>(tokens[3]));
boundBox.extend(vertex);
vertices.push_back(vertex);
} else if (tokens[0] == "vt") {
if (tokens.size() != 3) {
cerr << path << ": Texture coordinate command does not have correct number of components\n";
continue;
}
const Vector2f texcoord(FromString<float>(tokens[1]), FromString<float>(tokens[2]));
texcoords.push_back(texcoord);
} else if (tokens[0] == "vn") {
if (tokens.size() != 4) {
cerr << path << ": Normal command does not have correct number of components\n";
continue;
}
const Vector3f normal(FromString<float>(tokens[1]),
FromString<float>(tokens[2]),
FromString<float>(tokens[3]));
normals.push_back(normal);
} else if (tokens[0] == "f") {
Face face = { };
if (tokens.size() != 4 && tokens.size() != 5) {
cerr << path << ": Face command does not have correct number of arguments\n";
continue;
}
face.isQuad = tokens.size() == 5;
face.mat = MaterialLib::load(mtlPath, mtlName);
const size_t slashesCount = count(tokens[1].begin(), tokens[1].end(), '/');
switch (slashesCount) {
case 0: {
for (size_t i = 0; i < 3U + face.isQuad; i++) {
face.vertexIdxs[i] = indexFromStr(tokens[i + 1], vertices.size()) - 1;
}
faces.push_back(face);
break;
}
case 1: {
for (size_t i = 0; i < 3U + face.isQuad; i++) {
const std::string &token = tokens[i + 1];
const size_t slashPos = token.find('/');
face.vertexIdxs[i] = indexFromStr(token.substr(0, slashPos), vertices.size()) - 1;
if (token.size() - slashPos > 1)
face.texcoordIdxs[i] = indexFromStr(token.substr(slashPos + 1), texcoords.size()) - 1;
}
faces.push_back(face);
break;
}
case 2: {
for (size_t i = 0; i < 3U + face.isQuad; i++) {
const std::string &token = tokens[i + 1];
const size_t slash0Pos = token.find('/');
const size_t slash1Pos = token.find('/', slash0Pos + 1);
face.vertexIdxs[i] = indexFromStr(token.substr(0, slash0Pos), vertices.size()) - 1;
if (slash1Pos - slash0Pos > 1)
face.texcoordIdxs[i] = indexFromStr(token.substr(slash0Pos + 1, slash1Pos - slash0Pos),
texcoords.size()) - 1;
if (token.size() - slash0Pos > 1)
face.normalIdxs[i] = indexFromStr(token.substr(slash1Pos + 1), normals.size()) - 1;
}
faces.push_back(face);
break;
}
default:
cerr << path << ": Invalid face command in \"" << line << "\"\n";
//.........这里部分代码省略.........