Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

3 Dimensional Chat / [LOCKED] Somebody can awswer me a RTS game question

Author
Message
lidongheng
13
Years of Service
User Offline
Joined: 10th Jan 2011
Location:
Posted: 27th Jan 2011 22:29
This code something about to make terrian for RTS game that programming use c++ did somebody can tell me How to understand
CosInterpolate function the book say that is noise function I don't
clear understand noise function did somebody can told to me





HRESULT HEIGHTMAP::CreateRandomHeightMap(int seed, float noiseSize, float persistence, int octaves)
{
if(m_pHeightMapTexture != NULL){m_pHeightMapTexture->Release(); m_pHeightMapTexture = NULL;}
m_pDevice->CreateTexture(m_size.x, m_size.y, 1, D3DUSAGE_DYNAMIC, D3DFMT_L8, D3DPOOL_DEFAULT, &m_pHeightMapTexture, NULL);

D3DLOCKED_RECT lock;
m_pHeightMapTexture->LockRect(0, &lock, NULL, NULL);

//For each map node
for(int y=0;y<m_size.y;y++)
for(int x=0;x<m_size.x;x++)
{
//Scale x & y to the range of 0.0 - m_size
float xf = ((float)x / (float)m_size.x) * noiseSize;
float yf = ((float)y / (float)m_size.y) * noiseSize;

float total = 0;

// For each octave
for(int i=0;i<octaves;i++)
{
//Calculate frequency and amplitude (different for each octave)
float freq = pow(2, i);
float amp = pow(persistence, i);

//Calculate the x,y noise coordinates
float tx = xf * freq;
float ty = yf * freq;
int tx_int = tx;
int ty_int = ty;

//Calculate the fractions of x & y
float fracX = tx - tx_int;
float fracY = ty - ty_int;

//Get the noise of this octave for each of these 4 points
float v1 = Noise(tx_int + ty_int * 57 + seed);
float v2 = Noise(tx_int+ 1 + ty_int * 57 + seed);
float v3 = Noise(tx_int + (ty_int+1) * 57 + seed);
float v4 = Noise(tx_int + 1 + (ty_int+1) * 57 + seed);

//Smooth in the X-axis
float i1 = CosInterpolate(v1 , v2 , fracX);
float i2 = CosInterpolate(v3 , v4 , fracX);

//Smooth in the Y-axis
total += CosInterpolate(i1 , i2 , fracY) * amp;
}

int b = 128 + total * 128.0f;
if(b < 0)b = 0;
if(b > 255)b = 255;

BYTE *bDest = (BYTE*)lock.pBits;
bDest += y * lock.Pitch + x;
*bDest = b;

//Save to heightMap
m_pHeightMap[x + y * m_size.x] = ((float)b / 255.0f) * m_maxHeight;
}

m_pHeightMapTexture->UnlockRect(0);

return S_OK;
}

lidongheng
henry ham
16
Years of Service
User Offline
Joined: 3rd Aug 2007
Location: way way out there
Posted: 27th Jan 2011 22:41
again your posting in the wrong part of the forum

cheers henry

lidongheng
13
Years of Service
User Offline
Joined: 10th Jan 2011
Location:
Posted: 27th Jan 2011 23:25
you say I Was post to a wrong giva me sometime I want to explained to you I want somebody to tell me this question who is belong a RTS
game that RTS game is 3D game so I think I can ask question in this
3D chat board

lidongheng
Gencheff
13
Years of Service
User Offline
Joined: 12th Jun 2010
Location: UK by way of USSR
Posted: 27th Jan 2011 23:28
3D Modeling chat board , not programming... Go to Programming Talk with this...


PC Specs:Windows 7 Ultimate 64-bit,Intel Core i7 960 @ 3.20GHz,NVIDIA GeForce GTX 480,12GB RAM,2x Western Digital 997GB HDD
lazerus
16
Years of Service
User Offline
Joined: 30th Apr 2008
Location:
Posted: 28th Jan 2011 00:59
Well he'll learn eventually...

Deathead
17
Years of Service
User Offline
Joined: 14th Oct 2006
Location:
Posted: 28th Jan 2011 01:46
Quote: "3D Modeling chat board , not programming... Go to Programming Talk with this...
"

Quote: "Well he'll learn eventually...
"

It is actually the 3 Dimensional Chat board, so this would account for being 3 dimensional therefore relevant..

Guess people will learn eventually...


Design Runner
13
Years of Service
User Offline
Joined: 16th Oct 2010
Location: In my own little world.
Posted: 28th Jan 2011 02:09
Quote: "For everything about creating, modifying and using 3D models in your own games this is the forum to read."
One day people will learn to read the information on the back of a book.

"If you can't handle me at my worst, you sure as hell don't deserve me at my best"
PrimalBeans
13
Years of Service
User Offline
Joined: 14th Oct 2010
Location: The sewer.... hunting alligatiors.
Posted: 28th Jan 2011 02:25
lol seriously... isnt this like the 5th or 6th post here hes made and each time someones told him hes in the wrong place.... do you think if you gave him an answer he would understand anyway??? I dont even know what his post is about!

Gencheff
13
Years of Service
User Offline
Joined: 12th Jun 2010
Location: UK by way of USSR
Posted: 28th Jan 2011 14:33
Well he's from China,so I understand the language barrier,however this still isn't for this board.

Well alright,that aside , I think this might help him (atleast to a certain extent)

http://www.dreamincode.net/forums/topic/66480-perlin-noise/


PC Specs:Windows 7 Ultimate 64-bit,Intel Core i7 960 @ 3.20GHz,NVIDIA GeForce GTX 480,12GB RAM,2x Western Digital 997GB HDD

Login to post a reply

Server time is: 2024-05-18 06:26:29
Your offset time is: 2024-05-18 06:26:29