osgViewer.Keystone是OpenSceneGraph中的一个模块,用于网格扭曲或去畸变。它允许用户在可视化处理阶段对场景进行网格扭曲,从而使场景呈现出更真实的效果。
osgViewer.Keystone是OpenSceneGraph的一部分,因此它已经包含在OpenSceneGraph中,您无需单独安装它。
#include <osgViewer/Viewer>
#include <osgViewer/Keystone>
int main(int argc, char** argv)
{
osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer();
//创建Keystone
osg::ref_ptr<osgViewer::Keystone> keystone = new osgViewer::Keystone();
viewer->setCameraManipulator(keystone); //添加Keystone作为CameraManipulator
return viewer->run();
}
Keystone可以通过设置以下属性来配置:
setTopLeft()
:设置左上角网格控件(四个角点)的位置。setTopRight()
:设置右上角网格控件(四个角点)的位置。setBottomRight()
:设置右下角网格控件(四个角点)的位置。setBottomLeft()
:设置左下角网格控件(四个角点)的位置。#include <osgViewer/Viewer>
#include <osgViewer/Keystone>
int main(int argc, char** argv)
{
osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer();
//创建Keystone
osg::ref_ptr<osgViewer::Keystone> keystone = new osgViewer::Keystone();
//设置位置
keystone->setTopLeft(osg::Vec2(0.f, 0.f));
keystone->setTopRight(osg::Vec2(1.f, 0.f));
keystone->setBottomRight(osg::Vec2(1.f, 1.f));
keystone->setBottomLeft(osg::Vec2(0.f, 1.f));
viewer->setCameraManipulator(keystone); //添加Keystone作为CameraManipulator
return viewer->run();
}
#include <osgViewer/Viewer>
#include <osgViewer/Keystone>
int main(int argc, char** argv)
{
osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer();
//创建Keystone
osg::ref_ptr<osgViewer::Keystone> keystone = new osgViewer::Keystone();
//设置位置
keystone->setTopLeft(osg::Vec2(0.f, 0.f));
keystone->setTopRight(osg::Vec2(1.f, 0.f));
keystone->setBottomRight(osg::Vec2(1.f, 1.f));
keystone->setBottomLeft(osg::Vec2(0.f, 1.f));
viewer->setCameraManipulator(keystone); //添加Keystone作为CameraManipulator
// 进行网格扭曲
keystone->setUndistortionMode(osgViewer::Keystone::QUAD_MESH);
return viewer->run();
}