Re: [osg-users] Manipulator and selection

2012-05-14 Thread Bob Slobodan
Thank you for the answers.

I tried many different things with the depth test with different values for the 
far and near planes and different test function (LESS, LEQUAL, ...) but I 
couldn't get it to work. I finally decided to use the polygonOffset for the 
filled polygon and now at least I have the point and lines that always appear 
on top of surfaces.

So now I only have to figure out a way to solve this Point/Line z-fighting 
problem. Does anyone have a clue ?

Thank's again,
Bob

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=47667#47667





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Manipulator and selection

2012-05-10 Thread Bob Slobodan
Hi,

First of all, thank you for your answer. I took a look at osgscribe and I tried 
to do the same thing, but it doesn't really work. I tried many things but this 
is my last attempt:


Code:
geode = new osg::Geode;
geometry = new osg::Geometry;

osg::ref_ptrosg::Vec3Array v = new osg::Vec3Array;
geometry-setVertexArray(v.get());
v-push_back(vertex1-getPosition());
v-push_back(vertex2-getPosition());

setColor(SEGMENT_COLOR);
geometry-addPrimitiveSet(new 
osg::DrawArrays(osg::PrimitiveSet::LINES,0,v-size()));

geode-addDrawable(geometry.get());
addChild(geode.get());

//osg::StateSet* ss = getOrCreateStateSet();
osg::StateSet* stateset = new osg::StateSet;
osg::PolygonOffset* polyoffset = new osg::PolygonOffset;
polyoffset-setFactor(-1.0f);
polyoffset-setUnits(-1.0f);
osg::PolygonMode* polymode = new osg::PolygonMode;
polymode-setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::LINE);
stateset-setAttributeAndModes(polyoffset,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
stateset-setAttributeAndModes(polymode,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);

osg::ref_ptrosg::LineWidth line = new osg::LineWidth;
line-setWidth(SEGMENT_SIZE);
stateset-setAttribute(line.get()); 
stateset-setMode( GL_LIGHTING, osg::StateAttribute::OFF );

setStateSet(stateset);



This is part of my class Line that inherits from Group. But despite all that, I 
still have the same problem, some lines are still hidden by surfaces, and I'm 
unable to select some other lines.
What am I doing wrong ?


I also have another question for the manipulator. I want to enable the user to 
switch from a perspective view to an orthographic view. Everything works fine, 
but at some point, I need to force the computation of the new clipping planes. 
I can't wait for the auto computation and I'm not sure of how to do that.

After some researches I found out that the cull visitor would be perfect for 
that, but how can I attach a cull visitor to the camera ? I read in the FAQ 
that the Camera was a subclass of cullVisiotr, but it doesn't seem to wright. 
Does anyone have a clue?

Thanks again,
bob.

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=47637#47637





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Manipulator and selection

2012-05-10 Thread Jason Daly

On 05/10/2012 07:21 AM, Bob Slobodan wrote:

Hi,

First of all, thank you for your answer. I took a look at osgscribe and I tried 
to do the same thing, but it doesn't really work. I tried many things but this 
is my last attempt:


You may need to tweak the factor and units numbers for your particular 
application.  Here's a link that might help you understand what they're 
trying to do:


http://www.opengl.org/archives/resources/faq/technical/polygonoffset.htm



I also have another question for the manipulator. I want to enable the user to 
switch from a perspective view to an orthographic view. Everything works fine, 
but at some point, I need to force the computation of the new clipping planes. 
I can't wait for the auto computation and I'm not sure of how to do that.

After some researches I found out that the cull visitor would be perfect for 
that, but how can I attach a cull visitor to the camera ? I read in the FAQ 
that the Camera was a subclass of cullVisiotr, but it doesn't seem to wright. 
Does anyone have a clue?


osg::Camera inherits from CullSettings, not CullVisitor.  CullVisitor 
also inherits from CullSettings (via CullStack), so they're related, but 
neither is a direct ancestor or descendant of the other.


If you can't wait for the Viewer to adjust the clipping planes for you, 
another possibility is just to use a fixed set of clipping planes (one 
for perspective and one for ortho), and set the Camera to not compute 
the planes automatically.


--J
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Manipulator and selection

2012-05-10 Thread Jason Daly
OK, disregard everything I said about using osgscribe and Polygon Offset.  
Having just read the link I posted myself, I realized that glPolygonOffset only 
works for filled polygons and not lines or points.  Sorry for the misdirection.

Unfortunately, you'll have to come up with something a bit more clever for 
those.  I don't have any suggestions off the top of my head, but the FAQ entry 
does mention a couple of possibilities using the depth range or the stencil 
buffer.

There might also be a vertex shader solution.

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=47642#47642





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Manipulator and selection

2012-05-09 Thread Bob Slobodan
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   PointPoint  ...
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_ptrosg::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_castdouble(traits-width)/2.0, 
static_castdouble(traits-width)/2.0, 
-static_castdouble(traits-height)/2.0, 
static_castdouble(traits-height)/2.0, 1.0f, 1.0f);
setProjectionMatrixAsPerspective(30.0f, 
static_castdouble(traits-width)/static_castdouble(traits-height), 1.0f, 
1.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_ptrSRE_Camera camera = SRE::get()-getScene()-getCamera();
osg::ref_ptrosg::Group root = SRE::get()-getScene()-getRoot();

viewer-setCamera(camera.get());
viewer-setSceneData(root.get());

viewer-setCameraManipulator(manipulator.get());

osgQt::GraphicsWindowQt* gw = dynamic_castosgQt::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){

  

Re: [osg-users] Manipulator and selection

2012-05-09 Thread Bob Slobodan
I finally figured out what was the problem with the camera. It was just that I 
had really large coordinates (for example : 510, 510, 100). So I 
finally subtsracted an offset (510, 510, 0) to all my points and the 
manipulator now works just fine.

It also solved part of the selection problem. And now that I use a 
PolytopeIntersector instead of a line segment intersector, I can select what I 
want.

The last problem that I have now is to figured out how to make the point appear 
in front of the lines and the lines in front of the surfaces.
Does anyone have a clue of how to do that ?

Thanks,
bob.

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=47611#47611





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Manipulator and selection

2012-05-09 Thread Jason Daly

On 05/09/2012 07:34 AM, Bob Slobodan wrote:

I finally figured out what was the problem with the camera. It was just that I 
had really large coordinates (for example : 510, 510, 100). So I 
finally subtsracted an offset (510, 510, 0) to all my points and the 
manipulator now works just fine.

It also solved part of the selection problem. And now that I use a 
PolytopeIntersector instead of a line segment intersector, I can select what I 
want.

The last problem that I have now is to figured out how to make the point appear 
in front of the lines and the lines in front of the surfaces.
Does anyone have a clue of how to do that ?



Hi, Bob,

Take a look at the osgscribe example.  It shows how to use 
osg::PolygonOffset to show lines on top of surfaces.  You can probably 
extend that to handle the points as well.


--J

___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org