2 registered members (AndrewAMD, ozgur),
1,526
guests, and 8
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
terrain_pixel_for_pos or any formula, no work
#425864
07/11/13 21:04
07/11/13 21:04
|
Joined: Nov 2007
Posts: 318 Brasil, Paraná
NeoNeper
OP
Senior Member
|
OP
Senior Member
Joined: Nov 2007
Posts: 318
Brasil, Paraná
|
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
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. _______________________________________________________
|
|
|
Re: terrain_pixel_for_pos or any formula, no work
[Re: NeoNeper]
#425867
07/11/13 22:03
07/11/13 22:03
|
Joined: Nov 2007
Posts: 318 Brasil, Paraná
NeoNeper
OP
Senior Member
|
OP
Senior Member
Joined: Nov 2007
Posts: 318
Brasil, Paraná
|
for testing, i decreases the function and i use draw_point3d to verify if the location of the coordinates 3D were correct. It worked perfectly, and the 3Dpoints were placed exactly in the desired locations.
function terrain_paintest(...)
{
if(!skin) skin = ent_getskin(terrain,1);
var range = 64;
var format = bmap_lock(skin,0);
var i,j,fx,fy,ex,ey;
//x and y is the mouse cordenate in word 3D
fx = x -range; //X from
ex = x + range; //Y from
fy = y - range; //X End
ey = y + range; //Y End
for(j=fx; j<= ex; j++)
for(i=fy; i<= ey; i++)
{
if(vec_dist(_vec(x,y,0),_vec(j,i,0))<=(range/2))
{
draw_point3d(_vec(j,i,2), _vec(0,0,255), 100,2);
}
}
}
So the problem really is in receiving the correct coordinates of pixels! Can anyone help me? Using the same function but now instead of using points i use terrain_setpixel(terrain,j,i,skin,color);[b][/b] the positions of the painting are wrong!. no WOrk Fine.
for(j=fx; j<= ex; j++)
for(i=fy; i<= ey; i++)
{
if(vec_dist(_vec(x,y,0),_vec(j,i,0))<=(range/2))
{
//no working fine
terrain_setpixel(terrain,j,i,skin,color);
}
}
Last edited by NeoNeper; 07/11/13 22:08.
Please! Use easy words to be translated. because my English is not very good! Grateful. _______________________________________________________
|
|
|
|