|
本帖最后由 CWorld 于 2012-2-10 09:46 编辑
众所周知,osgautoCapture的例子是截屏例子,其中在指定了相机的 位置(经度lon,纬度lat、高度alt)
角度(heading,incline,roll)以后,有一段代码计算目标Target的位置和上方向,我想请教这段代码是如何根据位置和角度计算的目标Target的位置:
这段代码类似于gluLookAt(),其中对于eye的位置还可以理解,但是如何计算切线和目标的位置,请大家帮忙看看。- osg::Vec3d eye;
- csn->getEllipsoidModel()->convertLatLongHeightToXYZ(lat, lon, alt, eye.x(), eye.y(), eye.z());
- // Build matrix for computing target vector
- osg::Matrixd target_matrix = osg::Matrixd::rotate(-heading, osg::Vec3d(1,0,0),
- -lat, osg::Vec3d(0,1,0),
- lon, osg::Vec3d(0,0,1));
-
- // Compute tangent vector ...
- osg::Vec3d tangent = target_matrix.preMult(osg::Vec3d(0, 0, 1));
-
- // Compute non-inclined, non-rolled up vector ...
- osg::Vec3d up(eye);
- up.normalize();
-
- // Incline by rotating the target- and up vector around the tangent/up-vector
-
- // cross-product ...
- osg::Vec3d up_cross_tangent = up ^ tangent;
-
- osg::Matrixd incline_matrix = osg::Matrixd::rotate(incline, up_cross_tangent);
-
- osg::Vec3d target = incline_matrix.preMult(tangent);
-
- // Roll by rotating the up vector around the target vector ...
- osg::Matrixd roll_matrix = incline_matrix * osg::Matrixd::rotate(roll, target);
- up = roll_matrix.preMult(up);
-
- viewer.getCamera()->setViewMatrixAsLookAt(eye, eye+target, up);
复制代码 |
|