Pick

This function performs a pick from camera screen coordinates. The current buffer or context will be used for picking operations.

Syntax

Parameters

Returns

Returns true if anything was picked, otherwise false is returned.

Example

pickradius = 0.5

--Create a window
window = Window:Create()
context = Context:Create(window)
world = World:Create()
camera = Camera:Create()
camera:Move(0,0,-3)
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
picksphere = Model:Sphere()
picksphere:SetColor(1.0,0.0,0.0)
picksphere:SetPickMode(0)
picksphere:SetScale(pickradius*2.0)
picksphere:Hide()

while true do
if window:Closed() or window:KeyHit(Key.Escape) then return false end

if (window:MouseDown(1)) then

picksphere:Hide()
local pickinfo = PickInfo()
local p = window:GetMousePosition()
if (camera:Pick(p.x,p.y,pickinfo,pickradius,true)) then

picksphere:Show()
picksphere:SetPosition(pickinfo.position)
end
end

Time:Update()
world:Update()
world:Render()
context:Sync()
end