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

#include "Leadwerks.h"

using namespace Leadwerks;

int main(int argc, const char *argv[])
{
Leadwerks::Window* window = Leadwerks::Window::Create();
Context* context = Context::Create(window);
World* world = World::Create();
Camera* camera = Camera::Create();
camera->Move(0, 0, -8);
Light* light = DirectionalLight::Create();
light->SetRotation(35, 35, 0);
camera->SetProjectionMode(2);
camera->SetZoom(50);

float pickradius = 0.5;

//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
Entity* picksphere = Model::Sphere();
picksphere->SetColor(1.0, 0.0, 0.0);
picksphere->SetPickMode(0);
picksphere->SetScale(pickradius*2.0);
picksphere->Hide();

while (true)
{
if (window->Closed() || window->KeyDown(Key::Escape)) break;

if (window->MouseDown(1))
{
picksphere->Hide();
PickInfo pickinfo;
Vec3 p = window->GetMousePosition();
if (camera->Pick(p.x, p.y, pickinfo, pickradius, true))
{
picksphere->Show();
picksphere->SetPosition(pickinfo.position);
}
}

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