Allink  v0.1
DrawControl.cpp
1 #include "../../include/Draw.h"
2 
3 #ifdef __glut_h__
5 // Quaternione DxSx;
6 // Quaternione SuGiu;
7 // Quaternione Union;
8 // float Matrix[16];
9 // DxSx.AxisRotation(1.,0.,0.,AngleDxSx);
10 // SuGiu.AxisRotation(0.,1.,0.,AngleSuGiu);
11 // Union = DxSx * SuGiu;
12 // Union.CreateMatrix(Matrix);
13 // glMultMatrixf(Matrix);
14 }
15 void Draw::ChangeDxSx(GLfloat Movement){
16  if( POS(Movement) < IncrVisDxSx )
17  xa += Movement;
18  else{
19  if(Movement < 0)
20  xa -= IncrVisDxSx;
21  else
22  xa += IncrVisDxSx;
23  }
24  if( xa > 360.)
25  xa = -360.;
26  if( xa < -360.)
27  xa = 360.;
28  //yp += (float)(sin(xa/PI*180.));
29 }
30 void Draw::ChangeSuGiu(GLfloat Movement){
31  if( POS(Movement) < IncrVisSuGiu ){
32  if(ya > 90 && ya < 270
33  || (ya < -90 && ya > -270))
34  ya -= Movement;
35  else
36  ya += Movement;
37  }
38  else{
39  if(Movement < 0){
40  if(ya > 90 && ya < 270
41  || (ya < -90 && ya > -270))
42  ya += IncrVisSuGiu;
43  else
44  za -= IncrVisSuGiu;
45  //ya -= IncrVisDxSx;
46  }
47  else {
48  if(ya > 90 && ya < 270
49  || (ya < -90 && ya > -270))
50  ya -= IncrVisSuGiu;
51  else
52  za += IncrVisSuGiu;
53  //ya += IncrVisDxSx;
54  }
55  }
56  if( ya > 360.)
57  ya = -360.;
58  if( ya < -360.)
59  ya = 360.;
60  //xp += (float)(sin(ya/PI*180.));
61  //zp -= (float)(cos(ya/PI*180.));
62 }
63 void Draw::DMouseMove(int x,int y){
64  GLfloat Diff = 0.;
65  if(y > yRem){
66  Diff = 2.*(y - yRem);
67  ChangeDxSx(Diff);
68  }
69  else if(y < yRem){
70  Diff = 2.*(y - yRem);
71  ChangeDxSx(Diff);
72  }
73  if(x > xRem){
74  Diff = 2.*(x - xRem);
75  ChangeSuGiu(Diff);
76  }
77  else if(x < xRem){
78  Diff = 2.*(x - xRem);
79  ChangeSuGiu(Diff);
80  }
81  xRem = x;
82  yRem = y;
83  //printf("(%f,%f,%lf)\n",xa,ya,za);
84  glutPostRedisplay();
85 }
86 void Draw::Dmouse(int button, int state,int x,int y){
87  switch (button){
88  case GLUT_RIGHT_BUTTON:
89  // xRem = x;
90  // yRem = y;
91  break;
92  case GLUT_LEFT_BUTTON:
93  if(state==GLUT_DOWN){
94  if(ChangeMouse == 0){
95  // glutPassiveMotionFunc( MouseMove );
96  //glutIdleFunc(spinDisplay);
97  }
98  else {
99  // glutPassiveMotionFunc(NULL);
100  }
102  }
103  break;
104  case GLUT_WHEEL_DOWN:
105  zw -= .02;
106  glutPostRedisplay();
107  break;
108  case GLUT_WHEEL_UP:
109  zw += .02;
110  glutPostRedisplay();
111  break;
112  default:
113  break;
114  }
115 }
116 void Draw::Dspecial(int k, int x, int y)
117 {
118  switch (k) {
119  case GLUT_KEY_UP:
120  xf += 5.0;
121  break;
122  case GLUT_KEY_DOWN:
123  xf -= 5.0;
124  break;
125  case GLUT_KEY_LEFT:
126  yf += 5.0;
127  break;
128  case GLUT_KEY_RIGHT:
129  yf -= 5.0;
130  break;
131  default:
132  return;
133  }
134  glutPostRedisplay();
135 }
136 void Draw::ChooseBlend(int Which){
137  switch(Which){
138  case 1:
139  BlendSource = GL_SRC_ALPHA;
140  BlendDest = GL_ONE_MINUS_SRC_ALPHA;// GL_ONE_MINUS_DST_COLOR;
141  break;
142  case 2:
143  BlendSource = GL_SRC_ALPHA;
144  BlendDest = GL_ONE_MINUS_DST_ALPHA;
145  break;
146  case 3:
147  BlendSource = GL_DST_COLOR;
148  BlendDest = GL_ONE_MINUS_SRC_ALPHA;
149  break;
150  case 4:
151  BlendSource = GL_ONE_MINUS_SRC_ALPHA;
152  BlendDest = GL_ONE_MINUS_DST_COLOR;
153  break;
154  case 5:
155  BlendSource = GL_DST_COLOR;
156  BlendDest = GL_SRC_COLOR;
157  break;
158  case 6:
159  BlendSource = GL_ONE;
160  BlendDest = GL_SRC_COLOR;
161  break;
162  case 7:
163  BlendSource = GL_SRC_COLOR;
164  BlendDest = GL_ONE_MINUS_DST_COLOR;
165  break;
166  case 8:
167  BlendSource = GL_ONE_MINUS_SRC_ALPHA;
168  BlendDest = GL_ONE_MINUS_DST_COLOR;
169  break;
170  case 9:
171  BlendSource =GL_DST_COLOR ;
172  BlendDest = GL_ZERO;
173  break;
174  case 10:
175  BlendSource = GL_DST_COLOR;
176  BlendDest = GL_ONE_MINUS_SRC_ALPHA;
177  break;
178  }
179 }
180 void Draw::keyboardDraw(unsigned char key){
181  switch (key){
182  case 'a':
183  break;
184  case 'A':
185  IfImage=0;
186  glutPostRedisplay();
187  break;
188  case 'B':
189  if(IfBlend)
190  glEnable(GL_BLEND);
191  else
192  glDisable(GL_BLEND);
193  IfBlend != IfBlend;
194  break;
195  case 'C':
196  printf("Coordinate (%.2f,%.2f,%.2f) Angolo (%.2f,%.2f,%.2f) Luce (%.2f,%.2f,%.2f) Ruota %lf)\n"
197  ,xp,yp,zp,xa,ya,za,xf,yf,zf,zw);
198  break;
199  case 'f':
200  glutFullScreen();
201  glutPostRedisplay();
202  break;
203  case 'g':
204  gr += 1;pr=0;
205  if(gr == 3) gr=0;pr=1;
206  Lista(Values);
207  sprintf(info,"Grid visualized every %d system unit",GridStep);
208  glutPostRedisplay();
209  break;
210  case 'G':
211  GridStep += 1.;
212  for(int d=0;d<3;d++)
213  GridEdge[d] = (int)(GridStep*Edge[d]*InvScaleUn);
214  Lista(Values);
215  sprintf(info,"Grid visualized every %d system unit",GridStep);
216  glutPostRedisplay();
217  break;
218  case 'h':
219  glutIdleFunc(NULL);
220  break;
221  case 'l':
222  la = !la;
223  glutPostRedisplay();
224  break;
225  case 'L':
227  glutPostRedisplay();
228  break;
229  case 'k':
230  Step++;
231  IfInfo = 0;
232  glutPostRedisplay();
233  Picture();
234  IfInfo = 1;
235  //WritePngwriter();
236  break;
237  case 'm':
238  //OpenImage("SplineAngolose.tif");
239  //Menu();
240  break;
241  case 'M':
242  //glutDestroyMenu(menu);
243  break;
244  case 'p':
245  IfPoint++;
246  if(IfPoint == 2) IfPoint =0;
247  glutPostRedisplay();
248  break;
249  case 'P':
250  pr += 1;
251  if(pr == 2) pr =0;
252  if(pr == 1)
253  sprintf(info,"Prospective view");
254  else if(pr == 0)
255  sprintf(info,"Orthogonal view");
256  glutPostRedisplay();
257  break;
258  case 'q':
259  glutDestroyWindow(MainWindow);
260  exit(0);
261  break;
262  case 's':
263  IfScript = !IfScript;
264  ReadScript();
265  break;
266  case 'x':
267  xp += .1;
268  glutPostRedisplay();
269  break;
270  case 'X':
271  xp -= .1;
272  glutPostRedisplay();
273  break;
274  case 'y':
275  yp += .1;
276  glutPostRedisplay();
277  break;
278  case 'Y':
279  yp -= .1;
280  glutPostRedisplay();
281  break;
282  case 'w':
283  Rback = 1.0 - Rback;
284  Gback = 1.0 - Gback;
285  Bback = 1.0 - Bback;
286  Aback = 0.0;
287  Lista(Values);
288  glutPostRedisplay();
289  break;
290  case 'z':
291  zp += .1;
292  glutPostRedisplay();
293  break;
294  case 'Z':
295  zp -= .1;
296  glutPostRedisplay();
297  break;
298  case 27:
299  exit(0);
300  break;
301  case 40:
302  //glutIdleFunc(Expand);
303  break;
304  default:
305  break;
306  }
307 }
308 #endif
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
void DMouseMove(int x, int y)
How the scene rotate (Camera view should be implemented)
Definition: DrawControl.cpp:63
void ChangeDxSx(GLfloat Movement)
Movement right left.
Definition: DrawControl.cpp:15
int IfInfo
Removes the info line.
Definition: Draw.h:232
GLfloat IncrVisDxSx
Increment visual DxSx, SuGiu.
Definition: Draw.h:177
void ReadScript()
Reads and draw a script file.
Definition: DrawFile.cpp:285
GLfloat Rback
Background color.
Definition: Draw.h:155
void Dspecial(int k, int x, int y)
Boh.
int Picture()
Write a tiff file of the data in pixel.
Definition: DrawFile.cpp:183
int Values
Number of values to divide the edge in squares.
Definition: Draw.h:242
int gr
Puts/removes the grid.
Definition: Draw.h:218
int ChangeMouse
Boh.
Definition: Draw.h:254
void keyboardDraw(unsigned char key)
Combines the key with the functions.
int MainWindow
Refers to optional different windows.
Definition: Draw.h:226
int IfImage
Boh.
Definition: Draw.h:236
int la
Puts/removes the box edges.
Definition: Draw.h:216
int IfMaterial
Activate the illumination for a specific material.
Definition: Draw.h:240
void CameraQuat()
Quaternion camera implementation.
Definition: DrawControl.cpp:4
int IfPoint
Decides to draw points or spheres.
Definition: Draw.h:230
int yRem
Old y position of the mouse.
Definition: Draw.h:252
void Lista(int NSquare)
Definition of the primitives.
int Step
Current step for the picture&#39;s name.
Definition: Draw.h:244
GLfloat xa
Angles.
Definition: Draw.h:155
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
double Edge[3]
Box size.
Definition: Draw.h:262
int xRem
Old x position of the mouse.
Definition: Draw.h:250
void ChooseBlend(int Which)
Choose a different blending function.
char * info
Info line.
Definition: Draw.h:276
void Dmouse(int button, int state, int x, int y)
To launch the menu.
Definition: DrawControl.cpp:86
void ChangeSuGiu(GLfloat Movement)
Movement up-down.
Definition: DrawControl.cpp:30
double GridStep
Finess of the grid.
Definition: Draw.h:183