Re: [osg-users] PolytopeIntersector LIMIT_NEAREST (or LIMIT_ONE) different distances for different groupnodes

2016-06-01 Thread David Knipp
Hi robertosfield,

Thank you for you reply. 

This absolutley understandable. Every group can have it's own transformation 
and so every group has it's own local coordinates. Quite clear.

So i guess there is absolutley no way to caluclate distances in 
Worldcoordinates?

I admit, I don't understand much about how the IntersectionVisitor works and I 
still searching for the right lines in the osgUtil Project. 

I've just written simpel boolean collision code before.

PS: Would you mind to remove my email address from the qoute? : D I actually 
like that to be private. : ) 

Cheers,
NoxxKn

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





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


[osg-users] PolytopeIntersector LIMIT_NEAREST (or LIMIT_ONE) different distances for different groupnodes

2016-06-01 Thread David Knipp
Hi,

I'm very sorry that i have to create a new post. I'm currently facing a problem 
i can't solve on my own. 

Im working on a single Model which has a lot of group nodes and geometry nodes. 
This model is categorized in a few "main" groups. 

In the beginning i worked only with one of this main groups at once. 

The application does view this group and handle pickings on them. Everything 
worked nice and cleanly. After i was mixing some of the groups the results of 
the picker got strange. 

Groups got different distances and also the differences change if i just change 
the angle i'm looking at the model. (orbit manipulator! I don't change the 
distance!)

The strange behavior is that i start picking nodes that where BEHIND of the 
nodes i wanted to pick (in viewer).

I'm working with a picker like so:

int x = GET_X_LPARAM(lParam); // windows mouse pos
int y = GET_Y_LPARAM(lParam); // windows mouse pos

float _x = static_cast(x);
float _y = static_cast(y);

_x = 2.f * (_x - 0.f) / (window_width - 0.f) - 1.f;
_y = -(2.f * (_y - 0.f) / (window_height - 0.f) - 1.f);

double w = 0.005, h = 0.005;
osgUtil::PolytopeIntersector * picker = new 
osgUtil::PolytopeIntersector(osgUtil::Intersector::CoordinateFrame::PROJECTION, 
_x - w, _y - h, _x + w, _y + h);

picker->setIntersectionLimit(osgUtil::Intersector::LIMIT_NEAREST);
picker>setPrecisionHint(osgUtil::Intersector::PrecisionHint::USE_DOUBLE_CALCULATIONS);
picker->setDimensionMask(osgUtil::PolytopeIntersector::AllDims);

osgUtil::IntersectionVisitor iv(picker);
iv.setTraversalMode(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN);

viewer->getCamera()->accept(iv);

if (picker->containsIntersections()) {
   const osg::NodePath& nodePath = 
   picker->getFirstIntersection().nodePath;
   unsigned int idx = nodePath.size();
   while (idx--) {
// bla bla specifc
}
}

What i mean is described in Attachments.

First Image "pick-error.png":

Red: Calculated nearer (but are in viewer BEHIND!)
Green: Calculated further away (Actually the node i wanted to pick)

Second Image "pick-error2.png":

I just change the angle of the orbit viewer for about 30 degrees and don't 
change the distance to object. The Distances just explode to much higher 
values. (Note the Model should only be about "2.f" heigh!)

I guess the second image error was allways present, but i didn't realised it, 
because the picker worked allways right.

Another side node, the model seems to doesn't stand in the right position. It 
should be in 0 0 0 but is located anywhere like 1 -11 -180 or something like 
that. Which is very strange but never made a problem. 
For loading i do: 

// ... osg::MatrixTransform mt
const double angle = osg::DegreesToRadians(90.);
const osg::Vec3d axis(1, 0, 0);
mt->setMatrix(osg::Matrix::rotate(angle, axis));
mt->addChild(model);
root->addChild(mt);
..

I can't upload the model because it's not for public use.

I hope the informations are enough that some kind person can give me a hint.

I worked to all coordinate frames. Only Projection seemd to work for me. Never 
found the right matrices to make View or Model working. Precision Hint can be 
float which has the same errors. Intersection Limit can be "NO_LIMIT" and 
wouldn't change a thing.

A LineSegmentIntersector never found a result.

Cheers,
NoxxKn

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




Attachments: 
http://forum.openscenegraph.org//files/pick_error2_941.png
http://forum.openscenegraph.org//files/pick_error_165.png


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


Re: [osg-users] Point Selection in Point Cloud

2016-04-04 Thread David Knipp
Hi Bruno,

You can choose many different ways. OSG is not a collision detection library 
but it has some functionality you can play with. Also you can use bullet 
physics which is a free physics library. Also this is a pretty easy detection 
implementation and you can just do it on your own.

1. osg:

