Jump to content

Pick ignores model if pick position inside of model


Go to solution Solved by Josh,

Recommended Posts

Posted

And in same time PickFilter have this entity twice.

Example (space to do pick, result in console):

#include "Leadwerks.h"

using namespace Leadwerks;

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[]) {
    // Get the displays
    auto displays = GetDisplays();

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

    //Create world
    auto world = CreateWorld();

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

    //Set up camera
    auto camera = CreateCamera(world);
    camera->SetClearColor(0.125);
    camera->SetFov(70);
    camera->SetPosition(0, 2, -3);
    camera->SetRotation(25, 0, 0);

    //Add a light
    auto light = CreateDirectionalLight(world);
    light->SetRotation(35, 45, 0);
    light->SetColor(5);

    //Set up the scene
    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 spin_speed = 0.5f;
    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false) {
        if (window->KeyDown(KEY_SPACE)) {
            auto pick_info = world->Pick(b1->GetPosition(true), b1->GetPosition(true), 0, true, PickFilter);
            if (pick_info.success) {
                Print("True");
            } else {
                Print("False");
            }
        }
        // Update the world
        world->Update();
        // Render the world
        world->Render(framebuffer);
    }
    return 0;
}

 

Check out Slipgate Tactics demo, which is made with Ultra Engine/Leadwerks 5:

https://www.leadwerks.com/community/topic/61480-slipgate-tactics-demo/

  • 1 month later...
Posted

Why would this pick detect anything at all, if the start and end positions are the same?

auto pick_info = world->Pick(b1->GetPosition(true), b1->GetPosition(true), 0, true, PickFilter);

Even if you add a small distance, pick will only detect collision with the mesh polygons. Mesh data doesn't have a volume, it is just like an origami sculpture.

auto pick_info = world->Pick(b1->GetPosition(true), b1->GetPosition(true) + 0.1f, 0, true, PickFilter);

 

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

  • Solution
Posted

I tried setting b1's pick mode to PICK_COLLIDER, but the ray does not detect collision inside the box collider. I think this is probably just the way it works.

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[])
{
    {
       {
            // Get the displays
            auto displays = GetDisplays();

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

            //Create world
            auto world = CreateWorld();

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

            //Set up camera
            auto camera = CreateCamera(world);
            camera->SetClearColor(0.125);
            camera->SetFov(70);
            camera->SetPosition(0, 2, -3);
            camera->SetRotation(25, 0, 0);

            //Add a light
            auto light = CreateDirectionalLight(world);
            light->SetRotation(35, 45, 0);
            light->SetColor(5);

            //Set up the scene
            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);
            b1->SetPickMode(PICK_COLLIDER);

            auto spin_speed = 0.5f;
            while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false) {
                if (window->KeyDown(KEY_SPACE)) {
                    auto pick_info = world->Pick(b1->GetPosition(true), b1->GetPosition(true) + 0.1f, 0, true, PickFilter);
                    if (pick_info.success) {
                        Print("True");
                    }
                    else {
                        Print("False");
                    }
                }
                // Update the world
                world->Update();
                // Render the world
                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.

Posted

There is also an Collider::Collide method you might find useful. I used this in the FPS demo to handle held objects.

virtual vector<Collision> Collide(shared_ptr<Collider> collider, const Mat4& mat0, const Mat4& mat1, const int maxcollisions = 1);
virtual vector<Collision> Collide(shared_ptr<Collider> collider, const Mat4& mat0, const Mat4& mat1, const Vec3& velocity0, const Vec3& velocity1, const Vec3& omega0, const Vec3& omega1, const float timestep = 1.0f / 60.0f, const int maxcollisions = 1);

 

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

Posted
4 hours ago, Josh said:

There is also an Collider::Collide method you might find useful. I used this in the FPS demo to handle held objects.

But it works only for objects with masses.

After few months i can't recall now what exactly it was a case, but it was in my game. Will take in mind that pick detect only collision faces then i suppose.

Check out Slipgate Tactics demo, which is made with Ultra Engine/Leadwerks 5:

https://www.leadwerks.com/community/topic/61480-slipgate-tactics-demo/

Posted
17 minutes ago, Dreikblack said:

But it works only for objects with masses.

After few months i can't recall now what exactly it was a case, but it was in my game. Will take in mind that pick detect only collision faces then i suppose.

No, colliders have nothing to do with physics bodies and are completely separate. This function doesn't even run in the physics thread.

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

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.

×
×
  • Create New...