Vec3d f(center-eye);
f.normalize();
Vec3d s(f^up);
s.normalize();
Vec3d u(s^f);
u.normalize();
set(
s[0], u[0], -f[0], 0.0,
s[1], u[1], -f[1], 0.0,
s[2], u[2], -f[2], 0.0,
0.0, 0.0, 0.0, 1.0);//旋转分量
preMultTranslate(-eye);//平移分量
//------可以从线性相关表示
E(x, y,z) = E(eye1, eye2, eye3) + (s, u, -f)(x1, y1, z1);
(x1, y1, z1)= (x - eye1, y - eye2, z - eye3) * (s, u, -f);
x1, y1,z1为某点在(s, u,-f)组成的右手观察坐标系下的坐标,x,y,z为某点在单位E下的坐标
受眼睛的位置影响,在第四行 osg::vec3d v = -eye;
mm[4][0] = v[0] * s[0] + v[1] * s[1] + v[2] * s[3];
mm[4][1] = v[0] * u[0] + v[1] * u[1] + v[2] * u[3];
mm[4][2] = v[0] * f[0] + v[1] * f[1] + v[2] * f[3];
void Matrix_implementation::getLookAt(Vec3f& eye,Vec3f& center,Vec3f& up,value_type lookDistance) const
{
Matrix_implementation inv;
inv.invert(*this);
eye = osg::Vec3f(0.0,0.0,0.0)*inv;
up = transform3x3(*this,osg::Vec3f(0.0,1.0,0.0));
center = transform3x3(*this,osg::Vec3f(0.0,0.0,-1));
center.normalize();
center = eye + center*lookDistance;
}