// This creates a symmetric frustum.// It converts to 6 params (l, r, b, t, n, f) for glFrustum()// from given 4 params (fovy, aspect, near, far)
void makeFrustum(double fovY, double aspectRatio, double front, double back)
{
const double DEG2RAD = 3.14159265 / 180;
double tangent = tan(fovY/2 * DEG2RAD); // tangent of half fovY
double height = front * tangent;// half height of near plane
double width = height * aspectRatio;// half width of near plane// params: left, right, bottom, top, near, far
glFrustum(-width, width, -height, height, front, back);
}
再贴
///// set a perspective frustum with 6 params similar to glFrustum()// (left, right, bottom, top, near, far)// Note: this is for row-major notation. OpenGL needs transpose it///
void ModelGL::setFrustum(float l, float r, float b, float t, float n, float f)
{
matrixProjection.identity();
matrixProjection[0] = 2 * n / (r - l);
matrixProjection[2] = (r + l) / (r - l);
matrixProjection[5] = 2 * n / (t - b);
matrixProjection[6] = (t + b) / (t - b);
matrixProjection[10] = -(f + n) / (f - n);
matrixProjection[11] = -(2 * f * n) / (f - n);
matrixProjection[14] = -1;
matrixProjection[15] = 0;
}
///// set a orthographic frustum with 6 params similar to glOrtho()// (left, right, bottom, top, near, far)// Note: this is for row-major notation. OpenGL needs transpose it///
void ModelGL::setOrthoFrustum(float l, float r, float b, float t, float n,float f)
{
matrixProjection.identity();
matrixProjection[0] = 2 / (r - l);
matrixProjection[3] = -(r + l) / (r - l);
matrixProjection[5] = 2 / (t - b);
matrixProjection[7] = -(t + b) / (t - b);
matrixProjection[10] = -2 / (f - n);
matrixProjection[11] = -(f + n) / (f - n);}...// pass projection matrx to OpenGL before draw
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(matrixProjection.getTranspose());...