示例#1
0
int up(TIFF *T, int i)
{
    if (i < 6)
        return TIFFSetDirectory(T, i);
    else
    {
        if (up(T, face_parent(i)))
            return dn(T, face_index(i));
        else
            return 0;
    }
}
示例#2
0
文件: Mesh.hpp 项目: dowoncha/COMP575
	void load_mesh(std::string fileName)
	{
		std::ifstream fin(fileName.c_str());
		if (!fin.is_open())
		{
			printf("ERROR: Unable to load mesh from %s!\n", fileName.c_str());
			exit(0);
		}

		float xmin = FLT_MAX;
		float xmax = -FLT_MAX;
		float ymin = FLT_MAX;
		float ymax = -FLT_MAX;
		float zmin = FLT_MAX;
		float zmax = -FLT_MAX;

		while (true)
		{
			char line[1024] = {0};
			fin.getline(line, 1024);

			if (fin.eof())
				break;

			if (strlen(line) <= 1)
				continue;

			std::vector<std::string> tokens;
			tokenize(line, tokens, " ");

			if (tokens[0] == "v")
			{
				float x = atof(tokens[1].c_str());
				float y = atof(tokens[2].c_str());
				float z = atof(tokens[3].c_str());

				xmin = std::min(x, xmin);
				xmax = std::max(x, xmax);
				ymin = std::min(y, ymin);
				ymax = std::max(y, ymax);
				zmin = std::min(z, zmin);
				zmax = std::max(z, zmax);

				Vector3 position = {x, y, z};
				gPositions.push_back(position);
			}
			else if (tokens[0] == "vn")
			{
				float x = atof(tokens[1].c_str());
				float y = atof(tokens[2].c_str());
				float z = atof(tokens[3].c_str());
				Vector3 normal = {x, y, z};
				gNormals.push_back(normal);
			}
			else if (tokens[0] == "f")
			{
				unsigned int a = face_index(tokens[1].c_str());
				unsigned int b = face_index(tokens[2].c_str());
				unsigned int c = face_index(tokens[3].c_str());
				Triangle triangle;
				triangle.indices[0] = a - 1;
				triangle.indices[1] = b - 1;
				triangle.indices[2] = c - 1;
				gTriangles.push_back(triangle);
			}
		}

		fin.close();

		printf("Loaded mesh from %s. (%lu vertices, %lu normals, %lu triangles)\n", fileName.c_str(), gPositions.size(), gNormals.size(), gTriangles.size());
		printf("Mesh bounding box is: (%0.4f, %0.4f, %0.4f) to (%0.4f, %0.4f, %0.4f)\n", xmin, ymin, zmin, xmax, ymax, zmax);
	}