Polygon_set Parser::parsePolygonSetDefinition() { while (!_tokens.isDone()) { switch(_tokens.peek().type()) { case Token::KEYWORD_POLYGON: return Polygon_set(parsePolygonDefinition()); case Token::KEYWORD_MULTIPOLYGON: return parseMultipolygonDefinition(); default: std::cerr << "WARNING: Discarded invalid token: " << _tokens.peek().string() << std::endl; _tokens.discard(); break; } } return Polygon_set(); }
Polygon_set Parser::parseMultipolygonDefinition() { _tokens.consume(Token::KEYWORD_MULTIPOLYGON); if (_tokens.peek().type() == Token::KEYWORD_EMPTY) { _tokens.consume(Token::KEYWORD_EMPTY); return Polygon_set(); } return parsePolygonSet(); }
/* Adds a unit cube, axis-aligned and centered on zero to the Module. * If solid is zero, add only lines. If solid is non-zero, use * polygons. Only lines need to be supported now. */ void Module_cube(Module *md, int solid, Texture *tex[6]) { Point v[8]; Point tv[4]; Vector normal[4]; TextureCoord st[4]; printf("adding cube...\n"); // corners of a cube, centered at (0, 0, 0) Point_set( &v[0], -0.5, -0.5, -0.5 ); Point_set( &v[1], 0.5, -0.5, -0.5 ); Point_set( &v[2], 0.5, 0.5, -0.5 ); Point_set( &v[3], -0.5, 0.5, -0.5 ); Point_set( &v[4], -0.5, -0.5, 0.5 ); Point_set( &v[5], 0.5, -0.5, 0.5 ); Point_set( &v[6], 0.5, 0.5, 0.5 ); Point_set( &v[7], -0.5, 0.5, 0.5 ); // add only line if (solid == 0) { Line temp; Line_set(&temp,v[0],v[1]); Module_line(md,&temp); Line_set(&temp,v[0],v[3]); Module_line(md,&temp); Line_set(&temp,v[0],v[4]); Module_line(md,&temp); Line_set(&temp,v[1],v[2]); Module_line(md,&temp); Line_set(&temp,v[1],v[5]); Module_line(md,&temp); Line_set(&temp,v[2],v[3]); Module_line(md,&temp); Line_set(&temp,v[2],v[6]); Module_line(md,&temp); Line_set(&temp,v[3],v[7]); Module_line(md,&temp); Line_set(&temp,v[4],v[5]); Module_line(md,&temp); Line_set(&temp,v[4],v[7]); Module_line(md,&temp); Line_set(&temp,v[5],v[6]); Module_line(md,&temp); Line_set(&temp,v[6],v[7]); Module_line(md,&temp); } // use polygons else { Polygon temp; Polygon_setNULL(&temp); // THIS IS HARD-CODED !!!!! if (tex != NULL) { st[0].s = 372; st[0].t = 0; st[1].s = 0; st[1].t = 0; st[2].s = 0; st[2].t = 372; st[3].s = 372; st[3].t = 372; } // front side Polygon_set( &temp, 4, &(v[0]) ); Vector front = {{0.0,0.0,-1.0}}; normal[0] = normal[1] = normal[2] = normal[3] = front; Polygon_setNormals( &temp, 4, normal); if (tex != NULL) Module_texture(md,tex[0]); Polygon_setTexture(&temp, 4, st); Module_polygon(md,&temp); // back side Polygon_set( &temp, 4, &(v[4]) ); Vector back = {{0.0,0.0,1.0}}; normal[0] = normal[1] = normal[2] = normal[3] = back; Polygon_setNormals( &temp, 4, normal); if (tex != NULL) Module_texture(md,tex[1]); Polygon_setTexture(&temp, 4, st); Module_polygon(md,&temp); // top side Point_copy( &tv[0], &v[2] ); Point_copy( &tv[1], &v[3] ); Point_copy( &tv[2], &v[7] ); Point_copy( &tv[3], &v[6] ); Polygon_set( &temp, 4, tv ); Vector top = {{0.0,1.0,0.0}}; normal[0] = normal[1] = normal[2] = normal[3] = top; Polygon_setNormals( &temp, 4, normal); if (tex != NULL) Module_texture(md,tex[2]); Polygon_setTexture(&temp, 4, st); Module_polygon(md,&temp); // bottom side Point_copy( &tv[0], &v[0] ); Point_copy( &tv[1], &v[1] ); Point_copy( &tv[2], &v[5] ); Point_copy( &tv[3], &v[4] ); Polygon_set( &temp, 4, tv ); Vector bottom = {{0.0,-1.0,0.0}}; normal[0] = normal[1] = normal[2] = normal[3] = bottom; Polygon_setNormals( &temp, 4, normal); if (tex != NULL) Module_texture(md,tex[3]); Polygon_setTexture(&temp, 4, st); Module_polygon(md,&temp); // left side Point_copy( &tv[0], &v[0] ); Point_copy( &tv[1], &v[3] ); Point_copy( &tv[2], &v[7] ); Point_copy( &tv[3], &v[4] ); Polygon_set( &temp, 4, tv ); Vector left = {{-1.0,0.0,0.0}}; normal[0] = normal[1] = normal[2] = normal[3] = left; Polygon_setNormals( &temp, 4, normal); if (tex != NULL) Module_texture(md,tex[4]); Polygon_setTexture(&temp, 4, st); Module_polygon(md,&temp); // right side Point_copy( &tv[0], &v[1] ); Point_copy( &tv[1], &v[2] ); Point_copy( &tv[2], &v[6] ); Point_copy( &tv[3], &v[5] ); Polygon_set( &temp, 4, tv ); Vector right = {{1.0,0.0,0.0}}; normal[0] = normal[1] = normal[2] = normal[3] = right; Polygon_setNormals( &temp, 4, normal); if (tex != NULL) Module_texture(md,tex[5]); Polygon_setTexture(&temp, 4, st); Module_polygon(md,&temp); } return; }