UnProject

This function transforms a position in screen space onto a position in global space.

Syntax

Parameters

Returns

Returns a position in global space.

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, 1, -3);

Light* light = DirectionalLight::Create();
light->SetRotation(35, 35, 0);

//Create a model
Model* model = Model::Box();
model->SetColor(0.0, 0.0, 1.0);
model->SetRotation(0, -90, 0);

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

//UnProject mouse coordinates from screen space to world space and position the box there
Vec3 p = window->GetMousePosition();
p.z = 3;//distance in front of the camera to project to
p = camera->UnProject(p);
model->SetPosition(p);

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