PDA

View Full Version : Vertex array's for creating objects.



nexusone
02-01-2002, 08:38 AM
I have been trying to move away from having hard coded objects to using vertex array's to create my objects. I see this as a more flexible way to deal with an object.

With vertex array's maping 2D objects I have had good luck. but now I am working on creating 3D objects from vertex array's and having some problems of faces not being drawn.

I have been working with primitive shapes, and a four faced pryamid worked out fine.
Then someone here asked about a 5 faced pryamid so I redid my array to have 5 faces.

But now one of the faces does not come out right.

Here is my vertex array data for a five faced pryamid.

typedef struct
{
GLfloat xyz[3];

}Point3F;

static Point3F pryamid[21] = {{0.0f,1.0f,0.0f},{-1.0f,-1.0f,1.0f},{1.0f,-1.0f,1.0f},{0.0f,1.0f,0.0f},
{0.0f,1.0f,0.0f},{1.0f,-1.0f,1.0f},{1.0f,-1.0f,-1.0f},{0.0f,1.0f,0.0f},
{0.0f,1.0f,0.0f},{1.0f,-1.0f,-1.0f},{-1.0f,-1.0f,-1.0f},{0.0f,1.0f,0.0f},
{0.0f,1.0f,0.0f},{-1.0f,-1.0f,-1.0f},{-1.0f,-1.0f,1.0f},{0.0f,1.0f,0.0f},
{-1.0f,-1.0f,1.0f},{1.0f,-1.0f,1.0f},{1.0f,-1.0f,-1.0f},{-1.0f,-1.0f,-1.0f},{-1.0f,-1.0f,1.0f}};


glBegin(GL_POLYGON); //Draw it.
for(i=0;i<=20;i++)
{
glColor3f( abs(pryamid[i].xyz[0]), abs(pryamid[i].xyz[1]),abs(pryamid[i].xyz[2]));
glVertex3fv( &pryamid[i] );
}
glEnd();