Difference between revisions of "R3d.World:raycast"

From GiderosMobile
(Created page with "'''Available since:''' Gideros 2019.10<br/> '''Class:''' R3d.World<br/> === Description === You can use ReactPhysics3D to test intersection between a ray and the bodies o...")
 
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
(3 intermediate revisions by 2 users not shown)
Line 6: Line 6:
  
 
Ray casting can be performed against multiple bodies, a single body or any proxy shape of a given body.
 
Ray casting can be performed against multiple bodies, a single body or any proxy shape of a given body.
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
r3d.World:raycast(sx, sy, sz, ex, ey, ez, callback, category)
 
r3d.World:raycast(sx, sy, sz, ex, ey, ez, callback, category)
</source>
+
</syntaxhighlight>
  
 
=== Parameters ===
 
=== Parameters ===
Line 21: Line 21:
  
 
=== Example ===
 
=== Example ===
<source lang="lua">
+
<syntaxhighlight lang="lua">
</source>
+
function raycastcallback(c)
 +
print("world point coords:", c.worldPoint[1], c.worldPoint[2], c.worldPoint[3])
 +
print("world normal coords:", c.worldNormal[1], c.worldNormal[2], c.worldNormal[3])
 +
print("hit fraction:", c.hitFraction)
 +
print("mesh subpart:", c.meshSubpart)
 +
print("triangle index:", c.triangleIndex)
 +
for k, v in pairs(c.body) do
 +
print("body:", k, v)
 +
end
 +
for k, v in pairs(c.fixture) do
 +
print("fixture:", k, v)
 +
end
 +
end
 +
world:raycast(0, 0, 0, 0, 10, -32, raycastcallback)
 +
</syntaxhighlight>
  
 
{{R3d.World}}
 
{{R3d.World}}

Latest revision as of 15:31, 13 July 2023

Available since: Gideros 2019.10
Class: R3d.World

Description

You can use ReactPhysics3D to test intersection between a ray and the bodies of the world you have created.

Ray casting can be performed against multiple bodies, a single body or any proxy shape of a given body.

r3d.World:raycast(sx, sy, sz, ex, ey, ez, callback, category)

Parameters

sx: (number) the starting position of the raycast in the world x axis
sy: (number) the starting position of the raycast in the world y axis
sz: (number) the starting position of the raycast in the world z axis
ex: (number) the ending position of the raycast in the world x axis
ey: (number) the ending position of the raycast in the world y axis
ez: (number) the ending position of the raycast in the world z axis
callback: (function) the callback function
category: (number) bit mask for collision filtering optional

Example

function raycastcallback(c)
	print("world point coords:", c.worldPoint[1], c.worldPoint[2], c.worldPoint[3])
	print("world normal coords:", c.worldNormal[1], c.worldNormal[2], c.worldNormal[3])
	print("hit fraction:", c.hitFraction)
	print("mesh subpart:", c.meshSubpart)
	print("triangle index:", c.triangleIndex)
	for k, v in pairs(c.body) do
		print("body:", k, v)
	end
	for k, v in pairs(c.fixture) do
		print("fixture:", k, v)
	end
end
world:raycast(0, 0, 0, 0, 10, -32, raycastcallback)