using docks now for panels, also early tests for gizmo widget

master
Martin Felis 2017-04-11 12:56:09 +02:00
parent e6d12e22a2
commit 5921b226d8
4 changed files with 86 additions and 99 deletions

View File

@ -178,6 +178,7 @@ int main(void)
gGuiInputState->mouseScroll, gGuiInputState->mouseScroll,
width, width,
height); height);
ImGuizmo::BeginFrame();
static int64_t last = bx::getHPCounter(); static int64_t last = bx::getHPCounter();
int64_t pre_module_check = bx::getHPCounter(); int64_t pre_module_check = bx::getHPCounter();

View File

@ -370,6 +370,8 @@ void CharacterEntity::Update(float dt) {
mVelocity = mVelocity + acceleration * dt; mVelocity = mVelocity + acceleration * dt;
mPosition = mEntity->mTransform.translation;
if (mPosition[1] == 0.0f if (mPosition[1] == 0.0f
&& mController.mState[CharacterController::ControlStateJump]) { && mController.mState[CharacterController::ControlStateJump]) {
mVelocity[1] = cJumpVelocity; mVelocity[1] = cJumpVelocity;
@ -456,83 +458,85 @@ void ShowCharacterPropertiesWindow (CharacterEntity* character) {
assert (character != nullptr); assert (character != nullptr);
ImGui::SetNextWindowSize (ImVec2(600.f, 300.0f), ImGuiSetCond_Once); ImGui::SetNextWindowSize (ImVec2(600.f, 300.0f), ImGuiSetCond_Once);
ImGui::SetNextWindowPos (ImVec2(400.f, 16.0f), ImGuiSetCond_Once); ImGui::SetNextWindowPos (ImVec2(400.f, 16.0f), ImGuiSetCond_Once);
ImGui::Begin("Character");
if (ImGui::Button ("Reset")) { if(ImGui::BeginDock("Character")) {
character->Reset();
}
ImGui::Protot::DragFloat4Normalized ("Offset Quat", offset_quat.data(), if (ImGui::Button ("Reset")) {
0.01f, -1.0f, 1.0f); character->Reset();
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 (dof_modified) { ImGui::Protot::DragFloat4Normalized ("Offset Quat", offset_quat.data(),
VectorNd q = character->mRigState.q; 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( ImGui::LabelText("",
"Meshes", "Skeleton Bones %d",
0); character->mEntity->mSkeleton.mLocalTransforms.size());
if (node_open) { ImGui::LabelText("",
for (int i = 0; i < character->mEntity->mSkeleton.Length(); ++i) { "Rig Frames %d",
char buf[32]; character->mRigModel->mBodies.size());
snprintf (buf, 32, "Mesh %d", i);
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( if (ImGui::DragFloat (buf, &character->mRigState.q[i], 0.01, -10.0f, 10.0f)) {
buf, dof_modified = true;
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();
} }
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() { static struct module_state *module_init() {

View File

@ -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) { 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; int width, height;
assert (gWindow != nullptr); assert (gWindow != nullptr);
glfwGetWindowSize(gWindow, &width, &height); 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(width - dock_width, dock_top_offset),
ImVec2(dock_width, height - 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 - dock_width, height - 20.0f);
// state->renderer->resize (0, 20.0f, width, height - 20.0f);
ImGuizmo::Enable(true);
state->renderer->paintGL(); state->renderer->paintGL();
// ImGui::PopStyleColor();
return true; return true;
} }
@ -1278,6 +1272,8 @@ void Renderer::resize (int x, int y, int width, int height) {
cameras[i].width = static_cast<float>(width); cameras[i].width = static_cast<float>(width);
cameras[i].height = static_cast<float>(height); cameras[i].height = static_cast<float>(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() entities[i]->mSkeletonMeshes.GetBoneMatrix(j).data()
); );
} }
}
// for (size_t i = 0; i < entities.size(); i++) {
// Matrix44f ent_transform = entities[i]->mTransform.toMatrix();
// Matrix44f delta_matrix;
// for (uint32_t j = 0; j < entities[i]->mesh.meshes.size(); ++j) { ImGuizmo::Manipulate(
// bx::mtxMul( cameras[activeCameraIndex].mtxView,
// lightMtx, cameras[activeCameraIndex].mtxProj,
// entities[i]->mesh.meshMatrices[j].data(), ImGuizmo::TRANSLATE,
// lights[0].mtxShadow ImGuizmo::LOCAL,
// ); ent_transform.data(),
// delta_matrix.data()
// // compute world position of the light );
// Vector4f light_pos =
// entities[i]->mesh.meshMatrices[j] entities[i]->mTransform.fromMatrix(ent_transform);
// * SimpleMath::Map<Vector4f>(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()
// );
//
// }
} }
// render debug information // render debug information
@ -1713,7 +1698,6 @@ void Renderer::paintGL() {
// ImGui::SetNextWindowPos (ImVec2(10.f, 300.0f), ImGuiSetCond_Once); // ImGui::SetNextWindowPos (ImVec2(10.f, 300.0f), ImGuiSetCond_Once);
// //
if (ImGui::BeginDock("Render Settings")) { if (ImGui::BeginDock("Render Settings")) {
if(ImGui::DragFloat3 ("Light0 Pos", lights[0].pos.data(), 1.0f, -10.0f, 10.0f)) { if(ImGui::DragFloat3 ("Light0 Pos", lights[0].pos.data(), 1.0f, -10.0f, 10.0f)) {
} }

View File

@ -229,7 +229,6 @@ static void module_unload(struct module_state *state, void* write_serializer) {
void ShowModulesWindow(struct module_state *state) { void ShowModulesWindow(struct module_state *state) {
// ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4 (0.5f, 0.5f, 0.5f, 0.8f)); // ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4 (0.5f, 0.5f, 0.5f, 0.8f));
if (ImGui::BeginDock("Modules")) { if (ImGui::BeginDock("Modules")) {
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4 (0.5f, 0.0f, 0.0f, 1.f));
// ImGui::Columns(2); // ImGui::Columns(2);
int selected = state->modules_window_selected_index; int selected = state->modules_window_selected_index;
for (int i = 0; i < gModuleManager->mModules.size(); i++) { for (int i = 0; i < gModuleManager->mModules.size(); i++) {
@ -279,7 +278,6 @@ void ShowModulesWindow(struct module_state *state) {
} }
} }
ImGui::PopStyleColor();
ImGui::EndDock(); ImGui::EndDock();
// ImGui::PopStyleColor (); // ImGui::PopStyleColor ();