Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
1 registered members (Grant), 999 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Heightmap generator - Is there an existing one? #427290
08/06/13 12:40
08/06/13 12:40
Joined: Mar 2006
Posts: 1,993
Karlsruhe
PadMalcom Offline OP
Serious User
PadMalcom  Offline OP
Serious User

Joined: Mar 2006
Posts: 1,993
Karlsruhe
I wonder if there is already a heightmap generator somewhere in this forum?! laugh

Re: Heightmap generator - Is there an existing one? [Re: PadMalcom] #427360
08/07/13 08:36
08/07/13 08:36
Joined: Aug 2002
Posts: 3,258
Mainz
oliver2s Offline
Expert
oliver2s  Offline
Expert

Joined: Aug 2002
Posts: 3,258
Mainz
You are looking for code I guess?

Re: Heightmap generator - Is there an existing one? [Re: oliver2s] #427363
08/07/13 08:57
08/07/13 08:57
Joined: Mar 2003
Posts: 4,264
Wellington
Nems Offline

.
Nems  Offline

.

Joined: Mar 2003
Posts: 4,264
Wellington
They may have been wiped when the forum went thru some changes because I do recall something being worked on a while back now...

Otherwise, I may be off-base but MED is pretty good laugh

Re: Heightmap generator - Is there an existing one? [Re: Nems] #427367
08/07/13 09:20
08/07/13 09:20
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline
Expert
sivan  Offline
Expert

Joined: Mar 2011
Posts: 3,150
Budapest
a while ago I thought to write one but always postponed... collected some stuff that could help, but now only found this: a simple application with included source code: http://hme.sourceforge.net/


Free world editor for 3D Gamestudio: MapBuilder Editor
Re: Heightmap generator - Is there an existing one? [Re: PadMalcom] #427368
08/07/13 09:23
08/07/13 09:23
Joined: Jul 2010
Posts: 283
Germany
J
jenGs Offline
Member
jenGs  Offline
Member
J

Joined: Jul 2010
Posts: 283
Germany
Do you mean a procedural heightmap generator.
You can use the old libnoise library.
If you have interest I have written a DLL.

Re: Heightmap generator - Is there an existing one? [Re: jenGs] #427369
08/07/13 09:27
08/07/13 09:27
Joined: Mar 2006
Posts: 1,993
Karlsruhe
PadMalcom Offline OP
Serious User
PadMalcom  Offline OP
Serious User

Joined: Mar 2006
Posts: 1,993
Karlsruhe
Hey guys, thanks for your replies! I am preferably looking for code. I want to procedurally generate terrains with heightmap and textures.

Lemming sent me a nice implementation yesterday. I'll have a look at it and post the results soon. Thanks for your interest!

@jensGs: Thank you for the offer. But since I already have a lot of DLLs in TUST I'd like to keep the number of new ones small laugh

Re: Heightmap generator - Is there an existing one? [Re: PadMalcom] #427371
08/07/13 09:43
08/07/13 09:43
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline
Expert
sivan  Offline
Expert

Joined: Mar 2011
Posts: 3,150
Budapest
it would be great if you could write one, especially if supports multitexturing, based on height and slope data. the latter part is not so difficult, but a realistic terrain generator is not easy at all.


Free world editor for 3D Gamestudio: MapBuilder Editor
Re: Heightmap generator - Is there an existing one? [Re: PadMalcom] #427380
08/07/13 10:39
08/07/13 10:39
Joined: Aug 2002
Posts: 3,258
Mainz
oliver2s Offline
Expert
oliver2s  Offline
Expert

Joined: Aug 2002
Posts: 3,258
Mainz
Here's my Perlin Noise Generator script from old IceX2

For background information see this: http://freespace.virgin.net/hugo.elias/models/m_perlin.htm

Code:
function Cosine_Interpolate(var a, var b, var x)
{
	double ft = x * 3.1415927;
	double f = (1 - cos(ft)) * 0.5;
	return  a*(1-f) + b*f;
}

