Hi,
I started to work with OSG last week and I have some issues. For my project, I
need to navigate in a scene and select three types of objects : points, lines
and surfaces. I created 3 class : surface, point and line with this kind of
tree:
Surface
/ \
Line Line ...
/ \ / \
Point Point Point ...
The points also have references to its different parents (lines and segments)
to make the update of the shapes easier after the modification of a point.
Points can be shared by several lines ans surfaces and lines can also be shared
by several surfaces.
These three class inherit from Group and have a Geode and a geometry (a
polygon, a line or a point).
To navigate in the scene, I made my own manipulator. It works well with
translations, but I have some issues with rotations. Basically, it is very
similar to the orbit manipulator (same way to handle events) except that I do
not compute the position from the distance and the center of the sphere (I set
the position and simply update the position). Moreover I had the same problem
with the orbit manipulator so I don't think it might come from here.
The problem is that when I rotate, the camera is not really "stable". It's
shaking. If I'm far enough or if I go fast enough, I don't notice it. And I
can't figure out where it comes from. Here is the setup of my camera :
Code:
osg::DisplaySettings* ds = osg::DisplaySettings::instance().get();
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new
osg::GraphicsContext::Traits;
traits->windowName = "";
traits->windowDecoration = false;
traits->x = 100;
traits->y = 100;
traits->width = 100;
traits->height = 100;
traits->doubleBuffer = true;
traits->alpha = ds->getMinimumNumAlphaBits();
traits->stencil = ds->getMinimumNumStencilBits();
traits->sampleBuffers = ds->getMultiSamples();
traits->samples = ds->getNumMultiSamples();
setGraphicsContext( new osgQt::GraphicsWindowQt(traits.get()) );
setClearColor( osg::Vec4(0.2, 0.2, 0.6, 1.0) );
setViewport( new osg::Viewport(0, 0, traits->width, traits->height) );
//setProjectionMatrixAsOrtho(-static_cast<double>(traits->width)/2.0,
static_cast<double>(traits->width)/2.0,
-static_cast<double>(traits->height)/2.0,
static_cast<double>(traits->height)/2.0, 1.0f, 10000.0f);
setProjectionMatrixAsPerspective(30.0f,
static_cast<double>(traits->width)/static_cast<double>(traits->height), 1.0f,
10000.0f );
I have the same problem with the orthographic mode.
And here is My Qt widget :
Code:
SRE_OSGWidget::SRE_OSGWidget(QWidget* parent, SRE_Manipulator* m) :
QWidget(parent) {
manipulator= m;
viewer = new osgViewer::Viewer;
viewer->setThreadingModel(osgViewer::Viewer::ThreadPerCamera);
osg::ref_ptr<SRE_Camera> camera = SRE::get()->getScene()->getCamera();
osg::ref_ptr<osg::Group> root = SRE::get()->getScene()->getRoot();
viewer->setCamera(camera.get());
viewer->setSceneData(root.get());
viewer->setCameraManipulator(manipulator.get());
osgQt::GraphicsWindowQt* gw = dynamic_cast<osgQt::GraphicsWindowQt*>(
camera->getGraphicsContext() );
if(gw==NULL){
//TODO print error
exit(1);
}
QWidget* viewWidget = gw->getGLWidget();
QVBoxLayout* layout = new QVBoxLayout(this);
layout->addWidget(viewWidget);
connect( &timer, SIGNAL(timeout()), this, SLOT(update()) );
timer.start(10);
}
void SRE_OSGWidget::paintEvent(QPaintEvent* e){
viewer->frame();
}
Does anyone has any idea where it could come from?
If you need more info or code, tell me.
The following image illustrates my two other problems:
The first one is the one in the red circle. I would like to make the point
appear in front of the lines (and the lines in front of the polygon) when they
have the same coordinates but I don't know how to do it. For example, in the
image, we can see that the lines are over the point even though the coordinates
used to define the lines are the same as the one used for the point.
Is ther a state or a mode that would enable me to do it ?
And finally, the last problem is about the selection of objects. When I click
on a point or a line, it doesn't work. And sometimes, for some position of the
cursor, when I click on a polygon it doesn't work either (for example at the
position of the cursor in the image). Most of the time, I can correctly select
surfaces, but sometimes, the ray seems not to hit the first surface (but it can
hit the one behind). Here is the code that I used :
Code:
bool SRE_Controller::handleMousePush(const osgGA::GUIEventAdapter& ea,
osgGA::GUIActionAdapter& us){
addMouseEvent(ea);
unsigned int buttonMask = ea.getButtonMask();
if(buttonMask == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON){
osg::ref_ptr<osgUtil::LineSegmentIntersector> ray = new
osgUtil::LineSegmentIntersector(osgUtil::Intersector::PROJECTION,
ea.getXnormalized(), ea.getYnormalized());
osgUtil::IntersectionVisitor visitor(ray);
camera->accept(visitor);
if (ray->containsIntersections())
{
osgUtil::LineSegmentIntersector::Intersection
intersection = ray->getFirstIntersection();
(dynamic_cast<SRE_Component*>(intersection.nodePath.at(intersection.nodePath.size()-2)))->setColor(SELECTION_COLOR);
}
}
return false;
}
Sorry if my post is a little long but I really need help.
Thank you!
bob
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=47578#47578
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org