Gamestudio Links
Zorro Links
Newest Posts
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (degenerate_762, AbrahamR, AndrewAMD, ozgur), 667 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Zone limits and path #222520
08/19/08 19:06
08/19/08 19:06
Joined: Jun 2005
Posts: 87
France
MadJack Offline OP
Junior Member
MadJack  Offline OP
Junior Member

Joined: Jun 2005
Posts: 87
France
I needed to edit quickly zones (or regions) in WED. The idea is to trigger events when an entity get in a specific zone.
With the path editor, it's easy to draw polygons:


And here is a lite-c code that returns 1 if the entity is under the polygon, (0 if it's outside)
Code:
action testPoly()
{
	var aResult;
	
	aResult = inPoly(me, "path_000");
	
	printf("Result : %1d", (int) aResult);
	sys_exit("bye bye...");
}

//////////////////////////////////////////////////////////////////////////////////////																
//                                                                                  
//	  Function to detect if an Entity is under a polygon delimited by a closed path  
//                                                                                  
//	  Param 1 : ENTITY* aEntity	                                                   
//	  Param 2 : char* aPath                                                          
//                                                                                  
//	  Example : inPoly(me, "path_000");                                              
//                                                                                  
//////////////////////////////////////////////////////////////////////////////////////
var inPoly(ENTITY* aEntity, char* aPath)
{
	var 		i = 2, err = 0;
	var 		locCumulAngle = 0;
	ANGLE 	locAngle;

	var 		locVarAngle = 0, locDirectionFirstNode ;

	VECTOR 	locVecNode;
	
	err = path_set(aEntity, aPath);	// if err == 0  : something is wrong (aEntity or aPath)
	if (err < 3) return 0;	        // 3 nodes is the minimum for a polygon
	
	err = path_getnode(aEntity, 1, locVecNode.x, NULL);	// if err == 0  : error getting node info
	vec_sub(locVecNode.x,aEntity.x);	     // this is the vector from aEntity to node 1
	
	vec_to_angle(locAngle.pan,locVecNode.x);     // the first node direction
	locVarAngle = locAngle.pan;											
	locDirectionFirstNode = locVarAngle;	     // first node direction is stored for end use
	
	err = path_getnode(aEntity, i, locVecNode.x, NULL);
	while ( err > 0 )
	{
		vec_sub(locVecNode.x,aEntity.x);
		
		vec_to_angle(locAngle.pan,locVecNode.x);
		
		locCumulAngle += ang(locVarAngle - locAngle.pan);
		
		locVarAngle = locAngle.pan;
		
		i++;
		err = path_getnode(aEntity, i, locVecNode.x, NULL);		
		
	}
	
	locCumulAngle += ang(locVarAngle - locDirectionFirstNode);
	
	return ( abs(locCumulAngle) > 1 );
}


I hope this code will give ideas... smile


Commercial A7.25b
RUGod
Re: Zone limits and path [Re: MadJack] #222523
08/19/08 19:36
08/19/08 19:36
Joined: Oct 2006
Posts: 873
S
Shadow969 Offline
User
Shadow969  Offline
User
S

Joined: Oct 2006
Posts: 873
interesting approach, thanks for sharing smile

Re: Zone limits and path [Re: Shadow969] #222611
08/20/08 07:18
08/20/08 07:18
Joined: Mar 2006
Posts: 1,993
Karlsruhe
PadMalcom Offline
Serious User
PadMalcom  Offline
Serious User

Joined: Mar 2006
Posts: 1,993
Karlsruhe
Wow that could be really helpful smile Thanks

Re: Zone limits and path [Re: MadJack] #226009
09/07/08 09:37
09/07/08 09:37
Joined: Oct 2003
Posts: 827
22�21'24"N 114�07'30"E
Frederick_Lim Offline
User
Frederick_Lim  Offline
User

Joined: Oct 2003
Posts: 827
22�21'24"N 114�07'30"E
Amazing, many thanks!


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