Pick
This function performs a pick from camera screen coordinates. The current buffer or context will be used for picking operations.
Syntax
- bool Pick(number x, number y, PickInfo pick, number radius=0.0, bool closest=false, number collisiontype=0)
Parameters
- x: the x component of the screen coordinate to pick.
- y: the y component of the screen coordinate to pick.
- pickinfo: a PickInfo structure to hold information.
- radius: a radius can be specified to perform a swept sphere collision test.
- closest: if set to true the closest intersection will be found, otherwise the routine will return as soon as one object is picked.
- collisiontype: if specified, the entity collision type will be tested against this, and only colliding entities will be tested.
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