# 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 on other sites
stromchin    102
[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 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 on other sites
triangles    106
[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.