00001
00002
00003
00004
00005 #include "std/config.H"
00006 #include "geom/gl_view.H"
00007 #include "zxsils_texture.H"
00008
00009 using mlib::Wpt;
00010
00011
00012
00013
00014 int
00015 ZcrossTexture::draw(CVIEWptr& v)
00016 {
00017 if (_ctrl)
00018 return _ctrl->draw(v);
00019
00020
00021 _patch->mesh()->build_zcross_strips();
00022
00023
00024
00025
00026
00027 const ZcrossPath& zx_sils = _patch->cur_zx_sils();
00028
00029 if (zx_sils.empty())
00030 return 1;
00031
00032
00033 GLfloat w = float(v->line_scale()*_width);
00034 static bool antialias = Config::get_var_bool("ANTIALIAS_SILS",true,true);
00035 static bool drawback = Config::get_var_bool("DRAW_BACKFACING",false,true);
00036 if (antialias) {
00037
00038 GL_VIEW::init_line_smooth(w, GL_CURRENT_BIT);
00039 } else {
00040
00041 glPushAttrib(GL_LINE_BIT | GL_ENABLE_BIT | GL_CURRENT_BIT);
00042 glLineWidth(w);
00043 }
00044
00045 glDisable(GL_BLEND);
00046 glDisable(GL_LIGHTING);
00047 GL_COL(_color, alpha());
00048
00049
00050
00051 int n = zx_sils.num();
00052 bool started = false;
00053 bool lvis = false;
00054 bool vis = false;
00055
00056 static bool nodots = Config::get_var_bool("ZX_NO_DOTS",false,true);
00057 static bool nocolor = Config::get_var_bool("ZX_NO_COLOR",false,true);
00058
00059
00060 static bool closed = Config::get_var_bool("ZX_CLOSED",false,true);
00061
00062 srand48(0);
00063 if (!nocolor)
00064 glColor3d ( drand48(), drand48(), drand48() );
00065 else
00066 glColor3d ( 0.0, 0.0, 0.0 );
00067
00068 Wpt wp;
00069
00070 if (!nodots) {
00071 glPointSize(5.0);
00072 glBegin ( GL_POINTS ) ;
00073 for ( int k =0 ; k < n; k++ ) {
00074 glColor3d ( 0.0 , 0.0 , 1.0 );
00075 if ( zx_sils.face(k) == NULL )
00076 glColor3d ( 1.0, 0, 0 );
00077 glVertex3dv ( zx_sils.point(k).data() );
00078 }
00079 glEnd();
00080 }
00081 if ( !drawback ) {
00082 for (int i=0; i < n; i++) {
00083
00084 vis = zx_sils.grad(i);
00085
00086
00087 if ( vis ) {
00088
00089 if (!started ) {
00090 if ( zx_sils.face(i) ) {
00091 glBegin(GL_LINE_STRIP);
00092 zx_sils.face(i)->bc2pos ( zx_sils.bc(i) , wp );
00093 glVertex3dv( wp.data());
00094 started = true;
00095 }
00096 } else {
00097 if ( zx_sils.face(i) && i < n-1 ) {
00098 zx_sils.face(i)->bc2pos ( zx_sils.bc(i) , wp );
00099 glVertex3dv( wp.data());
00100 } else {
00101 zx_sils.face(i-1)->bc2pos ( zx_sils.bc(i) , wp );
00102 glVertex3dv( wp.data());
00103 glEnd();
00104 started = false;
00105 }
00106 }
00107 } else if ( lvis && started ) {
00108
00109 zx_sils.face(i-1)->bc2pos ( zx_sils.bc(i-1) , wp );
00110 glVertex3dv( wp.data());
00111 glEnd();
00112 started=false;
00113 }
00114 lvis = vis;
00115
00116 if ( !zx_sils.face(i) ) {
00117 if (!nocolor)
00118 glColor3d ( drand48(), drand48(), drand48() );
00119 else
00120 glColor3d ( 0.0, 0.0, 0.0);
00121 }
00122 }
00123 } else {
00124 Wpt first;
00125 for (int i=0; i < n; i++) {
00126 vis = true;
00127 if ( vis ) {
00128
00129 if (!started ) {
00130 if ( zx_sils.face(i) ) {
00131 glBegin(GL_LINE_STRIP);
00132 zx_sils.face(i)->bc2pos ( zx_sils.bc(i) , wp );
00133 if (!nocolor) {
00134 if ( !zx_sils.grad(i) )
00135 glColor3d( 1.0, 0.0 ,0.0 );
00136 else
00137 glColor3d( 0.0 , 0.0, 1.0 );
00138 } else {
00139 glColor3d( 0.0 , 0.0, 0.0 );
00140 }
00141 first = wp;
00142 glVertex3dv( wp.data());
00143 started = true;
00144 }
00145 } else {
00146 if (!nocolor) {
00147 if ( !zx_sils.grad(i) )
00148 glColor3d( 1.0, 0.0 ,0.0 );
00149 else
00150 glColor3d( 0.0 , 0.0, 1.0 );
00151 } else
00152 glColor3d( 0.0 , 0.0, 0.0 );
00153
00154 if ( zx_sils.face(i) && i < n-1 ) {
00155 zx_sils.face(i)->bc2pos ( zx_sils.bc(i) , wp );
00156 glVertex3dv( zx_sils.point(i).data());
00157 } else {
00158 zx_sils.face(i-1)->bc2pos ( zx_sils.bc(i) , wp );
00159 glVertex3dv( zx_sils.point(i-1).data());
00160 if (closed)
00161 glVertex3dv( first.data());
00162 glEnd();
00163 started = false;
00164 }
00165 }
00166 } else if ( lvis && started ) {
00167
00168 zx_sils.face(i-1)->bc2pos ( zx_sils.bc(i-1) , wp );
00169 glVertex3dv( zx_sils.point(i-1).data());
00170 glEnd();
00171 started=false;
00172 }
00173 lvis = vis;
00174 }
00175 }
00176
00177
00178 if (antialias)
00179 GL_VIEW::end_line_smooth();
00180 else
00181 glPopAttrib();
00182
00183 return 1;
00184 }
00185
00186