CedricGuillemet / ImGuizmo

Immediate mode 3D gizmo for scene editing and other controls based on Dear Imgui
MIT License
3.17k stars 895 forks source link

Orientation of Rotation Gizmo is flipped #222

Closed FSY1901 closed 2 years ago

FSY1901 commented 2 years ago

My Translation and Scaling Gizmos work fine and are oriented in the right way. My Rotation Gizmo works more or less but the orientation is messed up, as you can see below:

Screenshot (23) Screenshot (24)

I have no idea what might be wrong because the other two gizmos are displayed correctly(I use OpenGL's right handed coordinate system): Screenshot (25)

What might be the Issue? Thanks in advance.

CedricGuillemet commented 2 years ago

Did you do the screen shots with an identity matrix for the cube?

CedricGuillemet commented 2 years ago

Also, can you try to negate this value : https://github.com/CedricGuillemet/ImGuizmo/blob/a7ec0dd3b9e7dbd253c8ca891bbf621d82e3c804/ImGuizmo.cpp#L1038

FSY1901 commented 2 years ago

Did you do the screen shots with an identity matrix for the cube?

No the cube is scaled and translated

FSY1901 commented 2 years ago

Also, can you try to negate this value :

https://github.com/CedricGuillemet/ImGuizmo/blob/a7ec0dd3b9e7dbd253c8ca891bbf621d82e3c804/ImGuizmo.cpp#L1038

How would I do that?

FSY1901 commented 2 years ago

If you meant that:

gContext.mReversed = !((nearPos.z/nearPos.w) > (farPos.z / farPos.w));

It didn't work.

CedricGuillemet commented 2 years ago

Do you get a correct rotation gizmo when matrix is identity ?

FSY1901 commented 2 years ago

Do you get a correct rotation gizmo when matrix is identity ?

No

CedricGuillemet commented 2 years ago

can you try to use the view & projection matrix computation from the sample? I guess it's one of them that doesn't fit.

FSY1901 commented 2 years ago

can you try to use the view & projection matrix computation from the sample? I guess it's one of them that doesn't fit.

My view & projection matrix are calculated with glm:

projection = glm::perspective(glm::radians(45.0f), (float)m_window.m_width / (float)m_window.m_height, 0.01f, 100.0f);
view = glm::lookAt(cameraPos, cameraPos + cameraFront, Up);

They have worked so far with everything. And I don't understand what you mean by:

can you try to use the view & projection matrix computation from the sample?

Do you mean the two functions from main.cpp?

CedricGuillemet commented 2 years ago

yes, maybe they are different from glm, for some reason.

FSY1901 commented 2 years ago

can you try to use the view & projection matrix computation from the sample? I guess it's one of them that doesn't fit.

So I did this and it looks like this:

        float _pers[16];
    Perspective(45.0f, (float)m_PanelSize.x / (float)m_PanelSize.y, 0.1f, 100.0f, _pers);
    float _view[16] =
    { 1.f, 0.f, 0.f, 0.f,
    0.f, 1.f, 0.f, 0.f,
     0.f, 0.f, 1.f, 0.f,
    0.f, 0.f, 0.f, 1.f };
    float eye[] = {Camera::GetMain()->position.x, Camera::GetMain()->position.y , Camera::GetMain()->position.z };
    glm::vec3 direction;
    direction.x = Camera::GetMain()->rotation.x;
    direction.y = Camera::GetMain()->rotation.y;
    direction.z = Camera::GetMain()->rotation.z;
    glm::vec3 front = glm::normalize(direction);
    float at[3] = {
        eye[0] + front.x,
        eye[1] + front.y,
        eye[2] + front.z
        };
    float up[3] = {0, 1, 0};
    LookAt(eye, at, up, _view);

    ImGuizmo::Manipulate(_view, _pers, (ImGuizmo::OPERATION)op, ImGuizmo::MODE::LOCAL, glm::value_ptr(transform));

The result is still not right. The gizmos are off and the rotation gizmo is still flipped. I did it this way because I didn't understand what CamDistance in main.cpp was. So, what did I do wrong here?

CedricGuillemet commented 2 years ago

can you share your code on github? I can take a look

FSY1901 commented 2 years ago

The code is already on Github. The Project is called 'FSY-Engine'. The code is in FSY/src/D FSY/Application/Application.cpp

Though I should warn you that the code isn't very clean as I'm still working on it. The part where i render the gizmos is in 'RenderUI()'.

FSY1901 commented 2 years ago

can you share your code on github? I can take a look

Have you found anything?

CedricGuillemet commented 2 years ago

not yet

FSY1901 commented 2 years ago

OK I fixed it: In the function 'DrawRotationGizmo()' you calculate a float 'ng' like this:

float ng = angleStart + circleMul * ZPI * ((float)i / (float)halfCircleSegmentCount);

And basically for me it was just:

float ng = angleStart + -circleMul * ZPI * ((float)i / (float)halfCircleSegmentCount); //added a minus before circleMul
FSY1901 commented 2 years ago

not yet

I don't know if you have seen it, but i fixed it(The comment above this one). I'm just telling you so you don't have to look for a fix.

CedricGuillemet commented 2 years ago

Yes, I've seen the comment. Been busy lately :(