Skip to content

Commit

Permalink
fix picking issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Astral-C committed Sep 3, 2024
1 parent 3d0413f commit 43d35e4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
7 changes: 6 additions & 1 deletion src/UStarForgeApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,16 @@ bool UStarForgeApplication::Setup() {
ImGui_ImplGlfw_InitForOpenGL(mWindow, true);
ImGui_ImplOpenGL3_Init("#version 150");

J3D::Picking::InitFramebuffer(1280,720); //resize as a todo

if(!J3D::Picking::IsPickingEnabled()){
std::cout << "[StarForge]: Picking Ready" << std::endl;
}

glEnable(GL_MULTISAMPLE);

GCResourceManager.Init();

J3D::Picking::InitFramebuffer(1280,720); //resize as a todo

// Create viewer context
mContext = new UStarForgeContext();
Expand Down
28 changes: 18 additions & 10 deletions src/UStarForgeContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,9 @@ void UStarForgeContext::Render(float deltaTime) {

assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);


J3D::Picking::ResizeFramebuffer((uint32_t)winSize.x, (uint32_t)winSize.y);

}

glViewport(0, 0, (uint32_t)winSize.x, (uint32_t)winSize.y);
Expand All @@ -373,12 +376,11 @@ void UStarForgeContext::Render(float deltaTime) {
mRenderables.clear();
mRoot->Render(mRenderables, deltaTime);


J3D::Rendering::RenderPacketVector packets = J3D::Rendering::SortPackets(mRenderables, mCamera.GetPosition());
J3D::Rendering::Render(deltaTime, view, projection, packets);

// Combine these two into one

for(std::shared_ptr<SPathDOMNode> path : mRoot->GetChildrenOfType<SPathDOMNode>(EDOMNodeType::Path)){
std::shared_ptr<SZoneDOMNode> zone = path->GetParentOfType<SZoneDOMNode>(EDOMNodeType::Zone).lock();
if(zone->isVisible()) path->Render(&mCamera, zone->mTransform);
Expand All @@ -392,24 +394,30 @@ void UStarForgeContext::Render(float deltaTime) {
cursorPos = ImGui::GetCursorScreenPos();
ImGui::Image(reinterpret_cast<void*>(static_cast<uintptr_t>(mViewTex)), winSize, {0.0f, 1.0f}, {1.0f, 0.0f});

J3D::Picking::RenderPickingScene(view, projection, packets);
if(ImGui::IsItemClicked(0) && !ImGuizmo::IsOver()){
J3D::Picking::RenderPickingScene(view, projection, packets);
ImVec2 mousePos = ImGui::GetMousePos();

ImVec2 pickPos = {
((uint32_t)mousePos.x - (uint32_t)cursorPos.x), // what?
(uint32_t)winSize.y - ((uint32_t)mousePos.y - (uint32_t)cursorPos.y) // flip the y coordinate
};

// Check picking FB for paths, areas, billboards, etc
// Exit early if we found a selection here


// Check picking for J3DUltra
uint16_t modelID = std::get<0>(J3D::Picking::Query((uint32_t)mousePos.x - (uint32_t)cursorPos.x, (uint32_t)mousePos.y - (uint32_t)cursorPos.y));
uint16_t modelID = std::get<0>(J3D::Picking::Query((uint32_t)pickPos.x, (uint32_t)pickPos.y));

std::cout << "Readback model id at " << (uint32_t)mousePos.x - (uint32_t)cursorPos.x << "," << (uint32_t)mousePos.y - (uint32_t)cursorPos.y <<
" is " << modelID << std::endl;
std::cout << "Readback model id at " << (uint32_t)pickPos.x<< "," << (uint32_t)pickPos.y << " is " << modelID << std::endl;
for(auto object : mRoot->GetChildrenOfType<SObjectDOMNode>(EDOMNodeType::Object)){
if(object->GetModel() != nullptr && object->GetModel()->GetModelId()== modelID){
std::cout << "Selected model " << object->GetName() << std::endl;
selected = object;
break;
if(object->GetModel() != nullptr){
std::cout << "Model " << object->GetName() << " has ID " << object->GetModel()->GetModelId() << " : " << modelID << std::endl;
if(object->GetModel()->GetModelId() == modelID){
selected = object;
break;
}
}
}
}
Expand Down

0 comments on commit 43d35e4

Please sign in to comment.