HydroSDL/main.cpp

Go to the documentation of this file.
00001 
00009 #include <stdio.h>
00010 #include <stdlib.h>
00011 #include <string.h>
00012 //#include <math.h>
00013 
00014 
00015 #include "SDL.h"
00016 #include "SDL_OpenGL.h"
00017 
00018 #include "main.h"
00019 
00020 //----------------Includes for MATLAB MEX------------------------------------------
00021 #include "math.h"
00022 #include "mex.h"   
00023 //---------------------------------------------------------------------------------
00024 
00025 
00026 //----------------Includes for graphics------------------------------------------
00027 #include "oGL_graphics/graphics_relative.h"
00028 #include "oGL_graphics/solid_objects.h"
00029 //---------------------------------------------------------------------------------
00030 
00031 
00032 
00033 #include "string.h"
00034 
00035 //----------------Includes for hydropter-------------------------------------------
00036 #include "hydro_source/hydro_includes.h"
00037 //---------------------------------------------------------------------------------
00038 
00039 
00040 //-------------Includes for SUNDIALS CVODE solver:---------------------------------
00041 #include "CVODEincludes.h"  // ODE solver includes
00042 //---------------------------------------------------------------------------------
00043 
00044 //-------------Include for timing functions----------------------------------------
00045 #include "timing/timing.h"
00046 //---------------------------------------------------------------------------------
00047 
00048 #include "f.h"
00049 
00050 
00051 
00052 
00053 
00054 static GLboolean should_rotate = GL_TRUE; 
00055 
00056         /* Color depth in bits of our window. */ 
00057 //      int bpp = 0; 
00058         /* Flags we will pass into SDL_SetVideoMode. */ 
00059 //      int flags = 0; 
00060 
00061 float rot1 = 0.0f;
00062 float rot2 = 0.0f;
00063 
00064 int goLoop = 1;
00065 
00066 ODE_data f_dats; 
00067 ODE_data *f_dat = &f_dats;
00068         
00069 /*      
00070 GLfloat LightAmbient[]= { 0.35f, 0.35f, 0.5f, 1.0f };                           // Ambient Light Values ( NEW )
00071 GLfloat LightDiffuse[]= { 0.6f, 0.6f, 0.6f, 1.0f };                              // Diffuse Light Values ( NEW )
00072 GLfloat LightPosition[]= { -10.0f, 20.0f, 150.0f, 0.0f };                                // Light Position ( NEW )
00073 */      
00074         
00075 
00076 
00077 
00079 
00084 void quit_tutorial( int code ) 
00085 { 
00086         joystick_close();
00087         SDL_Quit( ); 
00088         close_font();
00089         /* Exit program. */ 
00090         //exit( code ); 
00091         free_wave_variables();
00092         solver_free(f_dat);
00093         delete f_dat->state; //delete_state(f_dat->state);
00094         Boat_delete();
00095         exit( code ); 
00096 }
00097 
00098 
00099 
00100  
00101 
00102 
00103 
00104 
00105 
00106 
00107 
00109 
00112 int main( int argc, char* argv[] ) 
00113 { 
00114         int width = 640; 
00115         int height = 480;
00116         
00117         //--------------------------------
00118         parameters Par; 
00119         parameters *P = &Par; 
00120         joy_parameters jPar;  
00121         joy_parameters *jP = &jPar;  
00122         datas dat;  
00123         datas *d = &dat; 
00124 //      ODE_data f_dats;  ///< ODE_data f_dats;  solver data structure, contains pointer to the other structures and some solver relative informations
00125 //      ODE_data *f_dat = &f_dats;  ///< ODE_data *f_dat;   pointer to f_dats, will be passed to solver relative functions
00126         //--------------------------------
00127         
00128         
00129         int kk;
00130 
00131         double *state = new double[STATENUM];
00132         char* flag;
00133         char def_flag[]  = "";
00134         char output_flag[]  = "output";
00135         long tLength;
00136 
00137         float Time;
00138         double time;
00139         bool go=1;
00140         
00141         read_arguments_from_file(P, jP, state, &time);
00142          pass_joy_parameters(jP);
00143         
00144 //      state = dummy_get_state();//state = get_state(nlhs, plhs, nrhs, prhs);
00145 
00146         f_dat->d = d;
00147         f_dat->P = P;
00148         
00149         
00150         f_dat->state = state;
00151         
00152         fprintf( stderr, "state: \n");
00153         for (kk=0; kk<12; kk++) fprintf( stderr,"%f \n", float(state[kk]));
00154         
00155 //      dummy_initParameters(P);
00156         
00157         f_dat->time_param = time; //a la place de get_time
00158         
00159         
00160         data_init(d);
00161         data_update_state(d, state);
00162         data_update_param(d, P);
00163         
00164         
00165         solver_init(f_dat);
00166         
00167         wave_init();
00168 
00169         Boat_create(d);
00170         
00171         
00172         //---------------------------------
00173         setup_SDL(width, height);
00174         
00175         kk = joystick_init(); //must be initialised _AFTER_ SDL
00176         
00177         
00178         setup_opengl( width, height ); 
00179         
00180         setup_font();
00181         
00182         
00183         while( getCallibatingPhase() )
00184         { 
00185                 process_events( ); 
00186                 kk = DrawGLScene(d);
00187                 SDL_GL_SwapBuffers(); 
00188                 do_on_keystate(d);      
00189         }
00190         
00191         tic(); // Measure time from now on
00192         
00193         while( go )
00194         { 
00195                 /* Process incoming events. */ 
00196                 process_events( ); 
00197                 Time = toc(); // Get total elapsed time
00198                 solve_ODE(f_dat, Time);
00199                 /* Draw the screen. */ 
00200                 //draw_screen( ); 
00201                 kk = DrawGLScene(d);
00202                 SDL_GL_SwapBuffers(); 
00203                 do_on_keystate(d);      
00204                 if ((f_dat->time_param != 0.0) && (d->t > f_dat->time_param)) go=0;
00205         }
00206         
00207         // If we reach this place, this that the simulation time was reached and that we have to write results to file:
00208         kk = write_results_to_file();
00209         
00210         quit_tutorial( 0 );
00211         
00212         return 0; 
00213 } 
00214 
00215 

Generated on Wed Sep 20 14:30:04 2006 for hydroSDL by  doxygen 1.4.7