// end a GL command list void VRML_LAYER::glEnd( void ) { switch( glcmd ) { case GL_LINE_LOOP: { // add the loop to the list of outlines std::list<int>* loop = new std::list<int>; if( !loop ) break; for( unsigned int i = 0; i < vlist.size(); ++i ) { loop->push_back( vlist[i]->o ); } outline.push_back( loop ); } break; case GL_TRIANGLE_FAN: processFan(); break; case GL_TRIANGLE_STRIP: processStrip(); break; case GL_TRIANGLES: processTri(); break; default: break; } while( !vlist.empty() ) vlist.pop_back(); glcmd = 0; }
// end a GL command list void VRML_LAYER::glEnd( void ) { switch( glcmd ) { case GL_LINE_LOOP: { // add the loop to the list of outlines std::list<int>* loop = new std::list<int>; if( !loop ) break; double firstX = 0.0; double firstY = 0.0; double lastX = 0.0; double lastY = 0.0; double curX, curY; double area = 0.0; if( vlist.size() > 0 ) { loop->push_back( vlist[0]->o ); firstX = vlist[0]->x; firstY = vlist[0]->y; lastX = firstX; lastY = firstY; } for( size_t i = 1; i < vlist.size(); ++i ) { loop->push_back( vlist[i]->o ); curX = vlist[i]->x; curY = vlist[i]->y; area += ( curX - lastX ) * ( curY + lastY ); lastX = curX; lastY = curY; } area += ( firstX - lastX ) * ( firstY + lastY ); outline.push_back( loop ); if( area <= 0.0 ) solid.push_back( true ); else solid.push_back( false ); } break; case GL_TRIANGLE_FAN: processFan(); break; case GL_TRIANGLE_STRIP: processStrip(); break; case GL_TRIANGLES: processTri(); break; default: break; } while( !vlist.empty() ) vlist.pop_back(); glcmd = 0; }