问题描述
我需要实现旋转相机的四元数.在实施四元数之前,我使用LookAt(& eye,& at,& up)表示摄像机坐标(vpn,vup等).
I need to implement a quaternion for rotating a camera. Before implementing quaternion, I use LookAt(&eye, &at, &up) for expressing a camera coordinate (vpn, vup, ...).
vec3 eye = vec3(0.0,0.0,-10.0);
vec3 to = vec3(0.0,0.0,0.0); // initial
vec3 up = vec3(0.0,1.0,0.0);
vec3 d = to - eye;
和显示回调.
m = LookAt(eye,to,up);
glUniformMatrix4fv(ModelView,1,GL_TRUE,m);
并添加一个旋转(仍然是欧几里德旋转和键盘交互)
and Add an rotation (it is still euclidean rotation, and keyboard interation)
case 'a':
temp = RotateX(1.0) * vec4(d,0);
temp1 = RotateX(1.0) * vec4(up,0);
d = vec3(temp.x, temp.y, temp.z);
up = vec3(temp1.x, temp1.y, temp1.z);
eye = to - d;
break;
case 'd':
temp = RotateY(1.0) * vec4(d,0);
temp1 = RotateY(1.0) * vec4(up,0);
d = vec3(temp.x, temp.y, temp.z);
up = vec3(temp1.x, temp1.y, temp1.z);
eye = to - d;
break;
所以我的问题是,LookAt函数仅使相机坐标化?是否有任何旋转矩阵可以使相机坐标?如您所见,我通过不在LookAt中使用某些旋转来旋转相机,我将通过使用四元数来旋转该相机.但是LookAt()使用一些旋转,我将实现LookAt的四元数版本以避免万向节锁定
So my question is, LookAt function is only making camera coordinate? Is there any rotation matrix to make camera coordinate? As you see I make rotate my camera by using some rotation not in LookAt, I will this rotation by using quaternion. However LookAt() uses some rotation, I will implement quaternion version of LookAt to avoid gimbal lock
推荐答案
LookAt所做的全部是平移T(这样新的原点在点眼处)后跟旋转R.旋转是通过构建一个3个向量的正交基准(由从眼睛到中心的向量定义的方向,直接指定的向上向量以及定义为垂直于两个向量的右向量). LookAt产生的最终transm是R * T.
All what LookAt does is a translation T (so that the new origin is at the point eye) followed by a rotation R. The rotation is defined by building an orthonormal basis from the 3 vectors (direction defined by the vector from eye to center, the up vector directly specified, and the right vector which is defined to be perpendicular to both). The final transorm produced by LookAt would be R*T.
如果正确指定输入向量,则可以使用LookAt进行万向节锁定,不会出现任何万向节锁定问题,但是您也可以通过位置向量(定义T)和方向四元数(定义R)来描述相机,而不必使用完全是LookAt.
You can use LookAt without any gimbal lock problems if you specify your input vectors correctly, but you can also describe your camera by a position vector (defining T) and orientation quaternion (defining R), and wouldn't have to use LookAt at all.
这篇关于关于LookAt()函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!