CedricGuillemet / ImGuizmo

Immediate mode 3D gizmo for scene editing and other controls based on Dear Imgui

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Orientation of Rotation Gizmo is flipped

FSY1901 opened this issue · comments

commented

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.

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

Also, can you try to negate this value :

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

commented

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

No the cube is scaled and translated

commented

Also, can you try to negate this value :

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

How would I do that?

commented

If you meant that:

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

It didn't work.

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

commented

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

No

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

commented

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?

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

commented

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?

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

commented

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()'.

commented

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

Have you found anything?

not yet

commented

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
commented

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.

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