///////////////////////////////
#include <acknex.h>
#include <default.c>
//#define test_1
//#define test_2
//#define test_3
//#define test_4
function main()
{
vec_set(screen_size,vector(800,600,0));
vec_set(screen_color,vector(50,1,1)); // dark blue
vec_set(sky_color,vector(50,1,1)); // dark blue
video_window(NULL,NULL,0,"terrain test");
level_load("");
def_debug();
def_move();
vec_set(d3d_lodfactor,vector(1,2,3));
BMAP* hm = "noise.jpg";
#ifdef test_1
//test 1 works fine with lod>0
terrain_lod=4;
#endif
#ifdef test_2
//test 2 does not work with lod>0
terrain_lod=4;
#endif
#ifdef test_3
//test 3 is the same as test 2 but with lod==0 it works fine
terrain_lod=0;
#endif
#ifdef test_4
//test 4 is the same as test 2 but with a wait(1) in the loop is
//needed for every update before it works ???
terrain_lod=4;
#endif
ENTITY *terrain=ent_createterrain(hm,nullvector,128,128,10);
//--------------------------------------------------------------
#ifdef test_1
//works fine with lod >0
int i=0;
for(i;i<ent_status(terrain,0);i++)
{
CONTACT *pos=ent_getvertex(terrain,NULL,i);
pos.v.y+=random(32);
ent_setvertex(terrain,pos,i);
}
#endif
//--------------------------------------------------------------
#ifdef test_2
//does not work with lod>0
int sx = bmap_width(hm);
int sy = bmap_height(hm);
int x=0,y=0;
VECTOR pos;
COLOR pixcol;
var format = bmap_lock(hm, 0);
for(x=0; x<sx; x++)
{
for(y=0; y<sx; y++)
{
VECTOR* pos = vector(
(terrain.x - terrain.min_x) - x * ((terrain.max_x - terrain.min_x) / sx),
(terrain.y - terrain.min_y) - y * ((terrain.max_y - terrain.min_y) / sy),0);
var v = ent_nextvertex(terrain, pos);
CONTACT* cpos = ent_getvertex(terrain,NULL,v);
var pix = pixel_for_bmap(hm, sx -x, y);
pixel_to_vec(pixcol, NULL, format, pix);
cpos.z = 0.1+(pixcol.blue );
cpos.v=NULL;
ent_setvertex(terrain,cpos,v);
}
}
bmap_unlock(hm);
#endif
//--------------------------------------------------------------
#ifdef test_3
//the same as test 2 but with no lod it works fine
int sx = bmap_width(hm);
int sy = bmap_height(hm);
int x=0,y=0;
VECTOR pos;
COLOR pixcol;
var format = bmap_lock(hm, 0);
for(x=0; x<sx; x++)
{
for(y=0; y<sx; y++)
{
VECTOR* pos = vector(
(terrain.x - terrain.min_x) - x * ((terrain.max_x - terrain.min_x) / sx),
(terrain.y - terrain.min_y) - y * ((terrain.max_y - terrain.min_y) / sy),0);
var v = ent_nextvertex(terrain, pos);
CONTACT* cpos = ent_getvertex(terrain,NULL,v);
var pix = pixel_for_bmap(hm, sx -x, y);
pixel_to_vec(pixcol, NULL, format, pix);
cpos.z = 0.1+(pixcol.blue );
cpos.v=NULL;
ent_setvertex(terrain,cpos,v);
}
}
bmap_unlock(hm);
#endif
//--------------------------------------------------------------
#ifdef test_4
//the same as test 2 but needs a wait(1) in the loop before it works ??
int sx = bmap_width(hm);
int sy = bmap_height(hm);
int x=0,y=0;
VECTOR pos;
COLOR pixcol;
var format = bmap_lock(hm, 0);
for(x=0; x<sx; x++)
{
for(y=0; y<sx; y++)
{
VECTOR* pos = vector(
(terrain.x - terrain.min_x) - x * ((terrain.max_x - terrain.min_x) / sx),
(terrain.y - terrain.min_y) - y * ((terrain.max_y - terrain.min_y) / sy),0);
var v = ent_nextvertex(terrain, pos);
CONTACT* cpos = ent_getvertex(terrain,NULL,v);
var pix = pixel_for_bmap(hm, sx -x, y);
pixel_to_vec(pixcol, NULL, format, pix);
cpos.z = 0.1+(pixcol.blue );
cpos.v=NULL;
ent_setvertex(terrain,cpos,v);
wait(1);////why ???
}
}
bmap_unlock(hm);
#endif
}