[osg-users] Picking and render to texture

2012-05-22 Thread Janosch Machowinski

Hello,
I got a problem with picking and render to texture.
I use an osg::Camera to render a part of my graph to
a texture and display it in an HUD. My problem
now is that when I pick, I can also pick objects that
were rendered to the texture.
My question would now be how could I avoid that
any object of the subgraph that is rendered to the
texture gets picked ?
Alternatively it would be ok, if I could pick on the
quad showing the texture and get the object that
was rendered to it.
Greetings
Janosch
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Picking and render to texture

2012-05-22 Thread Janosch Machowinski

Hi,
sorry I just figured out that I didn't make my problem
clear. I can pick ghost objects. Even if nothing is
drawn at a particular position on my screen, I get
picks to objects that were rendered to the texture.
Greetings
Janosch

On 22.05.2012 20:48, Janosch Machowinski wrote:

Hello,
I got a problem with picking and render to texture.
I use an osg::Camera to render a part of my graph to
a texture and display it in an HUD. My problem
now is that when I pick, I can also pick objects that
were rendered to the texture.
My question would now be how could I avoid that
any object of the subgraph that is rendered to the
texture gets picked ?
Alternatively it would be ok, if I could pick on the
quad showing the texture and get the object that
was rendered to it.
Greetings
Janosch
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org



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


[osg-users] Problem with draggers and HUD

2011-12-01 Thread Janosch Machowinski

Hi,
I got some problem with a dragger and a HUD.
To explain my problem, I attached a sample program.

What this program tries to archive is to draw a 2D
windows, with 3d object in front of it. If the header bar
of the window is dragged, the 3d object should move
accordingly. Sadly, nothing happens if I try to drag the
window. I also noticed that my way of suppressing the
camera movement seems to break dragging for some
reason.

Also I would be interested in a way, to scissor the 3d
objects to the size of the 2d window. Rendering into a
texture does not work for me, as I also do intersection
tests with the 3d objects.
Thanks in advance
Janosch


PROJECT(test)
SET(PROJECT_VERSION 1.0)
cmake_minimum_required(VERSION 2.6)
INCLUDE(FindPkgConfig)


find_package(OpenSceneGraph REQUIRED osgViewer osgWidget osgManipulator osgGA)
include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS})
link_directories(${OPENSCENEGRAPH_LIBRARY_DIRS})


SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -Wall -ggdb)

ADD_EXECUTABLE(test main.cpp)
target_link_libraries (test 
${OPENSCENEGRAPH_LIBRARIES}
)

#include osg/Node
#include osgViewer/Viewer
#include osgManipulator/Translate2DDragger
#include osg/ShapeDrawable

osg::Node *getQuadNode(double x, double y, double z, double width, double height, osg::Vec4 color)
{
osg::ref_ptrosg::Geode geode = new osg::Geode();

osg::StateSet* stateset = geode-getOrCreateStateSet();
stateset-setMode(GL_BLEND,osg::StateAttribute::ON);
stateset-setMode(GL_LIGHTING, osg::StateAttribute::OFF);
stateset-setRenderingHint(osg::StateSet::TRANSPARENT_BIN);

osg::Geometry* geom = new osg::Geometry;

osg::Vec3Array* vertices = new osg::Vec3Array;
vertices-push_back(osg::Vec3(x, y, z));
vertices-push_back(osg::Vec3(x + width, y, z));
vertices-push_back(osg::Vec3(x + width, y + height , z));
vertices-push_back(osg::Vec3(x, y + height, z));
geom-setVertexArray(vertices);

osg::Vec3Array* normals = new osg::Vec3Array;
normals-push_back(osg::Vec3(0.0f,0.0f,1.0f));
geom-setNormalArray(normals);
geom-setNormalBinding(osg::Geometry::BIND_OVERALL);

osg::Vec4Array* colors = new osg::Vec4Array;
colors-push_back(color);
geom-setColorArray(colors);
geom-setColorBinding(osg::Geometry::BIND_OVERALL);

geom-addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4));

geode-addDrawable(geom);

return geode.release();
}
osg::Node *getWindowHeader()
{
return getQuadNode(0,1.3,-30, 2.0, 0.2, osg::Vec4(0,0,0.9,1));
}

osg::Node *getWindow()
{
return getQuadNode(0,0,-30, 2.0, 1.3,osg::Vec4(0,0,0.6,1));
}

osg::Node *getDraggerWindowHeader(osg::MatrixTransform *transformHUD, osg::MatrixTransform *transform3d)
{
osgManipulator::Translate2DDragger *dragger = new osgManipulator::Translate2DDragger();

//setup header bar of window as draggable item
dragger-addChild(getWindowHeader());
// dragger-setupDefaultGeometry();

dragger-setHandleEvents(true);

dragger-addTransformUpdating(transformHUD);
dragger-addTransformUpdating(transform3d);

return dragger;
}

osg::Camera *getHUDCamera()
{
osg::Camera* camera = new osg::Camera();

camera-getOrCreateStateSet()-setMode(
GL_LIGHTING,
osg::StateAttribute::PROTECTED | osg::StateAttribute::OFF
);
camera-getOrCreateStateSet()-setMode(GL_BLEND, osg::StateAttribute::ON);
camera-getOrCreateStateSet()-setRenderingHint(osg::StateSet::TRANSPARENT_BIN);

camera-setProjectionMatrix(osg::Matrix::ortho2D(0.0, 4, 0.0f,3));
camera-setReferenceFrame(osg::Transform::ABSOLUTE_RF);
camera-setViewMatrix(osg::Matrix::identity());
camera-setClearMask(0);
// camera-setClearMask(GL_DEPTH_BUFFER_BIT);
camera-setRenderOrder(osg::Camera::POST_RENDER);

return camera;
}

osg::Node *getSphere()
{
osg::Group *group = new osg::Group();
osg::Geode *geode = new osg::Geode();

{
osg::ref_ptrosg::Sphere sphere = new osg::Sphere(osg::Vec3d(-5, -4, -20), 0.4);
osg::ShapeDrawable *ShapeDrawable = new osg::ShapeDrawable(sphere);
geode-addDrawable(ShapeDrawable);
}
group-addChild(geode);

osg::Geode *geode2 = new osg::Geode();

osg::ref_ptrosg::Sphere sphere = new osg::Sphere(osg::Vec3d(-4, -3, -20), 0.4);
osg::ShapeDrawable *ShapeDrawable = new osg::ShapeDrawable(sphere);
geode2-addDrawable(ShapeDrawable);
group-addChild(geode2);

return group;
}

class NoManipulator: public osgGA::CameraManipulator {
virtual osg::Matrixd getInverseMatrix() const {
	return osg::Matrixd::identity();
}

virtual osg::Matrixd getMatrix() const{
	return osg::Matrixd::identity();
}

virtual void setByInverseMatrix(const osg::Matrixd matrix) {};
virtual void setByMatrix(const osg::Matrixd matrix) {};
};

int main(int argc, char **argv)
{
osgViewer::Viewer *viewer = new osgViewer::Viewer();
viewer-setUpViewInWindow( 0, 0, 800, 600);