The TriMesh allows you to create a series of vertices linked into a mesh.
To create a simple pair of Triangles linked into a quad first add the 4 vertices to the TriMesh using \a appendVertex() and then add the vertices using the \a appendTriangle() method and passing the indices of the 3 vertices you want to connect Trimesh mesh; mesh.appendVertex(Vec3f(10, 10, 0 )); // appends the vertex mesh.appendColorRGB( Color(1, 0, 0) ); // sets the color for the vertex to red mesh.appendVertex( Vec3f(10, 100, 0) ); // appends the next vertex mesh.appendColorRGB( Color( 0, 1, 0 ) ); // sets the color for the next vertex to green mesh.appendVertex( Vec3f(100, 100, 0) ); mesh.appendColorRGB( Color( 0, 1, 0 ) ); mesh.appendVertex( Vec3f(100, 10, 0 )); mesh.appendColorRGB( Color( 1, 0, 0 ) );
get the index of the vertex. not necessary with this example, but good practice int vIdx0 = mesh.getNumVertices() - 4; int vIdx1 = mesh.getNumVertices() - 3; int vIdx2 = mesh.getNumVertices() - 2; int vIdx3 = mesh.getNumVertices() - 1;
now create the triangles from the vertices mesh.appendTriangle( vIdx0, vIdx1, vIdx2 ); mesh.appendTriangle( vIdx0, vIdx2, vIdx3 );