I did post this question on StackOverflow (
http://stackoverflow.com/questions/25576762/warped-scene-with-two-sets-of-geodes
), but I assume that this is a more appropriate place for questions.
I have a few objects that I want to combine into a scene graph:
Street inherits from Geode and has a Geometry child drawable made up
of a GL_LINE_STRIP.
Pointer inherits from PositionAttitudeTransform and contains a Geode
which contains two Geometry polygons.
When I add a bunch of Streets to a Group, it looks just fine. When I
add only the Pointer to a Group, it also looks fine. But if I somehow
have them both in the scene, the second one is screwed up. (This does
not happen if I have only two Pointers.) I posted some screenshots on
the StackOverflow site, in case you want to see them. Probably I’m
making some simple mistake—but I can’t see it!
Here is some code that causes the problem (I tried to shorten it a little):
// My libraries:
#include <asl/util/draw.h>
#include <asl/util/color.h>
using namespace asl;
#include <straph/point.h>
#include <straph/straph.h>
using namespace straph;
// Standard and OSG libraries:
#include <utility>
#include <boost/tuple/tuple.hpp> // tie
using namespace std;
#include <osg/ref_ptr>
#include <osg/Array>
#include <osg/Geometry>
#include <osg/Group>
#include <osg/LineWidth>
using namespace osg;
#include <osgUtil/Optimizer>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
using namespace osgViewer;
Geode* createStreet(const straph::Polyline& path, double width, const
Color& color)
{
ref_ptr<Geometry> geom (new Geometry);
// Set the shape:
ref_ptr<Vec3dArray> array (new Vec3dArray(path.size()));
for (unsigned i = 0; i < path.size(); ++i) {
(*array)[i] = toVec3d(path[i]);
}
geom->setVertexArray(array.get());
geom->addPrimitiveSet(new osg::DrawArrays(GL_LINE_STRIP, 0, array->size()));
// Set the normals:
ref_ptr<Vec3Array> normals (new Vec3Array(1));
(*normals)[0].set( 0.0f, 0.0f, 1.0f );
geom->setNormalArray( normals.get() );
geom->setNormalBinding( Geometry::BIND_OVERALL );
// Set the colors:
ref_ptr<Vec4Array> colors = new Vec4Array();
colors->push_back(color.get());
geom->setColorArray(colors);
geom->setColorBinding(osg::Geometry::BIND_OVERALL);
Geode* g = new Geode();
g->addDrawable(geom.get());
// Set the line width.
ref_ptr<LineWidth> lwidth (new LineWidth);
lwidth->setWidth(width);
g->getOrCreateStateSet()->setAttributeAndModes(lwidth, StateAttribute::ON);
return g;
}
Group* load_streets()
{
unique_ptr<Straph> graph = read_shapefile("mexico/roads", 6);
Group* root = new Group();
boost::graph_traits<straph::Straph>::edge_iterator ei, ee;
for (boost::tie(ei, ee) = edges(*graph); ei != ee; ++ei) {
const straph::Segment& s = (*graph)[*ei];
root->addChild(createStreet(s.polyline, 2.0, TangoColor::Aluminium4));
}
return root;
}
int main(int, char**)
{
Group* root = load_streets();
Pointer* p = new Pointer(6.0, TangoColor::Scarlet3, TangoColor::Black);
root->addChild(p);
Viewer viewer;
viewer.setSceneData(root);
viewer.getCamera()->setClearColor(Color(TangoColor::White).get());
viewer.run();
}
Thanks for the help! :-)

–Ben Morgan
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org