Files Classes Functions Hierarchy
00001 #include <cassert> 00002 using namespace std; 00003 00004 #include <gobj.h> 00005 #include <mazedisp02.h> 00006 #include <pointsdisplay.h> 00007 #include <typedefs.h> 00008 00009 00010 mazedisp02::mazedisp02 00011 ( 00012 doublec dx_, 00013 mazematrixD2<uint> const & mz_ 00014 ) 00015 : mz(mz_), dx(dx_), displaycellid(false), 00016 pipes(false), pipecolor(point3<double>(1.0,0.0,0.0)), 00017 walls(true), wallcolor(point3<double>(0.0,0.0,1.0)) 00018 { 00019 } 00020 00021 void mazedisp02::draw() 00022 { 00023 assert(mz.valid()); 00024 assert(mz.vi.size()==(1+mz.dim[2])); 00025 00026 gobjpush(new gobjglDisable(GL_LIGHTING)); 00027 gobjpush(new gobjglBegin(GL_LINES)); 00028 00029 uint m=mz.dim[0]; 00030 uint n=mz.dim[1]; 00031 00032 00033 00034 uint id; 00035 point2<uint> pos1; 00036 point2<double> pos2; 00037 uint K=m*n-1; 00038 00039 if (walls) 00040 { 00041 gobjpush(new gobjglColor3d(wallcolor)); 00042 00043 for (uint k=0; k<mz.dim[2]; ++k) 00044 { 00045 id=k+1; 00046 pos1.x = k % n; 00047 pos1.y = K/n-k/n; 00048 pos2.x = dx*pos1.x; 00049 pos2.y = dx*pos1.y; 00050 celldraw(mz.vi[id],pos2); 00051 } 00052 } 00053 00054 if (pipes) 00055 { 00056 gobjpush(new gobjglColor3d(pipecolor)); 00057 for (uint k=0; k<mz.dim[2]; ++k) 00058 { 00059 id=k+1; 00060 pos1.x = k % n; 00061 pos1.y = K/n-k/n; 00062 pos2.x = dx*pos1.x; 00063 pos2.y = dx*pos1.y; 00064 celldraw2(mz.vi[id],pos2); 00065 } 00066 } 00067 00068 gobjpush(new gobjglEnd()); 00069 00070 if (displaycellid) 00071 { 00072 vector< point2<double> > pi; 00073 pi.push_back(point2<double>()); 00074 00075 for (uint k=0; k<mz.dim[2]; ++k) 00076 { 00077 id=k+1; 00078 pos1.x = k % n; 00079 pos1.y = K/n-k/n; 00080 pos2.x = dx*pos1.x; 00081 pos2.y = dx*pos1.y; 00082 00083 pi.push_back(pos2+point2<double>(dx*0.5,dx*0.5)); 00084 } 00085 00086 assert(gobjContainer::global); 00087 gobjpush(new gobjglColor3f(point3<float>(1.0,0.0,0.0))); 00088 pointsdisplay2D< point2<double> > pd(*gobjContainer::global,pi,false,true,true); 00089 } 00090 00091 } 00092 00093 00094 void mazedisp02::celldraw 00095 ( 00096 cellD2<uint> const & x, 00097 point2<double> const & p00 00098 ) 00099 { 00100 point2<double> p10 = p00; 00101 p10.x += dx; 00102 point2<double> p01 = p00; 00103 p01.y += dx; 00104 point2<double> p11 = p00; 00105 p11.x += dx; 00106 p11.y += dx; 00107 00108 if (x.ni[1]==0) 00109 { 00110 gobjpush(new gobjglVertex2d(p10)); 00111 gobjpush(new gobjglVertex2d(p11)); 00112 } 00113 00114 if (x.ni[3]==0) 00115 { 00116 gobjpush(new gobjglVertex2d(p01)); 00117 gobjpush(new gobjglVertex2d(p00)); 00118 } 00119 00120 00121 if (x.ni[0]==0) 00122 { 00123 gobjpush(new gobjglVertex2d(p01)); 00124 gobjpush(new gobjglVertex2d(p11)); 00125 } 00126 00127 if (x.ni[2]==0) 00128 { 00129 gobjpush(new gobjglVertex2d(p00)); 00130 gobjpush(new gobjglVertex2d(p10)); 00131 } 00132 } 00133 00134 void mazedisp02::celldraw2 00135 ( 00136 cellD2<uint> const & x, 00137 point2<double> const & p00 00138 ) 00139 { 00140 double dx2 = dx*0.5; 00141 00142 point2<double> p3 = p00; 00143 p3.y += dx2; 00144 point2<double> p1 = p00; 00145 p1.x += dx; 00146 p1.y += dx2; 00147 point2<double> p0 = p00; 00148 p0.x += dx2; 00149 p0.y += dx; 00150 point2<double> p2 = p00; 00151 p2.x += dx2; 00152 00153 point2<double> pcenter = p00; 00154 pcenter.x += dx2; 00155 pcenter.y += dx2; 00156 00157 if (x.ni[1]!=0) 00158 { 00159 gobjpush(new gobjglVertex2d(pcenter)); 00160 gobjpush(new gobjglVertex2d(p1)); 00161 } 00162 00163 if (x.ni[3]!=0) 00164 { 00165 gobjpush(new gobjglVertex2d(pcenter)); 00166 gobjpush(new gobjglVertex2d(p3)); 00167 } 00168 00169 if (x.ni[0]!=0) 00170 { 00171 gobjpush(new gobjglVertex2d(pcenter)); 00172 gobjpush(new gobjglVertex2d(p0)); 00173 } 00174 00175 if (x.ni[2]!=0) 00176 { 00177 gobjpush(new gobjglVertex2d(pcenter)); 00178 gobjpush(new gobjglVertex2d(p2)); 00179 } 00180 } 00181 00182
1.5.8