图像在OSG中随着旋转而消失
Image is disappearing with rotation in OSG
我有一个简单的OSG程序,它制作一个x,y轴并随机化该轴内的点。目的是,这将导致为激光扫描数据制作3D查看器。(我知道它以前做过,但我们需要它超轻量级)。这是代码:
#include <osg/Node>
#include <osg/Group>
#include <osg/Geode>
#include <osg/Geometry>
#include <osg/Texture2D>
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <osg/PositionAttitudeTransform>
#include <osgGA/TrackballManipulator>
#include <time.h>
#include <cstdlib>
void addAxis(osg::ref_ptr<osg::Group> root) {
//ADD Y-Axis
osg::ref_ptr<osg::Geode> lineGeode = new osg::Geode();
osg::ref_ptr<osg::Geometry> yAxis = new osg::Geometry(), xAxis = new osg::Geometry();
lineGeode->addDrawable(yAxis);
lineGeode->addDrawable(xAxis);
root->addChild(lineGeode);
osg::ref_ptr<osg::Vec3Array> lineVertices = new osg::Vec3Array;
lineVertices->push_back( osg::Vec3( 0, 0, 0) );
lineVertices->push_back( osg::Vec3(0, 10, 0) );
yAxis->setVertexArray( lineVertices );
osg::ref_ptr<osg::DrawElementsUInt> lineBase =
new osg::DrawElementsUInt(osg::PrimitiveSet::LINES, 0);
lineBase->push_back(1);
lineBase->push_back(0);
yAxis->addPrimitiveSet(lineBase);
osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
colors->push_back(osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f) ); //index 0 red
yAxis->setColorArray(colors);
yAxis->setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE);
//ADD X Axis
lineVertices = new osg::Vec3Array;
lineVertices->push_back( osg::Vec3( 0, 0, 0) );
lineVertices->push_back( osg::Vec3(10, 0, 0) );
xAxis->setVertexArray( lineVertices );
lineBase =
new osg::DrawElementsUInt(osg::PrimitiveSet::LINES, 0);
lineBase->push_back(1);
lineBase->push_back(0);
xAxis->addPrimitiveSet(lineBase);
colors = new osg::Vec4Array;
colors->push_back(osg::Vec4(0.0f, 0.0f, 0.0f, 1.0f) ); //index 0 red
xAxis->setColorArray(colors);
xAxis->setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE);
}
void addPoint(osg::ref_ptr<osg::Group> root, std::vector<double> pointIn) {
osg::ref_ptr<osg::Geode> pointGeode = new osg::Geode();
osg::ref_ptr<osg::Geometry> pointGeometry = new osg::Geometry();
pointGeode->addDrawable(pointGeometry);
root->addChild(pointGeode);
osg::ref_ptr<osg::Vec3Array> point = new osg::Vec3Array;
point->push_back( osg::Vec3( pointIn[0], pointIn[1], pointIn[2]) );
pointGeometry->setVertexArray( point );
osg::ref_ptr<osg::DrawElementsUInt> points =
new osg::DrawElementsUInt(osg::PrimitiveSet::POINTS, 0);
points->push_back(0);
points->push_back(2);
points->push_back(1);
pointGeometry->addPrimitiveSet(points);
osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
colors->push_back(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f) );
pointGeometry->setColorArray(colors);
pointGeometry->setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE);
}
int main()
{
osgViewer::Viewer viewer;
osg::ref_ptr<osg::Group> root = new osg::Group();
addAxis(root);
std::vector<double> point;
for (int i = 0; i < 3; i++)
point.push_back(0);
srand(time(NULL));
root->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
viewer.setSceneData( root );
viewer.setCameraManipulator(new osgGA::TrackballManipulator());
viewer.realize();
int count = 0;
while( !viewer.done() )
{
if (count == 200) {
point[0] = (double)rand()*10.0/(double)INT_MAX;
point[1] = (double)rand()*10.0/(double)INT_MAX;
count = 0;
}
count++;
addPoint(root, point);
viewer.frame();
}
return 0;
}
此代码有效,它将生成一个 10 个单位长的 x/y 轴,并开始在该轴内生成随机点。但是,问题是当我在OSG查看器中旋转图像时,整个图像通常会消失。有时它可以通过旋转回到你开始的地方来恢复,但更多的时候它会永远消失。
有没有人知道为什么会发生这种情况?
我想
通了,在这种情况下的原因是点更新太快了。这导致可视化工具在渲染图像时非常困难,因为点正在快速进入。
相关文章:
- 与互斥锁相比,旋转锁可以保证上下文切换
- 将地址分配给本地指针后,公共对象的变量将消失
- 绘制旋转的三角形
- 旋转模型矩阵时的形状失真
- 四边形的 2D 旋转
- 垂直方向的 Gtk3+ 旋转按钮 (c/c++)
- 发布旋转矩阵(openGL/glm)
- 顺时针迭代旋转 3 位数字
- 形状对象的旋转和缩放不正确C++
- 如何在 OpenSceneGraph 中缩放/旋转/移动资产
- 应用投影矩阵后对象消失
- 如何有效地计算将单位立方体映射到自身的反射和旋转?
- 子轴围绕父轴而不是他自己的轴旋转
- 将使用太多的纹理插值器 - 带旋转的着色器
- 添加自定义析构函数时,Move 构造函数在派生类中消失
- SFML 向下移动时如何围绕屏幕中心旋转?
- 如何在OpenGL中正确旋转和缩放对象?
- 图像在OSG中随着旋转而消失
- 创建二叉搜索树类,一个节点在旋转后消失
- QT QSvgRenderer旋转文本消失