Pick

This function performs a pick operation on a single surface. The start and end pick positions should be in local space. If a radius is specified, it will also be in considered local space.

Syntax

Parameters

Returns

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

Example

--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)
camera:SetProjectionMode(2)
camera:SetZoom(50)

--Create a model
local model = Model:Sphere()
model:SetScale(3.6)

--Create a sphere to indicate where the pick hits
local picksphere = Model:Sphere()
picksphere:SetColor(1.0,0.0,0.0)
picksphere:SetScale(0.5)

--Get the model surface
local surface = model:GetSurface(0)

--Start and end pick points
local p0 = Vec3(-10,1,0)
local p1 = Vec3(10,1,0)

--Typically you would transform the pick points into local space
p0 = Transform:Point(p0,NULL,model)
p1 = Transform:Point(p1,NULL,model)

local pickinfo = PickInfo()
if (surface:Pick(p0,p1,pickinfo,Vec3(0,0,0),true)) then

--Transform back to world coordinates
pickinfo.position = Transform:Point(pickinfo.position,model,NULL)
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