look at: 
osg::PolytopyIntersector:


Code:

osgUtil::PolytopeIntersector * picker = new 
osgUtil::PolytopeIntersector(osgUtil::Intersector::CoordinateFrame::PROJECTION, 
rectangle_min_x, rectangle_min_y, rectangle_max_x, rectangle_maxy);

// setup picker ...
osgUtil::IntersectionVisitor intersecvisitor(picker);
// setup iv
viewer->getCamera()->accept(iv);




I'm not shure if it's possible to select a SINGLE Point from a geometry with 
this.

2. bullet physics

ask at bullet physics for this

3. own implementation:

an easy point in rectangle implementation:

Code:

bool point3DinsideRectangle2D(Position p, Rectangle r) {
   if(p.x < r.minPos.x || p.y < r.minPos.y)
   return false;
   if(p.x > r.maxPos.x || p.y > r.maxPos.y)
   return false;
   
}




If you would check every point like this it would take hours. So make this test 
above for each point after you checked the boundingbox of a geometry or 
drawable:


Code:

bool boundingBox3DinsideRectangle2D(BoundingBox bb, Rectangle r) {
   if(bb.xMin() < r.minPos.x || bb.yMin() < r.minPos.y)
   return false;
   if(bb.xMax() > r.maxPos.x || bb.yMax() > r.maxPos.y)
   return false;
   
}




You can implement this with a simple NodeVisitor. For the Rectangle make shure 
to transform the choosen min and max right.


Code:

   Rectangle r;
   
   // minP, maxP from selection
// transform them
   minP = this->mViewer->getCamera()->getProjectionMatrix() * 
this->mViewer->getCamera()->getViewMatrix() * minP;
   maxP = this->mViewer->getCamera()->getProjectionMatrix() * 
this->mViewer->getCamera()->getViewMatrix() * maxP;
   // compute new min max
  r.min.x = min(minP.x, maxP.x);
  r.min.y = min(minP.y, maxP.y);
  r.max.x = max(minP.x, maxP.x);
  r.max.y = max(minP.y, maxP.y);




Something like this should work. But using a Rectangle isn't actually right. A 
rectangle drawn on display will actually create a frustum with the view. (If 
look at a cuboid in 3D, you will see a frustum that you'r brain will interpret 
as cuboid)

If you like to use frustum google for:
"Point in Frustum"
And
"Intersection BoundingBox and Frustum"

I guess you will find plenty of stuff.

Cheers,
NoxxKn

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





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


Re: [osg-users] Get all vertices of an OSG Group

2016-03-31 Thread David Knipp
Hi Bemt,

i think you got something wrong in the beginning. There are 3 possible ways to 
apply a color to a vertex:

- Material: 
  Materials define how the surface is interacting with lights. 
  Most times you are only intereseted in diffuse value.

osg::Material * mat = 
dynamic_cast(geometry)->getOrCreateStateSet()->getAttribute(osg::StateAttribute::MATERIAL));
mat->getDiffuse(osg::Material::Face::FRONT_AND_BACK));

- ColorArray:
  A simple color value that is just applied to a vertex

ptrOSGNode->getColorArray()

- Texture:
  An image applied on the surface:

osg::Texture2D * texture = 
dynamic_cast(geometry)->getOrCreateStateSet()->getTextureAttribute(0,
 osg::StateAttribute::TEXTURE));

All these are DIFFERENT ways to apply a color to a vertex. You should have said 
in the beginning that you apply a texture to all vertices. : )

Your answer should be for one position:

i : index of current vertex

osg::Vec2Array * texCoords = dynamic_cast(geometry->getTexCoordArray(0)); 
osg::Vec4 color = texture->getImage()->getColor(texCoords->operator[](i));

Cheers,
NoxxKn

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





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


Re: [osg-users] determining new size of rendering window after a user resizing

2016-03-31 Thread David Knipp
Hi,

if you are working under windows you can cast a window to GraphicsHandleWin32 
as far as i know:

osgViewer::ViewerBase::Windows wins;
viewer->getWindows(wins);
osgViewer::GraphicsHandleWin32* win32Window = 
dynamic_cast(wins[0]);

if(win32Window) {
 // windows.h
 RECT r;
 GetWindowRect(win32Window->getHWND(), );
 // now use r.width and r.height
}

Cheers,
NoxxKn

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





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


Re: [osg-users] Tesselation on Model

2016-03-23 Thread David Knipp
Thank you very much Sebastian! You are awesome!

You really made my day. I can see the tesselation it's working now. : )

If I'm allowed to add one question for personal advancing. 

What do i have to change in the shader so that the model is normal again? 
My Model is looking like it was pressed to 2D papper and then got wrapped 
arround a ball. 

Is this because of the geometryshader of the example?

