Dreikblack Posted July 18, 2023 Share Posted July 18, 2023 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; } Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted July 18, 2023 Share Posted July 18, 2023 Those tests might be done in local space. You might have to transform your points and lines yourself. I had to that to somthing a while back with bones I think. Quote Link to comment Share on other sites More sharing options...
Dreikblack Posted July 18, 2023 Author Share Posted July 18, 2023 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. Quote Link to comment Share on other sites More sharing options...
Solution SpiderPig Posted July 18, 2023 Solution Share Posted July 18, 2023 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. 1 Quote Link to comment Share on other sites More sharing options...
Dreikblack Posted July 18, 2023 Author Share Posted July 18, 2023 Thanks! Works now with transforming: targetPos = TransformPoint(targetPos, Mat4(), model->GetMatrix()); 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.