fix test gizmo
This commit is contained in:
4
src/external/qtimgui/ImGuiRenderer.cpp
vendored
4
src/external/qtimgui/ImGuiRenderer.cpp
vendored
@@ -413,7 +413,7 @@ ImGuiRenderer* ImGuiRenderer::instance(ImGuiContext* context) {
|
||||
}
|
||||
else
|
||||
{
|
||||
instance = QtImGui::instances[context];
|
||||
instance = it->second;
|
||||
}
|
||||
|
||||
return instance;
|
||||
@@ -431,7 +431,7 @@ ImGuiRenderer* ImGuiRenderer::instance() {
|
||||
}
|
||||
else
|
||||
{
|
||||
instance = instances[context];
|
||||
instance = it->second;
|
||||
}
|
||||
|
||||
return instance;
|
||||
|
||||
@@ -6,10 +6,13 @@
|
||||
#include <noggit/ContextObject.hpp>
|
||||
#include <external/qtimgui/QtImGui.h>
|
||||
#include <external/qtimgui/imgui/imgui.h>
|
||||
#include <external/imguizmo/ImGuizmo.h>
|
||||
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
#include <stdexcept>
|
||||
#include <QMatrix4x4>
|
||||
#include <QVector3D>
|
||||
|
||||
|
||||
using namespace noggit::Red::AssetBrowser;
|
||||
@@ -62,7 +65,57 @@ void ModelViewer::paintGL()
|
||||
ImGui::SetCurrentContext(_imgui_context);
|
||||
QtImGui::newFrame();
|
||||
|
||||
ImGui::Text("Test");
|
||||
ImGuizmo::SetDrawlist();
|
||||
|
||||
|
||||
ImGuizmo::SetOrthographic(false);
|
||||
ImGuizmo::BeginFrame();
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImGuizmo::SetRect(0, 0, io.DisplaySize.x, io.DisplaySize.y);
|
||||
|
||||
auto obj_mat = _wmo_instances[0].transform_matrix().transposed();
|
||||
float matrixTranslation[3], matrixRotation[3], matrixScale[3];
|
||||
|
||||
ImGuizmo::DecomposeMatrixToComponents(obj_mat, matrixTranslation, matrixRotation, matrixScale);
|
||||
ImGuizmo::RecomposeMatrixFromComponents(matrixTranslation, matrixRotation, matrixScale, obj_mat);
|
||||
|
||||
auto delta_mat = math::matrix_4x4(math::matrix_4x4::unit).transposed();
|
||||
|
||||
auto mview = model_view().transposed();
|
||||
auto proj = projection().transposed();
|
||||
|
||||
ImGuizmo::SetID(0);
|
||||
ImGuizmo::Manipulate(static_cast<float*>(mview),
|
||||
static_cast<float*>(proj),
|
||||
ImGuizmo::TRANSLATE,
|
||||
ImGuizmo::WORLD,
|
||||
obj_mat,
|
||||
delta_mat,
|
||||
NULL);
|
||||
|
||||
|
||||
std::string test;
|
||||
for (int i = 0; i < 16; ++i)
|
||||
{
|
||||
test += std::to_string(static_cast<float*>(delta_mat)[i]) + " ";
|
||||
}
|
||||
|
||||
QMatrix4x4 new_mat (static_cast<float*>(delta_mat));
|
||||
QVector3D pos = {_wmo_instances[0].pos.x, _wmo_instances[0].pos.y, _wmo_instances[0].pos.z};
|
||||
QVector3D transform = pos * new_mat;
|
||||
_wmo_instances[0].pos = {transform.x(), transform.y(), transform.z()};
|
||||
_wmo_instances[0].recalcExtents();
|
||||
|
||||
test += "\n" + std::to_string(_wmo_instances[0].pos.x) + " "
|
||||
+ std::to_string(_wmo_instances[0].pos.y)
|
||||
+ " " + std::to_string(_wmo_instances[0].pos.z);
|
||||
|
||||
|
||||
|
||||
ImGui::Text(test.c_str());
|
||||
|
||||
|
||||
|
||||
ImGui::Render();
|
||||
|
||||
@@ -196,6 +249,8 @@ void ModelViewer::focusOutEvent(QFocusEvent* event)
|
||||
|
||||
void ModelViewer::keyPressEvent(QKeyEvent* event)
|
||||
{
|
||||
event->accept();
|
||||
|
||||
if (event->key() == Qt::Key_W)
|
||||
{
|
||||
moving = _move_sensitivity;
|
||||
|
||||
@@ -101,8 +101,12 @@ void ModelViewer::paintGL()
|
||||
|
||||
auto delta_mat = math::matrix_4x4(math::matrix_4x4::unit).transposed();
|
||||
|
||||
ImGuizmo::Manipulate(static_cast<float*>(model_view().transposed()),
|
||||
static_cast<float*>(projection().transposed()),
|
||||
auto mview = model_view().transposed();
|
||||
auto proj = projection().transposed();
|
||||
|
||||
ImGuizmo::SetID(1);
|
||||
ImGuizmo::Manipulate(static_cast<float*>(mview),
|
||||
static_cast<float*>(proj),
|
||||
ImGuizmo::TRANSLATE,
|
||||
ImGuizmo::WORLD,
|
||||
obj_mat,
|
||||
@@ -196,6 +200,7 @@ void ModelViewer::tick(float dt)
|
||||
|
||||
void ModelViewer::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
|
||||
QLineF const relative_movement (_last_mouse_pos, event->pos());
|
||||
|
||||
if (look)
|
||||
|
||||
Reference in New Issue
Block a user