Drawing sharp edges

The simplest way to achieve sharp edges is to add the vertices for all the triangles in mesh and not use the addTriangle() function at all and then call the mesh.setupIndicesAuto() function, which sets indices automatically such that vertices (0, 1, 2) are used for drawing the first triangle, vertices (4, 5, 6) for the second triangle, and so on.

Note

This is example 07-3D/04-PyramidSharpEdges. This example is a good starting point for drawing sharp 3D objects.

It is based on example 07-3D/03-PyramidLighting.

In the example with the pyramid, replace all the lines with addVertex() and addTriangle() with the following lines:

//Pyramid's base vertices
ofPoint v0 = ofPoint( -200, -100, 0 );
ofPoint v1 = ofPoint( 200, -100, 0 );
ofPoint v2 = ofPoint( 0, 200, 0 );
//Pyramid's top vertex
ofPoint v3 = ofPoint( 0, 0, 100 );
//Add triangles by its vertices
mesh.addVertex( v3 ); mesh.addVertex( v2 ); mesh.addVertex( v0 );
mesh.addVertex( v3 ); mesh.addVertex( v1 ); mesh.addVertex( v2 );
mesh.addVertex( v3 ); mesh.addVertex( v0 ); mesh.addVertex( v1 );
mesh.setupIndicesAuto();    //Set up indices

As a result, you will see a pyramid with sharp edges as shown in the following screenshot:

Drawing sharp edges

We have considered a basic workflow with meshes. Now we will consider other useful capabilities of the ofMesh class.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset