I am trying to use ImGuizmo and I am running into a bizarre situation.
Inside the main cpp file of the library there is this function:
static void ComputeCameraRay(vec_t& rayOrigin, vec_t& rayDir, ImVec2 position = ImVec2(gContext.mX, gContext.mY), ImVec2 size = ImVec2(gContext.mWidth, gContext.mHeight))
{
ImGuiIO& io = ImGui::GetIO();
matrix_t mViewProjInverse;
mViewProjInverse.Inverse(gContext.mViewMat * gContext.mProjectionMat);
const float mox = ((io.MousePos.x - position.x) / size.x) * 2.f - 1.f;
const float moy = (1.f - ((io.MousePos.y - position.y) / size.y)) * 2.f - 1.f;
const float zNear = gContext.mReversed ? (1.f - FLT_EPSILON) : 0.f;
const float zFar = gContext.mReversed ? 0.f : (1.f - FLT_EPSILON);
rayOrigin.Transform(makeVect(mox, moy, zNear, 1.f), mViewProjInverse);
rayOrigin *= 1.f / rayOrigin.w;
vec_t rayEnd;
rayEnd.Transform(makeVect(mox, moy, zFar, 1.f), mViewProjInverse);
rayEnd *= 1.f / rayEnd.w;
rayDir = Normalized(rayEnd - rayOrigin);
}
Pay attention to the io
variable. I have stepped through the function using gdb. I get this:
(gdb) p ImGui::GetIO().MousePos.x
$8 = 73
(gdb) p io.MousePos.x
$9 = 0
How is this possible? Yes io is a reference so something could overwrite its value, but it's a reference to the object returned by ImGui::GetIO()
. They should be identical. How is this possible?