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; }
bool CameraMath::isInFOV( osg::Vec3d point, osg::ref_ptr<osg::Camera> camera ) { double left, right, bottom, top, zNear, zFar; camera->getProjectionMatrixAsFrustum( left, right, bottom, top, zNear, zFar ); osg::Matrixd& mv = camera->getViewMatrix(); osg::Matrixd& mp = camera->getProjectionMatrix(); osg::Vec3d pView = point * mv * mp; if ( pView.z() < 0.0 ) { return false; } return true; }
const osg::Matrix &getProjectionMatrix() const { return mMainPass->getProjectionMatrix(); }
osg::Matrix getFromScreenMatrix( osg::ref_ptr< osg::Camera > camera,osg::Vec2 size ) { return osg::Matrix::inverse( camera->getViewMatrix() * camera->getProjectionMatrix() *( osg::Matrix::translate(1.0,1.0,1.0)*osg::Matrix::scale(0.5*size.x(),0.5*size.y(),0.5f))); }
osg::Matrix getToScreenMatrix( osg::ref_ptr< osg::Camera > camera,osg::Vec2 size ) { return osg::Matrix( camera->getViewMatrix() * camera->getProjectionMatrix() *( osg::Matrix::translate(1.0,1.0,1.0)*osg::Matrix::scale(0.5*size.x(),0.5*size.y(),0.5f)));//camera->getViewport()->computeWindowMatrix() ); }