G
Grubix
Guest
Hello, my first post here. My problem goes like this: I'm using simple script to draw a terrain in 3D using heightmap and I want to draw another one after going to the next room, but then the terrain glitches and gets just flat. It's propably because it uses global variables that get transferred to another room and it somehow screws everything up, so my guess is to make something a la terrain_end(); that could be used just before entering another room, but I'm not sure how to do that. Any suggestions on how to fix it, guys?
And as always, sórry fór bąd ęngliśh.
The script goes like this:
create event
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)
}
}
for(xx=0;xx<global.swidth-1;xx+=1){
d3d_model_primitive_begin(global.terrainmodel,pr_trianglestrip);
adraw=true;
for (yy=0;yy<global.sheight;yy+=1){
adraw = !adraw;
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,adraw,1);
z1=ds_grid_get(global.terraingrid,yy,xx);
d3d_model_vertex_normal_texture(global.terrainmodel,yy*global.terrainsize,xx*global.terrainsize,z1,0,0,1,adraw,0);
}
d3d_model_primitive_end(global.terrainmodel);
}
depth=-1;
draw event
//argument0 = terrain texture
d3d_set_culling(1);
d3d_model_draw(global.terrainmodel,0,0,0,background_get_texture(argument0))
d3d_set_culling(0);
And as always, sórry fór bąd ęngliśh.
The script goes like this:
create event
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)
}
}
for(xx=0;xx<global.swidth-1;xx+=1){
d3d_model_primitive_begin(global.terrainmodel,pr_trianglestrip);
adraw=true;
for (yy=0;yy<global.sheight;yy+=1){
adraw = !adraw;
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,adraw,1);
z1=ds_grid_get(global.terraingrid,yy,xx);
d3d_model_vertex_normal_texture(global.terrainmodel,yy*global.terrainsize,xx*global.terrainsize,z1,0,0,1,adraw,0);
}
d3d_model_primitive_end(global.terrainmodel);
}
depth=-1;
draw event
//argument0 = terrain texture
d3d_set_culling(1);
d3d_model_draw(global.terrainmodel,0,0,0,background_get_texture(argument0))
d3d_set_culling(0);