Changed OsgSceneHandler so it re-uses osgUtil::SceneView project and modelview

matrices.

Changed the osgpick demo so that it uses the OsgSceneHandler's projection and
modelview matrices where possible.
This commit is contained in:
Robert Osfield 2003-04-16 09:22:33 +00:00
parent fc4a2ab191
commit f9eb43083a
3 changed files with 24 additions and 20 deletions

View File

@ -125,12 +125,12 @@ void PickHandler::pick(const osgGA::GUIEventAdapter& ea)
Producer::Camera* cmm=_viewer->getCamera(i);
Producer::RenderSurface* rs = cmm->getRenderSurface();
std::cout << "checking camara "<<i<<std::endl;
//std::cout << "checking camara "<<i<<std::endl;
float pixel_x,pixel_y;
if (km->computePixelCoords(x,y,rs,pixel_x,pixel_y))
{
std::cout << " compute pixel coords "<<pixel_x<<" "<<pixel_y<<std::endl;
//std::cout << " compute pixel coords "<<pixel_x<<" "<<pixel_y<<std::endl;
int pr_wx, pr_wy;
unsigned int pr_width, pr_height;
@ -143,7 +143,7 @@ void PickHandler::pick(const osgGA::GUIEventAdapter& ea)
pr_wx += rs_wx;
pr_wy += rs_wy;
std::cout << " wx = "<<pr_wx<<" wy = "<<pr_wy<<" width="<<pr_width<<" height="<<pr_height<<std::endl;
//std::cout << " wx = "<<pr_wx<<" wy = "<<pr_wy<<" width="<<pr_width<<" height="<<pr_height<<std::endl;
@ -157,13 +157,23 @@ void PickHandler::pick(const osgGA::GUIEventAdapter& ea)
float rx = 2.0f*(pixel_x - (float)pr_wx)/(float)pr_width-1.0f;
float ry = 2.0f*(pixel_y - (float)pr_wy)/(float)pr_height-1.0f;
std::cout << " rx "<<rx<<" "<<ry<<std::endl;
osg::Matrix vum(osg::Matrix(cmm->getViewMatrix()) *
osg::Matrix(cmm->getProjectionMatrix())/* *
osg::Matrix::translate(1.0f,1.0f,1.0f) *
osg::Matrix::scale(0.5f,0.5f,0.5f)*/);
//std::cout << " rx "<<rx<<" "<<ry<<std::endl;
osgProducer::OsgSceneHandler* sh = dynamic_cast<osgProducer::OsgSceneHandler*>(cmm->getSceneHandler());
osg::Matrix vum;
if (sh!=0 && sh->getModelViewMatrix()!=0 && sh->getProjectionMatrix()!=0)
{
vum.set((*(sh->getModelViewMatrix())) *
(*(sh->getProjectionMatrix())));
}
else
{
vum.set(osg::Matrix(cmm->getViewMatrix()) *
osg::Matrix(cmm->getProjectionMatrix())/* *
osg::Matrix::translate(1.0f,1.0f,1.0f) *
osg::Matrix::scale(0.5f,0.5f,0.5f)*/);
}
osgUtil::PickVisitor iv;
osgUtil::IntersectVisitor::HitList& hlist=iv.getHits(scene, vum, rx,ry);
if (iv.hits())

View File

@ -85,10 +85,6 @@ class OSGPRODUCER_EXPORT OsgSceneHandler : public Producer::Camera::SceneHandler
virtual ~OsgSceneHandler() {}
osg::ref_ptr<osg::RefMatrix> mm;
osg::ref_ptr<osg::RefMatrix> pm;
osg::ref_ptr<Callback> _clearCallback;
osg::ref_ptr<Callback> _cullCallback;
osg::ref_ptr<Callback> _drawCallback;

View File

@ -20,8 +20,8 @@ using namespace osgProducer;
OsgSceneHandler::OsgSceneHandler( osg::DisplaySettings *ds) :
osgUtil::SceneView(ds)
{
mm = new osg::RefMatrix;
pm = new osg::RefMatrix;
setProjectionMatrix( new osg::RefMatrix );
setModelViewMatrix( new osg::RefMatrix );
}
void OsgSceneHandler::init()
@ -46,10 +46,8 @@ void OsgSceneHandler::clearImplementation(Producer::Camera& /*camera*/)
void OsgSceneHandler::cullImplementation(Producer::Camera &cam)
{
pm->set(cam.getProjectionMatrix());
mm->set(cam.getPositionAndAttitudeMatrix());
setProjectionMatrix( pm.get() );
setModelViewMatrix( mm.get() );
getProjectionMatrix()->set(cam.getProjectionMatrix());
getModelViewMatrix()->set(cam.getPositionAndAttitudeMatrix());
int x, y;
unsigned int w, h;