I apologize in advance if this ends up in the wrong thread. The thread I
am responding to is here:
http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/2007-November/004074.html
Thanks for the pointers on the shaders. As far as the other issue, I am
somewhat at a loss for what to post, because my OSG calls here are pretty
basic. What puzzles me is that the issue can be resolved if I stop
inserting data into the scene graph (either the points or the transform
updates). I have checked my values and they seem fine.
Here is the code that adds the points:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
int OSGScene::addRawPointCloud(
const std::vector<nrec::geometry::Point3D_d >& points,
const std::vector<nrec::geometry::Point3D_d >& colors)
{
boost::mutex::scoped_lock lock(mutex());
//Check vector sizes.
if(colors.size() != 1 && points.size() != colors.size())
{
//Invalid vector sizes.
throw std::runtime_error(
"Attempt to add point cloud with invalid vector lengths to OSGScene.");
//::: change to sacr error type
}
int id = getUniqueId();
//Scene graph component definition.
osg::ref_ptr<osg::Group> newPointCloudGroup = new osg::Group();
osg::ref_ptr<osg::Geode> newPointCloudGeode = new osg::Geode();
osg::ref_ptr<osg::Geometry> newPointCloudGeometry = new osg::Geometry();
osg::ref_ptr<osg::Vec3Array> newPointData = new osg::Vec3Array();
osg::ref_ptr<osg::Vec4Array> newColorData = new osg::Vec4Array();
//Fill osg vector types with necessary data.
std::vector<nrec::geometry::Point3D_d >::const_iterator colorIterator =
colors.begin();
std::vector<nrec::geometry::Point3D_d >::const_iterator pointIterator =
points.begin();
int colored = 0;
for(; pointIterator != points.end(); pointIterator++)
{
newPointData->push_back(osg::Vec3(
pointIterator->x(),
pointIterator->y(),
pointIterator->z()));
if(!colored || colors.size() > 1)
{
newColorData->push_back(osg::Vec4(
colorIterator->x(),
colorIterator->y(),
colorIterator->z(),
1));
colorIterator++;
colored = 1;
}
}
osg::Geometry::AttributeBinding binding = osg::Geometry::BIND_PER_VERTEX;
if(colors.size() == 1)
{
binding = osg::Geometry::BIND_OVERALL;
}
//Set up point cloud.
newPointCloudGeometry->setVertexArray(newPointData.get());
newPointCloudGeometry->setColorArray(newColorData.get());
newPointCloudGeometry->setColorBinding(binding);
newPointCloudGeometry->addPrimitiveSet(
new osg::DrawArrays(osg::PrimitiveSet::POINTS, 0, points.size()));
//Set up scene graph structure.
newPointCloudGeode->addDrawable(newPointCloudGeometry.get());
newPointCloudGroup->addChild(newPointCloudGeode.get());
//Point display settings.
newPointCloudGroup->getOrCreateStateSet()->setTextureAttributeAndModes(
0, new osg::PointSprite(), osg::StateAttribute::ON);
osg::ref_ptr<osg::Point> point = new osg::Point();
point->setSize(RAW_POINT_DISPLAY_SIZE);
newPointCloudGroup->getOrCreateStateSet()->setAttribute(point.get());
//Add to scene graph.
m_rawPointsNode->addChild(newPointCloudGroup.get());
return id;
}
And here is the code that updates the transform:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void OSGVehicleDisplay::updatePose(const sacr::Pose& newPose)
{
m_vehicleTransform->setPosition(
osg::Vec3d(newPose.x(), newPose.y(), newPose.z()));
m_vehicleTransform->setAttitude(osg::Quat(
newPose.rotZ(), osg::Vec3d(0,0,1),
newPose.rotY(), osg::Vec3d(0,1,0),
newPose.rotX(), osg::Vec3d(1,0,0)));
}
If I comment out the setPosition call in the transform update or I do not
insert the point geode into the scene graph (or leave it empty) everything
else works fine. If I don't, then nothing renders at all.
Debug output indicates that my values are valid. Is it possible to
overload OSG with insertions?
-Nicholas
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org