Cheers,
David

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





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


[osg-users] Tesselation on Model

2016-03-23 Thread David Knipp
Hi osg-Forum,

I'm kind of stuck with a problem in how to combine a tesslation shader in osg 
with a normal model right now. I really searched over google a couple of times 
and over the osg forum. I can't find an answer to my problem. Normally i prefer 
to not ask and just resolve it myself because thats my problem and not yours. 
As you can see this is my first post and i just registered here to ask that. 
I'm really sry for that.

The thing is that I'm currently working on is an application that will just 
display a model. The model i'm working on is a huge bunch of GroupNodes that 
resolve down in the tree to geode-group-nodes and then geometrynodes. I guess 
thats pretty normal. With default osg shaders everty thing works nice and 
smooth.

Now comes the problem. I have to tesselate the Model. 
I admit that im not used to programm shaders and only did it with DirectX 11. 
But the easy things worked back then. 
For this project i used the "osgtesselateshaders" example of yours and did just 
copy the shaders there. I know that now all the texture, material and own 
lightning won't work with this shaders. I just want to see if the wireframe 
will get tesselated. For that i create the osg::Program variable in a ref_ptr 
and then set the pointer of it to all geometrynodes of the model. Every 
Geometrynode will get his own uniform with "innerTesselation", 
"outerTesselation" variables and so own. I also created hotkeys for "+" and "-" 
that will change the values of all Geoemtrynode as pleased. 

The default shader of osg works perfectly fine with my programm but of course 
no tesselation will hapen. Now if i start the programm with the osg 
tesselateion shaders of "osgtesselateshaders" it will just print this in Visual 
Studio:

"Warning: detected OpenGL error 'invalid operation' at after 
RenderBin::draw(..)"

This warning pretty much says nothing as far as i have googeld it. Just says 
"some Problem ist here". Of course the viewer will show nothing of my model.

So now my question what do i have to change to make the shaders of the example 
work with a loaded model? Is it even possible to make this example work with a 
model? Isn't a model just a bunch of triangles (+ texture and materials) as the 
Icosahedron in the example? Whats the difference here?

It would be cool if somebody allready has an example on how to use an 
tesselation shader with a simpel model that he can (is allowed) to post here. 

I'm sry for the post if the problem is just a simple coding error.


Code:

// init of the programm
this->mShader = new osg::Program();
this->mShader->addShader(new osg::Shader(osg::Shader::VERTEX,   
shader::Shader::vertSource));
this->mShader->addShader(new osg::Shader(osg::Shader::TESSCONTROL,  
shader::Shader::tessControlSource));
this->mShader->addShader(new osg::Shader(osg::Shader::TESSEVALUATION,   
shader::Shader::tessEvalSource));
this->mShader->addShader(new osg::Shader(osg::Shader::GEOMETRY, 
shader::Shader::geomSource));
this->mShader->addShader(new osg::Shader(osg::Shader::FRAGMENT, 
shader::Shader::fragSource));
this->mShader->setParameter(GL_GEOMETRY_VERTICES_OUT_EXT, 3);
this->mShader->setParameter(GL_GEOMETRY_INPUT_TYPE_EXT, GL_TRIANGLES);
this->mShader->setParameter(GL_GEOMETRY_OUTPUT_TYPE_EXT, GL_TRIANGLE_STRIP);

n->setShader(this->mShader.get());





Code:

void scene::GroupNode::setShader(osg::Program * p) {
NodeIDMap::iterator itr;
for (itr = this->mChildren.begin(); itr != this->mChildren.end(); ++itr)
itr->second->setShader(p);
}





Code:

void scene::GeometryNode::setShader(osg::Program * p) {
auto *ss = this->mOSGNode->getOrCreateStateSet();
ss->setAttribute(p);
}





Code:

scene::GeometryNode::GeometryNode(osg::Geometry * ptrOSGNode) {
  
this->mTessInnerU = new osg::Uniform("TessLevelInner", 1.0f);
this->mTessOuterU = new osg::Uniform("TessLevelOuter", 1.0f);

osg::StateSet * state;
state = ptrOSGNode->getOrCreateStateSet();
state->addUniform(new osg::Uniform("AmbientMaterial", osg::Vec3(0.04f, 
0.04f, 0.04f)));
state->addUniform(new osg::Uniform("DiffuseMaterial", osg::Vec3(0.0f, 
0.75f, 0.75f)));
state->addUniform(new osg::Uniform("LightPosition", osg::Vec3(0.25f, 
0.25f, 1.0f)));
state->addUniform(this->mTessInnerU.get());
state->addUniform(this->mTessOuterU.get());
state->setAttribute(new osg::PatchParameter(3));
}




Thank you!

Cheers,
NoxxKn[/code]

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





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