Noise function

Started by
2 comments, last by triangles 12 years, 11 months ago

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;
}

Advertisement

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;
}




well, it's probably not exactly this:
http://freespace.vir...ls/m_perlin.htm (look at the end to skip the math)
http://en.wikipedia....ki/Perlin_noise
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.
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]

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]


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.

This topic is closed to new replies.

Advertisement