I'm trying to modify the code in lesson 11 so that the wave has a decreasing amplitude as it approaches the left (where the pole would be).
I've added in the FlagAdjust function as follows:
Gl.glBegin(Gl.GL_QUADS);
for(y = 0; y < 44; y++) {
for( x = 0; x < 44; x++ ) {
float_x = x / 44.0f;
float_y = y / 44.0f;
float_xb = (x + 1) / 44.0f;
float_yb = (y + 1) / 44.0f;
Gl.glTexCoord2f(float_x, float_y);
Gl.glVertex3f(points[x, y, 0], points[x, y, 1], FlagAdjust(x,y,points[x, y, 2]));
Gl.glTexCoord2f(float_x, float_yb);
Gl.glVertex3f(points[x, y + 1, 0], points[x, y + 1, 1], FlagAdjust(x,y,points[x, y + 1, 2]));
Gl.glTexCoord2f(float_xb, float_yb);
Gl.glVertex3f(points[x + 1, y + 1, 0], points[x + 1, y + 1, 1], FlagAdjust(x,y,points[x + 1, y + 1, 2]));
Gl.glTexCoord2f(float_xb, float_y);
Gl.glVertex3f(points[x + 1, y, 0], points[x + 1, y, 1], FlagAdjust(x,y,points[x + 1, y, 2]));
}
}
Gl.glEnd();
Here is the function FlagAdjust:
public static float FlagAdjust(int x, int y, float z)
// This function takes a wave applied to a cloth flag and
// makes it look more realistic.
{
float test = (44.0f - x);
z = z/test;
return z;
}
I'm dividing by the value test to slowly decrease the amplitude as x gets closer to the left edge of the flag. The problem is that if I do this, the right side of the flag (where the amplituded is larger) breaks up when the peak of the sine wave goes through it. In other words, there are vertical gaps. I can post images later if needed.
If I divide by a constant value, no matter how large (or how small), I don't get these vertical gaps. Any suggestions would be appreciated :)