Advertisement

Lesson 11 Modification

Started by November 07, 2004 06:12 PM
4 comments, last by Jondice 20 years ago
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 :)
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 + 1,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 + 1,y + 1,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 + 1,y,points[x + 1, y, 2]));                    }                }            Gl.glEnd();


It's late and I'm very tired, but try that. If by a miracle it does work but you can't understand why post again and I'll explain when I'm awake enough to give an explanation that will make sense [smile]

Enigma
Advertisement
Thanks very much! That fixed it, and I knew why as soon as I saw your solution.

Now I'm getting another problem though, maybe you've seen something like this before:



You can see the diagonal lines going out on the right ... not sure what might be causing that. There's always a small chance it could be this awful computer, but I'd say that more than likely its me.

[Edited by - Jondice on November 7, 2004 9:12:27 PM]
OK, I ran it on Nvidia hardware instead of ATI and didn't experience that problem ... I've had so much trouble from ATI we can probably just chalk it up to that.
I'd be suprised if something as simple as that was bugged in the ATI drivers. It looks like you're drawing an extra row of quads, with the vertices all at the origin, as if you're overrunning the bounds of your array somewhere.

Enigma
yeah, the z values for the last row were effectively infinite I suppose since I was dividing by zero by accident.

This topic is closed to new replies.

Advertisement