//Perlin Noise Heightmap Generator
///////////////////////////////
//recommended default values:
// size_ 			= 128
// freq_				= 64
// height_min_		= -50
// height_max_		= 200
// iterations_		= 5
// persistence_	= 2
BMAP* perlin_noise(var size_,var freq_,var height_min_,var height_max_,var iteration_,var persistence_)
{
	var format;
	var pixel;
	var px;
	var py;
	var alpha_ = 100;
	var h[2];
	var h1[2];
	var freq;
	VECTOR temp1;
	VECTOR temp2;
	VECTOR temp;
	var i;
	var px1;
	var py1;
	var a;
	var g=0;
	var c=0;
	var t;
	var k;
	var f;
	STRING* temp_str="";
	STRING* temp_str2="";
	var hmaphandle;

	var freq = freq_;
	var hmap_size = size_;
	var height_min = height_min_;
	var height_max = height_max_;
	var var_iteration=iteration_;
	var var_persistence=persistence_;

	BMAP* ptr_bmap_temp = bmap_createblack(size_,size_,24);

	t= 1; c=0; while(c < var_iteration)
	{
		i=0; px=0; py=0; while(i < (hmap_size/(freq/t))*(hmap_size/(freq/t)))
		{
			temp1.x = integer(random((height_max+150)-(height_min+150))+(height_min+150));
			temp1.x = clamp(temp1.x-150, 0, 255);
			format = bmap_lock(ptr_bmap_temp,0);
			pixel = pixel_for_vec(vector(temp1.x,temp1.x,temp1.x),alpha_,format);
			pixel_to_bmap(ptr_bmap_temp, px, py, pixel);
			bmap_unlock(ptr_bmap_temp);
			px+=(freq/t);
			if(px > hmap_size-1)
			{
				px=0;
				py+=(freq/t);
			}
			i+=1;
		}

		a=1/(freq/t); px1=0; py1=0; px=0; py=0; i=0; while(i < (hmap_size-(hmap_size/(freq/t)))*(hmap_size/(freq/t)))
		{
			format = bmap_lock(ptr_bmap_temp,0);
			pixel = pixel_for_bmap(ptr_bmap_temp, px, py);
			pixel_to_vec(temp1,alpha_,format,pixel);
			h[0]=temp1.x;
			pixel = pixel_for_bmap(ptr_bmap_temp, px+(freq/t), py);
			pixel_to_vec(temp1,alpha_,format,pixel);
			h[1]=temp1.x;
			pixel = pixel_for_bmap(ptr_bmap_temp, clamp(px-(freq/t),0,hmap_size-1), py);
			pixel_to_vec(temp1,alpha_,format,pixel);
			h1[0]=temp1.x;
			pixel = pixel_for_bmap(ptr_bmap_temp, clamp(px+((freq/t)*2),0,hmap_size-1), py);
			pixel_to_vec(temp1,alpha_,format,pixel);
			h1[1]=temp1.x;
			temp.x = Cosine_Interpolate(h[0], h[1], a);
			pixel = pixel_for_vec(vector(temp.x,temp.x,temp.x),alpha_,format);
			pixel_to_bmap(ptr_bmap_temp, px+px1+1, py, pixel);
			bmap_unlock(ptr_bmap_temp);
			px1+=1;
			a+=1/(freq/t);
			if(px1 > (freq/t)-2)
			{
				a=1/(freq/t);
				px+=(freq/t);
				px1=0;
				py1+=1;
				if(py1 > (hmap_size/(freq/t))-1)
				{
					px1=0;
					py1=0;
					px=0;
					py+=(freq/t);
					a=1/(freq/t);
				}
			}
			i+=1;
		}	
		
		a=1/(freq/t); px1=0; py1=0; px=0; py=0; i=0; while(i < (hmap_size-(hmap_size/(freq/t)))*(hmap_size))
		{
			format = bmap_lock(ptr_bmap_temp,0);
			pixel = pixel_for_bmap(ptr_bmap_temp, px, py);
			pixel_to_vec(temp1,alpha_,format,pixel);
			h[0]=temp1.x;
			pixel = pixel_for_bmap(ptr_bmap_temp, px, clamp(py+(freq/t), 0, hmap_size-1));
			pixel_to_vec(temp1,alpha_,format,pixel);
			h[1]=temp1.x;
			temp.x = Cosine_Interpolate(h[0], h[1], a);
			pixel = pixel_for_vec(vector(temp.x,temp.x,temp.x),alpha_,format);
			pixel_to_bmap(ptr_bmap_temp, px, py+py1+1, pixel);
			bmap_unlock(ptr_bmap_temp);
			py1+=1;
			a+=1/(freq/t);
			if(py1 > (freq/t)-2)
			{
				a=1/(freq/t);
				py+=(freq/t);
				py1=0;
				px1+=1;
				if(px1 > (hmap_size/(freq/t))-1)
				{
					py1=0;
					px1=0;
					py=0;
					px+=1;
					a=1/(freq/t);
				}
			}
			i+=1;
		}
		
		str_cpy(temp_str, "hmap");
		str_for_num(temp_str2, c);
		str_cat(temp_str, temp_str2);
		str_cat(temp_str, ".tga");
		hmaphandle = file_open_write(temp_str);
		px=0; py=hmap_size-1; i=0; while(i < hmap_size*hmap_size)
		{
			format = bmap_lock(ptr_bmap_temp,0);
			pixel = pixel_for_bmap(ptr_bmap_temp, px, py);
			pixel_to_vec(temp1,alpha_,format,pixel);
			bmap_unlock(ptr_bmap_temp);
			file_asc_write(hmaphandle, temp1.x);
			px+=1;
			if(px > hmap_size-1)
			{
				px=0;
				py-=1;
			}
			i+=1;
		}
		file_close(hmaphandle);

		c+=1;
		t*=var_persistence;
		t = clamp(t, 1, freq);
	}
	
	px=0; py=0; i=0; while(i < hmap_size*hmap_size)
	{
		format = bmap_lock(ptr_bmap_temp,0);
		pixel = pixel_for_vec(vector(0,0,0),alpha_,format);
		pixel_to_bmap(ptr_bmap_temp, px, py, pixel);
		bmap_unlock(ptr_bmap_temp);
		px+=1;
		if(px > hmap_size-1)
		{
			px=0;
			py+=1;
		}
		i+=1;
	}

	f=c-1; k=0; while(k < c)
	{
		str_cpy(temp_str, "hmap");
		str_for_num(temp_str2, f);
		str_cat(temp_str, temp_str2);
		str_cat(temp_str, ".tga");
		hmaphandle = file_open_read(temp_str);
		px=0; py=hmap_size-1; i=0; while(i < hmap_size*hmap_size)
		{
			temp1.x = file_asc_read(hmaphandle);
			format = bmap_lock(ptr_bmap_temp,0);
			pixel = pixel_for_bmap(ptr_bmap_temp, px, py);
			pixel_to_vec(temp2,alpha_,format,pixel);
			temp2.x = (temp2.x+temp1.x)/2;
			temp2.y = temp2.x;
			temp2.z = temp2.x;
			pixel = pixel_for_vec(temp2,alpha_,format);
			pixel_to_bmap(ptr_bmap_temp, px, py, pixel);
			bmap_unlock(ptr_bmap_temp);
			px+=1;
			if(px > hmap_size-1)
			{
				px=0;
				py-=1;
			}
			i+=1;
		}
		file_close(hmaphandle);
		k+=1;
		f-=1;
	}

	i=0; while(i < c)
	{
		str_cpy(temp_str, "hmap");
		str_for_num(temp_str2, i);
		str_cat(temp_str, temp_str2);
		str_cat(temp_str, ".tga");
		file_delete(temp_str);
		i+=1;
	}

	return ptr_bmap_temp;
}


Re: Heightmap generator - Is there an existing one? [Re: oliver2s] #427381
08/07/13 10:40
08/07/13 10:40
Joined: Mar 2006
Posts: 1,993
Karlsruhe
PadMalcom Offline OP
Serious User
PadMalcom  Offline OP
Serious User

Joined: Mar 2006
Posts: 1,993
Karlsruhe
Awesome, thank you! laugh

Re: Heightmap generator - Is there an existing one? [Re: PadMalcom] #427433
08/08/13 06:52
08/08/13 06:52
Joined: Mar 2006
Posts: 1,993
Karlsruhe
PadMalcom Offline OP
Serious User
PadMalcom  Offline OP
Serious User

Joined: Mar 2006
Posts: 1,993
Karlsruhe
Is there a way (namely a function) to create / load a simple flat heightmap WITHOUT loading a predefined hmp file?

EDIT: Found it! laugh

ent_createterrain(BMAP* skin, VECTOR* position, var nx, var ny, var size): ENTITY*

Last edited by PadMalcom; 08/08/13 07:09.

Moderated by  adoado, checkbutton, mk_1, Perro 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1