📄 cameraconfig.cpp
字号:
/* -*-c++-*- Producer - Copyright (C) 2001-2004 Don Burns * * This library is open source and may be redistributed and/or modified under * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or * (at your option) any later version. The full license is in LICENSE file * included with this distribution, and on the openscenegraph.org website. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * OpenSceneGraph Public License for more details. */#include <osg/Notify>#include <osg/ref_ptr>#include <osg/io_utils>#include <osgDB/FileUtils>#if defined(WIN32) && !defined(__CYGWIN__) #include <io.h> #include <windows.h> #include <winbase.h> // set up for windows so acts just like unix access(). #define F_OK 4#else // unix #include <unistd.h>#endif#ifdef _X11_IMPLEMENTATION# include <X11/Xlib.h>#endif#include <memory.h>#include <stdlib.h>#include <iostream>#include "CameraConfig.h"using namespace osgProducer;unsigned int CameraConfig::getNumberOfScreens(){#if 0 return RenderSurface::getNumberOfScreens();#else return 1;#endif}//////////////////CameraConfig::CameraConfig() : _can_add_visual_attributes(false), _current_render_surface(NULL), _can_add_render_surface_attributes(false), _current_camera(NULL), _can_add_camera_attributes(false), _input_area(NULL), _can_add_input_area_entries(false), _offset_shearx(0.0f), _offset_sheary(0.0f), _postmultiply(false) { _offset_matrix[0] = 1.0; _offset_matrix[1] = 0.0; _offset_matrix[2] = 0.0; _offset_matrix[3] = 0.0; _offset_matrix[4] = 0.0; _offset_matrix[5] = 1.0; _offset_matrix[6] = 0.0; _offset_matrix[7] = 0.0; _offset_matrix[8] = 0.0; _offset_matrix[9] = 0.0; _offset_matrix[10] = 1.0; _offset_matrix[11] = 0.0; _offset_matrix[12] = 0.0; _offset_matrix[13] = 0.0; _offset_matrix[14] = 0.0; _offset_matrix[15] = 1.0; _threadModelDirective = CameraGroup::getDefaultThreadModel();}void CameraConfig::beginVisual( void ){ _current_visual_chooser = new VisualChooser; _can_add_visual_attributes = true;}void CameraConfig::beginVisual( const char * name ){ std::pair<std::map<std::string,VisualChooser *>::iterator,bool> res = _visual_map.insert(std::pair<std::string,VisualChooser *>(std::string(name), new VisualChooser)); _current_visual_chooser = (res.first)->second; _can_add_visual_attributes = true;}void CameraConfig::setVisualSimpleConfiguration( void ){ if( !_current_visual_chooser.valid() || _can_add_visual_attributes == false ) { std::cerr << "CameraConfig::setVisualSimpleConfiguration() : ERROR no current visual\n"; return; } _current_visual_chooser->setSimpleConfiguration();}void CameraConfig::setVisualByID( unsigned int id ){ if( !_current_visual_chooser.valid() || _can_add_visual_attributes == false ) { std::cerr << "CameraConfig::setVisualByID(id) : ERROR no current visual\n"; return; } _current_visual_chooser->setVisualID( id );}void CameraConfig::addVisualAttribute( VisualChooser::AttributeName token, int param ){ if( !_current_visual_chooser.valid() || _can_add_visual_attributes == false ) { std::cerr << "CameraConfig::addVisualAttribute(token,param) : ERROR no current visual\n"; return; } _current_visual_chooser->addAttribute( token, param );}void CameraConfig::addVisualAttribute( VisualChooser::AttributeName token ){ if( !_current_visual_chooser.valid() || _can_add_visual_attributes == false) { std::cerr << "CameraConfig::addVisualAttribute(token) : ERROR no current visual\n"; return; } _current_visual_chooser->addAttribute( token );}void CameraConfig::addVisualExtendedAttribute( unsigned int token ){ if( !_current_visual_chooser.valid() || _can_add_visual_attributes == false) { std::cerr << "CameraConfig::addVisualExtendedAttribute(token) : ERROR no current visual\n"; return; } _current_visual_chooser->addExtendedAttribute( token );}void CameraConfig::addVisualExtendedAttribute( unsigned int token, int param ){ if( !_current_visual_chooser.valid() || _can_add_visual_attributes == false) { std::cerr << "CameraConfig::addVisualExtendedAttribute(token, param) : ERROR no current visual\n"; return; } _current_visual_chooser->addExtendedAttribute( token, param );}void CameraConfig::endVisual( void ){ _can_add_visual_attributes = false;}VisualChooser *CameraConfig::findVisual( const char *name ){ std::map<std::string, VisualChooser *>::iterator p; p = _visual_map.find( std::string(name) ); if( p == _visual_map.end() ) return NULL; else return (*p).second;}void CameraConfig::beginRenderSurface( const char *name ){ std::pair<std::map<std::string, osg::ref_ptr<RenderSurface> >::iterator,bool> res = _render_surface_map.insert(std::pair<std::string, osg::ref_ptr< RenderSurface> >( std::string(name), new RenderSurface)); _current_render_surface = (res.first)->second.get(); _current_render_surface->setWindowName( std::string(name) ); _can_add_render_surface_attributes = true;}void CameraConfig::setRenderSurfaceVisualChooser( const char *name ){ VisualChooser *vc = findVisual( name ); if( vc != NULL && _current_render_surface != NULL ) _current_render_surface->setVisualChooser( vc );}void CameraConfig::setRenderSurfaceVisualChooser( void ){ if( _current_render_surface != NULL && _current_visual_chooser.valid() ) _current_render_surface->setVisualChooser( _current_visual_chooser.get() );}void CameraConfig::setRenderSurfaceWindowRectangle( int x, int y, unsigned int width, unsigned int height ){ if( _current_render_surface != NULL ) _current_render_surface->setWindowRectangle( x, y, width, height );}void CameraConfig::setRenderSurfaceCustomFullScreenRectangle( int x, int y, unsigned int width, unsigned int height ){ if( _current_render_surface != NULL ) _current_render_surface->setCustomFullScreenRectangle( x, y, width, height );}void CameraConfig::setRenderSurfaceOverrideRedirect( bool flag ){ if( _current_render_surface != NULL ) _current_render_surface->useOverrideRedirect( flag );}void CameraConfig::setRenderSurfaceHostName( const std::string &name ){ if( _current_render_surface != NULL ) _current_render_surface->setHostName( name );}void CameraConfig::setRenderSurfaceDisplayNum( int n ){ if( _current_render_surface != NULL ) _current_render_surface->setDisplayNum( n );}void CameraConfig::setRenderSurfaceScreen( int n ){ if( _current_render_surface != NULL ) _current_render_surface->setScreenNum( n );}void CameraConfig::setRenderSurfaceBorder( bool flag ){ if( _current_render_surface != NULL ) _current_render_surface->useBorder( flag );}void CameraConfig::setRenderSurfaceDrawableType( RenderSurface::DrawableType drawableType ){ if( _current_render_surface != NULL ) _current_render_surface->setDrawableType( drawableType );}void CameraConfig::setRenderSurfaceRenderToTextureMode( RenderSurface::RenderToTextureMode rttMode ){ if( _current_render_surface != NULL ) _current_render_surface->setRenderToTextureMode( rttMode );}void CameraConfig::setRenderSurfaceReadDrawable( const char *name ){ if( _current_render_surface != NULL ) { osgProducer::RenderSurface *readDrawable = findRenderSurface( name ); if( readDrawable == NULL ) { std::cerr << "setRenderSurfaceReadDrawable(): No Render Surface by name of \"" << name << "\" was found!\n"; return; } _current_render_surface->setReadDrawable( readDrawable ); }}void CameraConfig::setRenderSurfaceInputRectangle( float x0, float x1, float y0, float y1 ){ if( _current_render_surface != NULL ) _current_render_surface->setInputRectangle( RenderSurface::InputRectangle(x0,x1,y0,y1) );}void CameraConfig::endRenderSurface( void ){ _can_add_render_surface_attributes = false;}RenderSurface *CameraConfig::findRenderSurface( const char *name ){ std::map<std::string, osg::ref_ptr<RenderSurface> >::iterator p; p = _render_surface_map.find( std::string(name) ); if( p == _render_surface_map.end() ) return NULL; else return (*p).second.get();}unsigned int CameraConfig::getNumberOfRenderSurfaces(){ return _render_surface_map.size();}RenderSurface *CameraConfig::getRenderSurface( unsigned int index ){ if( index >= _render_surface_map.size() ) return NULL; std::map <std::string, osg::ref_ptr<RenderSurface> >::iterator p; unsigned int i = 0; for( p = _render_surface_map.begin(); p != _render_surface_map.end(); p++ ) if( i++ == index ) break; if( p == _render_surface_map.end() ) return NULL; return (p->second.get());}void CameraConfig::addCamera( std::string name, Camera *camera ){ std::pair<std::map<std::string, osg::ref_ptr<Camera> >::iterator,bool> res = _camera_map.insert(std::pair<std::string, osg::ref_ptr<Camera> >(name, camera)); _current_camera = (res.first)->second.get(); _can_add_camera_attributes = true; RenderSurface *rs = camera->getRenderSurface(); if( rs->getWindowName() == osgProducer::RenderSurface::defaultWindowName ) { char name[80]; sprintf( name, "%s (%02d)", osgProducer::RenderSurface::defaultWindowName.c_str(), (int)_render_surface_map.size() ); rs->setWindowName( name ); } _render_surface_map.insert(std::pair<std::string, osg::ref_ptr<RenderSurface> >( rs->getWindowName(), rs ));}void CameraConfig::beginCamera( std::string name ){ Camera *camera = new Camera; std::pair<std::map<std::string, osg::ref_ptr<Camera> >::iterator,bool> res = _camera_map.insert(std::pair<std::string, osg::ref_ptr<Camera> >(name, camera)); _current_camera = (res.first)->second.get(); _can_add_camera_attributes = true;}void CameraConfig::setCameraRenderSurface( const char *name ){ RenderSurface *rs = findRenderSurface( name ); if( rs == NULL ) { std::cerr << "setCameraRenderSurface(): No Render Surface by name of \"" << name << "\" was found!\n"; return; } if( rs != NULL && _current_camera != NULL )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -