GluPerspective와 Glu없이 동일한 작업을 수행하려면 어떻게해야합니까? 감사합니다GLUPerspective의 원시 OpenGL 동등한 제품?
예 : gluPerspective (45.0, (float) w, (float) h, 1.0, 200.0);
GluPerspective와 Glu없이 동일한 작업을 수행하려면 어떻게해야합니까? 감사합니다GLUPerspective의 원시 OpenGL 동등한 제품?
예 : gluPerspective (45.0, (float) w, (float) h, 1.0, 200.0);
void gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar)
{
GLdouble xmin, xmax, ymin, ymax;
ymax = zNear * tan(fovy * M_PI/360.0);
ymin = -ymax;
xmin = ymin * aspect;
xmax = ymax * aspect;
glFrustum(xmin, xmax, ymin, ymax, zNear, zFar);
}
gluPerspective
설명서에 설명되어 있습니다. 방금 변환 적절한의 4x4 변환 행렬을 구축하고 현재로 곱셈 glMultMatrix
을 사용
void myGluPerspective(double fovy, double aspect, double zNear, double zFar)
{
double f = 1.0/tan(fovy * M_PI/360); // convert degrees to radians and divide by 2
double xform[16] =
{
f/aspect, 0, 0, 0,
0, f, 0, 0,
0, 0, (zFar + zNear)/(zFar - zNear), -1,
0, 0, 2*zFar*zNear/(zFar - zNear), 0
};
glMultMatrixd(xform);
}
gluPerspective
설명서에 작성된 내용
각도를 라디안으로 변환하지 않으면 degToRad (deg) {return deg * M_PI/180.0; }이므로 첫 번째 줄은 360 대신 180이되어야합니다. – prewett
@prewett : 각도를 라디안으로 변환하는 것뿐만 아니라 2로 나눕니다. 'gluPerspective'문서에서는 f = cotangent (fovy/2)라는 식을 설명합니다. '; degrees-to-radians 변환을하면 fovy/2는 fovy * M_PI/360이됩니다. –
죄송합니다. 이제 귀하의 의견에 표시됩니다. Mac의 내 창은 너무 작아서 전체 설명을 볼 수 없으며 실제로 스크롤 할 때까지 바보 같은 Lion + 스크롤 막대가 표시되지 않으므로 라디안 부분이 지나간 것이 더 이상 보이지 않았습니다. 미안합니다. – prewett