Sign in to follow this  
tnutty

Can you explain this code from NEHE

Recommended Posts

I am going through lesson 11 : wavy flag effect, and I am confused on one snippet that I will post, which is from the tutorial. I get it semi-what, but not enough to completely grasp it. Can you explain the code? here is the code :
if( wiggle_count == 2 )			// Used To Slow Down The 
	{
		
		
		for( y = 0; y < 45; y++ )  // Loop Through The Y Plane
		{
			hold=points[0][y][2];// Store Current Value One Left Side Of Wave
			for( x = 0; x < 44; x++)		// Loop Through The X Plane
			{
				// Current Wave Value Equals Value To The Right
				points[x][y][2] = points[x+1][y][2];
			}
			points[44][y][2]=hold;			// Last Value Becomes The Far Left Stored Value
		}
		wiggle_count = 0;				// Set Counter Back To Zero
	}
	wiggle_count++;						// Increase The Counter
I am not completely getting the meaning of the code.

Share this post


Link to post
Share on other sites
here is the link if you would like to read a few sentence from his tut.

http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=11.

I guess that block of code is supposed to make the flag wave by

shifting the wave to the left and shifting the end point to the beggining(the right), but I am not sure how its doing this completely.

Share this post


Link to post
Share on other sites
At the top, he fills out the points matrix with a bunch of values to make a simple standing wave.
The loop you posted just scrolls(with wraping) the values along the X plane of the matrix.
Thus, giving a very simple moving wave.
Since the scrolling is discrete (one X element each time through that section of code) he uses wiggle_count == 2 as a way to make sure it scrolls at a rate slower than one X column per frame.

Share this post


Link to post
Share on other sites
So the wiggles just "refreshes" the wave, by the inside loop, which
takes the first z value or the depth value and makes it the height thats on the right of it, and then I think he takes the last depth point and stores the value of the first so it repeats all over again?

IS this somewhere is the ballpark?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this