例如,我的对象的中心是(1,2,-1)。我如何修改opengl es“相机”的中心(坐标系的中心)从(0,0,0)到(1,2,-1)
如果我没记错的话,gluLookAt 就是执行此操作的工具,但它不包含在 openGl es 1.1 中。有没有其他函数可以实现相同的功能
最佳答案
gluLookAt
只是将当前矩阵与根据输入创建的明确定义的矩阵相乘。 Its man page包含您需要的公式。
例如:
void mygluLookAt(GLfloat eyeX, GLfloat eyeY, GLfloat eyeZ, GLfloat centreX, GLfloat centreY, GLfloat centreZ, GLfloat upX, GLfloat upY, GLfloat upZ)
{
GLfloat f[3] =
{
centreX - eyeX,
centreY - eyeY,
centreZ - eyeZ,
};
// make f and the up vector have unit length
GLfloat lengthOfF = sqrtf(f[0]*f[0] + f[1]*f[1] + f[2]*f[2]);
f[0] /= lengthOfF;
f[1] /= lengthOfF;
f[2] /= lengthOfF;
GLfloat lengthOfUp = sqrtf(upX*upX + upY*upY + upZ*upZ);
upX /= lengthOfUp;
upY /= lengthOfUp;
upZ /= lengthOfUp;
// use the cross product of f and Up to get s,
// and the cross product of s and f to get u
GLfloat s[3] =
{
f[1]*upZ - upY*f[2],
f[2]*upX - upZ*f[0],
f[0]*upY - upX*f[1]
};
GLfloat u[3] =
{
s[1]*f[2] - f[1]*s[2],
s[2]*f[0] - f[2]*s[0],
s[0]*f[1] - f[0]*s[1]
};
// Fill the matrix as prescribed.
// Note: OpenGL is "column major"
GLfloat M[16] =
{
s[0], u[0], -f[0], 0.0f,
s[1], u[1], -f[1], 0.0f,
s[2], u[2], -f[2], 0.0f,
0.0f, 0.0f, 0.0f, 1.0f
};
glMultMatrixf(M);
glTranslatef(-eyeX, -eyeY, -eyeZ);
}
这是从手册页直接输入的。因此它尚未经过测试,但如果我犯了任何错误,应该很容易发现。
关于Iphone OpenGl ES 1.1 : How to modify the camera center from (0, 0,0) 到 (x,y,z)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7426823/