PDA

View Full Version : object structure problem



04-03-2002, 01:39 AM
im trying to set up a structure for an object so i can redisplay all objects through a for loop as i add them . I call the draw_world method from the display method but when i try to run the program i get an unhandled exception saying "Error: expression cannot be evaluated" for each x1,y1,x2,y2 etc. what am i doing wrong thanks.


typedef struct {
GLfloat x1,y1,x2,y2,x3,y3,x4,y4,z; /* Vertices of polygon */
}object_type;

typedef struct
{
object_type object[50];
}world_data;

world_data *ot;
int object_count;

void init_world(world_data *ot)
{
object_count = 1;

/* object 1 - */


ot->object[0].x1 = 0.0;
ot->object[0].y1 = 0.0;
ot->object[0].x2 = 0.0;
ot->object[0].y2 = 0.2;
ot->object[0].x3 = 0.2;
ot->object[0].y3 = 0.2;
ot->object[0].x4 = 0.2;
ot->object[0].y4 = 0.0;
ot->object[0].z = 0.0;


}

void drawPolygon (GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2, GLfloat x3, GLfloat y3,GLfloat x4, GLfloat y4, GLfloat z)
{

glBegin (GL_POLYGON);
glVertex3f (x1, y1, z);
glVertex3f (x2, y2, z);
glVertex3f (x3, y3, z);
glVertex3f (x4, y4, z);
glEnd ();
}

void draw_world(world_data *ot)
{
init_world(ot);

int obj; // object counter

//////////////////////////////
// draw all the objects
for (obj = 0; obj < object_count; obj++) {


glPushMatrix();

drawPolygon(ot->object[obj].x1, ot->object[obj].y1,ot->object[obj].x2, ot->object[obj].y2,ot->object[obj].x3, ot->object[obj].y3,ot->object[obj].x4, ot->object[obj].y4, ot->object[obj].z);

glPopMatrix();
}
}

Morglum
04-03-2002, 02:28 AM
have you allocated memory for ot?
I mean, there should be somewhere at the beginning of your program a line like :
ot = new world_data;

Morglum

04-03-2002, 04:23 AM
that worked thanks alot