Sign in to follow this  
carl granberg

Noise function

Recommended Posts


I read the book<Programming Rts game programming with directx>I find a function Name is Noise,they are shown as below the are use to produce random height use for Terrain!if someone undertstand the code please explain to me!


float Noise(int x)
{
x = (x<<13) ^ x;
return (1.0 - ((x * (x*x * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0);
}

float CosInterpolate(float v1, float v2, float a)
{
float angle = a * D3DX_PI;
float prc = (1.0f - cos(angle)) * 0.5f;
return v1*(1.0f - prc) + v2*prc;
}

Share this post


Link to post
Share on other sites
[quote name='granberg' timestamp='1305801571' post='4812944']
I read the book<Programming Rts game programming with directx>I find a function Name is Noise,they are shown as below the are use to produce random height use for Terrain!if someone undertstand the code please explain to me!


float Noise(int x)
{
x = (x<<13) ^ x;
return (1.0 - ((x * (x*x * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0);
}

float CosInterpolate(float v1, float v2, float a)
{
float angle = a * D3DX_PI;
float prc = (1.0f - cos(angle)) * 0.5f;
return v1*(1.0f - prc) + v2*prc;
}


[/quote]

well, it's probably not exactly this:
[url="http://freespace.virgin.net/hugo.elias/models/m_perlin.htm"]http://freespace.vir...ls/m_perlin.htm[/url] (look at the end to skip the math)
[url="http://en.wikipedia.org/wiki/Perlin_noise"]http://en.wikipedia....ki/Perlin_noise[/url]
but it's at least probably something similar.
Just a function to calculate noise that some mathematician made up and it works great for making "realistic" terrain or clouds or things like that procedurally.

Share this post


Link to post
Share on other sites
why does no man give me an correct answer ,I need to buid na desert terrain /jungle terrain,so it is random height or use some special picture,so please first give me some noise function use in Rts 4
game produce differnt terrain!please email me at [email="frankluna11@yahoo.com"]frankluna11@yahoo.com[/email]

Share this post


Link to post
Share on other sites
[quote name='granberg' timestamp='1305806380' post='4812961']
why does no man give me an correct answer ,I need to buid na desert terrain /jungle terrain,so it is random height or use some special picture,so please first give me some noise function use in Rts 4
game produce differnt terrain!please email me at [email="frankluna11@yahoo.com"]frankluna11@yahoo.com[/email]
[/quote]

You need to ask a more specific question. What is it about the code you posted that you don't understand? Have you considered that the book you are using may not be the right place to start if you cannot understand the code it contains. Perhaps pick up a basic C++ coding book and then come back to this RTS book when you have learnt some more about coding.

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