Pick

This function performs a pick operation on a single entity.

Syntax

Parameters

Returns

Returns true if anything is hit, otherwise false is returned.

Remarks

This function should only be used in special cases. A World::Pick or Camera::Pick function call will be much faster in most cases, as it first performs an AABB intersection test with the ray.

Example

--Create a window
window = Window:Create()
context = Context:Create(window)
world = World:Create()
local camera = Camera:Create()
camera:SetRotation(35,0,0)
camera:Move(0,0,-8)
local light = DirectionalLight:Create()
light:SetRotation(35,35,0)
camera:SetProjectionMode(2)
camera:SetZoom(50)

--Create a model
local spherescale = 3.6
local model = Model:Sphere()
model:SetPickMode(Entity.SpherePick)
model:SetPickRadius(spherescale/2.0)
model:SetScale(model:GetPickRadius()*2.0)

--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.25
picksphere:SetScale(pickradius*2.0)

local pickinfo = PickInfo()
if (world:Pick(Vec3(-10,1,0),Vec3(10,1,0),pickinfo,pickradius,true)) then

picksphere:SetPosition(pickinfo.position)
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