Я анализирую .obj (созданный в Blender, если это поможет) в программу C++ в OpenGL, и, похоже, это уже близко. Вроде правильно находит нужные здесь вершины. Я пытаюсь создать заглавную букву I, которая будет перемещаться. Вот мой код для анализа:
Я анализирую .obj (созданный в Blender, если это поможет) в программу C++ в OpenGL, и, похоже, это уже близко. Вроде правильно находит нужные здесь вершины. Я пытаюсь создать заглавную букву I, которая будет перемещаться. Вот мой код для анализа:
FILE * file = fopen(filepath, "r"); if (file == NULL) { printf("Impossible to open the file !\n"); return false; }
while (1) { char lineHeader[128]; // read the first word of the line int res = fscanf(file, "%s", lineHeader); if (res == EOF) break; // EOF = End Of File. Quit the loop.
// For each vertex of each triangle for (unsigned int i = 0; i < vertexIndices.size(); i++) { unsigned int vertexIndex = vertexIndices[i]; glm::vec3 vertex = temp_vertices[vertexIndex - 1]; out_vertices.push_back(vertex); }
//For each vertex normal for (unsigned int i = 0; i < temp_normals.size(); i++) { out_normals.push_back(glm::normalize(temp_normals[i])); } }
glm::vec3 computeNormal(glm::vec3 const & a, glm::vec3 const & b, glm::vec3 const & c) { //Returns the (not normalized) face normal of each triangle return glm::cross(c - a, b - a); } [/code]
Вот код, который я использую для рисования проанализированных вершин:
[code]glBegin(GL_QUADS); glColor3f(0.2, 0.2, 0); for (int i = 0; i < vertices.size(); i++) { glVertex3f(vertices[i].x, vertices[i].y, vertices[i].z); glTexCoord3f(vertices[i].x, vertices[i].y, vertices[i].z); } for (int i = 0; i < normals.size(); i++) { glNormal3f(normals[i].x, normals[i].y, normals[i].z); } glEnd(); [/code]