Jump to content

Brush collider is ignored by Pick() when it's a child


Dreikblack
 Share

Recommended Posts

If brush was SetParented to a pivot World::Pick() starts ignoring it.

How it should be:

image.thumb.png.2ca4ef398d721d1645a978fca69fc579.png

How it is:

image.thumb.png.308cdd3d22ad11c18353bfff4aa72499.png

#include "UltraEngine.h"

using namespace UltraEngine;

bool PickFilter(std::shared_ptr<Entity> entity, std::shared_ptr<Object> extra) {
    if (entity->GetCollider() == nullptr) { return false; }
    return true;
}

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->SetFov(70);
    camera->SetPosition(0, 2, -3);
    camera->SetRotation(25, 0, 0);
    camera->SetDebugPhysicsMode(true);
    auto light = CreateDirectionalLight(world);
    light->SetRotation(35, 45, 0);
    light->SetColor(1);
    auto floor = CreatePlane(world, 100, 100);
    floor->Move(0, -1, 0);

    auto b1 = CreateBox(world, 2.0f);
    b1->SetPosition(-3.0f, 0.0f, 0.0f);
    b1->SetColor(1, 0, 0);
    auto pivotParent = CreatePivot(world);//added a parent here
    b1->SetParent(pivotParent);

    auto b2 = CreateBox(world, 2.0f);
    b2->SetColor(0.0f, 0.0f, 1.0f);
    b2->SetPosition(3.0f, 0.0f, 2.0f);
    b2->SetRotation(0.0f, 45.0f, 0.0f);

    auto pivot = CreatePivot(world);

    auto rod_scale = 5.0f;
    auto rod = CreateCylinder(world, 0.05f);
    rod->SetCollider(nullptr);
    rod->SetParent(pivot);
    rod->SetRotation(90.0f, 0.0f, 0.0f);
    rod->SetPosition(0.0f, 0.0f, rod_scale / 2.0f);
    rod->SetScale(1.0f, rod_scale, 1.0f);

    auto sphere = CreateSphere(world, 0.25f);
    sphere->SetCollider(nullptr);
    sphere->SetParent(pivot);
    sphere->SetColor(0, 1, 0);
    sphere->SetPosition(0.0f, 0.0f, rod_scale);

    auto spin_speed = 0.5f;
    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false) {
        pivot->Turn(0.0f, spin_speed, 0.0f);
        auto target_pos = Vec3(0.0f, 0.0f, rod_scale);
        target_pos = TransformPoint(target_pos, Mat4(), pivot->GetMatrix(true).Inverse());
        // Perform a ray cast
        auto pick_info = world->Pick(pivot->GetPosition(true), target_pos, 0.25f, true, PickFilter);
        if (pick_info.success) {
            sphere->SetPosition(pick_info.position, true);
        } else {
            sphere->SetPosition(target_pos, true);
        }
        world->Update();
        world->Render(framebuffer);
    }
    return 0;
}

 

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...