Hello,
I’m new to working with graphics in 3-D and openGL. I’m trying to get my head around the relationship between vertices and indices in oFMesh. I’ve been looking at Josh’s openGL tutorial (http://www.openframeworks.cc/tutorials/graphics/opengl.html) and the Programming Interactivity Book (http://shop.oreilly.com/product/0636920021735.do) Chapter 13: Graphics and openGL (along with a few other resources).
“A vertex is where a point in the mesh is located in 3-D space. An index is where that point is within the mesh” (Book)
"It’s (the index?) just a way of saying: I want this vertex to be used at this location. The mesh goes through the list of indices connected each set of three indices, each of which represents a vertex in the vertex array, to another vertex. It’s pretty rad and it saves you having to make and store more indices than necessary. A more typical usage is something like the following: (site)
ofMesh mesh;
for (int y = 0; y < height; y++){
for (int x = 0; x<width; x++){
mesh.addVertex(ofPoint(x,y,0)); // make a new vertex
mesh.addColor(ofFloatColor(0,0,0)); // add a color at that vertex
}
}
// now it's important to make sure that each vertex is correctly connected with the
// other vertices around it. This is done using indices, which you can set up like so:
for (int y = 0; y<height-1; y++){
for (int x=0; x<width-1; x++){
mesh.addIndex(x+y*width); // 0
mesh.addIndex((x+1)+y*width); // 1
mesh.addIndex(x+(y+1)*width); // 10
mesh.addIndex((x+1)+y*width); // 1
mesh.addIndex((x+1)+(y+1)*width); // 11
mesh.addIndex(x+(y+1)*width); // 10
}
}
I was thinking of the indices as a collection of all of the triangle points, per triangle, including the duplicate points (places where the triangles connect). I see the vertex as the specific location in space. But, I can’t get that to cognitively map correctly between the above code (addVertex & addMesh supplied values).
I was also looking at the isocahedron code example, and still puzzled.
#pragma once
#include "ofMain.h"
const int X = 158;
const int Z = 256;
//This is the data for the vertices, which keeps the data as simple as possible:
static GLfloat vdata[12][3] = {
{-X, 0.0, Z}, {X, 0.0, Z}, {-X, 0.0, -Z}, {X, 0.0, -Z},
{0.0, Z, X}, {0.0, Z, -X}, {0.0, -Z, X}, {0.0, -Z, -X},
{Z, X, 0.0}, {-Z, X, 0.0}, {Z, -X, 0.0}, {-Z, -X, 0.0} };
//data for the indices, representing the index of the vertices
//that are to be connected into the triangle.
//Youll notice that for 12 vertices you need 20 indices of 3 vertices each:
static GLint indices[20][3] = {
{0,4,1}, {0,9,4}, {9,5,4}, {4,5,8}, {4,8,1}, {8,10,1}, {8,3,10}, {5,3,8}, {5,2,3}, {2,7,3}, {7,10,3}, {7,6,10}, {7,11,6}, {11,0,6}, {0,1,6}, {6,1,10}, {9,0,11}, {9,11,2}, {9,2,5}, {7,2,11}
};
class icosahedron : public ofBaseApp{
public:
float ang;
ofMesh mesh;
void setup();
void update();
void draw();
};
Hmm…Can anyone shed some light on this? It’s still a bit foggy to me. Cheers!