⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 camera.cpp

📁 最新osg包
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    width = int(fw) - x;    height = int(fh) - y;}void Camera::setClearColor( float r, float g, float b, float a ){    _clear_color[0] = r;    _clear_color[1] = g;    _clear_color[2] = b;    _clear_color[3] = a;}void Camera::getClearColor( float& red, float& green, float& blue, float& alpha){    red = _clear_color[0];    green = _clear_color[1];    blue = _clear_color[2];    alpha = _clear_color[3];}void Camera::clear( void ) {#if 0    if( !_initialized ) _initialize();    int x, y;     unsigned int w, h;    getProjectionRectangle( x, y, w, h );    glViewport( x, y, w, h );    glScissor( x, y, w, h );    glClearColor( _clear_color[0], _clear_color[1], _clear_color[2], _clear_color[3] );    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );#endif}#if 0void Camera::Lens::_updateMatrix( void ){    switch( _projection )    {        case Perspective :            _matrix[ 0] = (2 * _nearClip)/(_right - _left);            _matrix[ 1] = 0.0;            _matrix[ 2] = 0.0;            _matrix[ 3] = 0.0;            _matrix[ 4] = 0.0;            _matrix[ 5] = (2 * _nearClip)/(_top-_bottom);            _matrix[ 6] = 0.0;            _matrix[ 7] = 0.0;            _matrix[ 8] = (_right + _left)/(_right-_left);            _matrix[ 9] = (_top+_bottom)/(_top-_bottom);            _matrix[10] = -(_farClip + _nearClip)/(_farClip-_nearClip);            _matrix[11] = -1.0;            _matrix[12] = 0.0;            _matrix[13] = 0.0;            _matrix[14] = -(2 * _farClip * _nearClip)/(_farClip-_nearClip);            _matrix[15] = 0.0;            _matrix[ 8] += -_xshear;            _matrix[ 9] += -_yshear;        _hfov = 2.0 * atan(((_right - _left) * 0.5)/_nearClip);        _vfov = 2.0 * atan(((_top - _bottom) * 0.5)/_nearClip);        break;    case Orthographic :            _matrix[ 0] = 2/(_ortho_right - _ortho_left);            _matrix[ 1] = 0.0;            _matrix[ 2] = 0.0;            _matrix[ 3] = 0.0;            _matrix[ 4] = 0.0;            _matrix[ 5] = 2/(_ortho_top - _ortho_bottom);            _matrix[ 6] = 0.0;            _matrix[ 7] = 0.0;            _matrix[ 8] = 0.0;            _matrix[ 9] = 0.0;            //_matrix[10] = -2.0/(_farClip - (-_farClip));            _matrix[10] = -2.0/(_farClip - _nearClip);            _matrix[11] = 0.0;            _matrix[12] = -(_ortho_right+_ortho_left)/(_ortho_right-_ortho_left);            _matrix[13] = -(_ortho_top+_ortho_bottom)/(_ortho_top-_ortho_bottom);            //_matrix[14] = -(_farClip+(-_farClip))/(_farClip-(-_farClip));            _matrix[14] = -(_farClip+_nearClip)/(_farClip-_nearClip);            _matrix[15] = 1.0;            _matrix[12] += _xshear;            _matrix[13] += _yshear;            //_hfov = 0.0;            //_vfov = 0.0;        break;    }}#endifvoid Camera::Lens::generateMatrix(float xshear, float yshear, osg::Matrix::value_type matrix[16] ){    switch( _projection )    {        case Perspective :            matrix[ 0] = (2 * _nearClip)/(_right - _left);            matrix[ 1] = 0.0;            matrix[ 2] = 0.0;            matrix[ 3] = 0.0;            matrix[ 4] = 0.0;            matrix[ 5] = (2 * _nearClip)/(_top-_bottom);            matrix[ 6] = 0.0;            matrix[ 7] = 0.0;            matrix[ 8] = (_right + _left)/(_right-_left);            matrix[ 9] = (_top+_bottom)/(_top-_bottom);            matrix[10] = -(_farClip + _nearClip)/(_farClip-_nearClip);            matrix[11] = -1.0;            matrix[12] = 0.0;            matrix[13] = 0.0;            matrix[14] = -(2 * _farClip * _nearClip)/(_farClip-_nearClip);            matrix[15] = 0.0;            matrix[ 8] += -xshear;            matrix[ 9] += -yshear;        break;    case Orthographic :            matrix[ 0] = 2/(_ortho_right - _ortho_left);            matrix[ 1] = 0.0;            matrix[ 2] = 0.0;            matrix[ 3] = 0.0;            matrix[ 4] = 0.0;            matrix[ 5] = 2/(_ortho_top - _ortho_bottom);            matrix[ 6] = 0.0;            matrix[ 7] = 0.0;            matrix[ 8] = 0.0;            matrix[ 9] = 0.0;            //_matrix[10] = -2.0/(_farClip - (-_farClip));            matrix[10] = -2.0/(_farClip - _nearClip);            matrix[11] = 0.0;            matrix[12] = -(_ortho_right+_ortho_left)/(_ortho_right-_ortho_left);            matrix[13] = -(_ortho_top+_ortho_bottom)/(_ortho_top-_ortho_bottom);            //_matrix[14] = -(_farClip+(-_farClip))/(_farClip-(-_farClip));            matrix[14] = -(_farClip+_nearClip)/(_farClip-_nearClip);            matrix[15] = 1.0;            matrix[12] += xshear;            matrix[13] += yshear;        break;    case Manual:        memcpy( matrix, _matrix, sizeof(osg::Matrix::value_type[16]));        if(xshear || yshear)        {            if (matrix[3]!=0.0 || matrix[7]!=0.0 || matrix[11]!=0.0 || matrix[15]!=1.0)            {                // It's not an orthographic matrix so just assume a perspective shear                matrix[ 8] += -xshear;                matrix[ 9] += -yshear;            }             else            {                 matrix[12] += xshear;                 matrix[13] += yshear;            }        }        break;    }}void Camera::Lens::_updateFOV(){    _hfov = 2.0 * atan(((_right - _left) * 0.5)/_nearClip);    _vfov = 2.0 * atan(((_top - _bottom) * 0.5)/_nearClip);    _aspect_ratio = tan(0.5*_hfov)/tan(0.5*_vfov);}void Camera::setOffset( const osg::Matrix::value_type matrix[16],  const osg::Matrix::value_type xshear,  const osg::Matrix::value_type yshear ){    memcpy( _offset._matrix, matrix, sizeof(osg::Matrix::value_type[16]));    _offset._xshear = xshear;    _offset._yshear = yshear;}void Camera::setOffset(  double xshear, double yshear ){    _offset._xshear = xshear;    _offset._yshear = yshear;}#if 0void Camera::setSyncBarrier( RefBarrier *b ){    _syncBarrier = b;}void Camera::setFrameBarrier( RefBarrier *b ){    _frameBarrier = b;}int Camera::cancel(){#if 1    _done = true;#endif        Thread::cancel();    return 0;    }void Camera::advance(){    _rs->makeCurrent();    _rs->swapBuffers();}void Camera::run( void ){    if( !_syncBarrier.valid() || !_frameBarrier.valid() )    {        std::cerr << "Camera::run() : Threaded Camera requires a Barrier\n";        return;    }    _done = false;    _initialize();    _syncBarrier->block();    while( !_done )    {        // printf("   Camera::run before frame block\n");        _frameBarrier->block();                if (_done) break;        // printf("   Camera::run after frame block\n");        frame(false);        if (_done) break;        // printf("   Camera::run before sycn block\n");        _syncBarrier->block();        if (_done) break;        // printf("   Camera::run after sycn block\n");        advance();    }        // printf("Exiting Camera::run cleanly\n");}bool Camera::removePreCullCallback( Callback *cb ){    return _removeCallback( preCullCallbacks, cb );}bool Camera::removePostCullCallback( Callback *cb ){    return _removeCallback( postCullCallbacks, cb );}bool Camera::removePreDrawCallback( Callback *cb ) {    return _removeCallback( preDrawCallbacks, cb );}bool Camera::removePostDrawCallback( Callback *cb ) {    return _removeCallback( postDrawCallbacks, cb );}bool Camera::removePostSwapCallback( Callback *cb ){    return _removeCallback( postSwapCallbacks, cb );}bool Camera::_removeCallback( std::vector < ref_ptr<Callback> > &callbackList, Callback *callback ){    std::vector < Producer::ref_ptr< Producer::Camera::Callback> >::iterator p;    p = std::find( callbackList.begin(), callbackList.end(), callback );    if( p == callbackList.end() )        return false;    callbackList.erase( p );    return true;}Camera::FrameTimeStampSet::FrameTimeStampSet():    _pipeStatsDoubleBufferIndex(0),    _pipeStatsFirstSync(true),    _initialized(false){    for( unsigned int i = 0; i < LastPipeStatsID; i++ )        _pipeStats[i] = 0.0;}Camera::FrameTimeStampSet::~FrameTimeStampSet(){}void Camera::FrameTimeStampSet::syncPipeStats(){    if( !_initialized )        return;    if( _pipeStatsFirstSync == true )    {        _pipeStatsFirstSync = false;        return;    }    // We get the stats from the previous frame    for( int i = 0; i < LastPipeStatsID; i++ )    {        if( _pipeStatsSetMask[1 - _pipeStatsDoubleBufferIndex]  & (1<<i) )            _pipeStats[i] = PipeTimer::instance()->getElapsedTime( _pipeStatsNames[i][ 1 - _pipeStatsDoubleBufferIndex] );    }    _pipeStatsFrameNumber = _frameNumber - 1;    _pipeStatsDoubleBufferIndex = 1 - _pipeStatsDoubleBufferIndex;    _pipeStatsSetMask[_pipeStatsDoubleBufferIndex] = 0;}void Camera::FrameTimeStampSet::beginPipeTimer( PipeStatsID id){    if( !_initialized )        _init();    PipeTimer::instance()->begin( _pipeStatsNames[id][_pipeStatsDoubleBufferIndex] );     _pipeStatsSetMask[_pipeStatsDoubleBufferIndex] |= (1<<id); }void Camera::FrameTimeStampSet::endPipeTimer() {     if( !_initialized )        return;    PipeTimer::instance()->end() ;}void Camera::FrameTimeStampSet::_init(){    if( _initialized )        return;    for( unsigned int i = 0; i < (unsigned int)LastPipeStatsID; i++ )        PipeTimer::instance()->genQueries( 2, _pipeStatsNames[i] );    _pipeStatsSetMask[0] = 0;    _pipeStatsSetMask[1] = 0;    _initialized = true;}const Camera::FrameTimeStampSet &Camera::getFrameStats(){     return _frameStamps; }#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -