//=========================================================================== // SISL - SINTEF Spline Library, version 4.5.0. // Definition and interrogation of NURBS curves and surfaces. // // Copyright (C) 2000-2005, 2010 SINTEF ICT, Applied Mathematics, Norway. // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation version 2 of the License. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., // 59 Temple Place - Suite 330, // Boston, MA 02111-1307, USA. // // Contact information: E-mail: tor.dokken@sintef.no // SINTEF ICT, Department of Applied Mathematics, // P.O. Box 124 Blindern, // 0314 Oslo, Norway. // // Other licenses are also available for this software, notably licenses // for: // - Building commercial software. // - Building software whose source code you wish to keep private. //=========================================================================== 00271 #ifndef QTMODE 00272 glutMotionFunc(MouseRotate); 00273 #else 00274 // 030917: setting global variable so that new qt event handler 00275 // knows what to do. 00276 extern bool enableMouseRotation; 00277 enableMouseRotation=true; 00278 #endif 00279 break; 00280 case GLUT_MIDDLE_BUTTON: 00281 #ifndef QTMODE 00282 glutMotionFunc(MouseZoom); 00283 #else 00284 // 030918: setting global variable so that new qt event handler 00285 // knows what to do. 00286 extern bool enableMouseZoom; 00287 enableMouseZoom=true; 00288 #endif 00289 break; 00290 case GLUT_RIGHT_BUTTON: 00291 #ifndef QTMODE 00292 glutMotionFunc(MouseTranslate); 00293 #else 00294 // 030918: setting global variable so that new qt event handler 00295 // knows what to do. 00296 extern bool enableMouseTranslate; 00297 enableMouseTranslate=true; 00298 #endif 00299 break; 00300 } 00301 } 00302 00303 if (state==GLUT_UP) 00304 { 00305 00306 #ifdef MIDDLE_EMU 00307 if (butt==GLUT_LEFT_BUTTON) 00308 left_down=0; 00309 if (butt==GLUT_RIGHT_BUTTON) 00310 right_down=0; 00311 #endif 00312 #ifdef QTMODE 00313 extern bool enableMouseRotation, enableMouseZoom, enableMouseTranslate; 00314 enableMouseRotation=false; 00315 enableMouseZoom=false; 00316 enableMouseTranslate=false; 00317 #endif 00318 00319 // 00320 // 020410: Introduced 'spin_speed', was 1 before, setting to 2. 00321 // There seems to be some confusion here as to whether 00322 // the ?rot-variables are ints or floats?! 00323 // 040220: Reducing to 1, seems to be very unwieldy with the new 00324 // GF4 card...(?!) 00325 // 040505: Nå med fx5900, 1.0 ser ut til å være alt for mye for 00326 // endel bview2-greier. 00327 // 00328 //const double spin_speed=2.0; 00329 //const double spin_speed=1.0; 00330 const double spin_speed=0.1; 00331 00332 // 00333 // 991123: This was a stupid thing to do! We don't need to 00334 // disable this one! It's only active while the button 00335 // is pressed down, anyway! 00336 // 00337 // glutMotionFunc(MouseDummy); 00338 if ((butt==GLUT_LEFT_BUTTON) && 00339 ((x-last_x0)*(x-last_x0)+(y-last_y0)*(y-last_y0)>4)) 00340 { 00341 if (!transversal_rotation(x, y, last_x0, last_y0)) 00342 { 00343 xrot=(y-last_y0)*spin_speed; 00344 yrot=(x-last_x0)*spin_speed; 00345 /* zrot=0;*/ 00346 } 00347 else 00348 { 00349 int s; 00350 int viewp[4]; 00351 00352 glGetIntegerv(GL_VIEWPORT, viewp); 00353 if (atan2(y-(viewp[1]+viewp[3])*0.5, 00354 x-(viewp[0]+viewp[2])*0.5)> 00355 atan2(last_y0-(viewp[1]+viewp[3])*0.5, 00356 last_x0-(viewp[0]+viewp[2])*0.5)) 00357 s=-1; 00358 else 00359 s=1; 00360 00361 /* xrot=0; 00362 yrot=0;*/ 00363 zrot=(s*(int)(sqrt((double)(SQR(y-last_y0)+SQR(x-last_x0))))* 00364 spin_speed); 00365 } 00366 } 00367 } 00368 00369 /* 00370 printf("butt=%d state=%d x=%d y=%d " 00371 "last_x=%d last_y=%d last_x=%d last_y=%d\n", 00372 butt, state, x, y, last_x, last_y, last_x0, last_y0); 00373 #ifdef MIDDLE_EMU 00374 // printf("Left down=%d, right down=%d\n", left_down, right_down); 00375 #endif 00376 puts(" "); 00377 */ 00378 draw_cursor(x, y); 00379 }
| void MouseRotate | ( | int | x, | |
| int | y | |||
| ) |
Definition at line 140 of file mouse.cpp.
References draw_cursor(), last_x, last_x0, last_y, last_y0, mouse_movement, rotate(), SQR, and transversal_rotation().
Referenced by main(), and Mouse().
00141 { 00142 int viewp[4]; 00143 //const double sensitiveness=0.1; 00144 // 030129: Reducing sensitivity slightly. 00145 //const double sensitiveness=0.05; 00146 // 030302: Reducing sensitivity slightly more, for demo. 00147 const double sensitiveness=0.02; 00148 00149 mouse_movement = mouse_movement || ((x!=last_x) || (y!=last_y)); 00150 00151 //puts("MouseRotate"); 00152 glGetIntegerv(GL_VIEWPORT, viewp); 00153 00154 draw_cursor(x, y); 00155 00156 if (!transversal_rotation(x, y, last_x, last_y)) 00157 rotate((x-last_x)*sensitiveness, (y-last_y)*sensitiveness, 0.0); 00158 else 00159 { 00160 int s; 00161 00162 if (atan2(y-(viewp[1]+viewp[3])*0.5, 00163 x-(viewp[0]+viewp[2])*0.5)> 00164 atan2(last_y-(viewp[1]+viewp[3])*0.5, 00165 last_x-(viewp[0]+viewp[2])*0.5)) 00166 s=-1; 00167 else 00168 s=1; 00169 00170 rotate(0.0, 0.0, 00171 s*sqrt((double)(SQR(x-last_x)+SQR(y-last_y)))*sensitiveness); 00172 } 00173 00174 last_x0=last_x; 00175 last_y0=last_y; 00176 last_x=x; 00177 last_y=y; 00178 }
| void MouseTranslate | ( | int | x, | |
| int | y | |||
| ) |
| void MouseZoom | ( | int | x, | |
| int | y | |||
| ) |
| int transversal_rotation | ( | int | x, | |
| int | y, | |||
| int | last_xx, | |||
| int | last_yy | |||
| ) |
Definition at line 104 of file mouse.cpp.
References allow_zrot, PI, and SQR.
Referenced by Mouse(), and MouseRotate().
00105 { 00106 int viewp[4]; 00107 00108 glGetIntegerv(GL_VIEWPORT, viewp); 00109 if ((fabs(((x-last_xx)*(x-(viewp[0]+viewp[2])*0.5)+ 00110 (y-last_yy)*(y-(viewp[1]+viewp[3])*0.5))/ 00111 sqrt((double)(SQR(x-last_xx)+SQR(y-last_yy)))/ 00112 sqrt((double)(SQR(x-(viewp[0]+viewp[2])*0.5)+ 00113 SQR(y-(viewp[1]+viewp[3])*0.5)))) > 00114 cos(50.0/180.0*PI)) || 00115 (sqrt((x-(viewp[0]+viewp[2])*0.5)*(x-(viewp[0]+viewp[2])*0.5)+ 00116 (y-(viewp[1]+viewp[3])*0.5)*(y-(viewp[1]+viewp[3])*0.5)) < 00117 0.2*sqrt((double)SQR(viewp[2]-viewp[0])+SQR(viewp[3]-viewp[1]))) || 00118 (!allow_zrot)) 00119 { 00120 /* puts("radielt");*/ 00121 return 0; 00122 } 00123 else 00124 { 00125 /* puts("transversalt");*/ 00126 return 1; 00127 } 00128 // draw_cursor(x, y); 00129 }
| GLboolean allow_zrot |
Definition at line 58 of file mouse.cpp.
Referenced by transversal_rotation().
| int last_x |
Definition at line 59 of file mouse.cpp.
Referenced by Mouse(), MouseRotate(), MouseTranslate(), and MouseZoom().
| int last_x0 |
Definition at line 59 of file mouse.cpp.
Referenced by Mouse(), and MouseRotate().
| int last_y |
Definition at line 59 of file mouse.cpp.
Referenced by Mouse(), MouseRotate(), MouseTranslate(), and MouseZoom().
| int last_y0 |
Definition at line 59 of file mouse.cpp.
Referenced by Mouse(), and MouseRotate().
| bool mouse_movement |
Definition at line 60 of file mouse.cpp.
Referenced by draw(), and MouseRotate().
1.6.3