OpenGL ES는 glLookAt() 함수가 없죠.. 때문에 불편해 하시는 분들이 많은데요,
사실 OpenGL에서 사용하는 여러가지 함수들을 ES 환경에서 구현하는 것은
크게 어렵지 않습니다.
다음은 es에서 사용할 lookAtf() 함수의 구현입니다.
GLvoid lookAtf(GLfloat eyeX, GLfloat eyeY, GLfloat eyeZ, GLfloat centerX, GLfloat centerY, GLfloat centerZ, GLfloat upX, GLfloat upY, GLfloat upZ )
...{
GLfloat forward[3], side[3], up[3];
GLfloat matrix[16];
forward[0] = centerX - eyeX;
forward[1] = centerY - eyeY;
forward[2] = centerZ - eyeZ;
VectorMathf::normalizef(forward);
up[0] = upX;
up[1] = upY;
up[2] = upZ;
VectorMathf::crossProductf(side, forward, up);
VectorMathf::normalizef(side);
VectorMathf::crossProductf(up, side, forward);
matrix[0] = side[0];
matrix[1] = up[0];
matrix[2] = -forward[0];
matrix[3] = 0.0f;
matrix[4] = side[1];
matrix[5] = up[1];
matrix[6] = -forward[1];
matrix[7] = 0.0f;
matrix[8] = side[2];
matrix[9] = up[2];
matrix[10] = -forward[2];
matrix[11] = 0.0f;
matrix[12] = 0.0f;
matrix[13] = 0.0f;
matrix[14] = 0.0f;
matrix[15] = 1.0f;
glMultMatrixf(matrix);
glTranslatef(-eyeX, -eyeY, -eyeZ);
}
//eyex, eyey, eyez (눈의 위치), centerx, centery, centerz(주시하고 있는 카메라의 주시점), upx, upy, upz (UPVECTOR)
* VectorMathf 는
- Class which supports the basic vector math operations.
입니다.
'OpenGL ES' 카테고리의 다른 글
[Tutorials] EGL & OpenGL ES 2.0 초기화 / 삼각형 그리기 (4) | 2010.11.11 |
---|---|
OpenGL ES 2.0 Emulator 개발 환경 구성 (0) | 2010.11.11 |
OpenGL ES 2.0 Reference Page (0) | 2010.10.15 |
[PPT] OpenGL ES Intro (0) | 2010.10.13 |