Project
This function transforms a position in global space onto a position in screen space.
Syntax
- Vec3 Project(const Vec3& position)
Parameters
- position: the position in global space to transform.
Returns
Returns a position in screen space. The X and Y components correspond to 2D screen coordinates, while the Z component contains the foreward distance to the projected point.
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);
//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;
//Make the model move in a circle
model->Turn(0, Leadwerks::Time::GetSpeed()*0.5, 0);
model->Move(0, 0, 0.1);
Leadwerks::Leadwerks::Time::Update();
world->Update();
world->Render();
Vec3 p = camera->Project(model->GetPosition());
std::string text = "This is a box!";
Font* font = context->GetFont();
p.x -= font->GetTextWidth(text) / 2;
p.y -= font->GetHeight() / 2;
context->SetBlendMode(Blend::Alpha);
context->DrawText(text, p.x, p.y);
context->Sync();
}
}