since i havent worked with heightmaps before attempting this
i took a piece of code from the tust library that apply's the
heightmap to the terrain , it is this piece of code wich i cannot
understand why lod doesnt work with it unless a wait(1) is added .

the code in test_1 i took from the forum from sivan works fine
with lod bigger than 0 .

the code in test_2 is the one i attempted to use from a tust example
but it does not work with lod above 0, in test_3 you can see it works
fine with lod at 0 , in test_4 you can see it only works with lod above 0
if a wait(1) is added inside the loops ,why would this happen ? its not my own
code because i needed an example and i encountered the lod thingy with it ,so
i am not saying its supposed to work but i cannot quite understand why it does'nt ??


Code:
///////////////////////////////
#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

}




uncomment the defines for each test

Last edited by Wjbender; 12/04/14 17:12.

Compulsive compiler