1. gluLookAt矩阵
这次使用opengl es 2.0中,由于里面没有gluLookAt这个函数,参考了网上的一些代码自己封装了一个,经过使用,没发现问题,具体代码如下:
void ESUTIL_API
esGluLookAt(ESMatrix *result, float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ)
{
float fx, fy, fz;
float rlf, rls;
float sx, sy, sz;
float ux, uy, uz;
fx = centerX - eyeX;
fy = centerY - eyeY;
fz = centerZ - eyeZ;
// Normalize f
rlf = 1.0f / sqrt(fx * fx + fy * fy + fz * fz);
fx *= rlf;
fy *= rlf;
fz *= rlf;
// compute s = f x up (x means "cross product")
sx = fy * upZ - fz * upY;
sy = fz * upX - fx * upZ;
sz = fx * upY - fy * upX;
// and normalize s
rls = 1.0f / sqrt(sx * sx + sy * sy + sz * sz);
sx *= rls;
sy *= rls;
sz *= rls;
// compute u = s x f
ux = sy * fz - sz * fy;
uy &