Exemple #1
0
    virtual void operator () (osg::RenderInfo& renderInfo) const
    {
        osg::Camera::DrawCallback::operator ()(renderInfo);

        if(save_dir.empty())
            return;

        if(paused)
            return;

        ++count;
        int x,y;
        unsigned int width,height;
        osg::ref_ptr<osg::Viewport> vp = vcamera->getViewport();
        x = vp->x();
        y = vp->y();
        width = vp->width();
        height = vp->height();

        osg::ref_ptr<osg::Image> image = new osg::Image;
        image->readPixels(x,y,width,height,GL_RGB,GL_UNSIGNED_BYTE);

        std::stringstream str;
        str << save_dir << "/image" << std::setfill('0') << setw(6) << count
            << setw(0) << ".png";

        if(osgDB::writeImageFile(*image,str.str()))
            std::cout << "Saving image to " << str.str() << std::endl;
        else
            std::cout << "Image saving failed!" << std::endl;
    }
Exemple #2
0
osg::Vec3d CameraMath::projectOnScreen( osg::ref_ptr<osg::Camera> camera, osg::Vec3d point )
{
	osg::Matrixd mv = camera->getViewMatrix();
	osg::Matrixd mp = camera->getProjectionMatrix();
	osg::Matrixd mw = camera->getViewport()->computeWindowMatrix();

	osg::Vec3d result = point * mv;
	result = result * mp;
	result = result * mw;

	return result;
}