3Д БУМ

3Д принтеры и всё что с ними связано

ЗД принтеры АБС пластик

Rendering the Results for the First Time

I bet you are anxious to see some results of your hard work, even though you haven’t added textures yet. In this section, you learn how to render the frames by themselves. A frame in the case of an MD2 model is simply a snapshot of the model in a certain position—simply different versions of the same set of vertices. For this reason, the other aspects of the model, such as the vertex indexes and texture coordi­nates, do not change.

It’s fairly simple; all you need are a few simple OpenGL commands, as follows:

■ glBegin(GL_TRIANGLES); tells the OpenGL that the vertices you send to it should be formed into triangles with every three vertices forming a separate triangle.

■ The glVertex3fv command sends OpenGL an array of three floating-point values that make up a three-dimensional vertex.

■ Last, glEnd() tells OpenGL that you are done rendering the triangles. All you need to do is render plain old triangles.

Take a look at the following code:

glBegin(GL_TRIANGLES); //You want to render triangles for(int i = 0; i < m_Head. m_iNumTriangles; i++)

//Loop through all the triangles, the number of //which is given in the file header.

{

//each triangle has exactly three vertices //the triangle structure contains three vertex indexes,

//and each frame contains its own vertices glVertex3fv(

m_pFrames[frame].m_pVerts[m_pTriangles[i].m_sVertIndices[0]]); glVertex3fv(

m_pFrames[frame].m_pVerts[m_pTriangles[i].m_sVertIndices[1]]); glVertex3fv(

m_pFrames[frame].m_pVerts[m_pTriangles[i].m_sVertIndices[2]]);

}

glEnd(); //Finish up with the list of triangles

Ugh, those vertex calls are a little confusing; lets break them down a little bit more. Each vertex looks something like this:

m_pFrames[frame].m_pVerts[m_pTriangles[i].m_sVertIndiaes[0]]

■ m_pFrames is an array that holds all of your frame data, including vertices.

■ frame is an index into the array of frames, it tells you which set of vertices to use. For instance, if frame was 0, it would use the vertices from frame #0.

Because each frame has its own set of vertices, .m_pVerts is a member of each frame structure. It holds every vertex for the frame. Using the triangle indexes, you must pick out which vertex you need. That’s where m_pTriangles[i].m_sVertIndices[0] comes in. m_pTriangles is the array of triangles, each which contains three vertex indexes. The i indicates which triangle is currently being rendered so the renderer knows which set of indexes to use. The very last part, m_sVertIndices[0], is the vertex index itself. Being that there are three of them, one for each point in the triangle, the 0, 1, and 2 are used to get each point, respectively.

Pretty cool, isn’t it? To look at the complete rendering code, check out the Render() function of the CMd2 class. This function will render the model in its initial position. Although there is extra code in the function for texturing, you should still be able to see the geometry code alone.

Just disregard any commands with “texture” or “texcoord” in them, such as glTexCoord2D. The remaining code will just render the triangles; try commenting out the lines pertaining to textures and recompiling.

Your email address will not be published. Required fields are marked *

*