Dreikblack Posted November 10 Share Posted November 10 If brush was SetParented to a pivot World::Pick() starts ignoring it. How it should be: How it is: #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; } Quote Link to comment Share on other sites More sharing options...
Dreikblack Posted November 10 Author Share Posted November 10 Managed to fix it in the game in Pivot's component Start() method by: auto entity = GetEntity(); if (entity) { entity->SetRotation(entity->GetRotation(true), true); } But resetting rotation does not work for this example O_o Quote Link to comment Share on other sites More sharing options...
Solution Josh Posted Thursday at 11:53 PM Solution Share Posted Thursday at 11:53 PM Set the parent pivot to have a pick mode: pivotParent->SetPickMode(PICK_COLLIDER); Don't use the pick filter, since this will abort when the pivot is encountered: //auto pick_info = world->Pick(pivot->GetPosition(true), target_pos, 0.25f, true, PickFilter); auto pick_info = world->Pick(pivot->GetPosition(true), target_pos, 0.25f, true); This is how the system is meant to work. Quote 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 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.