1

I'm using the following tutorial for drawing a mesh in OpenGL: https://www.d.umn.edu/~ddunham/cs5721f07/schedule/resources/lab_opengl07.html

At that site, there are links to the GLM source filesthat are used for loading an OBJ mesh. I am able to successfully draw a mesh using this technique. However, I need to be able to get the vertices of the mesh (say in a vector) to analyze and manipulate. How can this be done?

1 Answer 1

3

This should help (please refer to the provided header/source):

GLMmodel* model = glmReadOBJ(...);

int vertex_count = model->numvertices; // # of vertices in the mesh
float x0 = model->vertices[3 * 0 + 0]; // x coordinates of the 1st vertex 
float y0 = model->vertices[3 * 0 + 1]; // y coordinates of the 1st vertex
float z0 = model->vertices[3 * 0 + 2]; // z coordinates of the 1st vertex

float x1 = model->vertices[3 * 1 + 1]; // x coordinates of the 2nd vertex
...

int triangle_count = obj_model->numtriangles; // # of triangles in the mesh
const GLMtriangle& triangle0 = model->triangles[0]; // 1st triangle
int index0 = triangle0.vindices[0]; // index of the 1st vertex of the 1st triangle
...
const GLMtriangle& triangle1 = model->triangles[1]; // 2nd triangle
...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.