Allink
v0.1
|
00001 /*********************************************************************** 00002 DrawDefinition: Create some useful lists 00003 Copyright (C) 2008-2010 by Giovanni Marelli <sabeiro@virgilio.it> 00004 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 You should have received a copy of the GNU General Public License 00016 along with this program; If not, see <http://www.gnu.org/licenses/>. 00017 ***********************************************************************/ 00018 #include "../../include/Draw.h" 00019 00020 #ifdef __glut_h__ 00021 void Draw::InitConstant(){ 00022 spin = 0.;angolo = 0.; dspin = .1 ; 00023 xp=0. ; yp=0. ; zp= 0.; zw = -1.; 00024 xa=0. ; ya=0. ; za= 0.; 00025 xf=55. ; yf=5. ; zf= 0.; 00026 xi=-.4 ; yi=-.4 ; zi= -0.; 00027 xLeg=-1.4; yLeg=-.3 ; zLeg= 0.; 00028 dxLeg=.4;dyLeg=.8; 00029 xl0=1. ; yl0=1. ; zl0=1.; 00030 xl1=1. ; yl1=0. ; zl1=1.; 00031 Rback = 1.0; Gback = 1.0;Bback = 1.0;Aback = 0.0; 00032 GridStep = 2.; 00033 for(int d=0;d<3;d++) 00034 GridEdge[d] = (int)(GridStep*Edge[d]*InvScaleUn); 00035 Step = 0; 00036 pr = 1;//prospettiva 00037 IfPoint = 1;//point or Sphere 00038 IfInfo = 1; 00039 IfImage = 0; 00040 IfScript = 1; 00041 IfBlend = 1; 00042 la = 1; 00043 gr = 0; 00044 lu = 1; 00045 sp = 1; 00046 ne = 0; 00047 AngleDxSx = 0.; 00048 AngleSuGiu = 0.; 00049 IfMaterial = 1; 00050 ChooseDepthMap(0); 00051 sprintf(info,""); 00052 } 00053 int Draw::DefQuad(int NSquare){ 00054 glDeleteLists(Quad,1); 00055 Quad = glGenLists(1); 00056 double xEdge = 1./(double)NSquare*Edge[0]*InvScaleUn; 00057 double yEdge = 1./(double)NSquare*Edge[1]*InvScaleUn; 00058 glNewList(Quad,GL_COMPILE); 00059 glBegin(GL_POLYGON); 00060 glNormal3f(0.,0.,1.); 00061 glVertex3f(0,0,0); 00062 glVertex3f(xEdge,0,0); 00063 glVertex3f(xEdge,yEdge,0); 00064 glVertex3f(0,yEdge,0); 00065 glEnd(); 00066 glEndList(); 00067 return Quad; 00068 } 00069 int Draw::DefHexagon(){ 00070 glDeleteLists(Hexagon,1); 00071 Hexagon = glGenLists(1); 00072 glNewList(Hexagon,GL_COMPILE); 00073 double Lato=0.01; 00074 glBegin(GL_POLYGON); 00075 // glBegin(GL_POINTS); 00076 // glVertex3f(0.,0.,0.); 00077 glNormal3f(0.,0.,1.); 00078 glVertex3f(Lato*.5,-Lato*.87,0.); 00079 glVertex3f(Lato,0.,0.); 00080 glVertex3f(Lato*.5,Lato*.87,0.); 00081 glVertex3f(-Lato*.5,Lato*.87,0.); 00082 glVertex3f(-Lato,0.,0.); 00083 glVertex3f(-Lato*.5,-Lato*.87,0.); 00084 glEnd(); 00085 glEndList(); 00086 return Hexagon; 00087 } 00088 int Draw::DefCube(int NSquare){ 00089 glDeleteLists(Cube,1); 00090 Cube = glGenLists(1); 00091 double xEdge = 1./(double)NSquare*Edge[0]*InvScaleUn; 00092 double yEdge = 1./(double)NSquare*Edge[1]*InvScaleUn; 00093 double zEdge = 1./(double)NSquare*Edge[2]*InvScaleUn; 00094 glNewList(Cube,GL_COMPILE); 00095 glBegin(GL_QUADS); 00096 for(int f=0;f<2;f++){ 00097 glNormal3d(0.,0.,1.); 00098 glVertex3d(0,0,f*zEdge); 00099 glVertex3d(xEdge,0,f*zEdge); 00100 glVertex3d(xEdge,yEdge,f*zEdge); 00101 glVertex3d(0,yEdge,f*zEdge); 00102 glNormal3d(1.,0.,0.); 00103 glVertex3d(f*xEdge,0,0); 00104 glVertex3d(f*xEdge,0,zEdge); 00105 glVertex3d(f*xEdge,yEdge,zEdge); 00106 glVertex3d(f*xEdge,yEdge,0); 00107 glNormal3d(0.,1.,0.); 00108 glVertex3d(0,f*yEdge,0); 00109 glVertex3d(0,f*yEdge,zEdge); 00110 glVertex3d(xEdge,f*yEdge,zEdge); 00111 glVertex3d(xEdge,f*yEdge,0); 00112 } 00113 glEnd(); 00114 glEndList(); 00115 return Cube; 00116 } 00117 int Draw::DefWall(){ 00118 glDeleteLists(GlWall,1); 00119 GlWall = glGenLists(1); 00120 glEnable(GL_TEXTURE_2D); 00121 glNewList(GlWall,GL_COMPILE); 00122 DefTexture(); 00123 // GL_DECAL,GL_MODULATE,GL_BLEND,GL_REPLACE 00124 glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); 00125 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, 00126 GL_LINEAR_MIPMAP_LINEAR); 00127 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); 00128 // glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, 00129 // GL_NEAREST_MIPMAP_NEAREST); 00130 // glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); 00131 glBegin(GL_QUADS); 00132 glNormal3d(0.,0.,1.); 00133 glColor4f(1.,.0,.0,.5); 00134 glVertex3d(0.,0.,0.); 00135 glColor4f(1.,.4,.0,.5); 00136 glVertex3d(Edge[0]*InvScaleUn,0.,0.); 00137 glColor4f(1.,.4,.4,.5); 00138 glVertex3d(Edge[0]*InvScaleUn,Edge[1]*InvScaleUn,0.); 00139 glColor4f(1.,.0,.4,.5); 00140 glVertex3d(0.,Edge[1]*InvScaleUn,0.); 00141 glColor4f(1.,.2,.2,.5); 00142 glTexCoord2f(0.8, 0.8);glVertex3d(0.,0.,0.); 00143 glColor4f(1.,.2,.0,.5); 00144 glTexCoord2f(0.2, 0.8);glVertex3d(Edge[0]*InvScaleUn,0.,0.); 00145 glColor4f(1.,.0,.0,.5); 00146 glTexCoord2f(0.2, 0.2);glVertex3d(Edge[0]*InvScaleUn,Edge[1]*InvScaleUn,0.); 00147 glColor4f(1.,.0,.2,.5); 00148 glTexCoord2f(0.8, 0.2);glVertex3d(0.,Edge[1]*InvScaleUn,0.); 00149 glEnd(); 00150 glEndList(); 00151 glDisable(GL_TEXTURE_2D); 00152 return GlWall; 00153 } 00154 int Draw::DefArrow(){ 00155 glDeleteLists(Arrow,1); 00156 Arrow = glGenLists(1); 00157 glNewList(Arrow,GL_COMPILE); 00158 glNormal3f(0.,0.,-1.); 00159 glBegin(GL_LINES); 00160 glVertex3f(0.,0.,0.); 00161 glVertex3f(1.,0.,0.); 00162 glEnd(); 00163 glBegin(GL_LINES); 00164 glVertex3f(1.,0.,0.); 00165 glVertex3f(.95,.02,0.); 00166 glEnd(); 00167 glBegin(GL_LINES); 00168 glVertex3f(1.,0.,0.); 00169 glVertex3f(.95,-.02,0.); 00170 glEnd(); 00171 glEndList(); 00172 return Arrow; 00173 } 00174 int Draw::DefArrowThin(){ 00175 glDeleteLists(Arrow,1); 00176 Arrow = glGenLists(1); 00177 glNewList(Arrow,GL_COMPILE); 00178 glNormal3f(0.,0.,-1.); 00179 glBegin(GL_LINES); 00180 glVertex3f(0.,0.,0.); 00181 glVertex3f(1.,0.,0.); 00182 glEnd(); 00183 glBegin(GL_LINES); 00184 glVertex3f(1.,0.,0.); 00185 glVertex3f(.95,.002,0.); 00186 glEnd(); 00187 glBegin(GL_LINES); 00188 glVertex3f(1.,0.,0.); 00189 glVertex3f(.95,-.002,0.); 00190 glEnd(); 00191 glEndList(); 00192 return Arrow; 00193 } 00194 int Draw::DefPoint(){ 00195 glDeleteLists(Point,1); 00196 Point = glGenLists(1); 00197 glNewList(Point,GL_COMPILE); 00198 glBegin(GL_POINTS); 00199 glNormal3f(0.,0.,1.); 00200 glVertex3f(0,0,0); 00201 glEnd(); 00202 glEndList(); 00203 return Point; 00204 } 00205 double Draw::Normal(double *v,double *u,double *w,double *n){ 00206 double Norma = 0.; 00207 for(int d=0;d<3;d++){ 00208 int Coord1 = (d+1)%3; 00209 int Coord2 = (d+2)%3; 00210 double Uno = (v[Coord1] - w[Coord1])*(u[Coord2] - w[Coord2]); 00211 double Due = (v[Coord2] - w[Coord2])*(u[Coord1] - w[Coord1]); 00212 n[d] = Uno - Due; 00213 Norma += SQR(n[d]); 00214 } 00215 Norma = sqrt(Norma); 00216 for(int d=0;d<3;d++) 00217 n[d] /= Norma; 00218 return Norma; 00219 } 00220 int Draw::DefCylinder(double CyEdge,double CyHeight){ 00221 int ListRef = glGenLists(1); 00222 glEnable(GL_LIGHTING); 00223 glEnable( GL_LIGHT0 ); 00224 glMaterialfv(GL_BACK, GL_AMBIENT, DrAmbientRed); 00225 glMaterialfv(GL_BACK, GL_DIFFUSE, DrDiffuseRed); 00226 glMaterialfv(GL_FRONT, GL_AMBIENT, DrAmbientRed); 00227 glMaterialfv(GL_FRONT, GL_DIFFUSE, DrDiffuseRed); 00228 glMaterialfv(GL_FRONT, GL_SPECULAR, DrSpecularWhite); 00229 glMaterialf( GL_FRONT, GL_SHININESS, 25.0); 00230 glNewList(ListRef,GL_COMPILE); 00231 int NEdges = 40; 00232 double Angle = DUE_PI/(double)(NEdges); 00233 CyEdge *= InvScaleUn; 00234 CyHeight *= InvScaleUn; 00235 // glEnableClientState(GL_NORMAL_ARRAY); 00236 glBegin(GL_POLYGON);//Kork 00237 glNormal3f(0.,0.,-1.); 00238 for(int l=0;l<NEdges+1;l++){ 00239 glVertex3d(CyEdge*cos(Angle*l),CyEdge*sin(Angle*l),-CyHeight*.5); 00240 } 00241 glEnd();//Kork 00242 glBegin(GL_POLYGON);//Kork 00243 glNormal3f(0.,0.,1.); 00244 for(int l=0;l<NEdges+1;l++){ 00245 glVertex3d(CyEdge*cos(Angle*l),CyEdge*sin(Angle*l),CyHeight*.5); 00246 } 00247 glEnd();//Kork 00248 for(int l=0;l<NEdges;l++){ 00249 double v1[3] = {CyEdge*cos(Angle*l),CyEdge*sin(Angle*l),-CyHeight*.5}; 00250 double v2[3] = {CyEdge*cos(Angle*l),CyEdge*sin(Angle*l),CyHeight*.5}; 00251 double v3[3] = {CyEdge*cos(Angle*(l+1)),CyEdge*sin(Angle*(l+1)),CyHeight*.5}; 00252 double v4[3] = {CyEdge*cos(Angle*(l+1)),CyEdge*sin(Angle*(l+1)),-CyHeight*.5}; 00253 double vn[3]; 00254 glBegin(GL_POLYGON);//Side 00255 Normal(v2,v3,v1,vn); 00256 //printf("%lf %lf %lf\n",vn[0],vn[1],vn[2]); 00257 //printf("%lf %lf %lf\n",-sin(Angle*(l)),cos(Angle*(l)),0); 00258 glNormal3f(vn[0],vn[1],vn[2]); 00259 glNormal3f(-CyEdge*sin(Angle*(l)),CyEdge*cos(Angle*(l)),0); 00260 glVertex3d(v1[0],v1[1],v1[2]); 00261 Normal(v3,v4,v2,vn); 00262 glNormal3f(vn[0],vn[1],vn[2]); 00263 glNormal3f(-CyEdge*sin(Angle*(l)),CyEdge*cos(Angle*(l)),0); 00264 glVertex3d(v2[0],v2[1],v2[2]); 00265 Normal(v4,v1,v3,vn); 00266 glNormal3f(vn[0],vn[1],vn[2]); 00267 glNormal3f(-CyEdge*sin(Angle*(l+1)),CyEdge*cos(Angle*(l+1)),0); 00268 glVertex3d(v3[0],v3[1],v3[2]); 00269 Normal(v1,v2,v4,vn); 00270 glNormal3f(vn[0],vn[1],vn[2]); 00271 glNormal3f(-CyEdge*sin(Angle*(l+1)),CyEdge*cos(Angle*(l+1)),0); 00272 glVertex3d(v4[0],v4[1],v4[2]); 00273 glEnd();//Side 00274 } 00275 glEndList(); 00276 glDisable(GL_LIGHTING); 00277 return ListRef; 00278 //Cupola 00279 for(int cc=0;cc<NEdges/2;cc+=1){ 00280 for(int c=0;c<NEdges;c+=1){ 00281 double Quota = CyHeight*.5; 00282 if(cc > NEdges/4) Quota = - CyHeight*.5; 00283 double v1[3] = {CyEdge*cos(Angle*c)*sin(cc*Angle), 00284 CyEdge*sin(Angle*c)*sin(cc*Angle), 00285 CyEdge*cos(cc*Angle) + Quota}; 00286 double v2[3] = {CyEdge*cos(Angle*(c+1))*sin(cc*Angle), 00287 CyEdge*sin(Angle*(c+1))*sin(cc*Angle), 00288 CyEdge*cos(cc*Angle) + Quota}; 00289 double v3[3] = {CyEdge*cos(Angle*(c+1))*sin((cc+1)*Angle), 00290 CyEdge*sin(Angle*(c+1))*sin((cc+1)*Angle), 00291 CyEdge*cos((cc+1)*Angle) + Quota}; 00292 double v4[3] = {CyEdge*cos(Angle*c)*sin((cc+1)*Angle), 00293 CyEdge*sin(Angle*c)*sin((cc+1)*Angle), 00294 CyEdge*cos((cc+1)*Angle) + Quota}; 00295 double vn[3]; 00296 glBegin(GL_POLYGON);//Kork 00297 glNormal3f(vn[0],vn[1],vn[2]); 00298 Normal(v1,v2,v3,vn); 00299 glVertex3d(v1[0],v1[1],v1[2]); 00300 glNormal3f(vn[0],vn[1],vn[2]); 00301 Normal(v2,v3,v4,vn); 00302 glVertex3d(v2[0],v2[1],v2[2]); 00303 glNormal3f(vn[0],vn[1],vn[2]); 00304 Normal(v3,v4,v1,vn); 00305 glVertex3d(v3[0],v3[1],v3[2]); 00306 glNormal3f(vn[0],vn[1],vn[2]); 00307 Normal(v4,v1,v2,vn); 00308 glVertex3d(v4[0],v4[1],v4[2]); 00309 glEnd();//Kork 00310 } 00311 } 00312 glEndList(); 00313 return ListRef; 00314 // static GLUquadricObj *quadObj; 00315 // quadObj = gluNewQuadric(); 00316 // gluQuadricDrawStyle(quadObj, GLU_FILL); 00317 // gluQuadricNormals(quadObj, GLU_SMOOTH); 00318 // gluCylinder(quadObj, Nano->Rad*InvScaleUn, Nano->Rad*InvScaleUn, Nano->Height*InvScaleUn, 20, 20); 00319 } 00320 #include <vector> 00321 int Draw::DefMetalCylinder(double CyEdge,double CyHeight){ 00322 // GLfloat Light1[4] = {1.,1.,1.,1.}; 00323 // glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,Light1); 00324 // GLfloat Light2[4] = {1.,1.,1.,1.}; 00325 // glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,Light2); 00326 // GLfloat Light3[4] = {0.,0.,0.,1.}; 00327 // glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,Light3); 00328 int MetalCylinder = 0; 00329 MetalCylinder = glGenLists(1); 00330 glNewList(MetalCylinder,GL_COMPILE); 00331 int NEdges = 20; 00332 double Angle = DUE_PI/(double)(NEdges); 00333 glEnableClientState(GL_VERTEX_ARRAY); 00334 glEnable(GL_VERTEX_ARRAY); 00335 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 00336 glFrontFace(GL_CCW); //Tell OGL which orientation shall be the front face 00337 glShadeModel(GL_SMOOTH); 00338 glEnableClientState(GL_NORMAL_ARRAY); 00339 double Normal[3]={.1,.1,.1}; 00340 glNormalPointer(GL_FLOAT,sizeof(double),&Normal[0]); //Pointer to the first color*/ 00341 GLfloat *Kork = new GLfloat [2*3*(NEdges)]; 00342 vector <GLuint> VecIndices; 00343 for(int l=0;l<NEdges;l++){ 00344 Kork[(l)*3+0] = CyEdge*cos(Angle*l); 00345 Kork[(l)*3+1] = CyEdge*sin(Angle*l); 00346 Kork[(l)*3+2] = CyHeight*.5; 00347 VecIndices.push_back(l); 00348 } 00349 VecIndices.push_back(0); 00350 int NIndex = VecIndices.size(); 00351 // GLuint *Indices = new GLuint [NIndex]; 00352 // for(int i=0;i<NIndex;i++)Indices[i] = VecIndices[i]; 00353 GLuint *Indices = &VecIndices[0]; 00354 glVertexPointer(3,GL_FLOAT,3*sizeof(GLfloat),Kork); 00355 glDrawElements(GL_POLYGON,NIndex,GL_UNSIGNED_INT,Indices); 00356 for(int l=0;l<NEdges;l++) 00357 Kork[(l)*3+2] = -CyHeight*.5; 00358 glDrawElements(GL_POLYGON,NIndex,GL_UNSIGNED_INT,Indices); 00359 delete [] Kork; 00360 VecIndices.clear(); 00361 GLfloat *Side = new GLfloat [3*4]; 00362 for(int l=0;l<NEdges+1;l++){ 00363 Side[(0)*3+0] = CyEdge*cos(Angle*l); 00364 Side[(0)*3+1] = CyEdge*sin(Angle*l); 00365 Side[(0)*3+2] = -CyHeight*.5; 00366 VecIndices.push_back(0); 00367 Side[(1)*3+0] = CyEdge*cos(Angle*(l)); 00368 Side[(1)*3+1] = CyEdge*sin(Angle*(l)); 00369 Side[(1)*3+2] = CyHeight*.5; 00370 VecIndices.push_back(1); 00371 Side[(2)*3+0] = CyEdge*cos(Angle*(l+1)); 00372 Side[(2)*3+1] = CyEdge*sin(Angle*(l+1)); 00373 Side[(2)*3+2] = CyHeight*.5; 00374 VecIndices.push_back(2); 00375 Side[(3)*3+0] = CyEdge*cos(Angle*(l+1)); 00376 Side[(3)*3+1] = CyEdge*sin(Angle*(l+1)); 00377 Side[(3)*3+2] = -CyHeight*.5; 00378 VecIndices.push_back(3); 00379 Indices = &VecIndices[0]; 00380 glVertexPointer(3,GL_FLOAT,3*sizeof(GLfloat),Side); 00381 glDrawElements(GL_QUADS,4,GL_UNSIGNED_INT,Indices); 00382 } 00383 delete [] Side; 00384 VecIndices.clear(); 00385 glEndList(); 00386 return MetalCylinder; 00387 } 00388 00389 // Written by Chris Halsall (chalsall@chalsall.com) for the 00390 // O'Reilly Network on Linux.com (oreilly.linux.com). 00391 // May 2000. 00392 int Draw::DefTexture(){ 00393 GLuint Texture_ID = 0; 00394 GLenum gluerr; 00395 GLubyte tex[128][128][4]; 00396 int x,y,t; 00397 int hole_size = 3300; // ~ == 57.45 ^ 2. 00398 // Generate a texture index, then bind it for future operations. 00399 glGenTextures(1,&Texture_ID); 00400 glBindTexture(GL_TEXTURE_2D,Texture_ID); 00401 // Iterate across the texture array. 00402 for(y=0;y<128;y++) { 00403 for(x=0;x<128;x++) { 00404 // A simple repeating squares pattern. 00405 // Dark blue on white. 00406 if ( ( (x+4)%32 < 8 ) && ( (y+4)%32 < 8)) { 00407 tex[x][y][0]=tex[x][y][1]=0; tex[x][y][2]=120; 00408 } else { 00409 tex[x][y][0]=tex[x][y][1]=tex[x][y][2]=240; 00410 } 00411 // Make a round dot in the texture's alpha-channel. 00412 // Calculate distance to center (squared). 00413 t = (x-64)*(x-64) + (y-64)*(y-64) ; 00414 if ( t < hole_size) // Don't take square root; compare squared. 00415 tex[x][y][3]=255; // The dot itself is opaque. 00416 else if (t < hole_size + 100) 00417 tex[x][y][3]=128; // Give our dot an anti-aliased edge. 00418 else 00419 tex[x][y][3]=0; // Outside of the dot, it's transparent. 00420 } 00421 } 00422 // The GLU library helps us build MipMaps for our texture. 00423 if ((gluerr=gluBuild2DMipmaps(GL_TEXTURE_2D, 4, 128, 128, GL_RGBA, 00424 GL_UNSIGNED_BYTE, (void *)tex))) { 00425 fprintf(stderr,"GLULib%s\n",gluErrorString(gluerr)); 00426 exit(-1); 00427 } 00428 // Some pretty standard settings for wrapping and filtering. 00429 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); 00430 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); 00431 // We start with GL_DECAL mode. 00432 glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_DECAL); 00433 return Texture_ID; 00434 } 00435 int Draw::DefGriglia(){ 00436 glDisable(GL_LIGHTING); 00437 glDeleteLists(Griglia,1); 00438 Griglia = glGenLists(1); 00439 glNewList(Griglia,GL_COMPILE); 00440 glBegin(GL_LINES); 00441 glColor4f(1.-Rback,1.-Gback,1.-Bback,1.0); 00442 double Step[3]; 00443 glPushAttrib(GL_LIGHTING_BIT); 00444 glDisable(GL_LIGHTING); 00445 for(int d=0;d<3;d++){ 00446 //GridEdge[d] = (int)(GridStep*Edge[d]*InvScaleUn); 00447 Step[d] = Edge[d]*InvScaleUn/GridEdge[d]; 00448 } 00449 //--------------------------grid 00450 if(gr == 1){ 00451 for(int i=0;i<=GridEdge[0];i++){ 00452 for(int j=0;j<=GridEdge[1];j++){ 00453 glVertex3f(i*Step[0],j*Step[1],Edge[2]*InvScaleUn); 00454 glVertex3f(i*Step[0],j*Step[1],0); 00455 } 00456 } 00457 for(int j=0;j<=GridEdge[1];j++){ 00458 for(int k=0;k<=GridEdge[2];k++){ 00459 glVertex3f(0,j*Step[1],k*Step[2]); 00460 glVertex3f(Edge[0]*InvScaleUn,j*Step[1],k*Step[2]); 00461 } 00462 } 00463 for(int i=0;i<=GridEdge[0];i++){ 00464 for(int k=0;k<=GridEdge[2];k++){ 00465 glVertex3f(i*Step[0],0.,k*Step[2]); 00466 glVertex3f(i*Step[0],Edge[1]*InvScaleUn,k*Step[2]); 00467 } 00468 } 00469 } 00470 else if (gr == 2){ 00471 for(int i=0;i<=GridEdge[0];i++){ 00472 glVertex3f(i*Step[0],0.,Edge[2]*InvScaleUn); 00473 glVertex3f(i*Step[0],0.,0.); 00474 glVertex3f(i*Step[0],Edge[1]*InvScaleUn,0.); 00475 glVertex3f(i*Step[0],0.,0.); 00476 } 00477 for(int j=0;j<=GridEdge[1];j++){ 00478 glVertex3f(0,j*Step[1],0.); 00479 glVertex3f(Edge[0]*InvScaleUn,j*Step[1],0.); 00480 glVertex3f(0.,j*Step[1],0.); 00481 glVertex3f(0.,j*Step[1],InvScaleUn*Edge[2]); 00482 } 00483 for(int k=0;k<=GridEdge[2];k++){ 00484 glVertex3f(0.,0.,k*Step[2]); 00485 glVertex3f(0.,Edge[1]*InvScaleUn,k*Step[2]); 00486 glVertex3f(0.,0.,k*Step[2]); 00487 glVertex3f(Edge[0]*InvScaleUn,0.,k*Step[2]); 00488 } 00489 } 00490 //glDisable(GL_LINE_SMOOTH); 00491 //----------------------label 00492 for(int i=0;i<=GridEdge[0];i++){ 00493 //glPushMatrix();//info 00494 sprintf(Number,"%.2f",i/(double)GridEdge[0]); 00495 glRasterPos3f(i*Step[0],0.,0.); 00496 for (int l = 1; l < strlen(Number); l++) { 00497 glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, Number[l]); 00498 } 00499 glCallList(Point); 00500 //glPopMatrix();//info 00501 } 00502 for(int j=0;j<=GridEdge[1];j++){ 00503 //glPushMatrix();//info 00504 sprintf(Number,"%.2f",j/(double)GridEdge[1]); 00505 glRasterPos3f(0.,j*Step[1],0.); 00506 for (int l = 1; l < strlen(Number); l++) { 00507 glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, Number[l]); 00508 } 00509 glCallList(Point); 00510 //glPopMatrix();//info 00511 } 00512 for(int k=0;k<=GridEdge[2];k++){ 00513 //glPushMatrix();//info 00514 sprintf(Number,"%.2f",k/(double)GridEdge[2]); 00515 glRasterPos3f(0.,0.,k*Step[2]); 00516 for (int l = 1; l < strlen(Number); l++) { 00517 glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, Number[l]); 00518 } 00519 glCallList(Point); 00520 //glPopMatrix();//info 00521 } 00522 glColor4f(.2,.1,.7,1.); 00523 glRasterPos3f(-.1,0.,0.); 00524 glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,'0'); 00525 glRasterPos3f(Edge[0]*InvScaleUn+.1,0.,0.); 00526 glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,'x'); 00527 glRasterPos3f(0.,Edge[1]*InvScaleUn+.1,0.); 00528 glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,'y'); 00529 glRasterPos3f(0.,0.,Edge[2]*InvScaleUn+.1); 00530 glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,'z'); 00531 glEnd(); 00532 glPopAttrib(); 00533 glEndList(); 00534 return Griglia; 00535 } 00536 void Draw::Lista(int NSquare){ 00537 // glEnable(GL_LIGHTING); 00538 // glEnable(GL_COLOR_MATERIAL); 00539 // glEnable(GL_NORMALIZE); 00540 // //glEnable(GL_CULL_FACE); 00541 // glCullFace(GL_FRONT_AND_BACK);//Disegna anche il lato dietro 00542 // //glFrontFace(GL_CCW);//Senso antiorario 00543 // //glColorMaterial(GL_FRONT_AND_BACK,GL_EMISSION); 00544 // GLfloat Light1[4] = {0.,0.,0.,1.}; 00545 // glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,Light1); 00546 // GLfloat Light2[4] = {1.,1.,1.,1.}; 00547 // glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,Light2); 00548 // GLfloat Light3[4] = {0.,0.,0.,1.}; 00549 // glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,Light3); 00550 // GLfloat Light4[4] = {1.,1.,1.,1.}; 00551 // glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,Light3); 00552 // GLfloat Light5[4] = {1.,1.,1.,1.}; 00553 // glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,Light3); 00554 // glEnable(GL_NORMALIZE); 00555 DefPoint(); 00556 DefGriglia(); 00557 DefLegend(); 00558 DefArrowThin(); 00559 } 00560 static double WeightFuncSpline(const double x){ 00561 if(x < 0.) 00562 return 1.; 00563 if(fabs(x) < 1.) 00564 return 2.*fabs(x)*x*x - 3.*x*x + 1.; 00565 else 00566 return 0.; 00567 } 00568 static double Parab(const double x){ 00569 double Resp = -4.*x*x+4.; 00570 if(Resp < 0) Resp = 0.; 00571 return Resp; 00572 } 00573 void Draw::DepthMap1(double Val,GLfloat *Color){ 00574 Color[0] = (GLfloat)WeightFuncSpline((1.-Val)*.7); 00575 Color[1] = (GLfloat)Parab((Val-.5)*3.); 00576 Color[2] = (GLfloat)WeightFuncSpline((Val)*.7); 00577 Color[3] = 1.; 00578 } 00579 void Draw::ChooseDepthMap(int i){ 00580 if(i == 0) 00581 Depth_Map = &Draw::DepthMap1; 00582 } 00583 int Draw::DefLegend(){ 00584 glDisable(GL_LIGHTING); 00585 glDeleteLists(DrLegend,1); 00586 DrLegend = glGenLists(1); 00587 glNewList(DrLegend,GL_COMPILE); 00588 int NSlab = 100; 00589 GLfloat InvNSlab = 1./(GLfloat)NSlab; 00590 double dx = dxLeg*InvNSlab; 00591 double dy = dyLeg*InvNSlab; 00592 GLfloat Color[4]; 00593 char Number[10]; 00594 for(int i=0;i<NSlab;i++){ 00595 GLfloat x = xLeg;// + Size[0]*i*dx; 00596 GLfloat y = yLeg + dyLeg*i*dy; 00597 glBegin(GL_POLYGON); 00598 glNormal3d(0.,0.,1.); 00599 DepthMap(i*InvNSlab,Color); 00600 for(int d=0;d<3;d++)Color[d] -= .2; 00601 glColor4fv(Color); 00602 glVertex3d(x,y,zLeg); 00603 glVertex3d(x+dx,y,zLeg); 00604 glVertex3d(x+dx,y+dy,zLeg); 00605 glVertex3d(x,y+dy,zLeg); 00606 glEnd(); 00607 if(!(i%10)){ 00608 glPushMatrix();//Info 00609 sprintf(Number,"%.2f",i*InvNSlab); 00610 glRasterPos3f(xLeg+4.*dx,y,zLeg); 00611 for(int l=1;l<strlen(Number);l++){ 00612 //glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,Number[l]); 00613 glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,Number[l]); 00614 } 00615 glPopMatrix(); 00616 } 00617 } 00618 glPushMatrix();//Info 00619 sprintf(Number,"1.00"); 00620 glRasterPos3f(xLeg+4.*dx,yLeg+dyLeg,zLeg); 00621 for(int l=1;l<strlen(Number);l++){ 00622 //glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,Number[l]); 00623 glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,Number[l]); 00624 } 00625 glPopMatrix(); 00626 glEndList(); 00627 return DrLegend; 00628 } 00629 #endif // __glut_h__