3 registered members (Quad, Ayumi, AndrewAMD),
1,092
guests, and 1
spider. |
Key:
Admin,
Global Mod,
Mod
|
|
|
terrain_getpixel
#428051
08/16/13 23:30
08/16/13 23:30
|
Joined: Jul 2005
Posts: 187
lostzac
OP
Member
|
OP
Member
Joined: Jul 2005
Posts: 187
|
Anyone have an idea on how to use this command....I have read the manual and taking a look at the level.c, and I keep running into a syntex error...which is now driving me nuts.... terrain_getpixel(ENTITY* terrain, var x, var y, BMAP* skin): COLOR* I am using it as so
BMAP* _b = ent_getskin(ent,1);
COLOR* clr_b = terrain_getpixel(ent,ent.x+some_randnum,ent.y+somerandnum,_b);
Am I missing something ?
John C Leutz II
|
|
|
Re: terrain_getpixel
[Re: lostzac]
#428052
08/17/13 00:29
08/17/13 00:29
|
Joined: Jul 2005
Posts: 187
lostzac
OP
Member
|
OP
Member
Joined: Jul 2005
Posts: 187
|
Ok never-mind now its working I do not know why, It just started to work lol.... but now I have a different issue
var num_Vert = ent_vertices(ent);
var current_vert;
for(current_vert = 1; current_vert < num_Vert; current_vert++)
{
CONTACT* c = ent_getvertex(ent,NULL,current_vert);
COLOR* clr = terrain_getpixel(ent,c.x,c.y,NULL);
if(clr.blue == NULL)
{
error("Color not returned....");
}
else
{
c.z += 0.1+(clr.blue*altitude);
print_var(c.z);
//ent_setvertex(ent,c,current_vert);
}
}
c_updatehull(ent,1);
print_var is just a simple function that prints out the values of the number, I use this to see what results or if any are being returned... Half way through the function it crashes with an 1513 error.... I get about 10-20 values returned then error....any suggestions to point me in the right way... Im trying to write a simple terrain deformation from a height map... Step A Creates the height map... Step B assigns it to the terrain those work fine Step C Returns the color of a terrain texture at the given x y world position using terrain_getpixle and set the height of the vert accordingly...I just needed something simplistic for what I had in mind... anyways its again step c i am running into the issue with the above code UPDATE: The loop runs exactly 32 times before each crash....Still not sure why....The terrain is 256x256 (1089 verts) and the texture size I am using is also 256x256 though that should not matter....
Last edited by lostzac; 08/17/13 01:15.
John C Leutz II
|
|
|
Re: terrain_getpixel
[Re: sivan]
#428063
08/17/13 07:52
08/17/13 07:52
|
Joined: Jul 2005
Posts: 187
lostzac
OP
Member
|
OP
Member
Joined: Jul 2005
Posts: 187
|
Thanks for the suggestion... when i use COLOR clr instead of COLOR* clr I get can not convert POINTER to STRUCT COLOR.... So thinking along those lines I broke the function up
int return_blue(ENTITY* ent, VECTOR* pos)
{
COLOR* clr;
clr = terrain_getpixel(ent,pos.x,pos.y,NULL);
if(clr.blue == NULL) {return 0;}
return(clr.blue);
}
function tile_to_height(ENTITY* ent,BMAP* he_bmap,var altitude)
{
CONTACT* c;
COLOR* clr;
var num_Vert = ent_vertices(ent);
var current_vert;
var _tst = 0;
for(current_vert = 1; current_vert < num_Vert; current_vert++)
{
c = ent_getvertex(ent,NULL,current_vert);
_tst = return_blue(ent,vector(c.x,c.y,c.z));
print_var(current_vert);
print_var(_tst);
}
c_updatehull(ent,1);
}
Still Crashes at the same place...just now it crashes in the return_blue function....same amount of times it makes it through the loop....Is it possible that it has something with the cord...as according to the manual ent_getvertex returns the cords in the local entity coordinates and terrain_getpixel uses the world Cords...if so what would be the way to convert the position ? Ok by switching if (clr.blue == NULL) to if(clr == NULL) the function works...Not sure why it will not read the last vert in that column...Still thinking it has to do with the position...
Last edited by lostzac; 08/17/13 08:29.
John C Leutz II
|
|
|
Re: terrain_getpixel
[Re: sivan]
#428072
08/17/13 12:19
08/17/13 12:19
|
Joined: Jul 2005
Posts: 187
lostzac
OP
Member
|
OP
Member
Joined: Jul 2005
Posts: 187
|
Thanks again Sivan......I will modify it with that and let you know.....For something I thought should be a quick easy rough draft is turning into a project lol...
John C Leutz II
|
|
|
Re: terrain_getpixel
[Re: lostzac]
#428075
08/17/13 13:26
08/17/13 13:26
|
Joined: Jul 2005
Posts: 187
lostzac
OP
Member
|
OP
Member
Joined: Jul 2005
Posts: 187
|
Thanks Sivan your suggestions worked.. So using the Height map generator provided by oliver2s, I was able to generate a 2d map that I applied to a flat terrain as skin 1 then using the below code
int return_blue(ENTITY* ent, VECTOR* pos)
{
COLOR* clr;
clr = terrain_getpixel(ent,pos.x,pos.z,NULL);
if(clr == NULL) {return 0;}
return(clr.blue);
}
function tile_to_height(ENTITY* ent,BMAP* he_bmap,var altitude)
{
CONTACT* c;
COLOR* clr;
var num_Vert = ent_vertices(ent);
var current_vert;
var _tst = 0;
for(current_vert = 1; current_vert < num_Vert; current_vert++)
{
c = ent_getvertex(ent,NULL,current_vert);
_tst = return_blue(ent,vector(c.v.x,c.v.y,c.v.z));
//print_var(_tst);
c.v.y += 0.1 + (_tst * altitude);
ent_setvertex(ent,c,current_vert);
}
c_updatehull(ent,1);
}
I was able to deform the terrain to the height map, the next step i am going to do is apply some code I have taking from the terrain tools demo done back in 2010 by Emre Sasmaz to color the height map and apply a multi-texture shader (most likely use the one HeelX provided) ... to give it its texture... Im working on my dungeon generator for caves...and I wanted a quick way to generate the floor with out having to model a bunch of tiles....
Last edited by lostzac; 08/17/13 13:26.
John C Leutz II
|
|
|
|