00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00028 #include "Navigation.h"
00029 #include "trackball.h"
00030
00031 #include <iostream>
00032
00036 void reshape(int width, int height)
00037 {
00038
00039
00040 xGL = width;
00041 yGL = height;
00042
00043 glViewport(0, 0, xGL, yGL);
00044
00045 glMatrixMode (GL_PROJECTION);
00046 glLoadIdentity ();
00047
00048 float ratio = (float)width/(float)height;
00049 glOrtho(-2, 2, -2 / ratio, 2 / ratio, -10.0, 10.0);
00050
00051 glMatrixMode (GL_MODELVIEW);
00052 glLoadIdentity ();
00053
00054
00055 GLfloat mat_diffuse[] = { 0.5, 0.5, 0.9, 1.0 };
00056 GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
00057 GLfloat mat_shininess[] = { 100.0 };
00058 GLfloat light_position[] = { 10.0, 10.0, 30.0, 1.0 };
00059
00060 glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
00061 glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
00062 glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
00063
00064 glLightfv(GL_LIGHT0, GL_POSITION, light_position);
00065
00066 glEnable(GL_LIGHTING);
00067 glEnable(GL_LIGHT0);
00068 glDepthFunc(GL_LEQUAL);
00069 glEnable(GL_DEPTH_TEST);
00070 glEnable(GL_AUTO_NORMAL);
00071 glEnable(GL_NORMALIZE);
00072
00073 trackballWidth = width;
00074 trackballHeight = height;
00075 }
00076
00077
00081 void motion(int x, int y)
00082 {
00083 if (trackballTracking)
00084 {
00085 trackball(newQuaternion,
00086 (2.0 * trackballBeginX - trackballWidth) / trackballWidth,
00087 (trackballHeight - 2.0 * trackballBeginY) / trackballHeight,
00088 (2.0 * x - trackballWidth) / trackballWidth,
00089 (trackballHeight - 2.0 * y) / trackballHeight);
00090 add_quats(newQuaternion, currentQuaternion, currentQuaternion);
00091
00092 trackballLastTime = glutGet(GLUT_ELAPSED_TIME);
00093
00094 trackballBeginX = x;
00095 trackballBeginY = y;
00096 }
00097
00098 glutPostRedisplay();
00099 }
00100
00101
00105 void mouse(int button, int state, int x, int y)
00106 {
00107 std::cout << "Position de la souris : " << x << " " << y << std::endl;
00108
00109 if (state == GLUT_DOWN && button == trackballButton)
00110 {
00111
00112
00113
00114 trackballTracking = true;
00115
00116 trackballLastTime = glutGet(GLUT_ELAPSED_TIME);
00117
00118 trackballBeginX = x;
00119 trackballBeginY = y;
00120 }
00121 else {
00122 if (state == GLUT_UP && button == trackballButton) {
00123 trackballTracking = false;
00124 }
00125 }
00126
00127 glutPostRedisplay();
00128 }
00129
00130
00134 void keyboard(unsigned char key, int x, int y)
00135 {
00136 static int fullscreen = 0;
00137 static int old_x = 50;
00138 static int old_y = 50;
00139 static int old_width = 512;
00140 static int old_height = 512;
00141
00142 switch (key) {
00143 case 27:
00144 exit(0);
00145 break;
00146
00147 case 'f':
00148 fullscreen = !fullscreen;
00149 if (fullscreen) {
00150 old_x = glutGet(GLUT_WINDOW_X);
00151 old_y = glutGet(GLUT_WINDOW_Y);
00152 old_width = glutGet(GLUT_WINDOW_WIDTH);
00153 old_height = glutGet(GLUT_WINDOW_HEIGHT);
00154 glutFullScreen();
00155 }
00156 else {
00157 glutReshapeWindow(old_width, old_height);
00158 glutPositionWindow(old_x, old_y);
00159 }
00160 break;
00161
00162 case 'z':
00163 if (scale_factor > 0)
00164 scale_factor -= 0.05;
00165 break;
00166
00167 case 'Z':
00168 scale_factor += 0.05;
00169 break;
00170
00171 case 's':
00172 if (shadingMode == SHADING_WIRED) { shadingMode = SHADING_SMOOTH; break; }
00173 if (shadingMode == SHADING_SMOOTH) { shadingMode = SHADING_NO_SMOOTH; break; }
00174 if (shadingMode == SHADING_NO_SMOOTH) { shadingMode = SHADING_WIRED; break; }
00175
00176 case 'n':
00177 normalDisplaying = ! normalDisplaying;
00178 break;
00179 }
00180
00181 glutPostRedisplay();
00182 }
00183
00184
00188 void menu(int item)
00189 {
00190 keyboard((unsigned char)item, 0, 0);
00191 }
00192
00193
00197 void visible(int state)
00198 {
00199 if (state == GLUT_VISIBLE) {
00200 glutIdleFunc(idle);
00201
00202 }
00203 else
00204
00205 glutIdleFunc(idle);
00206
00207 }