Skip to content

Commit

Permalink
Changed OsgSceneHandler so it re-uses osgUtil::SceneView project and …
Browse files Browse the repository at this point in the history
…modelview

matrices.

Changed the osgpick demo so that it uses the OsgSceneHandler's projection and
modelview matrices where possible.
  • Loading branch information
robertosfield committed Apr 16, 2003
1 parent fc4a2ab commit f9eb430
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
30 changes: 20 additions & 10 deletions examples/osgpick/osgpick.cpp
Expand Up @@ -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;
Expand All @@ -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;



Expand All @@ -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())
Expand Down
4 changes: 0 additions & 4 deletions include/osgProducer/OsgSceneHandler
Expand Up @@ -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;
Expand Down
10 changes: 4 additions & 6 deletions src/osgProducer/OsgSceneHandler.cpp
Expand Up @@ -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()
Expand All @@ -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;
Expand Down

0 comments on commit f9eb430

Please sign in to comment.