00001
00010 #include "graphics_relative.h"
00011
00012 #include "../hydro_source/dataFillings.h"
00013
00014
00015
00016 GLuint base;
00017
00018
00019 bool keys[256];
00020 bool active=TRUE;
00021 bool fullscreen=TRUE;
00022
00023 bool light;
00024
00025
00026
00027 GLfloat viewAngle1 = 0.0;
00028 GLfloat viewAngle2 = 0.3;
00029 GLfloat dviewAngle = 0.01;
00030 GLfloat viewDist = 50.0;
00031 GLfloat dviewDist = 0.3;
00032
00033
00034 GLfloat LightAmbient[]= { 0.35f, 0.35f, 0.5f, 1.0f };
00035 GLfloat LightDiffuse[]= { 0.6f, 0.6f, 0.6f, 1.0f };
00036 GLfloat LightPosition[]= { -10.0f, 20.0f, 150.0f, 0.0f };
00037
00038
00039
00040 bool done=FALSE;
00041
00042
00043 bool doX = TRUE;
00044 bool doY = TRUE;
00045 bool doZ = TRUE;
00046 bool doR = TRUE;
00047 float dirX = 1.0f;
00048 float dirY = -1.0f;
00049 float dirZ = 1.0f;
00050 float dirR = 1.0f;
00051 float time_before = 0.0;
00052 float time_elapsed;
00053 float fps = 0.0;
00054 bool callibratingPhase = TRUE;
00055 bool onBoardView = FALSE;
00056
00057
00058 int bpp = 0;
00059
00060 int flags = 0;
00061
00062
00063 TTF_Font *font = NULL;
00064 TTF_Font *fontBIG = NULL;
00065 SDL_Surface *screen;
00066
00067
00068 SDL_Color text_color;
00069 SDL_Rect text_position;
00070
00071
00072 GLuint texture[2];
00073
00074
00075
00076 GLuint* get_texture()
00077 {
00078 return texture;
00079 }
00080
00081 bool getCallibatingPhase()
00082 {
00083 return callibratingPhase;
00084 }
00085
00086
00087 int my_round(double x)
00088 {
00089 return (int)(x + 0.5);
00090 }
00091
00092 int nextpoweroftwo(int x)
00093 {
00094 double logbase2 = log(x) / log(2);
00095 return my_round(pow(2,ceil(logbase2)));
00096 }
00097
00098
00099
00100
00101 void SDL_GL_RenderText(char *text,
00102 TTF_Font *font,
00103 SDL_Color color,
00104 SDL_Rect *location)
00105 {
00106 SDL_Surface *initial;
00107 SDL_Surface *intermediary;
00108 SDL_Rect rect;
00109 int w,h;
00110 GLuint texture;
00111
00112
00113 initial = TTF_RenderText_Blended(font, text, color);
00114
00115
00116 w = nextpoweroftwo(initial->w);
00117 h = nextpoweroftwo(initial->h);
00118
00119 intermediary = SDL_CreateRGBSurface(0, w, h, 32,
00120 0x0000ff00, 0x00ff0000, 0xff000000, 0x000000ff);
00121
00122 SDL_BlitSurface(initial, 0, intermediary, 0);
00123
00124
00125 glGenTextures(1, &texture);
00126 glBindTexture(GL_TEXTURE_2D, texture);
00127 glTexImage2D(GL_TEXTURE_2D, 0, 4, w, h, 0, GL_BGRA,
00128 GL_UNSIGNED_BYTE, intermediary->pixels );
00129
00130
00131 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
00132 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
00133
00134
00135 glEnable(GL_TEXTURE_2D);
00136 glBindTexture(GL_TEXTURE_2D, texture);
00137 glColor4f(1.0f, 1.0f, 1.0f,1.0f);
00138
00139
00140 glBegin(GL_QUADS);
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153 glTexCoord2f(0.0f, 0.0f);
00154 glVertex2f(location->x , location->y + h);
00155 glTexCoord2f(1.0f, 0.0f);
00156 glVertex2f(location->x + w, location->y + h);
00157 glTexCoord2f(1.0f, 1.0f);
00158 glVertex2f(location->x + w, location->y);
00159 glTexCoord2f(0.0f, 1.0f);
00160 glVertex2f(location->x , location->y);
00161
00162 glEnd();
00163
00164
00165 glFinish();
00166
00167
00168 location->w = initial->w;
00169 location->h = initial->h;
00170
00171
00172 SDL_FreeSurface(initial);
00173 SDL_FreeSurface(intermediary);
00174 glDeleteTextures(1, &texture);
00175 }
00176
00177 void glEnable2D()
00178 {
00179
00180 GLfloat vPort[4];
00181
00182 glGetFloatv(GL_VIEWPORT, vPort);
00183
00184
00185
00186
00187
00188
00189 glMatrixMode(GL_MODELVIEW);
00190 glPushMatrix();
00191 glLoadIdentity();
00192
00194
00195 SDL_Surface *screen = SDL_GetVideoSurface();
00196
00197
00198
00199
00200 glPushAttrib(GL_ENABLE_BIT);
00201 glDisable(GL_DEPTH_TEST);
00202 glDisable(GL_CULL_FACE);
00203 glEnable(GL_TEXTURE_2D);
00204
00205
00206 glEnable(GL_BLEND);
00207 glBlendFunc(GL_ONE, GL_ONE);
00208
00209
00210 glViewport(0, 0, screen->w, screen->h);
00211
00212 glMatrixMode(GL_PROJECTION);
00213 glPushMatrix();
00214 glLoadIdentity();
00215
00216
00217 glOrtho(0.0, (GLdouble)screen->w, 0.0 , (GLdouble)screen->h, -1.0, 1.0);
00218
00219
00220
00221
00222
00223 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
00224 }
00225
00226 void glDisable2D()
00227 {
00228
00229
00230
00231 glMatrixMode(GL_PROJECTION);
00232 glPopMatrix();
00233
00234 glPopAttrib();
00235
00237
00238
00239 glMatrixMode(GL_MODELVIEW);
00240 glPopMatrix();
00241 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00242 }
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256 void setup_opengl(int width, int height)
00257 {
00258 glShadeModel(GL_SMOOTH);
00259 glClearColor(0.3f, 0.3f, 1.0f, 0.0f);
00260
00261
00262 glClearDepth(1.0f);
00263 glEnable(GL_DEPTH_TEST);
00264 glDepthFunc(GL_LEQUAL);
00265
00266 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
00267
00268 glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient);
00269 glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse);
00270 glLightfv(GL_LIGHT0, GL_POSITION,LightPosition);
00271 glEnable(GL_LIGHT0);
00272 glEnable(GL_LIGHTING);
00273 glEnable( GL_COLOR_MATERIAL );
00274 glEnable(GL_NORMALIZE);
00275 glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
00276 glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, 1.0f );
00277
00278 glViewport(0, 0, width, height);
00279
00280 glMatrixMode(GL_PROJECTION);
00281 glLoadIdentity();
00282 gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, 1.0f, 200.0f);
00283 glMatrixMode(GL_MODELVIEW);
00284 glLoadIdentity();
00285 }
00286
00287
00288
00289
00290 void load_textures()
00291 {
00293
00294 glGenTextures( 2, texture );
00295
00296 glBindTexture( GL_TEXTURE_2D, texture[0] );
00297
00298
00299 SDL_Surface *tex = SDL_LoadBMP( "voile.bmp" );
00300
00301 SDL_LockSurface( tex );
00302
00303
00304 glTexImage2D( GL_TEXTURE_2D, 0, 3, tex->w, tex->h, 0, GL_BGR, GL_UNSIGNED_BYTE, tex->pixels );
00305
00306
00307 SDL_UnlockSurface( tex );
00308 SDL_FreeSurface( tex );
00309
00310
00311 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
00312 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
00313
00314
00315
00316 glBindTexture( GL_TEXTURE_2D, texture[1] );
00317
00318
00319 tex = SDL_LoadBMP( "pano.bmp" );
00320
00321 SDL_LockSurface( tex );
00322
00323
00324 glTexImage2D( GL_TEXTURE_2D, 0, 3, tex->w, tex->h, 0, GL_BGR, GL_UNSIGNED_BYTE, tex->pixels );
00325
00326
00327 SDL_UnlockSurface( tex );
00328 SDL_FreeSurface( tex );
00329
00330
00331 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
00332 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
00333 }
00334
00335
00336
00337 void resize_window(int height, int width)
00338 {
00339
00340
00341 screen = SDL_SetVideoMode( width, height, bpp, flags );
00342 if (screen == 0)
00343 {
00344 fprintf( stderr, "Video mode resize failed: %s\n",
00345 SDL_GetError( ) );
00346 quit_tutorial( 1 );
00347 }
00348 setup_opengl(width, height);
00349
00350 load_textures();
00351 }
00352
00353
00354
00355
00356 void setup_SDL(int width, int height)
00357 {
00358
00359 const SDL_VideoInfo* info = NULL;
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369 if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
00370 {
00371
00372 fprintf( stderr, "Video initialization failed: %s\n",
00373 SDL_GetError( ) );
00374 quit_tutorial( 1 );
00375 }
00376
00377
00378 info = SDL_GetVideoInfo( );
00379 if( !info )
00380 {
00381
00382 fprintf( stderr, "Video query failed: %s\n",
00383 SDL_GetError( ) );
00384 quit_tutorial( 1 );
00385 }
00386
00387 bpp = info->vfmt->BitsPerPixel;
00388
00389
00390 SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );
00391 SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 );
00392 SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );
00393 SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 24 );
00394 SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
00395
00396
00397 flags = SDL_RESIZABLE|SDL_OPENGL;
00398
00399 screen = SDL_SetVideoMode( width, height, bpp, SDL_RESIZABLE|SDL_OPENGL );
00400
00401 if( screen == 0)
00402 {
00403
00404
00405
00406
00407
00408 fprintf( stderr, "Video mode set failed: %s\n",
00409 SDL_GetError( ) );
00410 quit_tutorial( 1 );
00411 }
00412
00413 SDL_WM_SetCaption("Hydropter Simulator", 0);
00414
00415 load_textures();
00416 }
00417
00418
00419
00420
00421
00422
00423 void setup_font()
00424 {
00425 TTF_Init();
00426
00427 font = TTF_OpenFont("ActionMan.ttf", 18 );
00428 if (font==NULL) fprintf( stderr, "Could not open font \n");
00429 else fprintf( stderr, "Font opened \n");
00430
00431 fontBIG = TTF_OpenFont("ActionMan.ttf", 24 );
00432 if (font==NULL)
00433 {
00434 fprintf( stderr, "Could not open big font \n");
00435 fontBIG = font;
00436 }
00437 else fprintf( stderr, "Big font opened \n");
00438 }
00439
00440 void close_font()
00441 {
00442 if (font != NULL) TTF_CloseFont( font );
00443 TTF_Quit();
00444 }
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454 void SDL_GL_PrintText(TTF_Font *font,
00455 SDL_Color color,
00456 SDL_Rect *location,
00457 const char *fmt, ...)
00458 {
00459 char text[256];
00460 va_list ap;
00461
00462 if (fmt == NULL)
00463 return;
00464
00465 va_start(ap, fmt);
00466 vsprintf(text, fmt, ap);
00467 va_end(ap);
00468
00469 SDL_GL_RenderText(text, font, color, location);
00470 }
00471
00472
00473
00474
00475
00476 void draw_panorama()
00477 {
00478 float PanCenter, PanAngle;
00479
00480 PanCenter = -(viewAngle1 / 6.28) + 0.25;
00481 PanAngle = 0.1;
00482
00483 glBindTexture( GL_TEXTURE_2D, texture[1] );
00484 glEnable( GL_TEXTURE_2D );
00485 glDisable(GL_LIGHTING);
00486
00487 glBegin( GL_QUADS );
00488
00489 glColor3f(1.0f,1.0f,1.0f);
00490
00491
00492 glTexCoord2f( PanCenter-PanAngle, 0.0f );
00493 glVertex3f( 80.0f, 60.0f, -100.0f );
00494
00495 glTexCoord2f( PanCenter+PanAngle, 0.0f );
00496 glVertex3f( -80.0f, 60.0f, -100.0f );
00497
00498 glTexCoord2f( PanCenter+PanAngle, 1.0f );
00499 glVertex3f( -80.0f, -20.0f, -100.0f );
00500
00501 glTexCoord2f( PanCenter-PanAngle, 1.0f );
00502 glVertex3f( 80.0f, -20.0f, -100.0f );
00503
00504
00505
00506 glTexCoord2f( PanCenter-PanAngle, 0.0f );
00507 glVertex3f( 80.0f, 200.0f, 0.0f );
00508
00509 glTexCoord2f( PanCenter+PanAngle, 0.0f );
00510 glVertex3f( -80.0f, 200.0f, 0.0f );
00511
00512 glTexCoord2f( PanCenter+PanAngle, 0.01f );
00513 glVertex3f( -80.0f, 59.0f, -100.0f );
00514
00515 glTexCoord2f( PanCenter-PanAngle, 0.01f );
00516 glVertex3f( 80.0f, 59.0f, -100.0f );
00517
00518 glEnd();
00519
00520 glEnable(GL_LIGHTING);
00521 glDisable( GL_TEXTURE_2D );
00522
00523 }
00524
00525
00526
00527
00528
00529 int DrawGLScene(datas *d)
00530 {
00531 double sign;
00532 float X, Y, Z, R;
00533 double pilot[3];
00534 double a, b, c, A, B, C, phi, theta, psi;
00535 phi = d->phi;
00536 theta = d->theta;
00537 psi = d->psi;
00538
00539 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00540
00541
00542 if (abs((1.0f/time_elapsed))<300.0f) fps=0.99*fps+0.01*(1.0f/time_elapsed);
00543
00544
00545 glLoadIdentity();
00546
00547 glDisable(GL_LIGHTING);
00548
00549 glTranslatef(0.0f,0.0f,-1.0f);
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560 glLoadIdentity();
00561 glTranslatef(-0.45f,0.4f,-1.0f);
00562 glScalef(0.08f,0.08f,0.08f);
00563 Girouette_draw(d);
00564
00565 if (is_there_a_joystick())
00566 {
00567 joystick_getXYZR(&d->target_x, &d->target_y, &d->Hslider_x, &d->Vslider_x, doX, doY, doZ, doR);
00568 if (doX) d->target_x *= dirX;
00569 if (doY) d->target_y *= dirY;
00570 if (doZ) d->Hslider_x *= dirZ;
00571 if (doR) d->Vslider_x *= dirR;
00572 }
00573
00574 angles_update(d);
00575
00576
00577
00578 glLoadIdentity();
00579 glTranslatef(0.48f,-0.35f,-1.0f);
00580 glScalef(0.05f,0.05f,0.04f);
00581 Target_draw(d->target_x, d->target_y);
00582
00583 glLoadIdentity();
00584 glTranslatef(0.35f,-0.35f,-1.0f);
00585 glScalef(0.1f,0.1f,0.1f);
00586 HSlider_draw(d->Hslider_x);
00587
00588 glLoadIdentity();
00589 glTranslatef(0.25f,-0.35f,-1.0f);
00590 glScalef(0.1f,0.1f,0.1f);
00591 VSlider_draw(d->Vslider_x);
00592
00593 glEnable(GL_LIGHTING);
00594
00595
00596 glLoadIdentity();
00597
00598 if (cos(viewAngle2) >= 0) sign=1.0;
00599 else sign=-1.0;
00600
00601 if (!onBoardView)
00602 {
00603 gluLookAt( d->x - cos(viewAngle1)*cos(viewAngle2)*viewDist,
00604 d->y + sin(viewAngle1)*cos(viewAngle2)*viewDist,
00605 d->z + sin(viewAngle2)*viewDist,
00606
00607 d->x,d->y,d->z+12.0,
00608
00609 sin(viewAngle2)*cos(viewAngle1) * sign,
00610 -sin(viewAngle2)*sin(viewAngle1) * sign,
00611 cos(viewAngle2) * sign);
00612 }
00613 else
00614 {
00615
00616
00617 a = -15.0;
00618 b = 0.0;
00619 c = 4.0;
00620
00621 A = 100.0;
00622 B = 0.0;
00623 C = 0.0;
00624 pilot[0] = d->x + cos(psi)*cos(theta)*a-sin(psi)*cos(theta)*b+sin(theta)*c;
00625 pilot[1] = d->y + (sin(psi)*cos(phi)+cos(psi)*sin(theta)*sin(phi))*a+(cos(psi)*cos(phi)-sin(psi)*sin(theta)*sin(phi))*b-cos(theta)*sin(phi)*c;
00626 pilot[2] = d->z + (sin(psi)*sin(phi)-cos(psi)*sin(theta)*cos(phi))*a+(cos(psi)*sin(phi)+sin(psi)*sin(theta)*cos(phi))*b+cos(theta)*cos(phi)*c;
00627
00628 gluLookAt( pilot[0], pilot[1], pilot[2],
00629
00630 d->x + cos(psi)*cos(theta)*A-sin(psi)*cos(theta)*B+sin(theta)*C,
00631 d->y + (sin(psi)*cos(phi)+cos(psi)*sin(theta)*sin(phi))*A+(cos(psi)*cos(phi)-sin(psi)*sin(theta)*sin(phi))*B-cos(theta)*sin(phi)*C,
00632 d->z + (sin(psi)*sin(phi)-cos(psi)*sin(theta)*cos(phi))*A+(cos(psi)*sin(phi)+sin(psi)*sin(theta)*cos(phi))*B+cos(theta)*cos(phi)*C,
00633
00634 sin(d->theta),
00635 -cos(d->theta)*sin(d->phi),
00636 cos(d->theta)*cos(d->phi));
00637 }
00638
00639 glTranslatef(d->x,d->y,0.0);
00640
00641 wave_z_compute(d);
00642 Draw_sea();
00643
00644 glTranslatef(0.0,0.0,d->z);
00645 glRotatef(57.2958*d->phi,1.0f,0.0f,0.0f);
00646 glRotatef(57.2958*d->theta,0.0f,1.0f,0.0f);
00647 glRotatef(57.2958*d->psi,0.0f,0.0f,1.0f);
00648
00649
00650 Boat_draw();
00651 Sail_create_and_draw(d);
00652 RelativeWind_draw(d);
00653
00654 glLightfv(GL_LIGHT0, GL_POSITION,LightPosition);
00655
00656
00657 glLoadIdentity();
00658 if (cos(viewAngle2)<0.0)
00659 {
00660
00661 glRotatef(180.0f, 0.0f, 1.0f, 0.0f);
00662 glRotatef(180.0f, 0.0f, 0.0f, 1.0f);
00663 }
00664 glRotatef(57.2958*(sign*viewAngle2 - 0.3f) ,1.0f,0.0f,0.0f);
00665 draw_panorama();
00666
00667
00668
00669
00670 glEnable2D();
00671 glDisable(GL_DEPTH_TEST);
00672
00673 if (!callibratingPhase)
00674 {
00675
00676 text_color.r = (Uint8)200;
00677 text_color.g = (Uint8)200;
00678 text_color.b = (Uint8)200;
00679
00680
00681 text_position.x = 1*text_position.h;
00682 text_position.y = 5*text_position.h;
00683
00684
00685 SDL_GL_PrintText(font, text_color, &text_position, "Speed %3.2f", 3.6f*sqrt(d->dx*d->dx + d->dy*d->dy));
00686 text_position.x += 110; SDL_GL_PrintText(font, text_color, &text_position, "km/h"); text_position.x -= 110;
00687 text_position.y -= text_position.h;
00688 SDL_GL_PrintText(font, text_color, &text_position, "Course %3.0f",-57.2958f*atan(d->dy/d->dx));
00689 text_position.x += 110; SDL_GL_PrintText(font, text_color, &text_position, "deg"); text_position.x -= 110;
00690 text_position.y -= text_position.h;
00691 SDL_GL_PrintText(font, text_color, &text_position, "Wind Speed %3.2f", 3.6f*d->Wind);
00692 text_position.x += 160; SDL_GL_PrintText(font, text_color, &text_position, "km/h"); text_position.x -= 160;
00693 text_position.y -= text_position.h;
00694 SDL_GL_PrintText(font, text_color, &text_position, "Rel Wind Speed %3.2f", 3.6*sqrt((d->Wind_x - d->dx)*(d->Wind_x - d->dx)+(d->Wind_y - d->dy)*(d->Wind_y - d->dy)));
00695 text_position.x += 180; SDL_GL_PrintText(font, text_color, &text_position, "km/h"); text_position.x -= 180;
00696 text_position.y -= text_position.h;
00697 SDL_GL_PrintText(font, text_color, &text_position, "FPS %3.1f", fps);
00698 }
00699
00700 if (callibratingPhase)
00701 {
00702 text_color.r = (Uint8)255;
00703 text_color.g = (Uint8)100;
00704 text_color.b = (Uint8)100;
00705
00706
00707 text_position.x = screen->w /2 - 100;
00708 text_position.y = screen->h /2;
00709 SDL_GL_PrintText(fontBIG, text_color, &text_position, "Joystick Callibration");
00710
00711 text_color.r = (Uint8)100;
00712 text_color.g = (Uint8)255;
00713
00714 text_position.y -= text_position.h;
00715 text_position.x = screen->w /2 - 140;
00716 SDL_GL_PrintText(fontBIG, text_color, &text_position, "Move all axes and hit SPACE");
00717
00718
00719
00720 }
00721
00722
00723
00724
00725 glEnable(GL_DEPTH_TEST);
00726 glDisable2D();
00727
00728 return TRUE;
00729 }
00730
00731
00732
00733 void process_events( void )
00734 {
00735
00736 SDL_Event event;
00737
00738
00739 while( SDL_PollEvent( &event ) )
00740 {
00741 switch( event.type )
00742 {
00743 case SDL_KEYDOWN:
00744
00745 handle_key_down( &event.key.keysym );
00746 break;
00747 case SDL_QUIT:
00748
00749 quit_tutorial( 0 );
00750 break;
00751 case SDL_VIDEORESIZE:
00752 resize_window(event.resize.h, event.resize.w);
00753 break;
00754 }
00755 }
00756 }
00757
00758
00759
00760 void handle_key_down( SDL_keysym* keysym )
00761 {
00762 switch( keysym->sym )
00763 {
00764 case SDLK_ESCAPE:
00765 quit_tutorial( 0 );
00766 break;
00767
00768 case SDLK_y:
00769 dirY*=-1.0f;
00770 break;
00771 case SDLK_x:
00772 dirX*=-1.0f;
00773 break;
00774 case SDLK_c:
00775 dirZ*=-1.0f;
00776 break;
00777 case SDLK_v:
00778 dirR*=-1.0f;
00779 break;
00780
00781 case SDLK_1:
00782 doX=!doX;
00783 break;
00784 case SDLK_2:
00785 doY=!doY;
00786 break;
00787 case SDLK_3:
00788 doZ=!doZ;
00789 break;
00790 case SDLK_4:
00791 doR=!doR;
00792 break;
00793 case SDLK_SPACE:
00794 callibratingPhase = FALSE;
00795 break;
00796 case SDLK_o:
00797 onBoardView = !onBoardView;
00798 break;
00799
00800 default:
00801 break;
00802 }
00803 }
00804
00805
00806 void do_on_keystate(datas *d)
00807 {
00808 Uint8 *keystate = SDL_GetKeyState(NULL);
00809 time_elapsed = d->t - time_before;
00810 time_before = d->t;
00811
00812 if ( keystate[SDLK_q] ) viewAngle1 += dviewAngle;
00813 if ( keystate[SDLK_w] ) viewAngle1 -= dviewAngle;
00814
00815 if ( keystate[SDLK_e] ) viewAngle2 += dviewAngle;
00816 if ( keystate[SDLK_r] ) viewAngle2 -= dviewAngle;
00817
00818 if ( keystate[SDLK_t] ) viewDist += dviewDist;
00819 if ( keystate[SDLK_z] ) viewDist -= dviewDist;
00820
00821
00822 if (keystate[SDLK_UP] && d->target_y<1.0f) d->target_y += 1.5f*time_elapsed;
00823 if (keystate[SDLK_DOWN] && d->target_y>-1.0f) d->target_y -= 1.5f*time_elapsed;
00824
00825 if (keystate[SDLK_RIGHT] && d->target_x<1.0f) d->target_x += 1.5f*time_elapsed;
00826 if (keystate[SDLK_LEFT] && d->target_x>-1.0f) d->target_x -= 1.5f*time_elapsed;
00827
00828 if (keystate[SDLK_m] && d->Hslider_x<1.0f) d->Hslider_x += 1.5f*time_elapsed;
00829 if (keystate[SDLK_n] && d->Hslider_x>-1.0f) d->Hslider_x -= 1.5f*time_elapsed;
00830
00831 if (keystate[SDLK_h] && d->Vslider_x<1.0f) d->Vslider_x += 1.5f*time_elapsed;
00832 if (keystate[SDLK_b] && d->Vslider_x>-1.0f) d->Vslider_x -= 1.5f*time_elapsed;
00833
00834
00835
00836 if (keystate[SDLK_9]){
00837 d->Wind += 2.0f*time_elapsed;
00838 d->Wind_x = -d->Wind*cos(d->Wind_angle);
00839 d->Wind_y = -d->Wind*sin(d->Wind_angle);
00840 }
00841 if (keystate[SDLK_8] && d->Wind>0){
00842 d->Wind -= 2.0f*time_elapsed;
00843 d->Wind_x = -d->Wind*cos(d->Wind_angle);
00844 d->Wind_y = -d->Wind*sin(d->Wind_angle);
00845 }
00846
00847
00848 if (keystate[SDLK_7]) {
00849 d->Wave_amp0 += 0.15f*time_elapsed;
00850 d->Wave_amp[0] = d->Wave_amp0/2.0;
00851 d->Wave_amp[1] = d->Wave_amp0/4.0;
00852 d->Wave_amp1 = d->Wave_amp[0];
00853 d->Wave_amp2 = d->Wave_amp[1];
00854 }
00855 if (keystate[SDLK_6] && d->Wave_amp0>0.0f) {
00856 d->Wave_amp0 -= 0.15f*time_elapsed;
00857 d->Wave_amp[0] = d->Wave_amp0/2.0;
00858 d->Wave_amp[1] = d->Wave_amp0/4.0;
00859 d->Wave_amp1 = d->Wave_amp[0];
00860 d->Wave_amp2 = d->Wave_amp[1];
00861 }
00862
00863
00864 if (keystate[SDLK_k] && d->max_abs_angle_baume<1.4835f) {
00865 d->max_abs_angle_baume += 0.1745*time_elapsed;
00866 }
00867 if (keystate[SDLK_l] && d->max_abs_angle_baume>0.0f) {
00868 d->max_abs_angle_baume -= 0.1745*time_elapsed;
00869 }
00870
00871 d->tanAngle_sail = tan(d->angle_girouette);
00872 if (atan(d->tanAngle_sail)>d->max_abs_angle_baume) d->tanAngle_sail=tan(d->max_abs_angle_baume);
00873 if (atan(d->tanAngle_sail)< -d->max_abs_angle_baume) d->tanAngle_sail=tan(-d->max_abs_angle_baume);
00874 }
00875
00876
00877
00878
00879
00880
00881 void pass_joy_parameters(joy_parameters *jP)
00882 {
00883 doX = jP->doX;
00884 doY = jP->doY;
00885 doZ = jP->doZ;
00886 doR = jP->doR;
00887
00888 dirX = jP->dirX;
00889 dirY = jP->dirY;
00890 dirZ = jP->dirZ;
00891 dirR = jP->dirR;
00892 }