Reversing perspective foreshortening.
Hi. I have a 3D scene that I am rendering in a perspective projection. I have a camera that I use to orbit around the scene, always looking at the origin. In addition the scene itself can translate and rotate. In my scene I have 3D objects that get smaller as they get farther away from the camera as you would expect in a perspective projection. I want some 3D objects to remain the same size regardless of where they are in the scene. In a GLSL vertex shader I managed to linearize gl_Position.z and then reverse the foreshortening by doing the following...
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_Position.z = (gl_Position.z / 40.0) * gl_Position.w; // Linearize depth. 40 is the far plane.
gl_Position.w = 1.000;
Unfortunately now my 3D objects are in the wrong place in the scene. I suspect I may need to do something with gl_Position.x and gl_Position.y?
Any help would be appreciated.
At the top of the projection matrix I have glFrustum while at the top of the modelview matrix I have gluLookAt followed by the scene.