Class: Camera


This method performs a raycast at the specified screen coordinate.


Parameter Description
framebuffer framebuffer to test with
screencoord, (x, y) screen coordinate to pick
radius pick sphere radius
closest if true the closest point will be determined
filter optional callback to filter objects
extra extra value to send to filter callback


Returns a PickInfo structure. If the success member of the structure is true an object was hit, otherwise it will be false.

If a filter callback is provided it will be called for each entity that is evaluated. If the callback returns true the entity will be tested, otherwise it will be skipped.


#include "UltraEngine.h"

using namespace UltraEngine;

bool PickFilter(std::shared_ptr<Entity> entity, std::shared_ptr<Object> extra)
    return true;

int main(int argc, const char* argv[])
    //Get the displays
    auto displays = GetDisplays();

    //Create a window
    auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);

    //Create a world
    auto world = CreateWorld();

    //Create a framebuffer
    auto framebuffer = CreateFramebuffer(window);

    //Create light
    auto light = CreateBoxLight(world);
    light->SetRange(-10, 10);
    light->SetRotation(15, 15, 0);

    //Create camera
    auto camera = CreateCamera(world);
    camera->SetPosition(0, 0, -3);

    //Create scenery
    auto box = CreateBox(world);

    auto cone = CreateCone(world);
    cone->SetPosition(1.25, 0, 0);

    auto sphere = CreateSphere(world);
    sphere->SetPosition(-1.25, 0, 0);

    //Main loop
    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        //Click on an object to change its color
        if (window->MouseHit(MOUSE_LEFT))
            box->SetColor(1, 1, 1);
            cone->SetColor(1, 1, 1);
            sphere->SetColor(1, 1, 1);
            auto mousepos = window->GetMousePosition();
            auto pick = camera->Pick(framebuffer, mousepos.x, mousepos.y, 0, true, PickFilter, NULL);
            if (pick.success)
                pick.entity->SetColor(1, 0, 0);

    return 0;
Copyright © 2024 Ultra Software.
All rights reserved.