1
x, y 축을 만들고이 축의 내부에서 임의의 점을 랜덤하게 만드는 간단한 OSG 프로그램이 있습니다. 이것은 레이저 스캔 데이터에 대한 3D 뷰어를 만드는 데 그 의의가 있습니다. (나는 그것의 앞에 행해졌다는 것을 알고있다 그러나 우리는 최고 경량이기 위하여 그것을 필요로한다). 이 코드는 작동OSG에서 회전하면서 이미지가 사라짐
#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 뷰어에서 이미지를 회전하면 전체 이미지가 사라지는 문제가 있습니다. 때로는 시작한 곳으로 돌아가서 되돌릴 수 있지만 더 자주 영원히 사라집니다.
왜 이런 일이 발생했는지 알 수 있습니까?
저는 OSG에 익숙하지 않지만 그 스 니펫에서 회전 코드를 볼 수 없습니다. 당신이 추가 한 것을 가리킬 수 있습니까? 올바른 축을 중심으로 회전하고 있습니까? – Tim
이 코드는 마우스를 사용하여 이미지를 회전시키는 visuliser를 엽니 다. 각 프레임 사이에 무작위 지점을 추가 할 때 오류가 발생하기 시작합니다. –