Public Group

# Can you explain this code from NEHE

This topic is 3484 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 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 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?

1. 1
2. 2
3. 3
Rutin
16
4. 4
5. 5

• 10
• 11
• 14
• 10
• 25
• ### Forum Statistics

• Total Topics
632650
• Total Posts
3007645
• ### Who's Online (See full list)

There are no registered users currently online

×