Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (Quad, 1 invisible), 877 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
terrain_getpixel #428051
08/16/13 23:30
08/16/13 23:30
Joined: Jul 2005
Posts: 187
L
lostzac Offline OP
Member
lostzac  Offline OP
Member
L

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
Code:
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
L
lostzac Offline OP
Member
lostzac  Offline OP
Member
L

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

Code:
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: lostzac] #428061
08/17/13 07:33
08/17/13 07:33
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline
Expert
sivan  Offline
Expert

Joined: Mar 2011
Posts: 3,150
Budapest
try to move out CONTACT* c, and COLOR clr (I think if it's a local variable it should not be a pointer just like in case of vectors - the temporary vector quantity is limited to 32 if I remember well, so probably it is the error reason) before the loop and use only c = ent_getvertex... and clr = ...


Free world editor for 3D Gamestudio: MapBuilder Editor
Re: terrain_getpixel [Re: sivan] #428063
08/17/13 07:52
08/17/13 07:52
Joined: Jul 2005
Posts: 187
L
lostzac Offline OP
Member
lostzac  Offline OP
Member
L

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
Code:
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: lostzac] #428070
08/17/13 11:37
08/17/13 11:37
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline
Expert
sivan  Offline
Expert

Joined: Mar 2011
Posts: 3,150
Budapest
I think the loop should start at 0 and end with <ent_status(ent,0). of course in ent_getvertex the vertex number should be current_vert+1. or use a >= as loop end.

but the error reason is the line:
_tst = return_blue(ent,vector(c.x,c.y,c.z));
where you reach the max 32 temporary vector limit within a frame. you should use there simply c.v.x or c.x.

moreover in getpixel you should use x and z because contact uses DX coordinate system where y-z is swapped comparing to 3dgs coordinates.


Free world editor for 3D Gamestudio: MapBuilder Editor
Re: terrain_getpixel [Re: sivan] #428072
08/17/13 12:19
08/17/13 12:19
Joined: Jul 2005
Posts: 187
L
lostzac Offline OP
Member
lostzac  Offline OP
Member
L

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
L
lostzac Offline OP
Member
lostzac  Offline OP
Member
L

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

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


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1