- Title: Easy Heightmap
- Description: Create a working heightmap in 3 scripts
- GM Version: Game Maker 7
- Registered: Yes
- File Type: .Zip (contains 2 files, an example and the scripts)
- File Size: Approx 90KB
- File Link: Download (Host-a-net)
- You may also be interested in: GameDev Studio
Credit is always appreciated, but not required.
This is a very easy to use heightmap engine. It contains three scripts
terrain_create(); - creates the heightmap with the wanted settings terrain_draw(); - Draw the terrain terrain_get_z(); - Find the terrains Z at position [X,Y]
Screenshot:

Enjoy
Like this example? Then visit GM3D, You'll find many 3D things there
~~Brett14;
[EDIT]
After several requests for a script that stretches one texture over the whole terrain, I've decided instead of PM'ming them all the code just put it here. So if you want a stretched texture, then replace the create code with this. Thanks.
PLEASE NOTE: You'll need to remove the spaces between some lines that split the function names in half.
/*
****---- ~ Credit goes to: brett14 ~ ----****
THE TERRAIN SHOULD HAVE THE HIGHEST DEPTH (10000 etc. - it gets set to -1000 after initing this though)
loads the terrain from a heightmap sprite - it does not matter what the size of the sprite is (32x32, 64x64 or 128x128 is recommended)
Argument0 = terrain heightmap sprite
Argument1 = the size of the terrain squares (X,Y)
Argument2 = the height value of the terrain (Z)
*/
var counter,counter2,xx,yy;
global.swidth=sprite_get_width(argument0);
global.sheight=sprite_get_height(argument0);
global.terrainsize = argument1;
global.terraingrid=ds_grid_create(global.swidth,global.sheight);
global.terrainmodel=d3d_model_create();
draw_sprite_stretched(argument0,0,0,0,global.swidth+2,global.sheight
+2)
for(w=0;w<global.swidth+2;w+=1){
for(h=0;h<global.sheight+2;h+=1){
val=draw_getpixel(w,h)
valex=color_get_value(val)
ds_grid_set(global.terraingrid,w,h,valex/240*argument2)
}
}
counter2=0;
for(xx=0;xx<global.swidth-1;xx+=1){
d3d_model_primitive_begin(global.terrainmodel,pr_trianglestrip);
counter=0;
for (yy=0;yy<global.sheight;yy+=1){
z2=ds_grid_get(global.terraingrid,yy,xx+1);
d3d_model_vertex_normal_texture(global.terrainmodel,yy*global.terrainsize,(xx+1)*global.terrainsize,z2,0,0,1,counter,counter2+
1/global.swidth);
z1=ds_grid_get(global.terraingrid,yy,xx);
d3d_model_vertex_normal_texture(global.terrainmodel,yy*global.terrainsize,xx*g
lobal.terrainsize,z1,0,0,1,counter,counter2);
counter+=1/global.swidth;
}
counter2+=1/global.swidth;
d3d_model_primitive_end(global.terrainmodel);
}
depth=-1000;[/EDIT]
Edited by brett14, 14 March 2012 - 03:30 AM.











