The polyhedra has a triangular base with vertices:
v0 = (0,0,0) v1 = (1,0,0) v2 = (0.5,1,0) and uppermost vertex v3 = (0.5,0.5,1).
The 4 sides are:
base: v0, v2,v1
front: v0,v1,v3
right: v2,v3,v1
left: v0,v3,v2
There should really be a a file containing this information: eg,
simple_object.dat
4 number of vertices 0.0 0.0 0.0 vertex 0 1.0 0.0 0.0 vertex 1 0.5 1.0 0.0 vertex 2 0.5 0.5 1.0 vertex 3 define material 4 number of faces 3 number of vertices in face 0 0 2 1 vertices in face 0 define material usually will be 0 3 0 1 3 .......................... define material usually will be 0 3 2 3 1 define material usually will be 0 3 number of vertices in face 3 0 3 2 vertices in face 3 define material usually will be 0
Then you'd need a function to read the data from the file to build the Vertex-Face data structure.
Here, for illustrative purposes only, we will build the object directly, ie, without reading from a file.
/*defines total number of polygons allowed for the scene*/ #define MAX_FOR_SCENE 100 VertexArray *v; Face *face; FaceArray *facearray; int n, start, finish, i; GObject *simpleObject; v = newVertex(4); atPutVertex(v,0.0,0.0,0.0); atPutVertex(v,1.0,0.0,0.0); atPutVertex(v,0.5,1.0,0.0); atPutVertex(v,0.5,0.5,0.0); /*now create each face and add to the facearray*/ facearray = newFaceArray(MAX_FOR_SCENE); /*for face 0*/ face = newFace(v,0); addVertexToFace(face,2); addVertexToFace(face,1); /*put into face array at next free slot*/ start = n = nextFreeFaceArray(facearray); atPutFaceArray(facearray,n,face); /*for face 1*/ face = newFace(v,0); addVertexToFace(face,1); addVertexToFace(face,3); /*put into face array at next free slot*/ n = nextFreeFaceArray(facearray); atPutFaceArray(facearray,n,face); /*for face 2*/ face = newFace(v,2); addVertexToFace(face,3); addVertexToFace(face,1); /*put into face array at next free slot*/ n = nextFreeFaceArray(facearray); atPutFaceArray(facearray,n,face); /*for face 3*/ face = newFace(v,0); addVertexToFace(face,3); addVertexToFace(face,2); /*put into face array at next free slot*/ finish = n = nextFreeFaceArray(facearray); atPutFaceArray(facearray,n,face); /*compute the plane equations*/ for(i=start; i<=finish;++i) setPlaneEqOfFace(atFaceArray(facearray,i)); /*now create the object*/ simpleObject = newObject(facearray,1); addFacesToObject(simpleObject,start,finish-start+1);
Recall that we are using one FaceArray for the whole scene. Here the object we are creating happens to be the first one in, but that won't usually be the case, obviously. So we record the start and finish positions of the object in the FaceArray so that we know which range of the FaceArray to put into the GObject specification. Note that the above has not dealt at all with material, so this object will have a a default material.