18 #include "../../include/Draw.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.;
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;
54 glDeleteLists(
Quad,1);
58 glNewList(
Quad,GL_COMPILE);
62 glVertex3f(xEdge,0,0);
63 glVertex3f(xEdge,yEdge,0);
64 glVertex3f(0,yEdge,0);
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.);
89 glDeleteLists(
Cube,1);
94 glNewList(
Cube,GL_COMPILE);
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);
120 glEnable(GL_TEXTURE_2D);
121 glNewList(
GlWall,GL_COMPILE);
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);
132 glNormal3d(0.,0.,1.);
133 glColor4f(1.,.0,.0,.5);
134 glVertex3d(0.,0.,0.);
135 glColor4f(1.,.4,.0,.5);
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.);
151 glDisable(GL_TEXTURE_2D);
155 glDeleteLists(
Arrow,1);
156 Arrow = glGenLists(1);
157 glNewList(
Arrow,GL_COMPILE);
158 glNormal3f(0.,0.,-1.);
160 glVertex3f(0.,0.,0.);
161 glVertex3f(1.,0.,0.);
164 glVertex3f(1.,0.,0.);
165 glVertex3f(.95,.02,0.);
168 glVertex3f(1.,0.,0.);
169 glVertex3f(.95,-.02,0.);
175 glDeleteLists(
Arrow,1);
176 Arrow = glGenLists(1);
177 glNewList(
Arrow,GL_COMPILE);
178 glNormal3f(0.,0.,-1.);
180 glVertex3f(0.,0.,0.);
181 glVertex3f(1.,0.,0.);
184 glVertex3f(1.,0.,0.);
185 glVertex3f(.95,.002,0.);
188 glVertex3f(1.,0.,0.);
189 glVertex3f(.95,-.002,0.);
195 glDeleteLists(Point,1);
196 Point = glGenLists(1);
197 glNewList(Point,GL_COMPILE);
199 glNormal3f(0.,0.,1.);
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]);
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);
232 double Angle = DUE_PI/(double)(NEdges);
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);
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);
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};
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]);
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]);
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]);
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]);
276 glDisable(GL_LIGHTING);
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};
297 glNormal3f(vn[0],vn[1],vn[2]);
299 glVertex3d(v1[0],v1[1],v1[2]);
300 glNormal3f(vn[0],vn[1],vn[2]);
302 glVertex3d(v2[0],v2[1],v2[2]);
303 glNormal3f(vn[0],vn[1],vn[2]);
305 glVertex3d(v3[0],v3[1],v3[2]);
306 glNormal3f(vn[0],vn[1],vn[2]);
308 glVertex3d(v4[0],v4[1],v4[2]);
329 MetalCylinder = glGenLists(1);
330 glNewList(MetalCylinder,GL_COMPILE);
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);
337 glShadeModel(GL_SMOOTH);
338 glEnableClientState(GL_NORMAL_ARRAY);
339 double Normal[3]={.1,.1,.1};
340 glNormalPointer(GL_FLOAT,
sizeof(
double),&Normal[0]);
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);
349 VecIndices.push_back(0);
350 int NIndex = VecIndices.size();
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);
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);
393 GLuint Texture_ID = 0;
395 GLubyte tex[128][128][4];
397 int hole_size = 3300;
399 glGenTextures(1,&Texture_ID);
400 glBindTexture(GL_TEXTURE_2D,Texture_ID);
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;
409 tex[x][y][0]=tex[x][y][1]=tex[x][y][2]=240;
413 t = (x-64)*(x-64) + (y-64)*(y-64) ;
416 else if (t < hole_size + 100)
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));
429 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
430 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
432 glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_DECAL);
436 glDisable(GL_LIGHTING);
441 glColor4f(1.-
Rback,1.-Gback,1.-Bback,1.0);
443 glPushAttrib(GL_LIGHTING_BIT);
444 glDisable(GL_LIGHTING);
445 for(
int d=0;d<3;d++){
454 glVertex3f(i*Step[0],j*Step[1],0);
459 glVertex3f(0,j*Step[1],k*Step[2]);
465 glVertex3f(i*Step[0],0.,k*Step[2]);
473 glVertex3f(i*Step[0],0.,0.);
474 glVertex3f(i*Step[0],
Edge[1]*InvScaleUn,0.);
475 glVertex3f(i*Step[0],0.,0.);
478 glVertex3f(0,j*Step[1],0.);
480 glVertex3f(0.,j*Step[1],0.);
481 glVertex3f(0.,j*Step[1],InvScaleUn*
Edge[2]);
484 glVertex3f(0.,0.,k*Step[2]);
486 glVertex3f(0.,0.,k*Step[2]);
487 glVertex3f(
Edge[0]*InvScaleUn,0.,k*Step[2]);
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]);
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]);
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]);
522 glColor4f(.2,.1,.7,1.);
523 glRasterPos3f(-.1,0.,0.);
524 glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,
'0');
526 glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,
'x');
528 glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,
'y');
530 glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,
'z');
560 static double WeightFuncSpline(
const double x){
564 return 2.*fabs(x)*x*x - 3.*x*x + 1.;
568 static double Parab(
const double x){
569 double Resp = -4.*x*x+4.;
570 if(Resp < 0) Resp = 0.;
574 Color[0] = (GLfloat)WeightFuncSpline((1.-Val)*.7);
575 Color[1] = (GLfloat)Parab((Val-.5)*3.);
576 Color[2] = (GLfloat)WeightFuncSpline((Val)*.7);
584 glDisable(GL_LIGHTING);
589 GLfloat InvNSlab = 1./(GLfloat)NSlab;
590 double dx =
dxLeg*InvNSlab;
591 double dy = dyLeg*InvNSlab;
594 for(
int i=0;i<NSlab;i++){
596 GLfloat y = yLeg + dyLeg*i*dy;
598 glNormal3d(0.,0.,1.);
600 for(
int d=0;d<3;d++)Color[d] -= .2;
602 glVertex3d(x,y,zLeg);
603 glVertex3d(x+dx,y,zLeg);
604 glVertex3d(x+dx,y+dy,zLeg);
605 glVertex3d(x,y+dy,zLeg);
609 sprintf(Number,
"%.2f",i*InvNSlab);
610 glRasterPos3f(
xLeg+4.*dx,y,zLeg);
611 for(
int l=1;l<strlen(Number);l++){
613 glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,Number[l]);
619 sprintf(Number,
"1.00");
620 glRasterPos3f(
xLeg+4.*dx,yLeg+dyLeg,zLeg);
621 for(
int l=1;l<strlen(Number);l++){
623 glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,Number[l]);
void DepthMap1(double Val, GLfloat *Color)
Depth map.
GLfloat xp
Translation, wheel.
int GridEdge[3]
Number of lines per edge.
double InvScaleUn
Rescale the three orthogonal directions.
int IfInfo
Removes the info line.
GLuint Hexagon
Refers to the list of a hexagon.
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.
GLuint Arrow
Refers to the list of a arrow.
GLuint DrLegend
Refers to the list of the legend.
int DefCube(int NSquare)
Cube.
GLfloat Rback
Background color.
int sp
Enables/disables spot light.
void DepthMap(double Val, GLfloat *Color)
Pointer to a generic function.
GLfloat xl1
Position of the light1.
int gr
Puts/removes the grid.
int DefQuad(int NSquare)
Quad.
GLuint GlWall
Refers to the list of a wall.
void ChooseDepthMap(int n)
Choose Depth map.
GLuint Point
Refers to the list of the point.
GLuint Quad
Refers to the list of the square.
int la
Puts/removes the box edges.
int DefCylinder(double Rad, double Height)
Cylinder.
void InitConstant()
Initializes all the view constants.
GLuint Griglia
Refers to the list of the grid.
DEPTH_MAP Depth_Map
Pointer to a distance/field function.
int IfMaterial
Activate the illumination for a specific material.
GLuint Cube
Refers to the list of the texture.
int IfPoint
Decides to draw points or spheres.
GLfloat AngleDxSx
Angle DxSx, SuGiu.
GLfloat xl0
Position of the light0.
void Lista(int NSquare)
Definition of the primitives.
GLfloat xLeg
Position of the legend.
GLuint MetalCylinder
Refers to the list of another cylinder (obsolete)
int Step
Current step for the picture's name.
int DefTexture()
Define a simple texture.
GLfloat xf
Orientation of the light.
int IfScript
Ignores the script file.
int IfBlend
Activate the blending.
GLfloat dxLeg
Width of the legend.
GLfloat xi
Position of the info string.
char * Number
Characters for the grid.
int lu
Enables/disables illumination.
int DefLegend()
Depth map.
double GridStep
Finess of the grid.