float nearPlane = 0.05; // Our near rendering plane float screenAspect = 1.0; // Leave this for future fixes glMatrixMode(GL_PROJECTION); // We're going to modify the projection matrix glLoadIdentity(); // Clear it first // Set our frustum view matrix. glFrustum( nearPlane*(-0.5 * screenAspect + x)/z, nearPlane*(0.5 * screenAspect + x)/z, nearPlane*(-0.5 + y)/z, nearPlane*(0.5 + y)/z, nearPlane, 100.0); glMatrixMode(GL_MODELVIEW); // Switch back to model matrix // Move our scene so that it appears to actually be the screen matrixTranslate (&zTransform, x, y, 1 - z);
voidmatrixTranslate (CompTransform *transform, float x, float y, float z){ float *m = transform->m; m[12] = m[0] * x + m[4] * y + m[8] * z + m[12]; m[13] = m[1] * x + m[5] * y + m[9] * z + m[13]; m[14] = m[2] * x + m[6] * y + m[10] * z + m[14]; m[15] = m[3] * x + m[7] * y + m[11] * z + m[15];}
// Move our scene so that it appears to actually be the screen matrixTranslate (&zTransform, x, y, 1 - z);