Allink
v0.1
|
00001 #include "../../include/Draw.h" 00002 00003 #ifdef __glut_h__ 00004 void Draw::CameraQuat(){ 00005 // Quaternione DxSx; 00006 // Quaternione SuGiu; 00007 // Quaternione Union; 00008 // float Matrix[16]; 00009 // DxSx.AxisRotation(1.,0.,0.,AngleDxSx); 00010 // SuGiu.AxisRotation(0.,1.,0.,AngleSuGiu); 00011 // Union = DxSx * SuGiu; 00012 // Union.CreateMatrix(Matrix); 00013 // glMultMatrixf(Matrix); 00014 } 00015 void Draw::ChangeDxSx(GLfloat Movement){ 00016 if( POS(Movement) < IncrVisDxSx ) 00017 xa += Movement; 00018 else{ 00019 if(Movement < 0) 00020 xa -= IncrVisDxSx; 00021 else 00022 xa += IncrVisDxSx; 00023 } 00024 if( xa > 360.) 00025 xa = -360.; 00026 if( xa < -360.) 00027 xa = 360.; 00028 //yp += (float)(sin(xa/PI*180.)); 00029 } 00030 void Draw::ChangeSuGiu(GLfloat Movement){ 00031 if( POS(Movement) < IncrVisSuGiu ){ 00032 if(ya > 90 && ya < 270 00033 || (ya < -90 && ya > -270)) 00034 ya -= Movement; 00035 else 00036 ya += Movement; 00037 } 00038 else{ 00039 if(Movement < 0){ 00040 if(ya > 90 && ya < 270 00041 || (ya < -90 && ya > -270)) 00042 ya += IncrVisSuGiu; 00043 else 00044 za -= IncrVisSuGiu; 00045 //ya -= IncrVisDxSx; 00046 } 00047 else { 00048 if(ya > 90 && ya < 270 00049 || (ya < -90 && ya > -270)) 00050 ya -= IncrVisSuGiu; 00051 else 00052 za += IncrVisSuGiu; 00053 //ya += IncrVisDxSx; 00054 } 00055 } 00056 if( ya > 360.) 00057 ya = -360.; 00058 if( ya < -360.) 00059 ya = 360.; 00060 //xp += (float)(sin(ya/PI*180.)); 00061 //zp -= (float)(cos(ya/PI*180.)); 00062 } 00063 void Draw::DMouseMove(int x,int y){ 00064 GLfloat Diff = 0.; 00065 if(y > yRem){ 00066 Diff = 2.*(y - yRem); 00067 ChangeDxSx(Diff); 00068 } 00069 else if(y < yRem){ 00070 Diff = 2.*(y - yRem); 00071 ChangeDxSx(Diff); 00072 } 00073 if(x > xRem){ 00074 Diff = 2.*(x - xRem); 00075 ChangeSuGiu(Diff); 00076 } 00077 else if(x < xRem){ 00078 Diff = 2.*(x - xRem); 00079 ChangeSuGiu(Diff); 00080 } 00081 xRem = x; 00082 yRem = y; 00083 //printf("(%f,%f,%lf)\n",xa,ya,za); 00084 glutPostRedisplay(); 00085 } 00086 void Draw::Dmouse(int button, int state,int x,int y){ 00087 switch (button){ 00088 case GLUT_RIGHT_BUTTON: 00089 // xRem = x; 00090 // yRem = y; 00091 break; 00092 case GLUT_LEFT_BUTTON: 00093 if(state==GLUT_DOWN){ 00094 if(ChangeMouse == 0){ 00095 // glutPassiveMotionFunc( MouseMove ); 00096 //glutIdleFunc(spinDisplay); 00097 } 00098 else { 00099 // glutPassiveMotionFunc(NULL); 00100 } 00101 ChangeMouse = !ChangeMouse; 00102 } 00103 break; 00104 case GLUT_WHEEL_DOWN: 00105 zw -= .02; 00106 glutPostRedisplay(); 00107 break; 00108 case GLUT_WHEEL_UP: 00109 zw += .02; 00110 glutPostRedisplay(); 00111 break; 00112 default: 00113 break; 00114 } 00115 } 00116 void Draw::Dspecial(int k, int x, int y) 00117 { 00118 switch (k) { 00119 case GLUT_KEY_UP: 00120 xf += 5.0; 00121 break; 00122 case GLUT_KEY_DOWN: 00123 xf -= 5.0; 00124 break; 00125 case GLUT_KEY_LEFT: 00126 yf += 5.0; 00127 break; 00128 case GLUT_KEY_RIGHT: 00129 yf -= 5.0; 00130 break; 00131 default: 00132 return; 00133 } 00134 glutPostRedisplay(); 00135 } 00136 void Draw::ChooseBlend(int Which){ 00137 switch(Which){ 00138 case 1: 00139 BlendSource = GL_SRC_ALPHA; 00140 BlendDest = GL_ONE_MINUS_SRC_ALPHA;// GL_ONE_MINUS_DST_COLOR; 00141 break; 00142 case 2: 00143 BlendSource = GL_SRC_ALPHA; 00144 BlendDest = GL_ONE_MINUS_DST_ALPHA; 00145 break; 00146 case 3: 00147 BlendSource = GL_DST_COLOR; 00148 BlendDest = GL_ONE_MINUS_SRC_ALPHA; 00149 break; 00150 case 4: 00151 BlendSource = GL_ONE_MINUS_SRC_ALPHA; 00152 BlendDest = GL_ONE_MINUS_DST_COLOR; 00153 break; 00154 case 5: 00155 BlendSource = GL_DST_COLOR; 00156 BlendDest = GL_SRC_COLOR; 00157 break; 00158 case 6: 00159 BlendSource = GL_ONE; 00160 BlendDest = GL_SRC_COLOR; 00161 break; 00162 case 7: 00163 BlendSource = GL_SRC_COLOR; 00164 BlendDest = GL_ONE_MINUS_DST_COLOR; 00165 break; 00166 case 8: 00167 BlendSource = GL_ONE_MINUS_SRC_ALPHA; 00168 BlendDest = GL_ONE_MINUS_DST_COLOR; 00169 break; 00170 case 9: 00171 BlendSource =GL_DST_COLOR ; 00172 BlendDest = GL_ZERO; 00173 break; 00174 case 10: 00175 BlendSource = GL_DST_COLOR; 00176 BlendDest = GL_ONE_MINUS_SRC_ALPHA; 00177 break; 00178 } 00179 } 00180 void Draw::keyboardDraw(unsigned char key){ 00181 switch (key){ 00182 case 'a': 00183 break; 00184 case 'A': 00185 IfImage=0; 00186 glutPostRedisplay(); 00187 break; 00188 case 'B': 00189 if(IfBlend) 00190 glEnable(GL_BLEND); 00191 else 00192 glDisable(GL_BLEND); 00193 IfBlend != IfBlend; 00194 break; 00195 case 'C': 00196 printf("Coordinate (%.2f,%.2f,%.2f) Angolo (%.2f,%.2f,%.2f) Luce (%.2f,%.2f,%.2f) Ruota %lf)\n" 00197 ,xp,yp,zp,xa,ya,za,xf,yf,zf,zw); 00198 break; 00199 case 'f': 00200 glutFullScreen(); 00201 glutPostRedisplay(); 00202 break; 00203 case 'g': 00204 gr += 1;pr=0; 00205 if(gr == 3) gr=0;pr=1; 00206 Lista(Values); 00207 sprintf(info,"Grid visualized every %d system unit",GridStep); 00208 glutPostRedisplay(); 00209 break; 00210 case 'G': 00211 GridStep += 1.; 00212 for(int d=0;d<3;d++) 00213 GridEdge[d] = (int)(GridStep*Edge[d]*InvScaleUn); 00214 Lista(Values); 00215 sprintf(info,"Grid visualized every %d system unit",GridStep); 00216 glutPostRedisplay(); 00217 break; 00218 case 'h': 00219 glutIdleFunc(NULL); 00220 break; 00221 case 'l': 00222 la = !la; 00223 glutPostRedisplay(); 00224 break; 00225 case 'L': 00226 IfMaterial = !IfMaterial; 00227 glutPostRedisplay(); 00228 break; 00229 case 'k': 00230 Step++; 00231 IfInfo = 0; 00232 glutPostRedisplay(); 00233 Picture(); 00234 IfInfo = 1; 00235 //WritePngwriter(); 00236 break; 00237 case 'm': 00238 //OpenImage("SplineAngolose.tif"); 00239 //Menu(); 00240 break; 00241 case 'M': 00242 //glutDestroyMenu(menu); 00243 break; 00244 case 'p': 00245 IfPoint++; 00246 if(IfPoint == 2) IfPoint =0; 00247 glutPostRedisplay(); 00248 break; 00249 case 'P': 00250 pr += 1; 00251 if(pr == 2) pr =0; 00252 if(pr == 1) 00253 sprintf(info,"Prospective view"); 00254 else if(pr == 0) 00255 sprintf(info,"Orthogonal view"); 00256 glutPostRedisplay(); 00257 break; 00258 case 'q': 00259 glutDestroyWindow(MainWindow); 00260 exit(0); 00261 break; 00262 case 's': 00263 IfScript = !IfScript; 00264 ReadScript(); 00265 break; 00266 case 'x': 00267 xp += .1; 00268 glutPostRedisplay(); 00269 break; 00270 case 'X': 00271 xp -= .1; 00272 glutPostRedisplay(); 00273 break; 00274 case 'y': 00275 yp += .1; 00276 glutPostRedisplay(); 00277 break; 00278 case 'Y': 00279 yp -= .1; 00280 glutPostRedisplay(); 00281 break; 00282 case 'w': 00283 Rback = 1.0 - Rback; 00284 Gback = 1.0 - Gback; 00285 Bback = 1.0 - Bback; 00286 Aback = 0.0; 00287 Lista(Values); 00288 glutPostRedisplay(); 00289 break; 00290 case 'z': 00291 zp += .1; 00292 glutPostRedisplay(); 00293 break; 00294 case 'Z': 00295 zp -= .1; 00296 glutPostRedisplay(); 00297 break; 00298 case 27: 00299 exit(0); 00300 break; 00301 case 40: 00302 //glutIdleFunc(Expand); 00303 break; 00304 default: 00305 break; 00306 } 00307 } 00308 #endif