Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

billybob

why does this cause my terrain to become massivley tall?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts


  

void smoothHeightMap(int iterations)
{
	int i, j, x, y;
	float st, sm[8];
	for(i = 0; i < iterations; i++)
	{
		for(y = 1; y < terrain_y - 1; y++)
		{
			for(x = 1; x < terrain_x - 1; x++)
			{
				sm[0] = terrain_HeightMap[x-1][y-1];
				sm[1] = terrain_HeightMap[x-1][y];
				sm[2] = terrain_HeightMap[x-1][y+1];
				sm[3] = terrain_HeightMap[x][y-1];
				sm[4] = terrain_HeightMap[x][y];
				sm[5] = terrain_HeightMap[x][y+1];
				sm[6] = terrain_HeightMap[x+1][y-1];
				sm[7] = terrain_HeightMap[x+1][y];
				sm[8] = terrain_HeightMap[x+1][y+1];
				st = 0;
				for(j = 0; j < 9; j++)
				{
					st = st + sm[j];
				}
				terrain_HeightMap[x][y] = float(st / 9);
			}
		}
	}
}
  
its supposed to smooth the terrain out by averaging the 9 heights around it and making that the new height. but it causes the terrain to grow miles high after only two iterations. did i make some stupid mistake i can''t seem to find for hours and hours?

Share this post


Link to post
Share on other sites
Advertisement
Well, for one thing you initalised sm with 8 members but i think there are meant to be nine. This could be a mistake when transfering the code to the forum, but if not then I think that is your problem, could be wrong though

[edited by - Grambo on July 28, 2002 8:34:54 PM]

Share this post


Link to post
Share on other sites
When you define an [8] array, you create [0]-[7].

Thus,
sm[8] = terrain_HeightMap[x+1][y+1];
cannot be done, and
j < 9
should be < 8

just change the [8] array to [9].

------------
aud.vze.com - The Audacious Engine <-- It''s not much, yet. But it''s mine... my own... my preciousssss...
MSN: nmaster42@hotmail.com, AIM: LockePick42, ICQ: 74128155

Share this post


Link to post
Share on other sites
oh it does that automatically?!?! crap, i need to fix a lot of things. i though you initalized it with the number that you needed including 0. sorry for the thread

Share this post


Link to post
Share on other sites
Are you sure about that LockePick? I''ve always created the array with one less element (ie, if I needed 5 I would do nums[4]) and I''ve never ran into any problems. In which cases do you create the array with the higher number and when do you do it with one less? Do you always do the full number and I''ve just been lucky?

Share this post


Link to post
Share on other sites
Ivve always used the higher number, and when I haven''t it usually crashed my program, so I think you must have been lucky Ivko. Either that or something strange is going on

Share this post


Link to post
Share on other sites
quote:
Original post by Grambo
Ivve always used the higher number, and when I haven''t it usually crashed my program, so I think you must have been lucky Ivko. Either that or something strange is going on


there have been a few times when i run my program, i cause aol instant messenger''s buddy list window to freeze. i wonder if i''m overrunning my arrays?!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Ivko
Are you sure about that LockePick? I''ve always created the array with one less element (ie, if I needed 5 I would do nums[4]) and I''ve never ran into any problems. In which cases do you create the array with the higher number and when do you do it with one less? Do you always do the full number and I''ve just been lucky?


WELLLLLLL...

You can do this as many times as you want, wherever you want and etc. BUUUUUT, when you do this your not reserving the last block of mem thath you think your reserving and so if the computer decides to use that space for some other data then your "last" entry in your array will be terminally corrupted. So you can say that if you want you can pass the array bounds at will (you can even just reserve 10 and use 10000), but you risk corrupting your data because your not reserving those blocks (worse yet, you could even pass over other data in memory and corrupt it with data that you want to put into the array).

Think of an array as a pointer to the first block in mem and then accessing [1] would be a pointer++ operation. This might help you understand why you risk writing over other data and losing array data.

I think this is a great reason *NOT* to pass the bounds in arrays.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!