Programming/openGL2019. 6. 1. 21:27

답답해서 뜯어보는중 ㅋㅋ

왜 이런 생각을 안했었지?

 

 

근데 본다고 이해할수 있는건 또 별개의 문제네 ㅋㅋㅋ

#define __glPi 3.14159265358979323846

 

void GLAPIENTRY

gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar)

{

GLdouble m[4][4];

double sine, cotangent, deltaZ;

double radians = fovy / 2 * __glPi / 180;

 

deltaZ = zFar - zNear;

sine = sin(radians);

if ((deltaZ == 0) || (sine == 0) || (aspect == 0)) {

    return;

}

cotangent = COS(radians) / sine;

 

__gluMakeIdentityd(&m[0][0]);

m[0][0] = cotangent / aspect;

m[1][1] = cotangent;

m[2][2] = -(zFar + zNear) / deltaZ;

m[2][3] = -1;

m[3][2] = -2 * zNear * zFar / deltaZ;

m[3][3] = 0;

glMultMatrixd(&m[0][0]);

}

 

void GLAPIENTRY

gluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx,

     GLdouble centery, GLdouble centerz, GLdouble upx, GLdouble upy,

     GLdouble upz)

{

float forward[3], side[3], up[3];

GLfloat m[4][4];

 

forward[0] = centerx - eyex;

forward[1] = centery - eyey;

forward[2] = centerz - eyez;

 

up[0] = upx;

up[1] = upy;

up[2] = upz;

 

normalize(forward);

 

/* Side = forward x up */

cross(forward, up, side);

normalize(side);

 

/* Recompute up as: up = side x forward */

cross(side, forward, up);

 

__gluMakeIdentityf(&m[0][0]);

m[0][0] = side[0];

m[1][0] = side[1];

m[2][0] = side[2];

 

m[0][1] = up[0];

m[1][1] = up[1];

m[2][1] = up[2];

 

m[0][2] = -forward[0];

m[1][2] = -forward[1];

m[2][2] = -forward[2];

 

glMultMatrixf(&m[0][0]);

glTranslated(-eyex, -eyey, -eyez);

}

'Programming > openGL' 카테고리의 다른 글

glEnable(), glPushAttrib()  (0) 2020.04.04
openGL superbible 3rd ed. 읽기 시작  (0) 2020.04.03
gl glx glu glut 소스코드  (0) 2019.05.31
glulookat / gluperspective / glfrustrum / glortho  (0) 2019.05.30
gl model view projection mat  (0) 2019.05.29
Posted by 구차니