Jump to content
  • Advertisement
Sign in to follow this  
Saya

Simple Heightmap generation problem

This topic is 3822 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

Hello. I just started to learn terrain rendering and generation. I am now able to render a map given a heightmap properly with the normals etc (well its very basic but it works so im happy :) ). So i started trying to generate a heightmap. I took my simple algorithm from here: http://www.lighthouse3d.com/opengl/terrain/index.php?fault My problem is, the same heightmap is ALWAYS generated. But random seems to work well everywhere else so i cant find the problem. Also the height seems to only increase and never decrease like it should (heightMap[x][y] -= 0.01;) The heightmap is properly initialized to 0 before the height generation. heres my code:
	/**generate a random heightmap*/
	float v, a, b, c, d;
	for( int i = 0; i < 1000; ++i )
	{
		v = rand();
		a = sin(v);
		b = cos(v);
		d = hypotf(size_x,size_y);
		c = ( rand() / RAND_MAX ) * d - d/2;	
		
		for( int x = 0; x < (int)size_x; ++x )
		{
			for( int y = 0; y < (int)size_y; ++y )
			{
				if ( a*x + b*y - c > 0 ) 
					heightMap[x][y] += 0.01;
				else
					heightMap[x][y] -= 0.01;
			}
		}
	}

Share this post


Link to post
Share on other sites
Advertisement
ugh nevermind i found the problem...
i was doing rand() / RAND_MAX but since rand() is an int it gave always the same result ( 1 ).
I just did (float)rand()/RAND_MAX -> problem solved.
Thanks anyways.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!