Jump to content

GetCollider()->IntersectsPoint() return true for an old collider position


Go to solution Solved by SpiderPig,

Recommended Posts

Posted

GetCollider()->IntersectsPoint() seems to ignore changes of position and rotation of model with collider

#include "UltraEngine.h"

using namespace UltraEngine;

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 framebuffer
    auto framebuffer = CreateFramebuffer(window);

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

    //Create a camera    
    auto camera = CreateCamera(world);
    camera->SetClearColor(0.8);
    camera->Turn(35, 0, 0);
    camera->Move(0, 0, -2);
    camera->SetDebugPhysicsMode(true);

    //Create light
    auto light = CreateBoxLight(world);
    light->SetRange(-20, 20);
    light->SetArea(20, 20);
    light->SetRotation(35, 35, 0);

    auto unlitMaterial = CreateMaterial();
    auto unlitShader = LoadShaderFamily("Shaders/Unlit.json");
    unlitMaterial->SetShaderFamily(unlitShader);

    int width = 2, height = 1, length = 3;
    auto model = CreateModel(world);
    auto mesh = model->AddMesh();

    mesh->AddVertex(0, 0, 0); //S
    mesh->AddVertex(-width * 0.5, -height * 0.5, length);//NW
    mesh->AddVertex(width * 0.5, -height * 0.5, length);//NE

    mesh->AddPrimitive(2, 1, 0);//S , NW, NE

    mesh->AddVertex(-width * 0.5, height * 0.5, length);//NW h
    mesh->AddVertex(width * 0.5, height * 0.5, length);//NE h

    mesh->AddPrimitive(0, 3, 4);//S , NW h, NE h

    mesh->AddPrimitive(0, 1, 3);//left

    mesh->AddPrimitive(4, 3, 1); //"face"
    mesh->AddPrimitive(2, 4, 1); //"face"


    mesh->AddPrimitive(0, 4, 2); //"right"

    auto& mat = unlitMaterial;
    mat->SetTransparent(true);
    model->SetMaterial(mat);
    model->SetColor(0.5f, 0.8f, 0, 0.25f);

    auto collider = CreateConvexHullCollider(mesh);
    model->SetCollider(collider);

    Vec3 targetPos(3, 0.5f, 0);
    model->Point(targetPos, 2, 1, 0);
    bool isInside = model->GetCollider()->IntersectsPoint(0, 0.5f, 3);
    Print(isInside);//should be false for this old position
    isInside = model->GetCollider()->IntersectsPoint(targetPos);
    Print(isInside);//should be true for this new position
    //Main loop
    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
    {
        world->Update();
        world->Render(framebuffer);
    }
    return 0;
}

 

Posted

I think i know how to transform a position from global to local (global pos - mode.pos) but i have no idea what to with rotation since it's still a tetrahedron and rotation should matters for position transforming.

  • Solution
Posted

I think there's a TransformPoint function that takes a source and target matrix... the matrix for your point might just be Mat4() with no arguments.  Target matrix would be the models matrix.

  • Thanks 1

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