Added handling of CameraNode into PickVisitor in src/osgProducer/Viewer.cpp. This
is unlikely to be the final solution, but does at least fix part of the problem of handling picking HUD's underneath CameraNodes.
This commit is contained in:
parent
7e858b15f1
commit
b0df518d11
@ -25,6 +25,7 @@
|
||||
#include <osg/Depth>
|
||||
#include <osg/Projection>
|
||||
#include <osg/MatrixTransform>
|
||||
#include <osg/CameraNode>
|
||||
#include <osg/io_utils>
|
||||
|
||||
#include <osgText/Text>
|
||||
@ -108,18 +109,19 @@ void PickHandler::pick(const osgGA::GUIEventAdapter& ea)
|
||||
}
|
||||
|
||||
osg::Node* createHUD(osgText::Text* updateText)
|
||||
{ // create the hud. derived from osgHud.cpp
|
||||
{
|
||||
|
||||
// create the hud. derived from osgHud.cpp
|
||||
// adds a set of quads, each in a separate Geode - which can be picked individually
|
||||
// eg to be used as a menuing/help system!
|
||||
// Can pick texts too!
|
||||
osg::MatrixTransform* modelview_abs = new osg::MatrixTransform;
|
||||
modelview_abs->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
|
||||
modelview_abs->setMatrix(osg::Matrix::identity());
|
||||
|
||||
osg::Projection* projection = new osg::Projection;
|
||||
projection->setMatrix(osg::Matrix::ortho2D(0,1280,0,1024));
|
||||
projection->addChild(modelview_abs);
|
||||
|
||||
|
||||
osg::CameraNode* hudCamera = new osg::CameraNode;
|
||||
hudCamera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
|
||||
hudCamera->setProjectionMatrixAsOrtho2D(0,1280,0,1024);
|
||||
hudCamera->setViewMatrix(osg::Matrix::identity());
|
||||
hudCamera->setRenderOrder(osg::CameraNode::POST_RENDER);
|
||||
hudCamera->setClearMask(GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
std::string timesFont("fonts/times.ttf");
|
||||
|
||||
@ -133,7 +135,7 @@ osg::Node* createHUD(osgText::Text* updateText)
|
||||
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
|
||||
stateset->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
|
||||
geode->setName("simple");
|
||||
modelview_abs->addChild(geode);
|
||||
hudCamera->addChild(geode);
|
||||
|
||||
osgText::Text* text = new osgText::Text;
|
||||
geode->addDrawable( text );
|
||||
@ -172,7 +174,7 @@ osg::Node* createHUD(osgText::Text* updateText)
|
||||
quad->setVertexArray(vertices);
|
||||
quad->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4));
|
||||
geode->addDrawable(quad);
|
||||
modelview_abs->addChild(geode);
|
||||
hudCamera->addChild(geode);
|
||||
|
||||
position += delta;
|
||||
}
|
||||
@ -186,7 +188,7 @@ osg::Node* createHUD(osgText::Text* updateText)
|
||||
stateset->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
|
||||
geode->setName("The text label");
|
||||
geode->addDrawable( updateText );
|
||||
modelview_abs->addChild(geode);
|
||||
hudCamera->addChild(geode);
|
||||
|
||||
updateText->setCharacterSize(20.0f);
|
||||
updateText->setFont(timesFont);
|
||||
@ -197,7 +199,7 @@ osg::Node* createHUD(osgText::Text* updateText)
|
||||
position += delta;
|
||||
}
|
||||
|
||||
return projection;
|
||||
return hudCamera;
|
||||
|
||||
}
|
||||
|
||||
|
@ -88,17 +88,16 @@ public:
|
||||
_nodeMaskOverride = mask; }
|
||||
|
||||
|
||||
virtual void apply(osg::Projection& pr)
|
||||
{ // stack the intersect rays, transform to new projection, traverse
|
||||
// Assumes that the Projection is an absolute projection
|
||||
void handleProjectionMatrix(const osg::Matrixd& matrix, osg::Group& node)
|
||||
{
|
||||
osg::Matrixd mt;
|
||||
mt.invert(pr.getMatrix());
|
||||
mt.invert(matrix);
|
||||
osg::Vec3 npt=osg::Vec3(xp,yp,-1.0f) * mt, farpt=osg::Vec3(xp,yp,1.0f) * mt;
|
||||
|
||||
// traversing the nodes children, using the projection direction
|
||||
for (unsigned int i=0; i<pr.getNumChildren(); i++)
|
||||
for (unsigned int i=0; i<node.getNumChildren(); i++)
|
||||
{
|
||||
osg::Node *nodech=pr.getChild(i);
|
||||
osg::Node *nodech=node.getChild(i);
|
||||
osgUtil::IntersectVisitor::HitList &hli=_piv.getIntersections(nodech,npt, farpt);
|
||||
for(osgUtil::IntersectVisitor::HitList::iterator hitr=hli.begin();
|
||||
hitr!=hli.end();
|
||||
@ -111,6 +110,19 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
virtual void apply(osg::Projection& pr)
|
||||
{
|
||||
handleProjectionMatrix(pr.getMatrix(), pr);
|
||||
}
|
||||
|
||||
virtual void apply(osg::CameraNode& camera)
|
||||
{
|
||||
// just handling the projection matrix here, this leaves the question about non identity view matrices....
|
||||
// we need to think about the effects of this. Robert Osfield, Novemenber 2005.
|
||||
handleProjectionMatrix(camera.getProjectionMatrix(), camera);
|
||||
}
|
||||
|
||||
osgUtil::IntersectVisitor::HitList& getHits(osg::Node *node, const osg::Vec3& near_point, const osg::Vec3& far_point)
|
||||
{
|
||||
// High level get intersection with sceneview using a ray from x,y on the screen
|
||||
|
Loading…
Reference in New Issue
Block a user