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

#include "App.h"

using namespace Leadwerks;

App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {}

App::~App() { delete world; delete window; }

bool App::Start()
{
window = Window::Create();
context = Context::Create(window);
world = World::Create();
camera = Camera::Create();
camera->Move(0,0,-8);
Light* light = DirectionalLight::Create();
light->SetRotation(35,35,0);
camera->SetProjectionMode(2);
camera->SetZoom(50);

//Create a model
float spherescale = 3.6;
Model* 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
Model* picksphere = Model::Sphere();
picksphere->SetColor(1.0,0.0,0.0);
picksphere->SetPickMode(0);

float pickradius = 0.25;
picksphere->SetScale(pickradius*2.0);

PickInfo pickinfo;
if (model->Pick(Vec3(-10,1,0),Vec3(10,1,0),pickinfo,pickradius,true))
{
picksphere->SetPosition(pickinfo.position);
}
else
{
picksphere->Release();
}

return true;
}

bool App::Loop()
{
if (window->Closed() || window->KeyDown(Key::Escape)) return false;

Leadwerks::Time::Update();
world->Update();
world->Render();
context->Sync();

return true;
}