Programming and Graphics

(Kiana) #1

250 Introduction to C++ Programming and Graphics


The main programobj3dis identical to programplot3d, except that
the data definition module reads:


int vertices;

ifstream file9("obj3d.inp");

nc = 0; // count the number of elements

another:

file9 >> vertices; // number of vertices
if(vertices==0){goto done;}// end of triangles

nc = nc+1;
np[nc]==vertices;
for(int i=1; i<=vertices;i++)
{
file9 >> xd[nc][i] >> yd[nc][i] >> zd[nc][i];
}

goto another; // read again
done: // done reading

file9.close();
cout << nc;

The triangle vertices are recorded in the fileobj3d.inpin the following
format:


3
0.00000 0.00000 0.62573
0.08762 0.00000 0.62272
0.00000 0.17524 0.62272
3
0.08762 0.00000 0.62272
...
3
0.48196 -1.15671 -0.33737
0.57835 -0.96392 -0.33737
0.57174 -1.14349 -0.26681
0

where the three dots denote further element blocks.


The graphics output of the code is shown in Figure 7.8.1.
Free download pdf