• 01-25-2013, 01:33 PM
holyll
Hi,
I'm trying to do a simple cloth simulation based on the Opengl SuperBible.
We consider that we have vertices that are connected to each other.
For each vertice, we only consider perturbation due to 4 adjacents points.
In my code below I first try to find the index of each vertex being processed then its 4 neighbours that I put in connection array.

Than I simply apply physics laws.
The problem is that I have warnings :

0(31) : warning C7050: "connection[0]" might be used before being initialized
0(31) : warning C7050: "connection[1]" might be used before being initialized
0(31) : warning C7050: "connection[2]" might be used before being initialized
0(31) : warning C7050: "connection[3]" might be used before being initialized

I don't understand why the neighbours are not being initialized ?
And obviously the rendering result is not what I expected.

Code :

```#version 400 in vec3 position; in vec3 velocity;   //Outs out vec3 position_out; out vec3 velocity_out;   //Uniforms uniform float t; uniform samplerBuffer tex_position; uniform samplerBuffer tex_velocity;   //consts const float c = 0.04; const vec3 gravity = vec3(0.0,-0.03,0.0); const float k = 1.0;   void main(void) { int N = 64; vec3 F; //Force on the mass vec3 v = velocity; // Final velocity; vec3 s = vec3(0.0); //Displacement step int index = gl_VertexID; int ix = index%N; int iy = index/N; int connection[4];   if(ix == 0) { connection[0] = index; } else if(ix == N-1) { connection[2] = index; } else { connection[0] = index-1; connection[2] = index+1; } if(iy == 0) { connection[1] = index; } else if(iy == N-1) { connection[3] = index; }   else { connection[1] = index-N+1; connection[3] = index+N-1; }   if(index != 0 && index != N-1) { F = gravity- c*velocity; for(int i=0; i< 4; i++) { if(connection[i] != index) { vec3 q = texelFetch(tex_position,connection[i]).xyz; vec3 d = q-position; float x = length(d); F += -k*(1-x)*normalize(d); } }   s = velocity*t+0.5*F*t*t; v = velocity + F*t; }           position_out = position + s; velocity_out = v; }```
• 01-25-2013, 05:56 PM
holyll