Difference between revisions of "B2.World:rayCast"
(Created page with "__NOTOC__ '''Available since:''' Gideros 2011.6<br/> === Description === <br /> Ray-cast the world for all fixtures in the path of the ray. Your callback controls whether you...") |
|||
Line 25: | Line 25: | ||
<br /> | <br /> | ||
<source lang="lua"> | <source lang="lua"> | ||
− | + | b2.World:rayCast(x1,y1,x2,y2,listener,data) | |
</source> | </source> | ||
− | '''x1 | + | '''x1''': (number) the x coordinate of the ray starting point ''''''<br/> |
− | '''y1 | + | '''y1''': (number) the y coordinate of the ray starting point ''''''<br/> |
− | '''x2 | + | '''x2''': (number) the x coordinate of the ray ending point ''''''<br/> |
− | '''y2 | + | '''y2''': (number) the y coordinate of the ray ending point ''''''<br/> |
− | '''listener | + | '''listener''': (function) the listener function that processes the results ''''''<br/> |
− | '''data | + | '''data''': (any) an optional data parameter that is passed as a first argument to the listener function '''optional'''<br/> |
Revision as of 10:20, 23 August 2018
Available since: Gideros 2011.6
Description
Ray-cast the world for all fixtures in the path of the ray. Your callback controls whether you get the closest point, any point, or n-points. The ray-cast ignores shapes that contain the starting point.
Listener function is called for each fixture found in the query and accepts 6 parameters (7 if data parameter is provided):
1. the fixture hit by the ray
2. the x coordinate of the point of initial intersection
3. the y coordinate of the point of initial intersection
4. the x coordinate of the normal vector at the point of intersection
5. the y coordinate of the normal vector at the point of intersection
6. fraction
You control how the ray cast proceeds by returning a number:
<ul>
<li>return no value or -1: ignore this fixture and continue</li>
<li>return 0: terminate the ray cast</li>
<li>return fraction: clip the ray to this point</li>
<li>return 1: don't clip the ray and continue</li>
</ul>
b2.World:rayCast(x1,y1,x2,y2,listener,data)
'x1: (number) the x coordinate of the ray starting point '
'y1: (number) the y coordinate of the ray starting point '
'x2: (number) the x coordinate of the ray ending point '
'y2: (number) the y coordinate of the ray ending point '
'listener: (function) the listener function that processes the results '
data: (any) an optional data parameter that is passed as a first argument to the listener function optional