GithubHelp home page GithubHelp logo

Comments (2)

CedricGuillemet avatar CedricGuillemet commented on August 15, 2024

ImGuizmo uses mouse position reported by imgui. Usualy, when I get mouse position issues, it's because of inverted Y. Do you get a detection when you mouse the mouse verticaly?
For the matrix, maybe you matrix is row major instead of column major. Did you try to use an identity matrix?

from imguizmo.

mel-florance avatar mel-florance commented on August 15, 2024

Hello,

First of all thanks a lot, after some research with your answer i managed to get it to work like a charm !

Indeed i found that the gizmo can get flipped on the Y axis (up) when the fov has a bad value like 60, so i managed to fix that issue by using the glm::perspectiveFov method with a fov in radians, and then i flipped each axis manually.

Then i also noticed that i wasn't updated the transform of my object properly (which requires to update the position, rotation and scale of my transform (which is then converted back to my engine to a matrix for parenting and stuff)).

Here the final code i used, if it can help someone else:

ImGuizmo::SetDrawlist();
ImGuizmo::SetRect(rect_pos.x, rect_pos.y, size.x, size.y - 22.0f);

Node* node = editor->getEngine()->getScenesManager()->getActiveScene()->getSceneGraph()->getNodes()[1];
glm::mat4 proj = glm::perspectiveFov(cam->getFov(), size.x, size.y, cam->getClipNear(), cam->getClipFar());
glm::mat4 view = cam->getViewMatrix();
glm::mat4 object = node->transform.getMatrix();

view[0][1] = -view[0][1];
view[1][1] = -view[1][1];
view[2][1] = -view[2][1];
			
ImGuizmo::Manipulate(
    glm::value_ptr(view),
    glm::value_ptr(proj),
    ImGuizmo::TRANSLATE, 
    ImGuizmo::LOCAL,  
    &object[0][0]
);

float matrixTranslation[3], matrixRotation[3], matrixScale[3];
ImGuizmo::DecomposeMatrixToComponents(&object[0][0], matrixTranslation, matrixRotation, matrixScale);

node->transform.setPosition(glm::vec3(matrixTranslation[0], matrixTranslation[1], matrixTranslation[2]));
node->transform.setRotation(glm::vec3(glm::radians(matrixRotation[0]), glm::radians(matrixRotation[1]), glm::radians(matrixRotation[2])));
node->transform.setScale(glm::vec3(matrixScale[0], matrixScale[1], matrixScale[2]));

from imguizmo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.