I'm not managing to get the exact position of the pixels of the skin of my terrain.

after trying to make the calculations manually and not succeed I tried using the function, terrain_setpixel and resulted in the same problem I was having manually.


As you can see in the picture above, when I try to post the position indicated by the position of the mouse in the 3D world, he paints in a wrong position.

I have a another project that working .
In this project that works correctly, the difference it is on creation of this terrain.
In the functional project, I created the terrain from a existing HMP. ent_createlocal()...

In this current project which I can not get the correct coordinates, I am using dynamic terrain. ent_createterrain...

SAMPLE
Code:
function terrain_paintPixel(ENTITY* terrain,x,y,BMAP* skin, var brushSize, COLOR* color)
{
		

	if(!skin) skin = ent_getskin(terrain,1);
	
	//Convert word for pixel cordenate
	VECTOR* pos = terrain_pixel_for_pos(terrain,x,y,skin);
	if (!pos) return;

	var range = 64; //Range of the brush
	
	var format = bmap_lock(skin,0);	
	var i,j,fx,fy,ex,ey;	
	
	fx = pos.x -range; //X from
	ex = pos.x + range; //Y from	
	
	fy = pos.y - range; //X End
	ey = pos.y + range; //Y End

	VECTOR skinpos; //receive pixel for word cordenates for vec_dist
	var pixel;
	
	for(j=fx; j<= ex; j++)
	for(i=fy; i<= ey; i++)
	{		
//Convert pixel for word cordenate    
vec_set(skinpos,terrain_pixel_to_pos(terrain,j,i,skin));	
		
                //round brush
		if(vec_dist(_vec(x,y,0),_vec(skinpos.x,skinpos.y,0))<=(range/2))
		{			
			pixel = pixel_for_vec(color,100,format);
			pixel_to_bmap(skin,j,i,pixel);	//No correct position		
			
		}
		
		
	}
	
	bmap_unlock(skin);
	
}



I can not understand why it is not working correctly.
Does anyone know tell me if the problem is in USE dynamic terrain? (ent_createterrain...).


Last edited by NeoNeper; 07/11/13 22:09.

Please! Use easy words to be translated. because my English is not very good! Grateful.
_______________________________________________________