#include <osg/Node>
#include <osg/Shape>
#include <osgViewer/Viewer>
#include <osg/ShapeDrawable>
#pragma comment(lib,"osgd.lib")
#pragma comment(lib,"osgViewerd.lib")
class MaskCallBack :public osg::NodeCallback
{
public:
MaskCallBack(osg::Node* node) :m_mask(0), m_node(node), m_tick(0){}
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
{
if (m_tick < 1000)
{
m_tick++;
return;
}
else
{
m_tick = 0;
}
if (m_node)
m_node->setNodeMask(m_mask);
if (node)
node->setNodeMask(m_mask = ~m_mask);
}
protected:
~MaskCallBack(){}
unsigned int m_mask;
osg::ref_ptr<osg::Node> m_node;
unsigned int m_tick;
};
int main(int *argc, char *argv[])
{
osgViewer::Viewer viewer;
osg::ref_ptr<osg::Group> group = new osg::Group;
osg::ref_ptr<osg::Geode> node1 = new osg::Geode;
osg::ref_ptr<osg::ShapeDrawable> shape1 = new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(100, 0, 0), 20.0));
shape1->setColor(osg::Vec4(1, 0, 0, 1));
node1->addDrawable(shape1.get());
osg::ref_ptr<osg::Geode> node2 = new osg::Geode;
osg::ref_ptr<osg::ShapeDrawable> shape2 = new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(-100, 0, 0), 20.0));
shape2->setColor(osg::Vec4(0, 1, 0, 1));
node2->addDrawable(shape2.get());
//node1->setNodeMask(0x0);
node1->setUpdateCallback(new MaskCallBack(node2));
node2->setUpdateCallback(new MaskCallBack(node1));
group->addChild(node1.get());
group->addChild(node2.get());
viewer.setSceneData(group.get());
viewer.realize();
viewer.run();
}
osg节点轮流显示,隐藏和显示
4星 · 超过85%的资源 需积分: 49 166 浏览量
2017-04-15
12:15:02
上传
评论 1
收藏 7.73MB ZIP 举报
GreenArrowMan
- 粉丝: 1w+
- 资源: 48
最新资源
- 老飞飞搭建基础通用数据库V19数据库.rar
- jquery.js
- 机械设计多工位ACF贴胶带&预压设备sw18可编辑非常好的设计图纸100%好用.zip
- 基于Pytorch复现Point-Transformer,用于ShapeNet数据集点云分割
- 【医学影像分析】2D超声图像的分割检测(Ultrasound Nerve Segmentation - Kaggle数据集)
- 嘎嘎香的五款神仙谷歌插件
- .arch书源导入教程.mp4
- 贪心算法介绍及代码示例讲解
- CR13SP35MSI64 Crystal 水晶报表运行组件最后版本64位
- 图像分类数据集:玉米叶是否感染分类数据集(2分类,包含训练集、验证集)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