weird problems with my realtime mesh changer

Started by
2 comments, last by Norbs 22 years, 4 months ago
Hey all, ok I''m getting some wierd crash messages some of the time only when I am changing the mesh in real time. It''s telling me that its doing an invalid floating point operation on the lines i''ll point out. However If I''m not changing the matix, it works....Can someone plz point out to me what the problem is?? I call it with this line: t=(clock()-initTime)/CLK_TCK; //i initialize the clock farther up. recalc( matrix, t, centers ); CreatePlane( 2.0, matrix, 2.0, 7, 7 ); The matrix is an array of 49. I''m pretty sure im not over running the bounds of my array, because I''ve tried increasing it...nada. I''m trying to create a plane with a certain amount of vertices so I can animate it. SHould I be doing something differently to achieve this end? void CreatePlane( float width, float *height, float length, int widthseg, int lengthseg ) { int i=0; float xstep=width/widthseg; // <------ crashes at this line float zstep=length/lengthseg; // <------ and this one too float initwidth=width; float initlength=length; glBindTexture(GL_TEXTURE_2D, g_Texture[0]); glBegin (GL_QUADS); // This is our BEGIN to draw for (float length=initlength/(-2); length<=((initlength/2)-zstep); length+=zstep ) for(float width=initwidth/(-2); width<= ((initwidth/2)-xstep); width+=xstep) { // Display the top left vertice glTexCoord2f(0.0f, 1.0f); glVertex3f(width, height, length); // Display the bottom left vertice glTexCoord2f(0.0f, 0.0f); glVertex3f(width, height[i+row], length+zstep); // Display the bottom right vertice glTexCoord2f(1.0f, 0.0f); glVertex3f(width+xstep, height[i+row+1], length+zstep); // Display the top right vertice glTexCoord2f(1.0f, 1.0f); glVertex3f(width+xstep, height[i+1], length); i++; } glEnd(); // This is the END of drawing } /////////////////////////////Here is that mesh changing function const int MAXSIZE=49; int row =sqrt(MAXSIZE); const float xscale=1.0; const float yscale=1.0; void recalc( float * matrix, float time, DATA *centers ) { float dis; float h; int i=0; clear( matrix ); //resets it to zero while ( centers.startTime>=0 ) { for (int point=0; point<MAXSIZE;point++ ) { dis=sqrt( pow( ((point % row)-(centers.center % row ))*xscale , 2) + pow( ((point /row )-(centers.center/row))*yscale, 2) ); if ( (time-centers.startTime-dis) > 0 ) { h=-3*sin(5*( time-centers.startTime)- dis ) * float (exp( double( (-time-centers.startTime)/5.0 ) ) ); matrix[point]+=h; } } i++; } } the centers bit is just an array of structures that can keep track of the center points of the waves, and when they start. I''ve tested this function may times; it works. But as soon as I try to use it in ogl, the program crashes Thanks for any help you give…. Norbs </i>
Advertisement
Usually if a program crashes when you are dividing, it means you''re dividing by zero. Hope that helps.

---------------

I finally got it all together...
...and then forgot where I put it.
But it works some of the time

I can run it once or twice and then I get that error message. If you look at the code, it SHOULDN''t be zero, values are hard coded into the program.
But it works some of the time

I can run it once or twice and then I get that error message. If you look at the code, it SHOULDN''t be zero, values are hard coded into the program.

This topic is closed to new replies.

Advertisement