Jump to content

GetEntitiesInArea finds prefabs which are beyond area


Dreikblack
 Share

Go to solution Solved by Josh,

Recommended Posts

Prefab: WallLight3.zip

#include "UltraEngine.h"

using namespace UltraEngine;

int main(int argc, const char* argv[]) {
    auto displays = GetDisplays();
    auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);
    auto world = CreateWorld();
    auto framebuffer = CreateFramebuffer(window);

    auto camera = CreateCamera(world);
    camera->SetClearColor(0.125);
    camera->SetPosition(0, 0, -3);

    auto light = CreateBoxLight(world);
    light->SetRotation(45, 35, 0);
    light->SetRange(-10, 10);
    light->SetColor(2);

    auto prefab = LoadPrefab(world, "WallLight3.pfb");

    Vec3 realPosition(10, 0, 10);
    float radius = 0.8f;
    Vec3 positionLower = realPosition;
    positionLower.x = positionLower.x - radius;
    positionLower.z = positionLower.z - radius;
    positionLower.y = positionLower.y - radius;

    Vec3 positionUpper = realPosition;
    positionUpper.x = positionUpper.x + radius;
    positionUpper.z = positionUpper.z + radius;
    positionUpper.y = positionUpper.y + radius;

    for (auto& foundEntity : world->GetEntitiesInArea(positionLower, positionUpper)) {
        Print(foundEntity->name + " found");
    }

    //Main loop
    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false) {
        world->Update();
        world->Render(framebuffer);
    }
    return 0;
}

 

Link to comment
Share on other sites

  • 3 months later...
  • Solution

Only top-level entities are returned, so the bounds used is the recursive bounds that includes all children. This code shows it is working correctly:

#include "UltraEngine.h"

using namespace UltraEngine;

int main(int argc, const char* argv[]) {
    auto displays = GetDisplays();
    auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);
    auto world = CreateWorld();
    auto framebuffer = CreateFramebuffer(window);

    auto camera = CreateCamera(world);
    camera->SetClearColor(0.125);
    camera->SetPosition(0, 0, -3);

    auto light = CreateBoxLight(world);
    light->SetRotation(45, 35, 0);
    light->SetRange(-10, 10);
    light->SetColor(2);

    auto prefab = LoadPrefab(world, "WallLight3.pfb");

    auto bounds = prefab->GetBounds(BOUNDS_RECURSIVE);

    Vec3 realPosition(10, 0, 10);
    float radius = 0.8f;
    Vec3 positionLower = realPosition;
    positionLower.x = positionLower.x - radius;
    positionLower.z = positionLower.z - radius;
    positionLower.y = positionLower.y - radius;

    Vec3 positionUpper = realPosition;
    positionUpper.x = positionUpper.x + radius;
    positionUpper.z = positionUpper.z + radius;
    positionUpper.y = positionUpper.y + radius;

    auto bounds2 = Aabb(positionLower, positionUpper);
    Print(bounds2.IntersectsAabb(bounds));

    return 0;

    for (auto& foundEntity : world->GetEntitiesInArea(positionLower, positionUpper)) {
        Print(foundEntity->name + " found");
    }

    //Main loop
    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false) {
        world->Update();
        world->Render(framebuffer);
    }
    return 0;
}

 

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

The light bounds are important because it is used to determine what objects the light interacts with, like for triggering a refresh of the shadow.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

No, but it is simple enough to add a post-processing step for the list:

std::vector<shared_ptr<Entity> > newlist;
for (auto entity : entities)
{
  if (not entity->GetBounds(BOUNDS_GLOBAL).IntersectsAabb(bounds)) continue;
  newlist.push_back(entity);
}

 

  • Like 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...