diff --git a/src/main.cc b/src/main.cc index 40a3960..c43d956 100644 --- a/src/main.cc +++ b/src/main.cc @@ -178,6 +178,7 @@ int main(void) gGuiInputState->mouseScroll, width, height); + ImGuizmo::BeginFrame(); static int64_t last = bx::getHPCounter(); int64_t pre_module_check = bx::getHPCounter(); diff --git a/src/modules/CharacterModule.cc b/src/modules/CharacterModule.cc index 4367cd3..009c548 100644 --- a/src/modules/CharacterModule.cc +++ b/src/modules/CharacterModule.cc @@ -370,6 +370,8 @@ void CharacterEntity::Update(float dt) { mVelocity = mVelocity + acceleration * dt; + mPosition = mEntity->mTransform.translation; + if (mPosition[1] == 0.0f && mController.mState[CharacterController::ControlStateJump]) { mVelocity[1] = cJumpVelocity; @@ -456,83 +458,85 @@ void ShowCharacterPropertiesWindow (CharacterEntity* character) { assert (character != nullptr); ImGui::SetNextWindowSize (ImVec2(600.f, 300.0f), ImGuiSetCond_Once); ImGui::SetNextWindowPos (ImVec2(400.f, 16.0f), ImGuiSetCond_Once); - ImGui::Begin("Character"); - if (ImGui::Button ("Reset")) { - character->Reset(); - } + if(ImGui::BeginDock("Character")) { - ImGui::Protot::DragFloat4Normalized ("Offset Quat", offset_quat.data(), - 0.01f, -1.0f, 1.0f); - - ImGui::DragFloat3 ("Position", character->mPosition.data(), 0.01, -10.0f, 10.0f); - ImGui::DragFloat3 ("Velocity", character->mVelocity.data(), 0.01, -10.0f, 10.0f); - float angle = atan2 (-character->mVelocity[2], character->mVelocity[0]); - ImGui::LabelText ("", "Angle %f", angle * 180.f / M_PI); - - ImGui::LabelText("", - "Skeleton Bones %d", - character->mEntity->mSkeleton.mLocalTransforms.size()); - - ImGui::LabelText("", - "Rig Frames %d", - character->mRigModel->mBodies.size()); - - bool node_open = ImGui::TreeNodeEx( - "DOFs", - 0); - if (node_open) { - bool dof_modified = false; - for (int i = 0; i < character->mRigModel->q_size; ++i) { - char buf[32]; - snprintf (buf, 32, "DOF %d", i); - - if (ImGui::DragFloat (buf, &character->mRigState.q[i], 0.01, -10.0f, 10.0f)) { - dof_modified = true; - } + if (ImGui::Button ("Reset")) { + character->Reset(); } - if (dof_modified) { - VectorNd q = character->mRigState.q; - } + ImGui::Protot::DragFloat4Normalized ("Offset Quat", offset_quat.data(), + 0.01f, -1.0f, 1.0f); - ImGui::TreePop(); - } + ImGui::DragFloat3 ("Position", character->mPosition.data(), 0.01, -10.0f, 10.0f); + ImGui::DragFloat3 ("Velocity", character->mVelocity.data(), 0.01, -10.0f, 10.0f); + float angle = atan2 (-character->mVelocity[2], character->mVelocity[0]); + ImGui::LabelText ("", "Angle %f", angle * 180.f / M_PI); - node_open = ImGui::TreeNodeEx( - "Meshes", - 0); + ImGui::LabelText("", + "Skeleton Bones %d", + character->mEntity->mSkeleton.mLocalTransforms.size()); - if (node_open) { - for (int i = 0; i < character->mEntity->mSkeleton.Length(); ++i) { - char buf[32]; - snprintf (buf, 32, "Mesh %d", i); + ImGui::LabelText("", + "Rig Frames %d", + character->mRigModel->mBodies.size()); - ImGuiTreeNodeFlags node_flags = 0; + bool node_open = ImGui::TreeNodeEx( + "DOFs", + 0); + if (node_open) { + bool dof_modified = false; + for (int i = 0; i < character->mRigModel->q_size; ++i) { + char buf[32]; + snprintf (buf, 32, "DOF %d", i); - bool node_open = ImGui::TreeNodeEx( - buf, - node_flags); - - if (node_open) { - Transform &transform = character->mEntity->mSkeleton.mLocalTransforms[i]; - - ImGui::DragFloat3 ("Position", transform.translation.data(), 0.01, -10.0f, 10.0f); - if (ImGui::Protot::DragFloat4Normalized ("Rotation", transform.rotation.data(), 0.001, -1.0f, 1.0f)) { - if (isnan(transform.rotation.squaredNorm())) { - std::cout << "nan! " << transform.rotation.transpose() << std::endl; - abort(); - } + if (ImGui::DragFloat (buf, &character->mRigState.q[i], 0.01, -10.0f, 10.0f)) { + dof_modified = true; } - ImGui::DragFloat3 ("Scale", transform.scale.data(), 0.01, 0.001f, 10.0f); - - ImGui::TreePop(); } + + if (dof_modified) { + VectorNd q = character->mRigState.q; + } + + ImGui::TreePop(); + } + + node_open = ImGui::TreeNodeEx( + "Meshes", + 0); + + if (node_open) { + for (int i = 0; i < character->mEntity->mSkeleton.Length(); ++i) { + char buf[32]; + snprintf (buf, 32, "Mesh %d", i); + + ImGuiTreeNodeFlags node_flags = 0; + + bool node_open = ImGui::TreeNodeEx( + buf, + node_flags); + + if (node_open) { + Transform &transform = character->mEntity->mSkeleton.mLocalTransforms[i]; + + ImGui::DragFloat3 ("Position", transform.translation.data(), 0.01, -10.0f, 10.0f); + if (ImGui::Protot::DragFloat4Normalized ("Rotation", transform.rotation.data(), 0.001, -1.0f, 1.0f)) { + if (isnan(transform.rotation.squaredNorm())) { + std::cout << "nan! " << transform.rotation.transpose() << std::endl; + abort(); + } + } + ImGui::DragFloat3 ("Scale", transform.scale.data(), 0.01, 0.001f, 10.0f); + + ImGui::TreePop(); + } + } + ImGui::TreePop(); } - ImGui::TreePop(); } - ImGui::End(); + ImGui::EndDock(); } static struct module_state *module_init() { diff --git a/src/modules/RenderModule.cc b/src/modules/RenderModule.cc index 163e07b..6aaefac 100644 --- a/src/modules/RenderModule.cc +++ b/src/modules/RenderModule.cc @@ -119,10 +119,6 @@ static void module_unload(struct module_state *state, void* write_serializer) { } static bool module_step(struct module_state *state, float dt) { - float deltaTime = 0.3; - std::ostringstream s; - s << "RenderModule: 2 Runtime Object 4 " << deltaTime << " update called!"; - int width, height; assert (gWindow != nullptr); glfwGetWindowSize(gWindow, &width, &height); @@ -136,15 +132,13 @@ static bool module_step(struct module_state *state, float dt) { ImVec2(width - dock_width, dock_top_offset), ImVec2(dock_width, height - dock_top_offset) ); -// ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4 (0.5f, 0.5f, 0.5f, 0.5f)); state->renderer->resize (0, 20.0f, width - dock_width, height - 20.0f); -// state->renderer->resize (0, 20.0f, width, height - 20.0f); + + ImGuizmo::Enable(true); state->renderer->paintGL(); -// ImGui::PopStyleColor(); - return true; } @@ -1278,6 +1272,8 @@ void Renderer::resize (int x, int y, int width, int height) { cameras[i].width = static_cast(width); cameras[i].height = static_cast(height); } + + ImGuizmo::SetRect(view_offset_x, view_offset_y, view_width, view_height); } } @@ -1564,32 +1560,21 @@ void Renderer::paintGL() { entities[i]->mSkeletonMeshes.GetBoneMatrix(j).data() ); } + } - // - // - // -// for (uint32_t j = 0; j < entities[i]->mesh.meshes.size(); ++j) { -// bx::mtxMul( -// lightMtx, -// entities[i]->mesh.meshMatrices[j].data(), -// lights[0].mtxShadow -// ); -// -// // compute world position of the light -// Vector4f light_pos = -// entities[i]->mesh.meshMatrices[j] -// * SimpleMath::Map(lights[0].pos, 4, 1); -// -// bgfx::setUniform(lights[0].u_lightPos, light_pos.data()); -// bgfx::setUniform(lights[0].u_lightMtx, lightMtx); -// bgfxutils::meshSubmit ( -// entities[i]->mesh.meshes[j]->mBgfxMesh, -// &s_renderStates[RenderState::Scene], -// 1, -// entities[i]->mesh.meshMatrices[j].data() -// ); -// -// } + for (size_t i = 0; i < entities.size(); i++) { + Matrix44f ent_transform = entities[i]->mTransform.toMatrix(); + Matrix44f delta_matrix; + ImGuizmo::Manipulate( + cameras[activeCameraIndex].mtxView, + cameras[activeCameraIndex].mtxProj, + ImGuizmo::TRANSLATE, + ImGuizmo::LOCAL, + ent_transform.data(), + delta_matrix.data() + ); + + entities[i]->mTransform.fromMatrix(ent_transform); } // render debug information @@ -1713,7 +1698,6 @@ void Renderer::paintGL() { // ImGui::SetNextWindowPos (ImVec2(10.f, 300.0f), ImGuiSetCond_Once); // if (ImGui::BeginDock("Render Settings")) { - if(ImGui::DragFloat3 ("Light0 Pos", lights[0].pos.data(), 1.0f, -10.0f, 10.0f)) { } diff --git a/src/modules/TestModule.cc b/src/modules/TestModule.cc index ab25f09..f27c1fe 100644 --- a/src/modules/TestModule.cc +++ b/src/modules/TestModule.cc @@ -229,7 +229,6 @@ static void module_unload(struct module_state *state, void* write_serializer) { void ShowModulesWindow(struct module_state *state) { // ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4 (0.5f, 0.5f, 0.5f, 0.8f)); if (ImGui::BeginDock("Modules")) { - ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4 (0.5f, 0.0f, 0.0f, 1.f)); // ImGui::Columns(2); int selected = state->modules_window_selected_index; for (int i = 0; i < gModuleManager->mModules.size(); i++) { @@ -279,7 +278,6 @@ void ShowModulesWindow(struct module_state *state) { } } - ImGui::PopStyleColor(); ImGui::EndDock(); // ImGui::PopStyleColor ();