Allink  v0.1
DrawDefinition.cpp
1 /***********************************************************************
2 DrawDefinition: Create some useful lists
3 Copyright (C) 2008-2010 by Giovanni Marelli <sabeiro@virgilio.it>
4 
5 
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; If not, see <http://www.gnu.org/licenses/>.
17 ***********************************************************************/
18 #include "../../include/Draw.h"
19 
20 #ifdef __glut_h__
22  spin = 0.;angolo = 0.; dspin = .1 ;
23  xp=0. ; yp=0. ; zp= 0.; zw = -1.;
24  xa=0. ; ya=0. ; za= 0.;
25  xf=55. ; yf=5. ; zf= 0.;
26  xi=-.4 ; yi=-.4 ; zi= -0.;
27  xLeg=-1.4; yLeg=-.3 ; zLeg= 0.;
28  dxLeg=.4;dyLeg=.8;
29  xl0=1. ; yl0=1. ; zl0=1.;
30  xl1=1. ; yl1=0. ; zl1=1.;
31  Rback = 1.0; Gback = 1.0;Bback = 1.0;Aback = 0.0;
32  GridStep = 2.;
33  for(int d=0;d<3;d++)
34  GridEdge[d] = (int)(GridStep*Edge[d]*InvScaleUn);
35  Step = 0;
36  pr = 1;//prospettiva
37  IfPoint = 1;//point or Sphere
38  IfInfo = 1;
39  IfImage = 0;
40  IfScript = 1;
41  IfBlend = 1;
42  la = 1;
43  gr = 0;
44  lu = 1;
45  sp = 1;
46  ne = 0;
47  AngleDxSx = 0.;
48  AngleSuGiu = 0.;
49  IfMaterial = 1;
50  ChooseDepthMap(0);
51  sprintf(info,"");
52 }
53 int Draw::DefQuad(int NSquare){
54  glDeleteLists(Quad,1);
55  Quad = glGenLists(1);
56  double xEdge = 1./(double)NSquare*Edge[0]*InvScaleUn;
57  double yEdge = 1./(double)NSquare*Edge[1]*InvScaleUn;
58  glNewList(Quad,GL_COMPILE);
59  glBegin(GL_POLYGON);
60  glNormal3f(0.,0.,1.);
61  glVertex3f(0,0,0);
62  glVertex3f(xEdge,0,0);
63  glVertex3f(xEdge,yEdge,0);
64  glVertex3f(0,yEdge,0);
65  glEnd();
66  glEndList();
67  return Quad;
68 }
70  glDeleteLists(Hexagon,1);
71  Hexagon = glGenLists(1);
72  glNewList(Hexagon,GL_COMPILE);
73  double Lato=0.01;
74  glBegin(GL_POLYGON);
75  // glBegin(GL_POINTS);
76  // glVertex3f(0.,0.,0.);
77  glNormal3f(0.,0.,1.);
78  glVertex3f(Lato*.5,-Lato*.87,0.);
79  glVertex3f(Lato,0.,0.);
80  glVertex3f(Lato*.5,Lato*.87,0.);
81  glVertex3f(-Lato*.5,Lato*.87,0.);
82  glVertex3f(-Lato,0.,0.);
83  glVertex3f(-Lato*.5,-Lato*.87,0.);
84  glEnd();
85  glEndList();
86  return Hexagon;
87 }
88 int Draw::DefCube(int NSquare){
89  glDeleteLists(Cube,1);
90  Cube = glGenLists(1);
91  double xEdge = 1./(double)NSquare*Edge[0]*InvScaleUn;
92  double yEdge = 1./(double)NSquare*Edge[1]*InvScaleUn;
93  double zEdge = 1./(double)NSquare*Edge[2]*InvScaleUn;
94  glNewList(Cube,GL_COMPILE);
95  glBegin(GL_QUADS);
96  for(int f=0;f<2;f++){
97  glNormal3d(0.,0.,1.);
98  glVertex3d(0,0,f*zEdge);
99  glVertex3d(xEdge,0,f*zEdge);
100  glVertex3d(xEdge,yEdge,f*zEdge);
101  glVertex3d(0,yEdge,f*zEdge);
102  glNormal3d(1.,0.,0.);
103  glVertex3d(f*xEdge,0,0);
104  glVertex3d(f*xEdge,0,zEdge);
105  glVertex3d(f*xEdge,yEdge,zEdge);
106  glVertex3d(f*xEdge,yEdge,0);
107  glNormal3d(0.,1.,0.);
108  glVertex3d(0,f*yEdge,0);
109  glVertex3d(0,f*yEdge,zEdge);
110  glVertex3d(xEdge,f*yEdge,zEdge);
111  glVertex3d(xEdge,f*yEdge,0);
112  }
113  glEnd();
114  glEndList();
115  return Cube;
116 }
118  glDeleteLists(GlWall,1);
119  GlWall = glGenLists(1);
120  glEnable(GL_TEXTURE_2D);
121  glNewList(GlWall,GL_COMPILE);
122  DefTexture();
123  // GL_DECAL,GL_MODULATE,GL_BLEND,GL_REPLACE
124  glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
125  glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,
126  GL_LINEAR_MIPMAP_LINEAR);
127  glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
128  // glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,
129  // GL_NEAREST_MIPMAP_NEAREST);
130  // glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
131  glBegin(GL_QUADS);
132  glNormal3d(0.,0.,1.);
133  glColor4f(1.,.0,.0,.5);
134  glVertex3d(0.,0.,0.);
135  glColor4f(1.,.4,.0,.5);
136  glVertex3d(Edge[0]*InvScaleUn,0.,0.);
137  glColor4f(1.,.4,.4,.5);
138  glVertex3d(Edge[0]*InvScaleUn,Edge[1]*InvScaleUn,0.);
139  glColor4f(1.,.0,.4,.5);
140  glVertex3d(0.,Edge[1]*InvScaleUn,0.);
141  glColor4f(1.,.2,.2,.5);
142  glTexCoord2f(0.8, 0.8);glVertex3d(0.,0.,0.);
143  glColor4f(1.,.2,.0,.5);
144  glTexCoord2f(0.2, 0.8);glVertex3d(Edge[0]*InvScaleUn,0.,0.);
145  glColor4f(1.,.0,.0,.5);
146  glTexCoord2f(0.2, 0.2);glVertex3d(Edge[0]*InvScaleUn,Edge[1]*InvScaleUn,0.);
147  glColor4f(1.,.0,.2,.5);
148  glTexCoord2f(0.8, 0.2);glVertex3d(0.,Edge[1]*InvScaleUn,0.);
149  glEnd();
150  glEndList();
151  glDisable(GL_TEXTURE_2D);
152  return GlWall;
153 }
155  glDeleteLists(Arrow,1);
156  Arrow = glGenLists(1);
157  glNewList(Arrow,GL_COMPILE);
158  glNormal3f(0.,0.,-1.);
159  glBegin(GL_LINES);
160  glVertex3f(0.,0.,0.);
161  glVertex3f(1.,0.,0.);
162  glEnd();
163  glBegin(GL_LINES);
164  glVertex3f(1.,0.,0.);
165  glVertex3f(.95,.02,0.);
166  glEnd();
167  glBegin(GL_LINES);
168  glVertex3f(1.,0.,0.);
169  glVertex3f(.95,-.02,0.);
170  glEnd();
171  glEndList();
172  return Arrow;
173 }
175  glDeleteLists(Arrow,1);
176  Arrow = glGenLists(1);
177  glNewList(Arrow,GL_COMPILE);
178  glNormal3f(0.,0.,-1.);
179  glBegin(GL_LINES);
180  glVertex3f(0.,0.,0.);
181  glVertex3f(1.,0.,0.);
182  glEnd();
183  glBegin(GL_LINES);
184  glVertex3f(1.,0.,0.);
185  glVertex3f(.95,.002,0.);
186  glEnd();
187  glBegin(GL_LINES);
188  glVertex3f(1.,0.,0.);
189  glVertex3f(.95,-.002,0.);
190  glEnd();
191  glEndList();
192  return Arrow;
193 }
195  glDeleteLists(Point,1);
196  Point = glGenLists(1);
197  glNewList(Point,GL_COMPILE);
198  glBegin(GL_POINTS);
199  glNormal3f(0.,0.,1.);
200  glVertex3f(0,0,0);
201  glEnd();
202  glEndList();
203  return Point;
204 }
205 double Draw::Normal(double *v,double *u,double *w,double *n){
206  double Norma = 0.;
207  for(int d=0;d<3;d++){
208  int Coord1 = (d+1)%3;
209  int Coord2 = (d+2)%3;
210  double Uno = (v[Coord1] - w[Coord1])*(u[Coord2] - w[Coord2]);
211  double Due = (v[Coord2] - w[Coord2])*(u[Coord1] - w[Coord1]);
212  n[d] = Uno - Due;
213  Norma += SQR(n[d]);
214  }
215  Norma = sqrt(Norma);
216  for(int d=0;d<3;d++)
217  n[d] /= Norma;
218  return Norma;
219 }
220 int Draw::DefCylinder(double CyEdge,double CyHeight){
221  int ListRef = glGenLists(1);
222  glEnable(GL_LIGHTING);
223  glEnable( GL_LIGHT0 );
224  glMaterialfv(GL_BACK, GL_AMBIENT, DrAmbientRed);
225  glMaterialfv(GL_BACK, GL_DIFFUSE, DrDiffuseRed);
226  glMaterialfv(GL_FRONT, GL_AMBIENT, DrAmbientRed);
227  glMaterialfv(GL_FRONT, GL_DIFFUSE, DrDiffuseRed);
228  glMaterialfv(GL_FRONT, GL_SPECULAR, DrSpecularWhite);
229  glMaterialf( GL_FRONT, GL_SHININESS, 25.0);
230  glNewList(ListRef,GL_COMPILE);
231  int NEdges = 40;
232  double Angle = DUE_PI/(double)(NEdges);
233  CyEdge *= InvScaleUn;
234  CyHeight *= InvScaleUn;
235  // glEnableClientState(GL_NORMAL_ARRAY);
236  glBegin(GL_POLYGON);//Kork
237  glNormal3f(0.,0.,-1.);
238  for(int l=0;l<NEdges+1;l++){
239  glVertex3d(CyEdge*cos(Angle*l),CyEdge*sin(Angle*l),-CyHeight*.5);
240  }
241  glEnd();//Kork
242  glBegin(GL_POLYGON);//Kork
243  glNormal3f(0.,0.,1.);
244  for(int l=0;l<NEdges+1;l++){
245  glVertex3d(CyEdge*cos(Angle*l),CyEdge*sin(Angle*l),CyHeight*.5);
246  }
247  glEnd();//Kork
248  for(int l=0;l<NEdges;l++){
249  double v1[3] = {CyEdge*cos(Angle*l),CyEdge*sin(Angle*l),-CyHeight*.5};
250  double v2[3] = {CyEdge*cos(Angle*l),CyEdge*sin(Angle*l),CyHeight*.5};
251  double v3[3] = {CyEdge*cos(Angle*(l+1)),CyEdge*sin(Angle*(l+1)),CyHeight*.5};
252  double v4[3] = {CyEdge*cos(Angle*(l+1)),CyEdge*sin(Angle*(l+1)),-CyHeight*.5};
253  double vn[3];
254  glBegin(GL_POLYGON);//Side
255  Normal(v2,v3,v1,vn);
256  //printf("%lf %lf %lf\n",vn[0],vn[1],vn[2]);
257  //printf("%lf %lf %lf\n",-sin(Angle*(l)),cos(Angle*(l)),0);
258  glNormal3f(vn[0],vn[1],vn[2]);
259  glNormal3f(-CyEdge*sin(Angle*(l)),CyEdge*cos(Angle*(l)),0);
260  glVertex3d(v1[0],v1[1],v1[2]);
261  Normal(v3,v4,v2,vn);
262  glNormal3f(vn[0],vn[1],vn[2]);
263  glNormal3f(-CyEdge*sin(Angle*(l)),CyEdge*cos(Angle*(l)),0);
264  glVertex3d(v2[0],v2[1],v2[2]);
265  Normal(v4,v1,v3,vn);
266  glNormal3f(vn[0],vn[1],vn[2]);
267  glNormal3f(-CyEdge*sin(Angle*(l+1)),CyEdge*cos(Angle*(l+1)),0);
268  glVertex3d(v3[0],v3[1],v3[2]);
269  Normal(v1,v2,v4,vn);
270  glNormal3f(vn[0],vn[1],vn[2]);
271  glNormal3f(-CyEdge*sin(Angle*(l+1)),CyEdge*cos(Angle*(l+1)),0);
272  glVertex3d(v4[0],v4[1],v4[2]);
273  glEnd();//Side
274  }
275  glEndList();
276  glDisable(GL_LIGHTING);
277  return ListRef;
278  //Cupola
279  for(int cc=0;cc<NEdges/2;cc+=1){
280  for(int c=0;c<NEdges;c+=1){
281  double Quota = CyHeight*.5;
282  if(cc > NEdges/4) Quota = - CyHeight*.5;
283  double v1[3] = {CyEdge*cos(Angle*c)*sin(cc*Angle),
284  CyEdge*sin(Angle*c)*sin(cc*Angle),
285  CyEdge*cos(cc*Angle) + Quota};
286  double v2[3] = {CyEdge*cos(Angle*(c+1))*sin(cc*Angle),
287  CyEdge*sin(Angle*(c+1))*sin(cc*Angle),
288  CyEdge*cos(cc*Angle) + Quota};
289  double v3[3] = {CyEdge*cos(Angle*(c+1))*sin((cc+1)*Angle),
290  CyEdge*sin(Angle*(c+1))*sin((cc+1)*Angle),
291  CyEdge*cos((cc+1)*Angle) + Quota};
292  double v4[3] = {CyEdge*cos(Angle*c)*sin((cc+1)*Angle),
293  CyEdge*sin(Angle*c)*sin((cc+1)*Angle),
294  CyEdge*cos((cc+1)*Angle) + Quota};
295  double vn[3];
296  glBegin(GL_POLYGON);//Kork
297  glNormal3f(vn[0],vn[1],vn[2]);
298  Normal(v1,v2,v3,vn);
299  glVertex3d(v1[0],v1[1],v1[2]);
300  glNormal3f(vn[0],vn[1],vn[2]);
301  Normal(v2,v3,v4,vn);
302  glVertex3d(v2[0],v2[1],v2[2]);
303  glNormal3f(vn[0],vn[1],vn[2]);
304  Normal(v3,v4,v1,vn);
305  glVertex3d(v3[0],v3[1],v3[2]);
306  glNormal3f(vn[0],vn[1],vn[2]);
307  Normal(v4,v1,v2,vn);
308  glVertex3d(v4[0],v4[1],v4[2]);
309  glEnd();//Kork
310  }
311  }
312  glEndList();
313  return ListRef;
314  // static GLUquadricObj *quadObj;
315  // quadObj = gluNewQuadric();
316  // gluQuadricDrawStyle(quadObj, GLU_FILL);
317  // gluQuadricNormals(quadObj, GLU_SMOOTH);
318  // gluCylinder(quadObj, Nano->Rad*InvScaleUn, Nano->Rad*InvScaleUn, Nano->Height*InvScaleUn, 20, 20);
319 }
320 #include <vector>
321 int Draw::DefMetalCylinder(double CyEdge,double CyHeight){
322  // GLfloat Light1[4] = {1.,1.,1.,1.};
323  // glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,Light1);
324  // GLfloat Light2[4] = {1.,1.,1.,1.};
325  // glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,Light2);
326  // GLfloat Light3[4] = {0.,0.,0.,1.};
327  // glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,Light3);
328  int MetalCylinder = 0;
329  MetalCylinder = glGenLists(1);
330  glNewList(MetalCylinder,GL_COMPILE);
331  int NEdges = 20;
332  double Angle = DUE_PI/(double)(NEdges);
333  glEnableClientState(GL_VERTEX_ARRAY);
334  glEnable(GL_VERTEX_ARRAY);
335  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
336  glFrontFace(GL_CCW); //Tell OGL which orientation shall be the front face
337  glShadeModel(GL_SMOOTH);
338  glEnableClientState(GL_NORMAL_ARRAY);
339  double Normal[3]={.1,.1,.1};
340  glNormalPointer(GL_FLOAT,sizeof(double),&Normal[0]); //Pointer to the first color*/
341  GLfloat *Kork = new GLfloat [2*3*(NEdges)];
342  vector <GLuint> VecIndices;
343  for(int l=0;l<NEdges;l++){
344  Kork[(l)*3+0] = CyEdge*cos(Angle*l);
345  Kork[(l)*3+1] = CyEdge*sin(Angle*l);
346  Kork[(l)*3+2] = CyHeight*.5;
347  VecIndices.push_back(l);
348  }
349  VecIndices.push_back(0);
350  int NIndex = VecIndices.size();
351  // GLuint *Indices = new GLuint [NIndex];
352  // for(int i=0;i<NIndex;i++)Indices[i] = VecIndices[i];
353  GLuint *Indices = &VecIndices[0];
354  glVertexPointer(3,GL_FLOAT,3*sizeof(GLfloat),Kork);
355  glDrawElements(GL_POLYGON,NIndex,GL_UNSIGNED_INT,Indices);
356  for(int l=0;l<NEdges;l++)
357  Kork[(l)*3+2] = -CyHeight*.5;
358  glDrawElements(GL_POLYGON,NIndex,GL_UNSIGNED_INT,Indices);
359  delete [] Kork;
360  VecIndices.clear();
361  GLfloat *Side = new GLfloat [3*4];
362  for(int l=0;l<NEdges+1;l++){
363  Side[(0)*3+0] = CyEdge*cos(Angle*l);
364  Side[(0)*3+1] = CyEdge*sin(Angle*l);
365  Side[(0)*3+2] = -CyHeight*.5;
366  VecIndices.push_back(0);
367  Side[(1)*3+0] = CyEdge*cos(Angle*(l));
368  Side[(1)*3+1] = CyEdge*sin(Angle*(l));
369  Side[(1)*3+2] = CyHeight*.5;
370  VecIndices.push_back(1);
371  Side[(2)*3+0] = CyEdge*cos(Angle*(l+1));
372  Side[(2)*3+1] = CyEdge*sin(Angle*(l+1));
373  Side[(2)*3+2] = CyHeight*.5;
374  VecIndices.push_back(2);
375  Side[(3)*3+0] = CyEdge*cos(Angle*(l+1));
376  Side[(3)*3+1] = CyEdge*sin(Angle*(l+1));
377  Side[(3)*3+2] = -CyHeight*.5;
378  VecIndices.push_back(3);
379  Indices = &VecIndices[0];
380  glVertexPointer(3,GL_FLOAT,3*sizeof(GLfloat),Side);
381  glDrawElements(GL_QUADS,4,GL_UNSIGNED_INT,Indices);
382  }
383  delete [] Side;
384  VecIndices.clear();
385  glEndList();
386  return MetalCylinder;
387 }
388 
389 // Written by Chris Halsall (chalsall@chalsall.com) for the
390 // O'Reilly Network on Linux.com (oreilly.linux.com).
391 // May 2000.
393  GLuint Texture_ID = 0;
394  GLenum gluerr;
395  GLubyte tex[128][128][4];
396  int x,y,t;
397  int hole_size = 3300; // ~ == 57.45 ^ 2.
398  // Generate a texture index, then bind it for future operations.
399  glGenTextures(1,&Texture_ID);
400  glBindTexture(GL_TEXTURE_2D,Texture_ID);
401  // Iterate across the texture array.
402  for(y=0;y<128;y++) {
403  for(x=0;x<128;x++) {
404  // A simple repeating squares pattern.
405  // Dark blue on white.
406  if ( ( (x+4)%32 < 8 ) && ( (y+4)%32 < 8)) {
407  tex[x][y][0]=tex[x][y][1]=0; tex[x][y][2]=120;
408  } else {
409  tex[x][y][0]=tex[x][y][1]=tex[x][y][2]=240;
410  }
411  // Make a round dot in the texture's alpha-channel.
412  // Calculate distance to center (squared).
413  t = (x-64)*(x-64) + (y-64)*(y-64) ;
414  if ( t < hole_size) // Don't take square root; compare squared.
415  tex[x][y][3]=255; // The dot itself is opaque.
416  else if (t < hole_size + 100)
417  tex[x][y][3]=128; // Give our dot an anti-aliased edge.
418  else
419  tex[x][y][3]=0; // Outside of the dot, it's transparent.
420  }
421  }
422  // The GLU library helps us build MipMaps for our texture.
423  if ((gluerr=gluBuild2DMipmaps(GL_TEXTURE_2D, 4, 128, 128, GL_RGBA,
424  GL_UNSIGNED_BYTE, (void *)tex))) {
425  fprintf(stderr,"GLULib%s\n",gluErrorString(gluerr));
426  exit(-1);
427  }
428  // Some pretty standard settings for wrapping and filtering.
429  glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
430  glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
431  // We start with GL_DECAL mode.
432  glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_DECAL);
433  return Texture_ID;
434 }
436  glDisable(GL_LIGHTING);
437  glDeleteLists(Griglia,1);
438  Griglia = glGenLists(1);
439  glNewList(Griglia,GL_COMPILE);
440  glBegin(GL_LINES);
441  glColor4f(1.-Rback,1.-Gback,1.-Bback,1.0);
442  double Step[3];
443  glPushAttrib(GL_LIGHTING_BIT);
444  glDisable(GL_LIGHTING);
445  for(int d=0;d<3;d++){
446  //GridEdge[d] = (int)(GridStep*Edge[d]*InvScaleUn);
447  Step[d] = Edge[d]*InvScaleUn/GridEdge[d];
448  }
449  //--------------------------grid
450  if(gr == 1){
451  for(int i=0;i<=GridEdge[0];i++){
452  for(int j=0;j<=GridEdge[1];j++){
453  glVertex3f(i*Step[0],j*Step[1],Edge[2]*InvScaleUn);
454  glVertex3f(i*Step[0],j*Step[1],0);
455  }
456  }
457  for(int j=0;j<=GridEdge[1];j++){
458  for(int k=0;k<=GridEdge[2];k++){
459  glVertex3f(0,j*Step[1],k*Step[2]);
460  glVertex3f(Edge[0]*InvScaleUn,j*Step[1],k*Step[2]);
461  }
462  }
463  for(int i=0;i<=GridEdge[0];i++){
464  for(int k=0;k<=GridEdge[2];k++){
465  glVertex3f(i*Step[0],0.,k*Step[2]);
466  glVertex3f(i*Step[0],Edge[1]*InvScaleUn,k*Step[2]);
467  }
468  }
469  }
470  else if (gr == 2){
471  for(int i=0;i<=GridEdge[0];i++){
472  glVertex3f(i*Step[0],0.,Edge[2]*InvScaleUn);
473  glVertex3f(i*Step[0],0.,0.);
474  glVertex3f(i*Step[0],Edge[1]*InvScaleUn,0.);
475  glVertex3f(i*Step[0],0.,0.);
476  }
477  for(int j=0;j<=GridEdge[1];j++){
478  glVertex3f(0,j*Step[1],0.);
479  glVertex3f(Edge[0]*InvScaleUn,j*Step[1],0.);
480  glVertex3f(0.,j*Step[1],0.);
481  glVertex3f(0.,j*Step[1],InvScaleUn*Edge[2]);
482  }
483  for(int k=0;k<=GridEdge[2];k++){
484  glVertex3f(0.,0.,k*Step[2]);
485  glVertex3f(0.,Edge[1]*InvScaleUn,k*Step[2]);
486  glVertex3f(0.,0.,k*Step[2]);
487  glVertex3f(Edge[0]*InvScaleUn,0.,k*Step[2]);
488  }
489  }
490  //glDisable(GL_LINE_SMOOTH);
491  //----------------------label
492  for(int i=0;i<=GridEdge[0];i++){
493  //glPushMatrix();//info
494  sprintf(Number,"%.2f",i/(double)GridEdge[0]);
495  glRasterPos3f(i*Step[0],0.,0.);
496  for (int l = 1; l < strlen(Number); l++) {
497  glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, Number[l]);
498  }
499  glCallList(Point);
500  //glPopMatrix();//info
501  }
502  for(int j=0;j<=GridEdge[1];j++){
503  //glPushMatrix();//info
504  sprintf(Number,"%.2f",j/(double)GridEdge[1]);
505  glRasterPos3f(0.,j*Step[1],0.);
506  for (int l = 1; l < strlen(Number); l++) {
507  glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, Number[l]);
508  }
509  glCallList(Point);
510  //glPopMatrix();//info
511  }
512  for(int k=0;k<=GridEdge[2];k++){
513  //glPushMatrix();//info
514  sprintf(Number,"%.2f",k/(double)GridEdge[2]);
515  glRasterPos3f(0.,0.,k*Step[2]);
516  for (int l = 1; l < strlen(Number); l++) {
517  glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, Number[l]);
518  }
519  glCallList(Point);
520  //glPopMatrix();//info
521  }
522  glColor4f(.2,.1,.7,1.);
523  glRasterPos3f(-.1,0.,0.);
524  glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,'0');
525  glRasterPos3f(Edge[0]*InvScaleUn+.1,0.,0.);
526  glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,'x');
527  glRasterPos3f(0.,Edge[1]*InvScaleUn+.1,0.);
528  glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,'y');
529  glRasterPos3f(0.,0.,Edge[2]*InvScaleUn+.1);
530  glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,'z');
531  glEnd();
532  glPopAttrib();
533  glEndList();
534  return Griglia;
535 }
536 void Draw::Lista(int NSquare){
537  // glEnable(GL_LIGHTING);
538  // glEnable(GL_COLOR_MATERIAL);
539  // glEnable(GL_NORMALIZE);
540  // //glEnable(GL_CULL_FACE);
541  // glCullFace(GL_FRONT_AND_BACK);//Disegna anche il lato dietro
542  // //glFrontFace(GL_CCW);//Senso antiorario
543  // //glColorMaterial(GL_FRONT_AND_BACK,GL_EMISSION);
544  // GLfloat Light1[4] = {0.,0.,0.,1.};
545  // glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,Light1);
546  // GLfloat Light2[4] = {1.,1.,1.,1.};
547  // glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,Light2);
548  // GLfloat Light3[4] = {0.,0.,0.,1.};
549  // glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,Light3);
550  // GLfloat Light4[4] = {1.,1.,1.,1.};
551  // glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,Light3);
552  // GLfloat Light5[4] = {1.,1.,1.,1.};
553  // glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,Light3);
554  // glEnable(GL_NORMALIZE);
555  DefPoint();
556  DefGriglia();
557  DefLegend();
558  DefArrowThin();
559 }
560 static double WeightFuncSpline(const double x){
561  if(x < 0.)
562  return 1.;
563  if(fabs(x) < 1.)
564  return 2.*fabs(x)*x*x - 3.*x*x + 1.;
565  else
566  return 0.;
567 }
568 static double Parab(const double x){
569  double Resp = -4.*x*x+4.;
570  if(Resp < 0) Resp = 0.;
571  return Resp;
572 }
573 void Draw::DepthMap1(double Val,GLfloat *Color){
574  Color[0] = (GLfloat)WeightFuncSpline((1.-Val)*.7);
575  Color[1] = (GLfloat)Parab((Val-.5)*3.);
576  Color[2] = (GLfloat)WeightFuncSpline((Val)*.7);
577  Color[3] = 1.;
578 }
580  if(i == 0)
582 }
584  glDisable(GL_LIGHTING);
585  glDeleteLists(DrLegend,1);
586  DrLegend = glGenLists(1);
587  glNewList(DrLegend,GL_COMPILE);
588  int NSlab = 100;
589  GLfloat InvNSlab = 1./(GLfloat)NSlab;
590  double dx = dxLeg*InvNSlab;
591  double dy = dyLeg*InvNSlab;
592  GLfloat Color[4];
593  char Number[10];
594  for(int i=0;i<NSlab;i++){
595  GLfloat x = xLeg;// + Size[0]*i*dx;
596  GLfloat y = yLeg + dyLeg*i*dy;
597  glBegin(GL_POLYGON);
598  glNormal3d(0.,0.,1.);
599  DepthMap(i*InvNSlab,Color);
600  for(int d=0;d<3;d++)Color[d] -= .2;
601  glColor4fv(Color);
602  glVertex3d(x,y,zLeg);
603  glVertex3d(x+dx,y,zLeg);
604  glVertex3d(x+dx,y+dy,zLeg);
605  glVertex3d(x,y+dy,zLeg);
606  glEnd();
607  if(!(i%10)){
608  glPushMatrix();//Info
609  sprintf(Number,"%.2f",i*InvNSlab);
610  glRasterPos3f(xLeg+4.*dx,y,zLeg);
611  for(int l=1;l<strlen(Number);l++){
612  //glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,Number[l]);
613  glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,Number[l]);
614  }
615  glPopMatrix();
616  }
617  }
618  glPushMatrix();//Info
619  sprintf(Number,"1.00");
620  glRasterPos3f(xLeg+4.*dx,yLeg+dyLeg,zLeg);
621  for(int l=1;l<strlen(Number);l++){
622  //glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,Number[l]);
623  glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,Number[l]);
624  }
625  glPopMatrix();
626  glEndList();
627  return DrLegend;
628 }
629 #endif // __glut_h__
void DepthMap1(double Val, GLfloat *Color)
Depth map.
GLfloat xp
Translation, wheel.
Definition: Draw.h:155
int GridEdge[3]
Number of lines per edge.
Definition: Draw.h:264
double InvScaleUn
Rescale the three orthogonal directions.
Definition: Draw.h:181
int IfInfo
Removes the info line.
Definition: Draw.h:232
GLuint Hexagon
Refers to the list of a hexagon.
Definition: Draw.h:185
int DefGriglia()
Griglia.
int DefMetalCylinder(double Rad, double Height)
Metallic cylinder.
double Normal(double *v, double *u, double *w, double *n)
Calculate the normal.
int ne
Enables/disables fog.
Definition: Draw.h:224
GLuint Arrow
Refers to the list of a arrow.
Definition: Draw.h:206
GLuint DrLegend
Refers to the list of the legend.
Definition: Draw.h:187
int DefCube(int NSquare)
Cube.
GLfloat Rback
Background color.
Definition: Draw.h:155
int sp
Enables/disables spot light.
Definition: Draw.h:222
void DepthMap(double Val, GLfloat *Color)
Pointer to a generic function.
Definition: Draw.h:113
GLfloat spin
Obsolete.
Definition: Draw.h:155
GLfloat xl1
Position of the light1.
Definition: Draw.h:155
int gr
Puts/removes the grid.
Definition: Draw.h:218
int DefQuad(int NSquare)
Quad.
GLuint GlWall
Refers to the list of a wall.
Definition: Draw.h:204
void ChooseDepthMap(int n)
Choose Depth map.
int IfImage
Boh.
Definition: Draw.h:236
GLuint Point
Refers to the list of the point.
Definition: Draw.h:193
GLuint Quad
Refers to the list of the square.
Definition: Draw.h:191
int la
Puts/removes the box edges.
Definition: Draw.h:216
int DefCylinder(double Rad, double Height)
Cylinder.
void InitConstant()
Initializes all the view constants.
GLuint Griglia
Refers to the list of the grid.
Definition: Draw.h:189
DEPTH_MAP Depth_Map
Pointer to a distance/field function.
Definition: Draw.h:111
int IfMaterial
Activate the illumination for a specific material.
Definition: Draw.h:240
GLuint Cube
Refers to the list of the texture.
Definition: Draw.h:208
int IfPoint
Decides to draw points or spheres.
Definition: Draw.h:230
int DefArrow()
Arrow.
GLfloat AngleDxSx
Angle DxSx, SuGiu.
Definition: Draw.h:179
int DefWall()
Wall.
int DefHexagon()
Hexagon.
GLfloat xl0
Position of the light0.
Definition: Draw.h:155
void Lista(int NSquare)
Definition of the primitives.
GLfloat xLeg
Position of the legend.
Definition: Draw.h:155
GLuint MetalCylinder
Refers to the list of another cylinder (obsolete)
Definition: Draw.h:197
int Step
Current step for the picture&#39;s name.
Definition: Draw.h:244
int DefTexture()
Define a simple texture.
GLfloat xa
Angles.
Definition: Draw.h:155
int DefArrowThin()
Arrow.
GLfloat xf
Orientation of the light.
Definition: Draw.h:155
int IfScript
Ignores the script file.
Definition: Draw.h:234
int IfBlend
Activate the blending.
Definition: Draw.h:238
GLfloat dxLeg
Width of the legend.
Definition: Draw.h:155
GLfloat xi
Position of the info string.
Definition: Draw.h:155
double Edge[3]
Box size.
Definition: Draw.h:262
int DefPoint()
Point.
char * info
Info line.
Definition: Draw.h:276
char * Number
Characters for the grid.
Definition: Draw.h:272
int lu
Enables/disables illumination.
Definition: Draw.h:220
int DefLegend()
Depth map.
double GridStep
Finess of the grid.
Definition: Draw.h:183