This function performs a pick operation on all entities in a world that intersect the specified line.
Returns true if anything is hit, otherwise false is returned.
--Create a window
window = Window:Create()
context = Context:Create(window)
world = World:Create()
local camera = Camera:Create()
camera:Move(0,0,-8)
local light = DirectionalLight:Create()
light:SetRotation(35,35,0)
--Create a model
local model1 = Model:Box()
model1:SetPosition(2,0,0)
local model2 = Model:Box()
model2:SetPosition(-2,0,0)
model2:SetPickMode(0) -- Disable picking on the first hit entity
--Create a sphere to indicate where the pick hits
local picksphere = Model:Sphere()
picksphere:SetColor(1.0,0.0,0.0)
picksphere:SetPickMode(0)
local pickradius = 0.5
picksphere:SetScale(pickradius*2.0)
world:Update()
local pickinfo = PickInfo()
if (world:Pick(-10,0.75,0,10,0.75,0,pickinfo,pickradius,true)) then
picksphere:SetPosition(pickinfo.position)
--Make sure the pick mode equals Entity:PolygonPick
Debug:Assert(pickinfo.entity:GetPickMode()==Entity.PolygonPick)
else
picksphere:Release()
end
while true do
if window:Closed() or window:KeyHit(Key.Escape) then return false end
Time:Update()
world:Update()
world:Render()
context:Sync()
end