|
下面这段代码无法修改相机的视点:
osgViewer::Viewer* OSGViewer = p3DRenderEngine->getViewer();
osg::Node* sceneData = OSGViewer->getSceneData();
osg::Group* root = dynamic_cast<osg::Group*>(sceneData);
osg::Node* scene = root->getNumChildren() > 0 ? root->getChild(0) : nullptr;
osg::ComputeBoundsVisitor boundVisitor;
scene->accept(boundVisitor);
osg::BoundingBox bb = boundVisitor.getBoundingBox();
osg::Vec3d center = bb.center();
double distance = bb.radius() * 2;
osg::Vec3d target = osg::Vec3(center.x(), center.y(), 0);
osg::Vec3d eye = target + osg::Vec3(0, 0, distance);
osg::Vec3d up = osg::Vec3(0, 0, 1);
OSGViewer->getCamera()->setViewMatrixAsLookAt(eye, target, up);
OSGViewer->getCamera()->setProjectionMatrixAsOrtho(-distance, distance, -distance, distance, 1, 100);
下面这段代码可以:
osg::Node* sceneData = OSGViewer->getSceneData();
osg::Group* root = dynamic_cast<osg::Group*>(sceneData);
osg::Node* scene = root->getNumChildren() > 0 ? root->getChild(0) : nullptr;
osg::ComputeBoundsVisitor boundVisitor;
scene->accept(boundVisitor);
osg::BoundingBox bb = boundVisitor.getBoundingBox();
osg::Vec3d center = bb.center();
double distance = bb.radius() * 2;
osg::Matrixd matrix;
matrix.makeRotate(osg:uat(osg:I_2, osg::Vec3d(0, 0, 1)));
matrix.preMultTranslate(osg::Vec3d(0, 0, distance));
matrix.preMultScale(osg::Vec3d(1, 1, 1));
OSGViewer->getCameraManipulator()->setByMatrix(matrix);
osg::Matrixd projMatrix;
projMatrix = osg::Matrixd:rtho2D(-distance, distance, -distance, distance);
OSGViewer->getCamera()->setProjectionMatrix(projMatrix);
上面两端代码主要是为了实现俯视图的效果,但是仅仅通过相机来设置结果是不正确的,只有投影的效果,不管怎么该eye,target都没有作用!请教一下哪位大佬可以解答一下? |
|