diff --git a/docs/tasks/Bugs.todo b/docs/tasks/Bugs.todo index 5c588f3..e498a54 100644 --- a/docs/tasks/Bugs.todo +++ b/docs/tasks/Bugs.todo @@ -1,5 +1,7 @@ High Importance: + ✔ Rotated children translate in local space instead of world space (set the parents velocity and see the rotated child move incorrectly) @done(22-10-18 13:46) + ✔ Parent/child transform hierarchy doesn't seem to work correctly in general @done(22-10-18 13:46) ☐ Colors are not saved accurately ✔ Add Component button on properties view no longer works @critical @done(22-09-07 13:44) ✔ AssetBrowser back button does not stop at the asset root directory @high @done(22-07-05 13:53) diff --git a/docs/tasks/editor.todo b/docs/tasks/editor.todo index 7d7842e..782be5b 100644 --- a/docs/tasks/editor.todo +++ b/docs/tasks/editor.todo @@ -51,6 +51,7 @@ Editor: GUI Panels: World View: + ☐ Add frame feature to center the camera on the selected entity ✔ Middle Mouse view dragging @done(22-09-08 15:45) ✔ Render the current world and display on view panel @done(22-09-08 15:45) ☐ Optional and adjustable grid display diff --git a/src/run_modes/editor/panels/world_view.cpp b/src/run_modes/editor/panels/world_view.cpp index a7078cd..1bac09a 100644 --- a/src/run_modes/editor/panels/world_view.cpp +++ b/src/run_modes/editor/panels/world_view.cpp @@ -143,7 +143,7 @@ namespace lunarium { namespace editor ImGui::SameLine(); if (ImGui::ImageButton((ImTextureID)DataManager::mStop->GetGLID64(), - ImVec2(DataManager::mStop->GetWidth(), DataManager::mStop->GetHeight()))) + ImVec2(DataManager::mStop->GetWidth(), DataManager::mStop->GetHeight())) && mSimRunning) { mpEditor->OnStop(); mpWorld->ResetState(mWorldState); diff --git a/src/run_modes/testbed/scenes/simple_render_scene.cpp b/src/run_modes/testbed/scenes/simple_render_scene.cpp index a494818..4a907a8 100644 --- a/src/run_modes/testbed/scenes/simple_render_scene.cpp +++ b/src/run_modes/testbed/scenes/simple_render_scene.cpp @@ -62,14 +62,18 @@ namespace lunarium mParentPos = glm::vec3(300.0f, 300.0f, 0.0f); mChildPos = glm::vec3(250.0f, 0.0f, 0.0f); + mChild2Pos = glm::vec3(100.f, 100.0f, 0.0f); mParentAngle = 0.0f; mChildAngle = 0.0f; + mChild2Angle = 0.0f; + mParentPos2 = glm::vec3(700.0f, 200.0f, 0.0f); mChildPos2 = glm::vec3(-300.0f, 50.0f, 0.0f); mParentPos3 = glm::vec3(200.0f, 600.0f, 0.0f); mChildPos3 = glm::vec3(150.0f, 100.0f, 0.0f); + mChildPos3_2 = glm::vec3(150.0f, 0.0f, 0.0f); angle = 0.0f; box_angle = 0.0f; @@ -303,21 +307,30 @@ namespace lunarium g.DrawQuad(Rectangle(mParentPos.x, mParentPos.y, 50.0f, 50.0f), Color::Blue(), nullptr, mParentAngle); glm::mat4 parent = glm::mat4(1.0f); parent = glm::translate(parent, mParentPos); - parent = glm::rotate(parent, mParentAngle, glm::vec3(0.0f, 0.0f, 1.0f)); + parent = glm::rotate(parent, mParentAngle * -1.0f, glm::vec3(0.0f, 0.0f, 1.0f)); g.DrawQuad(Rectangle(mChildPos.x, mChildPos.y, 50.0f, 50.0f), Color::Green(), nullptr, mChildAngle, Rectangle(-1, -1, -1, -1), parent); g.DrawLine(glm::vec2(mParentPos.x, mParentPos.y), glm::vec2(mParentPos.x + mChildPos.x, mParentPos.y + mChildPos.y), Color::Blue(), 1.5f); - - g.DrawQuad(Rectangle(mParentPos2.x, mParentPos2.y, 50.0f, 50.0f), Color::Red()); - parent = glm::mat4(1.0f); - parent = glm::translate(parent, mParentPos2); - g.DrawQuad(Rectangle(mChildPos2.x, mChildPos2.y, 50.0f, 50.0f), Color::White(), nullptr, mChildAngle, Rectangle(-1, -1, -1, -1), parent); - g.DrawLine(glm::vec2(mParentPos2.x, mParentPos2.y), glm::vec2(mParentPos2.x + mChildPos2.x, mParentPos2.y + mChildPos2.y), Color::Red(), 1.5f); - - g.DrawQuad(Rectangle(mParentPos3.x, mParentPos3.y, 50.0f, 50.0f), Color::Black()); - parent = glm::mat4(1.0f); - parent = glm::translate(parent, mParentPos3); - g.DrawQuad(Rectangle(mChildPos3.x, mChildPos3.y, 50.0f, 50.0f), Color(0.75f, 0.15f, 0.5f, 1.0f), nullptr, mChildAngle, Rectangle(-1, -1, -1, -1), parent); - g.DrawLine(glm::vec2(mParentPos3.x, mParentPos3.y), glm::vec2(mParentPos3.x + mChildPos3.x, mParentPos3.y + mChildPos3.y), Color::Black(), 1.5f); + parent = glm::translate(parent, mChildPos); + parent = glm::rotate(parent, mChildAngle * -1.0f, glm::vec3(0.0f, 0.0f, 1.0f)); + g.DrawQuad(Rectangle(mChild2Pos.x, mChild2Pos.y, 50.0f, 50.0f), Color::Green(), nullptr, mChild2Angle, Rectangle(-1, -1, -1, -1), parent); + g.DrawLine(glm::vec2(mParentPos.x + mChildPos.x, mParentPos.y + mChildPos.y), glm::vec2(mParentPos.x + mChildPos.x + mChild2Pos.x, mParentPos.y + mChildPos.y + mChild2Pos.y), Color::Blue(), 1.5f); + + + // g.DrawQuad(Rectangle(mParentPos2.x, mParentPos2.y, 50.0f, 50.0f), Color::Red()); + // parent = glm::mat4(1.0f); + // parent = glm::translate(parent, mParentPos2); + // g.DrawQuad(Rectangle(mChildPos2.x, mChildPos2.y, 50.0f, 50.0f), Color::White(), nullptr, mChildAngle, Rectangle(-1, -1, -1, -1), parent); + // g.DrawLine(glm::vec2(mParentPos2.x, mParentPos2.y), glm::vec2(mParentPos2.x + mChildPos2.x, mParentPos2.y + mChildPos2.y), Color::Red(), 1.5f); + + // g.DrawQuad(Rectangle(mParentPos3.x, mParentPos3.y, 50.0f, 50.0f), Color::Black()); + // parent = glm::mat4(1.0f); + // parent = glm::translate(parent, mParentPos3); + // g.DrawQuad(Rectangle(mChildPos3.x, mChildPos3.y, 50.0f, 50.0f), Color(0.75f, 0.15f, 0.5f, 1.0f), nullptr, mChildAngle, Rectangle(-1, -1, -1, -1), parent); + // g.DrawLine(glm::vec2(mParentPos3.x, mParentPos3.y), glm::vec2(mParentPos3.x + mChildPos3.x, mParentPos3.y + mChildPos3.y), Color::Black(), 1.5f); + + // parent = glm::translate(parent, mChildPos3); + // g.DrawQuad(Rectangle(mChildPos3_2.x, mChildPos3_2.y, 50.0f, 50.0f), Color(0.75f, 0.15f, 0.5f, 1.0f), nullptr, mChildAngle, Rectangle(-1, -1, -1, -1), parent); + // g.DrawLine(glm::vec2(mParentPos3.x + mChildPos3.x, mParentPos3.y + mChildPos3.y), glm::vec2(mParentPos3.x + mChildPos3.x + mChildPos3_2.x, mParentPos3.y + mChildPos3.y + mChildPos3_2.y), Color::Black(), 1.5f); } ///////////////////////////////////////////////////////////////////// @@ -425,6 +438,7 @@ namespace lunarium ImGui::Text("Group One:"); float parent_pos[3] = { mParentPos.x, mParentPos.y, mParentPos.z }; float child_pos[3] = { mChildPos.x, mChildPos.y, mChildPos.z }; + float child2_pos[3] = { mChild2Pos.x, mChild2Pos.y, mChild2Pos.z }; ImGui::Text("Parent Position:"); ImGui::SameLine(); @@ -435,7 +449,7 @@ namespace lunarium ImGui::Text("Parent Angle:"); ImGui::SameLine(); - ImGui::DragFloat("##ParentAngle", &mParentAngle); + ImGui::DragFloat("##ParentAngle", &mParentAngle, 0.1f); ImGui::Text("Child Position:"); ImGui::SameLine(); @@ -446,46 +460,65 @@ namespace lunarium ImGui::Text("Child Angle:"); ImGui::SameLine(); - ImGui::DragFloat("##ChildAngle", &mChildAngle); - - - // GROUP TWO - ImGui::Text("Group two:"); - float parent_pos2[3] = { mParentPos2.x, mParentPos2.y, mParentPos2.z }; - float child_pos2[3] = { mChildPos2.x, mChildPos2.y, mChildPos2.z }; + ImGui::DragFloat("##ChildAngle", &mChildAngle, 0.1f); - ImGui::Text("Parent Position:"); + ImGui::Text("Child 2 Position:"); ImGui::SameLine(); - if (ImGui::DragFloat3("##ParentPos2", parent_pos2)) + if (ImGui::DragFloat3("##Child2Pos", child2_pos)) { - mParentPos2 = { parent_pos2[0], parent_pos2[1], parent_pos2[2] }; + mChild2Pos = { child2_pos[0], child2_pos[1], child2_pos[2] }; } - ImGui::Text("Child Position:"); + ImGui::Text("Child 2 Angle:"); ImGui::SameLine(); - if (ImGui::DragFloat3("##ChildPos2", child_pos2)) - { - mChildPos2 = { child_pos2[0], child_pos2[1], child_pos2[2] }; - } + ImGui::DragFloat("##Child2Angle", &mChild2Angle, 0.1f); - // GROUP THREE - ImGui::Text("Group three:"); - float parent_pos3[3] = { mParentPos3.x, mParentPos3.y, mParentPos3.z }; - float child_pos3[3] = { mChildPos3.x, mChildPos3.y, mChildPos3.z }; - ImGui::Text("Parent Position:"); - ImGui::SameLine(); - if (ImGui::DragFloat3("##ParentPos3", parent_pos3)) - { - mParentPos3 = { parent_pos3[0], parent_pos3[1], parent_pos3[2] }; - } + // GROUP TWO + // ImGui::Text("Group two:"); + // float parent_pos2[3] = { mParentPos2.x, mParentPos2.y, mParentPos2.z }; + // float child_pos2[3] = { mChildPos2.x, mChildPos2.y, mChildPos2.z }; - ImGui::Text("Child Position:"); - ImGui::SameLine(); - if (ImGui::DragFloat3("##ChildPos3", child_pos3)) - { - mChildPos3 = { child_pos3[0], child_pos3[1], child_pos3[2] }; - } + // ImGui::Text("Parent Position:"); + // ImGui::SameLine(); + // if (ImGui::DragFloat3("##ParentPos2", parent_pos2)) + // { + // mParentPos2 = { parent_pos2[0], parent_pos2[1], parent_pos2[2] }; + // } + + // ImGui::Text("Child Position:"); + // ImGui::SameLine(); + // if (ImGui::DragFloat3("##ChildPos2", child_pos2)) + // { + // mChildPos2 = { child_pos2[0], child_pos2[1], child_pos2[2] }; + // } + + // // GROUP THREE + // ImGui::Text("Group three:"); + // float parent_pos3[3] = { mParentPos3.x, mParentPos3.y, mParentPos3.z }; + // float child_pos3[3] = { mChildPos3.x, mChildPos3.y, mChildPos3.z }; + // float child_pos3_2[3] = { mChildPos3_2.x, mChildPos3_2.y, mChildPos3_2.z }; + + // ImGui::Text("Parent Position:"); + // ImGui::SameLine(); + // if (ImGui::DragFloat3("##ParentPos3", parent_pos3)) + // { + // mParentPos3 = { parent_pos3[0], parent_pos3[1], parent_pos3[2] }; + // } + + // ImGui::Text("Child Position:"); + // ImGui::SameLine(); + // if (ImGui::DragFloat3("##ChildPos3", child_pos3)) + // { + // mChildPos3 = { child_pos3[0], child_pos3[1], child_pos3[2] }; + // } + + // ImGui::Text("Child Position:"); + // ImGui::SameLine(); + // if (ImGui::DragFloat3("##ChildPos3_2", child_pos3_2)) + // { + // mChildPos3_2 = { child_pos3_2[0], child_pos3_2[1], child_pos3_2[2] }; + // } } ImGui::EndChild(); diff --git a/src/run_modes/testbed/scenes/simple_render_scene.h b/src/run_modes/testbed/scenes/simple_render_scene.h index 223c46c..66e008e 100644 --- a/src/run_modes/testbed/scenes/simple_render_scene.h +++ b/src/run_modes/testbed/scenes/simple_render_scene.h @@ -124,12 +124,15 @@ namespace lunarium float mParentAngle; glm::vec3 mChildPos; float mChildAngle; + glm::vec3 mChild2Pos; + float mChild2Angle; glm::vec3 mParentPos2; glm::vec3 mChildPos2; glm::vec3 mParentPos3; glm::vec3 mChildPos3; + glm::vec3 mChildPos3_2; struct GridTestObj { diff --git a/src/world/world.cpp b/src/world/world.cpp index 3f01fa9..ac2b924 100644 --- a/src/world/world.cpp +++ b/src/world/world.cpp @@ -95,10 +95,11 @@ namespace lunarium glm::mat4 parent_transform = glm::mat4(1.0f); if (pEnt->HasComponent()) { - parent_transform = GetParentTransform(uuid); + + parent_transform = GetParentTransform(pEnt->GetComponent().Parent); } - pGraphics->DrawQuad(rect, color, nullptr, -transform.Rotation.z, Rectangle(-1, -1, -1, -1), parent_transform); + pGraphics->DrawQuad(rect, color, nullptr, transform.Rotation.z, Rectangle(-1, -1, -1, -1), parent_transform); } } @@ -214,14 +215,17 @@ namespace lunarium if (p->HasComponent()) { - TransformComponent t = p->GetComponent(); - transform = t.GetTransform(); + if (p->HasComponent()) { - transform *= GetParentTransform(p->GetComponent().Parent); + transform = GetParentTransform(p->GetComponent().Parent); } + TransformComponent t = p->GetComponent(); + transform = glm::translate(transform, t.Position); + transform = glm::rotate(transform, t.Rotation.z * -1.0f, glm::vec3(0.0f, 0.0f, 1.0f)); + } return transform;