⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 glbox.c

📁 任意给定三维空间的点集
💻 C
📖 第 1 页 / 共 2 页
字号:
    glRotatef( xRot, 1.0, 0.0, 0.0 );     glRotatef( yRot, 0.0, 1.0, 0.0 );     glRotatef( zRot, 0.0, 0.0, 1.0 );    glTranslatef( xTrans, yTrans, 0 );    GLfloat specular [] = { 0.250, 0.25, 0.25, 1.0 };    GLfloat shininess [] = { 10000.050 };    //GLfloat position1 [] = { 1000.0, 1000.0, -1000, 0.0 };        // Set the clear color to black    glClearColor(0.6, 0.6, 0.6, 0 );    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);        // Set the shading model    glShadeModel(GL_SMOOTH);        // Set the polygon mode to fill    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);    //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);        // Enable depth testing for hidden line removal    glEnable(GL_DEPTH_TEST);        // Define material properties of specular color and degree of     // shininess.  Since this is only done once in this particular     // example, it applies to all objects.  Material properties can     // be set for individual objects, individual faces of the objects,    // individual vertices of the faces, etc...     glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);    glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, shininess);        // Set the GL_AMBIENT_AND_DIFFUSE color state variable to be the    // one referred to by all following calls to glColor    glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);    glEnable(GL_COLOR_MATERIAL);        double param = 0.9145;    GLfloat lmodel_ambient[] = { param, param, param, 1.0 };    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);    // Create a Directional Light Source    GLfloat position [] = { 1000.0, 1000.0, 1000, 0.0 };    GLfloat light0_diffuse[] = { 1.0, 1.0, 1.0, 1.0};    glEnable( GL_NORMALIZE );    //glDisable( GL_CULL_FACE );    glLightfv(GL_LIGHT0, GL_POSITION, position );    glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);    //static GLfloat pos[4] = {5.0, 5.0, 10.0, 1.0 };    //glLightfv( GL_LIGHT0, GL_POSITION, pos );        //glLightfv(GL_LIGHT1, GL_POSITION, position1 );        glEnable(GL_LIGHT0);    glEnable(GL_LIGHT1);    glEnable(GL_LIGHTING);}#endif  // GOGIvoid  draw_vertex( H3dsVert   & v, double  fscale ){    /*printf( "draw_vertex: (%g, %g, %g)\n",            (v.x + glb_translate_x ) * glb_scale,            (v.y + glb_translate_y ) * glb_scale,            (v.z + glb_translate_z ) * glb_scale );    */    glVertex3f( (v.x + glb_translate_x ) * glb_scale,                (v.y + glb_translate_y ) * glb_scale,                (v.z + glb_translate_z ) * glb_scale );}void  transform_pnt( const H3dsVert   & v,                     Point3d  & pnt ){    pnt.setCoord( 0, (v.x + glb_translate_x ) * glb_scale );    pnt.setCoord( 1, (v.y + glb_translate_y ) * glb_scale );    pnt.setCoord( 2, (v.z + glb_translate_z ) * glb_scale );}void  transform_pnt( const Point3d   & v,                     Point3d  & pnt ){    pnt.setCoord( 0, (v[0] + glb_translate_x ) * glb_scale );    pnt.setCoord( 1, (v[1] + glb_translate_y ) * glb_scale );    pnt.setCoord( 2, (v[2] + glb_translate_z ) * glb_scale );}void   do_draw_polymodel( PolyModel * scene ){    ArrPoint3d  & verts( scene->getVertices() );    bool   f_worst_vertex;    int  max;    double  radius;    Point3d  worst_vertex;    max = scene->getFacesNum();    f_worst_vertex = true;    if  ( ( ! f_worst_vertex )  &&  ( max > 50000 ) )        max = 50000;    radius = scene->modelBB.get_diam() / 12.0;    if  ( f_worst_vertex )         worst_vertex = scene->getWorstVertex();    printf( "\n\nWorst vertex: " );    worst_vertex.print();    printf( "\n\n" );    printf( "radius: %g\n", radius );    for  ( int  ind = 0; ind < max; ind++ ) {        FaceIds   face;                face = scene->getFace( ind );                Point3d   & v0( verts[ face.a ] );                if  ( ( f_worst_vertex )                &&  ( pnt_distance( v0, worst_vertex ) > radius ) )            continue;        Point3d   & v1( verts[ face.b ] );        Point3d   & v2( verts[ face.c ] );                Point3d  pnts[ 3 ];                transform_pnt( v0, pnts[ 0 ] );        transform_pnt( v1, pnts[ 1 ] );        transform_pnt( v2, pnts[ 2 ] );                            Point3d  norm = pnt_get_triangle_norm( pnts[ 0 ], pnts[ 1 ],                                               pnts[ 2 ] );                            glColor3f( 0.0, 1.0, 1.0 );                //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);        glBegin(GL_POLYGON);                              glNormal3f( norm[ 0 ], norm[ 1 ], norm[ 2 ] );                                glVertex3f( pnts[ 0 ][ 0 ], pnts[ 0 ][ 1 ], pnts[ 0 ][ 2 ] );        glNormal3f( norm[ 0 ], norm[ 1 ], norm[ 2 ] );                        glVertex3f( pnts[ 1 ][ 0 ], pnts[ 1 ][ 1 ], pnts[ 1 ][ 2 ] );        glNormal3f( norm[ 0 ], norm[ 1 ], norm[ 2 ] );                        glVertex3f( pnts[ 2 ][ 0 ], pnts[ 2 ][ 1 ], pnts[ 2 ][ 2 ] );                //draw_vertex( v0, fscale );        //draw_vertex( v1, fscale );        //draw_vertex( v2, fscale );                glEnd();                /*        glColor3f( 1.0, 0.0, 0.0 );                glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);        glBegin(GL_POLYGON);                              glNormal3f( norm[ 0 ], norm[ 1 ], norm[ 2 ] );                                glVertex3f( pnts[ 0 ][ 0 ], pnts[ 0 ][ 1 ], pnts[ 0 ][ 2 ] );        glNormal3f( norm[ 0 ], norm[ 1 ], norm[ 2 ] );                        glVertex3f( pnts[ 1 ][ 0 ], pnts[ 1 ][ 1 ], pnts[ 1 ][ 2 ] );        glNormal3f( norm[ 0 ], norm[ 1 ], norm[ 2 ] );                        glVertex3f( pnts[ 2 ][ 0 ], pnts[ 2 ][ 1 ], pnts[ 2 ][ 2 ] );                //draw_vertex( v0, fscale );        //draw_vertex( v1, fscale );        //draw_vertex( v2, fscale );                glEnd();        */            }}void   do_draw( H3dsScene * scene ){    //printf( "do_draw!\n" );    //printf( "scene->meshobjs: %d\n",    //        scene->meshobjs );    for  ( int  ind = 0; ind < scene->meshobjs; ind++ ) {        H3dsMeshObj  & obj( scene->meshobjlist[ ind ] );        for  ( int  ind = 0; ind < obj.faces; ind++ ) {            H3dsFace   & face( obj.facelist[ ind ] );            H3dsVert   & v0( obj.vertlist[ face.p0 ] );            H3dsVert   & v1( obj.vertlist[ face.p1 ] );            H3dsVert   & v2( obj.vertlist[ face.p2 ] );            Point3d  pnts[ 3 ];                        transform_pnt( v0, pnts[ 0 ] );            transform_pnt( v1, pnts[ 1 ] );            transform_pnt( v2, pnts[ 2 ] );                        Point3d  norm = pnt_get_triangle_norm( pnts[ 0 ], pnts[ 1 ],                                                   pnts[ 2 ] );                        //printf( "v0: (%g, %g, %g)\n",            //        v0.x, v0.y, v0.z );            //printf( "v1: (%g, %g, %g)\n",            //        v1.x, v1.y, v1.z );            //printf( "v2: (%g, %g, %g)\n",            //        v2.x, v2.y, v2.z );            glColor3f( 0.0, 1.0, 1.0 );            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);            glBegin(GL_POLYGON);                          glNormal3f( norm[ 0 ], norm[ 1 ], norm[ 2 ] );                            glVertex3f( pnts[ 0 ][ 0 ], pnts[ 0 ][ 1 ], pnts[ 0 ][ 2 ] );            glNormal3f( norm[ 0 ], norm[ 1 ], norm[ 2 ] );                            glVertex3f( pnts[ 1 ][ 0 ], pnts[ 1 ][ 1 ], pnts[ 1 ][ 2 ] );            glNormal3f( norm[ 0 ], norm[ 1 ], norm[ 2 ] );                            glVertex3f( pnts[ 2 ][ 0 ], pnts[ 2 ][ 1 ], pnts[ 2 ][ 2 ] );            //draw_vertex( v0, fscale );            //draw_vertex( v1, fscale );            //draw_vertex( v2, fscale );                    glEnd();            glColor3f( 1.0, 0.0, 0.0 );            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);            glBegin(GL_POLYGON);                          glNormal3f( norm[ 0 ], norm[ 1 ], norm[ 2 ] );                            glVertex3f( pnts[ 0 ][ 0 ], pnts[ 0 ][ 1 ], pnts[ 0 ][ 2 ] );            glNormal3f( norm[ 0 ], norm[ 1 ], norm[ 2 ] );                            glVertex3f( pnts[ 1 ][ 0 ], pnts[ 1 ][ 1 ], pnts[ 1 ][ 2 ] );            glNormal3f( norm[ 0 ], norm[ 1 ], norm[ 2 ] );                            glVertex3f( pnts[ 2 ][ 0 ], pnts[ 2 ][ 1 ], pnts[ 2 ][ 2 ] );            //draw_vertex( v0, fscale );            //draw_vertex( v1, fscale );            //draw_vertex( v2, fscale );                    glEnd();        }    }}void GLBox::drawScene(){    int  delta;    //printf( "drawScene!\n" );    if  ( scene == NULL ) {        delta = max( p_arr->size() / 1000, 1 );        for  ( int  ind = 0; ind < p_arr->size(); ind += delta ) {            Point3d  & pnt( (*p_arr)[ ind ] );                        glColor3f( 0.0, 0.0, 1.0 );            glPushMatrix();            glTranslatef( pnt[ 0 ], pnt[ 1 ], pnt[ 2 ] );            glutSolidCube( 0.01 );            glPopMatrix();                }    }    if  ( p_diam_pair != NULL ) {        glColor3f( 1.0, 0.0, 0.0 );        glPushMatrix();        glTranslatef( p_diam_pair->p[ 0 ],                      p_diam_pair->p[ 1 ],                       p_diam_pair->p[ 2 ] );        glutSolidCube( 0.02 );        glPopMatrix();                glPushMatrix();        glTranslatef( p_diam_pair->q[ 0 ],                      p_diam_pair->q[ 1 ],                       p_diam_pair->q[ 2 ] );        //glutSolidSphere( 1.0, 4, 4 );        //printf( "solid!\n" );        glutSolidCube( 0.02 );        glPopMatrix();            }    if  ( scene != NULL )         do_draw( (H3dsScene *)scene );    if  ( poly_scene != NULL )         do_draw_polymodel( (PolyModel *)poly_scene );    glFlush();}/*!  Generate an OpenGL display list for the object to be shown, i.e. the box*/GLuint GLBox::makeObject(){	    GLuint list;    list = glGenLists( 1 );    glNewList( list, GL_COMPILE );    glEndList();    return list;}//int NumVerts = 0;void   GLBox::comp_diameter(){    p_diam_pair = tester_inner( p_arr, "" );    resetDisplay();        repaint();}/* glbox.C - End of File ------------------------------------------*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -