I have a plane in 3D space, which is facing the camera that I want to be able to place at the same position as where I click. However, the position of the plane overshoots the mouse cursor. This is for a dynamic GUI that I want to be able to move about and interact with the widgets on the UI.
void mouse::unProjectMouse(float width, float height, camera* viewportCamera)
{
if(NULL == viewportCamera)
{
std::cout<<CNTRLCALL<<"camera failed! failed to un-project mouse";
} else {
glm::vec4 viewport = glm::vec4(0, 0, width, height);
glm::mat4 tmpView = viewportCamera->updateView();
glm::mat4 tmpProj = viewportCamera->updateProjection();
glm::vec3 screenPos = glm::vec3(mouseX, height-mouseY - 1.0f, 1.0f);
glm::vec3 worldPos = glm::unProject(screenPos, tmpView, tmpProj, viewport);
worldPos = worldPos / (worldPos.z * -1.0f);
mouseWorldX = worldPos.x;
mouseWorldY = worldPos.y;
mouseWorldZ = worldPos.z;
}
}
I am at a loss here as to why the plane is not aligning correctly with the mouse.