compiler errors - compiling code for 'iWave' Surface simulation by Jerry Tessendorf -
compiler errors - compiling code for 'iWave' Surface simulation by Jerry Tessendorf -
i found code in paper written simulation of fluid surfaces http://www-evasion.imag.fr/people/fabrice.neyret/images/fluids-nuages/waves/jonathan/articlescg/simulating-ocean-water-01.pdf
but when seek run code in dev c++ bunch of compiler errors "stray '\146' in program"
the compiler errors fixed, due wrong formatted ' pdf.
the code compiles without error, when runs nil happens @ all.
could help me? code shown below
#include <cmath> #ifdef __apple__ #include <glut/glut.h> #else #include <gl/gl.h> // opengl itself. #include <gl/glu.h> // glu back upwards library. #include <gl/glut.h> // glut back upwards library. #endif #include <iostream> using namespace std; int iwidth, iheight, size; float *display_map; float *obstruction; float *source; float *height; float *previous_height; float *vertical_derivative; float scaling_factor; float kernel[13][13]; int paint_mode; enum{ paint_obstruction, paint_source }; bool regenerate_data; bool toggle_animation_on_off; float dt, alpha, gravity; float obstruction_brush[3][3]; float source_brush[3][3]; int xmouse_prev, ymouse_prev; //-------------------------------------------------------- // // initialization routines // // // initialize of fields 0 void initialize( float *data, int size, float value ) { for(int i=0;i<size;i++ ) { data[i] = value; } } // compute elements of convolution kernel void initializekernel() { double dk = 0.01; double sigma = 1.0; double norm = 0; for(double k=0;k<10;k+=dk) { norm += k*k*exp(-sigma*k*k); } for( int i=-6;i<=6;i++ ) { for( int j=-6;j<=6;j++ ) { double r = sqrt( (float)(i*i + j*j) ); double kern = 0; for( double k=0;k<10;k+=dk) { kern += k*k*exp(-sigma*k*k)*j0(r*k); } kernel[i+6][j+6] = kern / norm; } } } void initializebrushes() { obstruction_brush[1][1] = 0.0; obstruction_brush[1][0] = 0.5; obstruction_brush[0][1] = 0.5; obstruction_brush[2][1] = 0.5; obstruction_brush[1][2] = 0.5; obstruction_brush[0][2] = 0.75; obstruction_brush[2][0] = 0.75; obstruction_brush[0][0] = 0.75; obstruction_brush[2][2] = 0.75; source_brush[1][1] = 1.0; source_brush[1][0] = 0.5; source_brush[0][1] = 0.5; source_brush[2][1] = 0.5; source_brush[1][2] = 0.5; source_brush[0][2] = 0.25; source_brush[2][0] = 0.25; source_brush[0][0] = 0.25; source_brush[2][2] = 0.25; } void clearobstruction() { for(int i=0;i<size;i++ ){ obstruction[i] = 1.0; } } void clearwaves() { for(int i=0;i<size;i++ ) { height[i] = 0.0; previous_height[i] = 0.0; vertical_derivative[i] = 0.0; } } //---------------------------------------------------- void converttodisplay() { for(int i=0;i<size;i++ ) { display_map[i] = 0.5*( height[i]/scaling_factor + 1.0 )*obstruction[i]; } } //---------------------------------------------------- // // these 2 routines, // // computeverticalderivative() // propagate() // // heart of iwave algorithm. // // in propagate(), have not bothered handle // boundary conditions. makes outermost // 6 pixels way around deed hard wall. // void computeverticalderivative() { // first step: interior for(int ix=6;ix<iwidth-6;ix++) { for(int iy=6;iy<iheight-6;iy++) { int index = ix + iwidth*iy; float vd = 0; for(int iix=-6;iix<=6;iix++) { for(int iiy=-6;iiy<=6;iiy++) { int iindex = ix+iix + iwidth*(iy+iiy); vd += kernel[iix+6][iiy+6] * height[iindex]; } } vertical_derivative[index] = vd; } } } void propagate() { // apply obstruction for( int i=0;i<size;i++ ) { height[i] *= obstruction[i]; } // compute vertical derivative computeverticalderivative(); // advance surface float adt = alpha*dt; float adt2 = 1.0/(1.0+adt); for( int i=0;i<size;i++ ) { float temp = height[i]; height[i] = height[i]*(2.0-adt)-previous_height[i]-gravity*vertical_derivative[i]; height[i] *= adt2; height[i] += source[i]; height[i] *= obstruction[i]; previous_height[i] = temp; // reset source each step source[i] = 0; } } //------------------------------------------ // // painting , display code // void resetscalefactor( float amount ) { scaling_factor *= amount; } void dabsomepaint( int x, int y ) { int xstart = x - 1; int ystart = y - 1; if( xstart < 0 ){ xstart = 0; } if( ystart < 0 ){ ystart = 0; } int xend = x + 1; int yend = y + 1; if( xend >= iwidth ){ xend = iwidth-1; } if( yend >= iheight ){ yend = iheight-1; } if( paint_mode == paint_obstruction ) { for(int ix=xstart;ix <= xend; ix++) { for( int iy=ystart;iy<=yend; iy++) { int index = ix + iwidth*(iheight-iy-1); obstruction[index] *= obstruction_brush[ix-xstart][iy-ystart]; } } } else if( paint_mode == paint_source ) { for(int ix=xstart;ix <= xend; ix++) { for( int iy=ystart;iy<=yend; iy++) { int index = ix + iwidth*(iheight-iy-1); source[index] += source_brush[ix-xstart][iy-ystart]; } } } return; } //---------------------------------------------------- // // gl , glut callbacks // //---------------------------------------------------- void cbdisplay( void ) { glclear(gl_color_buffer_bit ); gldrawpixels( iwidth, iheight, gl_luminance, gl_float, display_map ); glutswapbuffers(); } // animate , display new result void cbidle() { if( toggle_animation_on_off ) { propagate(); } converttodisplay(); cbdisplay(); } void cbonkeyboard( unsigned char key, int x, int y ) { switch (key) { case ’-’: case ’_’: resetscalefactor( 1.0/0.9 ); regenerate_data = true; break; case ’+’: case ’=’: resetscalefactor( 0.9 ); regenerate_data = true; break; case ’ ’: toggle_animation_on_off = !toggle_animation_on_off; case ’o’: paint_mode = paint_obstruction; break; case ’s’: paint_mode = paint_source; break; case ’b’: clearwaves(); clearobstruction(); initialize( source, size, 0.0 ); break; default: break; } } void cbmousedown( int button, int state, int x, int y ) { if( button != glut_left_button ) { return; } if( state != glut_down ) { return; } xmouse_prev = x; ymouse_prev = y; dabsomepaint( x, y ); } void cbmousemove( int x, int y ) { xmouse_prev = x; ymouse_prev = y; dabsomepaint( x, y ); } //--------------------------------------------------- int main(int argc, char** argv) { // initialize few variables iwidth = iheight = 200; size = iwidth*iheight; dt = 0.03; alpha = 0.3; gravity = 9.8 * dt * dt; scaling_factor = 1.0; toggle_animation_on_off = true; // allocate space fields , initialize them height = new float[size]; previous_height = new float[size]; vertical_derivative = new float[size]; obstruction = new float[size]; source = new float[size]; display_map = new float[size]; clearwaves(); clearobstruction(); converttodisplay(); initialize( source, size, 0 ); initializebrushes(); // build convolution kernel initializekernel(); // glut routines glutinit(&argc, argv); glutinitdisplaymode(glut_rgba | glut_double); glutinitwindowsize( iwidth, iheight ); // open window char title[] = "iwave demo"; int window_id = glutcreatewindow( title ); glclearcolor( 1,1,1,1 ); glutdisplayfunc(&cbdisplay); glutidlefunc(&cbidle); glutkeyboardfunc(&cbonkeyboard); glutmousefunc( &cbmousedown ); glutmotionfunc( &cbmousemove ); glutmainloop(); homecoming 1; }; `
you've copy-pasted code pdf used luxury-quality unicode quote marks instead of plain old standard quote marks.
yours:
’
everyone else's:
'
do search-and-replace , should work. it's possible there's other, nice-but-not-ascii characters you'll have fix.
compiler-errors simulation
Comments
Post a Comment