Created a dedicated include/osgViewer/config and src/osgViewer/config directories to place all the Config classes.
This commit is contained in:
parent
9552567cd4
commit
625821a91a
@ -30,12 +30,27 @@
|
||||
#include <osgGA/TrackballManipulator>
|
||||
#include <osgViewer/Viewer>
|
||||
#include <osgViewer/ViewerEventHandlers>
|
||||
#include <osgViewer/config/SingleWindow>
|
||||
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
osg::ArgumentParser arguments(&argc,argv);
|
||||
|
||||
|
||||
osg::ref_ptr<osgViewer::Config> config;
|
||||
std::string configFile;
|
||||
if (arguments.read("-c",configFile))
|
||||
{
|
||||
config = osgDB::readFile<osgViewer::Config>(configFile);
|
||||
}
|
||||
if (!config)
|
||||
{
|
||||
config = new osgViewer::SingleWindow(100,100,800,600,0);
|
||||
}
|
||||
|
||||
OSG_NOTICE<<"Config "<<config.get()<<std::endl;
|
||||
|
||||
// initialize the viewer.
|
||||
osgViewer::Viewer viewer(arguments);
|
||||
|
||||
@ -56,6 +71,13 @@ int main( int argc, char **argv )
|
||||
|
||||
viewer.setSceneData(model.get());
|
||||
|
||||
if (config.valid())
|
||||
{
|
||||
config->configure(viewer);
|
||||
|
||||
osgDB::writeObjectFile(*config,"myconfig.osgx");
|
||||
}
|
||||
|
||||
// add the state manipulator
|
||||
viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) );
|
||||
|
||||
@ -65,6 +87,8 @@ int main( int argc, char **argv )
|
||||
// add camera manipulator
|
||||
viewer.setCameraManipulator(new osgGA::TrackballManipulator());
|
||||
|
||||
#if 0
|
||||
|
||||
|
||||
OSG_NOTICE<<"KeystoneFileNames.size()="<<ds->getKeystoneFileNames().size()<<std::endl;
|
||||
for(osg::DisplaySettings::FileNames::iterator itr = ds->getKeystoneFileNames().begin();
|
||||
@ -110,7 +134,7 @@ int main( int argc, char **argv )
|
||||
|
||||
viewer.setUpViewForKeystone(keystone.get());
|
||||
}
|
||||
|
||||
#endif
|
||||
viewer.realize();
|
||||
|
||||
while(!viewer.done())
|
||||
|
@ -14,7 +14,10 @@
|
||||
#ifndef OSGVIEWER_CONFIG
|
||||
#define OSGVIEWER_CONFIG 1
|
||||
|
||||
#include <osg/Object>
|
||||
#include <osg/DisplaySettings>
|
||||
#include <osg/Geometry>
|
||||
#include <osg/Image>
|
||||
|
||||
#include <osgViewer/Export>
|
||||
|
||||
namespace osgViewer {
|
||||
@ -23,7 +26,7 @@ namespace osgViewer {
|
||||
class View;
|
||||
|
||||
/** Config base class for encapsulating view configuration.*/
|
||||
class Config : public osg::Object
|
||||
class OSGVIEWER_EXPORT Config : public osg::Object
|
||||
{
|
||||
public:
|
||||
|
||||
@ -35,7 +38,10 @@ class Config : public osg::Object
|
||||
|
||||
/** configure method that is overridden by Config subclasses.*/
|
||||
virtual void configure(osgViewer::View& /*view*/) const {}
|
||||
|
||||
virtual osg::DisplaySettings* getActiveDisplaySetting(osgViewer::View& view) const;
|
||||
};
|
||||
#if 0
|
||||
|
||||
class OSGVIEWER_EXPORT ViewAcrossAllScreens : public Config
|
||||
{
|
||||
@ -46,7 +52,6 @@ class OSGVIEWER_EXPORT ViewAcrossAllScreens : public Config
|
||||
|
||||
META_Object(osgViewer,ViewAcrossAllScreens);
|
||||
|
||||
/** configure method that is overridden by Config subclasses.*/
|
||||
virtual void configure(osgViewer::View& view) const;
|
||||
};
|
||||
|
||||
@ -61,7 +66,6 @@ class OSGVIEWER_EXPORT ViewInWindow : public Config
|
||||
|
||||
META_Object(osgViewer,ViewInWindow);
|
||||
|
||||
/** configure method that is overridden by Config subclasses.*/
|
||||
virtual void configure(osgViewer::View& view) const;
|
||||
|
||||
void setX(int x) { _x = x; }
|
||||
@ -85,41 +89,51 @@ class OSGVIEWER_EXPORT ViewInWindow : public Config
|
||||
unsigned int _screenNum;
|
||||
};
|
||||
|
||||
#if 0
|
||||
|
||||
/** single camera associated with a single full screen GraphicsWindow.*/
|
||||
class OSGVIEWER_EXPORT ViewOnSingleScreen : public Config
|
||||
{
|
||||
public:
|
||||
|
||||
ViewOnSingleScreen(unsigned int screenNum=0);
|
||||
ViewOnSingleScreen(const ViewOnSingleScreen& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
ViewOnSingleScreen(unsigned int screenNum=0) : _screenNum(screenNum) {}
|
||||
ViewOnSingleScreen(const ViewOnSingleScreen& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : Config(rhs,copyop), _screenNum(rhs._screenNum) {}
|
||||
|
||||
META_Object(osgViewer,ViewOnSingleScreen);
|
||||
|
||||
/** configure method that is overridden by Config subclasses.*/
|
||||
virtual void configure(osgViewer::View& view);
|
||||
virtual void configure(osgViewer::View& view) const;
|
||||
|
||||
void setScreenNum(int sn) { _screenNum = sn; }
|
||||
int getScreenNum() const { return _screenNum; }
|
||||
void setScreenNum(unsigned int sn) { _screenNum = sn; }
|
||||
unsigned int getScreenNum() const { return _screenNum; }
|
||||
|
||||
protected:
|
||||
|
||||
unsigned int _screenNum;
|
||||
};
|
||||
|
||||
|
||||
/** spherical display using 6 slave cameras rendering the 6 sides of a cube map, and 7th camera doing distortion correction to present on a spherical display.*/
|
||||
class OSGVIEWER_EXPORT ViewFor3DSphericalDisplay : public Config
|
||||
{
|
||||
public:
|
||||
|
||||
ViewFor3DSphericalDisplay(double radius=1.0, double collar=0.45, unsigned int screenNum=0, osg::Image* intensityMap=0, const osg::Matrixd& projectorMatrix = osg::Matrixd());
|
||||
ViewFor3DSphericalDisplay(const ViewFor3DSphericalDisplay& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
ViewFor3DSphericalDisplay(double radius=1.0, double collar=0.45, unsigned int screenNum=0, osg::Image* intensityMap=0, const osg::Matrixd& projectorMatrix = osg::Matrixd()):
|
||||
_radius(radius),
|
||||
_collar(collar),
|
||||
_screenNum(screenNum),
|
||||
_intensityMap(intensityMap),
|
||||
_projectorMatrix(projectorMatrix) {}
|
||||
|
||||
META_Object(osgViewer,ViewOnSingleScreen);
|
||||
ViewFor3DSphericalDisplay(const ViewFor3DSphericalDisplay& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
|
||||
Config(rhs,copyop),
|
||||
_radius(rhs._radius),
|
||||
_collar(rhs._collar),
|
||||
_screenNum(rhs._screenNum),
|
||||
_intensityMap(rhs._intensityMap),
|
||||
_projectorMatrix(rhs._projectorMatrix) {}
|
||||
|
||||
/** configure method that is overridden by Config subclasses.*/
|
||||
virtual void configure(osgViewer::View& view);
|
||||
META_Object(osgViewer,ViewFor3DSphericalDisplay);
|
||||
|
||||
virtual void configure(osgViewer::View& view) const;
|
||||
|
||||
void setRadius(double r) { _radius = r; }
|
||||
double getRadius() const { return _radius; }
|
||||
@ -131,18 +145,20 @@ class OSGVIEWER_EXPORT ViewFor3DSphericalDisplay : public Config
|
||||
unsigned int getScreenNum() const { return _screenNum; }
|
||||
|
||||
void setIntensityMap(osg::Image* im) { _intensityMap = im; }
|
||||
osg::Image* getIntensityMap() const { return _intensityMap; }
|
||||
const osg::Image* getIntensityMap() const { return _intensityMap.get(); }
|
||||
|
||||
void setProjectionMatrix(const osg::Matrixd& m) { _intensityMap = m; }
|
||||
osg::Matrixd& getIntensityMap() const { return _intensityMap; }
|
||||
void setProjectionMatrix(const osg::Matrixd& m) { _projectorMatrix = m; }
|
||||
const osg::Matrixd& getProjectionMatrix() const { return _projectorMatrix; }
|
||||
|
||||
protected:
|
||||
|
||||
osg::Geometry* create3DSphericalDisplayDistortionMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector, double sphere_radius, double collar_radius,osg::Image* intensityMap, const osg::Matrix& projectorMatrix) const;
|
||||
|
||||
double _radius;
|
||||
double _collar;
|
||||
unsigned int _screenNum;
|
||||
osg::ref_ref<osg::Image> _intensityMap;
|
||||
const osg::Matrixd _projectorMatrix;
|
||||
osg::ref_ptr<osg::Image> _intensityMap;
|
||||
osg::Matrixd _projectorMatrix;
|
||||
};
|
||||
|
||||
/** spherical display by rendering main scene to a panoramic 2:1 texture and then doing distortion correction to present onto a spherical display.*/
|
||||
@ -155,8 +171,7 @@ class OSGVIEWER_EXPORT ViewForPanoramicSphericalDisplay : public Config
|
||||
|
||||
META_Object(osgViewer,ViewOnSingleScreen);
|
||||
|
||||
/** configure method that is overridden by Config subclasses.*/
|
||||
virtual void configure(osgViewer::View& view);
|
||||
virtual void configure(osgViewer::View& view) const;
|
||||
|
||||
void setRadius(double r) { _radius = r; }
|
||||
double getRadius() const { return _radius; }
|
||||
@ -168,10 +183,10 @@ class OSGVIEWER_EXPORT ViewForPanoramicSphericalDisplay : public Config
|
||||
unsigned int getScreenNum() const { return _screenNum; }
|
||||
|
||||
void setIntensityMap(osg::Image* im) { _intensityMap = im; }
|
||||
osg::Image* getIntensityMap() const { return _intensityMap; }
|
||||
const osg::Image* getIntensityMap() const { return _intensityMap; }
|
||||
|
||||
void setProjectionMatrix(const osg::Matrixd& m) { _intensityMap = m; }
|
||||
osg::Matrixd& getIntensityMap() const { return _intensityMap; }
|
||||
void setProjectionMatrix(const osg::Matrixd& m) { _projectorMatrix = m; }
|
||||
const osg::Matrixd& getProjectionMatrix() const { return _projectorMatrix; }
|
||||
|
||||
protected:
|
||||
|
||||
@ -179,7 +194,7 @@ class OSGVIEWER_EXPORT ViewForPanoramicSphericalDisplay : public Config
|
||||
double _collar;
|
||||
unsigned int _screenNum;
|
||||
osg::ref_ref<osg::Image> _intensityMap;
|
||||
const osg::Matrixd _projectorMatrix;
|
||||
osg::Matrixd _projectorMatrix;
|
||||
};
|
||||
|
||||
/** autostereoscopic Philips WoWvx display.*/
|
||||
@ -193,8 +208,7 @@ class OSGVIEWER_EXPORT ViewForWoWVxDisplay : public Config
|
||||
|
||||
META_Object(osgViewer,ViewForWoWVxDisplay);
|
||||
|
||||
/** configure method that is overridden by Config subclasses.*/
|
||||
virtual void configure(osgViewer::View& view);
|
||||
virtual void configure(osgViewer::View& view) const;
|
||||
|
||||
void setScreenNum(unsigned int n) { _screenNum = n; }
|
||||
unsigned int getScreenNum() const { return _screenNum; }
|
||||
@ -249,7 +263,7 @@ class OSGVIEWER_EXPORT DepthPartition : public Config
|
||||
/** for setting up depth partitioning on the specified camera.*/
|
||||
bool setUpDepthPartitionForCamera(osg::Camera* cameraToPartition, DepthPartitionSettings* dps=0);
|
||||
|
||||
virtual void configure(osgViewer::View& view);
|
||||
virtual void configure(osgViewer::View& view) const;
|
||||
|
||||
protected:
|
||||
};
|
||||
|
36
include/osgViewer/config/AcrossAllScreens
Normal file
36
include/osgViewer/config/AcrossAllScreens
Normal file
@ -0,0 +1,36 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef OSGVIEWER_AcrossAllScreens
|
||||
#define OSGVIEWER_AcrossAllScreens 1
|
||||
|
||||
#include <osgViewer/Config>
|
||||
|
||||
namespace osgViewer {
|
||||
|
||||
class OSGVIEWER_EXPORT AcrossAllScreens : public Config
|
||||
{
|
||||
public:
|
||||
|
||||
AcrossAllScreens() {}
|
||||
AcrossAllScreens(const AcrossAllScreens& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): Config(rhs,copyop) {}
|
||||
|
||||
META_Object(osgViewer, AcrossAllScreens);
|
||||
|
||||
virtual void configure(osgViewer::View& view) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
149
include/osgViewer/config/PanoramicSphericalDisplay
Normal file
149
include/osgViewer/config/PanoramicSphericalDisplay
Normal file
@ -0,0 +1,149 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef OSGVIEWER_PanoramicSphericalDisplay
|
||||
#define OSGVIEWER_PanoramicSphericalDisplay 1
|
||||
|
||||
#include <osgViewer/Config>
|
||||
|
||||
namespace osgViewer {
|
||||
|
||||
/** spherical display by rendering main scene to a panoramic 2:1 texture and then doing distortion correction to present onto a spherical display.*/
|
||||
class OSGVIEWER_EXPORT PanoramicSphericalDisplay : public Config
|
||||
{
|
||||
public:
|
||||
|
||||
PanoramicSphericalDisplay(double radius=1.0, double collar=0.45, unsigned int screenNum=0, osg::Image* intensityMap=0, const osg::Matrixd& projectorMatrix = osg::Matrixd()):
|
||||
_radius(radius),
|
||||
_collar(collar),
|
||||
_screenNum(screenNum),
|
||||
_intensityMap(intensityMap),
|
||||
_projectorMatrix(projectorMatrix) {}
|
||||
|
||||
PanoramicSphericalDisplay(const PanoramicSphericalDisplay& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
|
||||
Config(rhs, copyop),
|
||||
_radius(rhs._radius),
|
||||
_collar(rhs._collar),
|
||||
_screenNum(rhs._screenNum),
|
||||
_intensityMap(rhs._intensityMap),
|
||||
_projectorMatrix(rhs._projectorMatrix) {}
|
||||
|
||||
|
||||
META_Object(osgViewer,PanoramicSphericalDisplay);
|
||||
|
||||
virtual void configure(osgViewer::View& view) const;
|
||||
|
||||
void setRadius(double r) { _radius = r; }
|
||||
double getRadius() const { return _radius; }
|
||||
|
||||
void setCollar(double r) { _collar = r; }
|
||||
double getCollar() const { return _collar; }
|
||||
|
||||
void setScreenNum(unsigned int n) { _screenNum = n; }
|
||||
unsigned int getScreenNum() const { return _screenNum; }
|
||||
|
||||
void setIntensityMap(osg::Image* im) { _intensityMap = im; }
|
||||
const osg::Image* getIntensityMap() const { return _intensityMap.get(); }
|
||||
|
||||
void setProjectionMatrix(const osg::Matrixd& m) { _projectorMatrix = m; }
|
||||
const osg::Matrixd& getProjectionMatrix() const { return _projectorMatrix; }
|
||||
|
||||
protected:
|
||||
|
||||
osg::Geometry* createParoramicSphericalDisplayDistortionMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector, double sphere_radius, double collar_radius, osg::Image* intensityMap, const osg::Matrix& projectorMatrix) const;
|
||||
|
||||
double _radius;
|
||||
double _collar;
|
||||
unsigned int _screenNum;
|
||||
osg::ref_ptr<osg::Image> _intensityMap;
|
||||
osg::Matrixd _projectorMatrix;
|
||||
};
|
||||
|
||||
#if 0
|
||||
/** autostereoscopic Philips WoWvx display.*/
|
||||
class OSGVIEWER_EXPORT ViewForWoWVxDisplay : public Config
|
||||
{
|
||||
public:
|
||||
|
||||
ViewForWoWVxDisplay();
|
||||
ViewForWoWVxDisplay(unsigned int screenNum, unsigned char wow_content, unsigned char wow_factor, unsigned char wow_offset, float wow_disparity_Zd, float wow_disparity_vz, float wow_disparity_M, float wow_disparity_C);
|
||||
ViewForWoWVxDisplay(const ViewForWoWVxDisplay& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Object(osgViewer,ViewForWoWVxDisplay);
|
||||
|
||||
virtual void configure(osgViewer::View& view) const;
|
||||
|
||||
void setScreenNum(unsigned int n) { _screenNum = n; }
|
||||
unsigned int getScreenNum() const { return _screenNum; }
|
||||
|
||||
void set(unsigned char c) { _wow_content = c; }
|
||||
double get() const { return _wow_content; }
|
||||
|
||||
void set(unsigned char c) { _wow_factor = c; }
|
||||
double get() const { return _wow_factor; }
|
||||
|
||||
void set(unsigned char c) { _wow_offset = c; }
|
||||
double get() const { return _wow_offset; }
|
||||
|
||||
void setWowDisparityZD(float c) { _wow_disparity_Zd = c; }
|
||||
float getWowDisparityZD() const { return _wow_disparity_Zd; }
|
||||
|
||||
void setWowDisparityVZ(float c) { _wow_disparity_vz = c; }
|
||||
float getWowDisparityVZ() const { return _wow_disparity_vz; }
|
||||
|
||||
void setWowDisparityM(float c) { _wow_disparity_M = c; }
|
||||
float getWowDisparityM() const { return _wow_disparity_M; }
|
||||
|
||||
void setWowDisparityC(float c) { _wow_disparity_C = c; }
|
||||
float getWowDisparityC() const { return _wow_disparity_C; }
|
||||
|
||||
protected:
|
||||
|
||||
unsigned int _screenNum;
|
||||
unsigned char _wow_content;
|
||||
unsigned char _wow_factor;
|
||||
unsigned char _wow_offset;
|
||||
float _wow_disparity_Zd;
|
||||
float _wow_disparity_vz;
|
||||
float _wow_disparity_M;
|
||||
float _wow_disparity_C;
|
||||
};
|
||||
|
||||
/** Configure view with DepthPartition.*/
|
||||
class OSGVIEWER_EXPORT DepthPartition : public Config
|
||||
{
|
||||
public:
|
||||
|
||||
DepthPartition(DepthPartitionSettings* dsp=0);
|
||||
|
||||
DepthPartition(const ViewForWoWVxDisplay& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Object(osgViewer,DepthPartition);
|
||||
|
||||
void setDepthPartionSettings(DepthPartitionSettings* dsp) const { _dps = dps; }
|
||||
const DepthPartitionSettings* getDepthPartionSettings() const { return _dps; }
|
||||
|
||||
/** for setting up depth partitioning on the specified camera.*/
|
||||
bool setUpDepthPartitionForCamera(osg::Camera* cameraToPartition, DepthPartitionSettings* dps=0);
|
||||
|
||||
virtual void configure(osgViewer::View& view) const;
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
43
include/osgViewer/config/SingleScreen
Normal file
43
include/osgViewer/config/SingleScreen
Normal file
@ -0,0 +1,43 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef OSGVIEWER_SingleScreen
|
||||
#define OSGVIEWER_SingleScreen 1
|
||||
|
||||
#include <osgViewer/Config>
|
||||
|
||||
namespace osgViewer {
|
||||
|
||||
/** single camera associated with a single full screen GraphicsWindow.*/
|
||||
class OSGVIEWER_EXPORT SingleScreen : public Config
|
||||
{
|
||||
public:
|
||||
|
||||
SingleScreen(unsigned int screenNum=0) : _screenNum(screenNum) {}
|
||||
SingleScreen(const SingleScreen& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : Config(rhs,copyop), _screenNum(rhs._screenNum) {}
|
||||
|
||||
META_Object(osgViewer, SingleScreen);
|
||||
|
||||
virtual void configure(osgViewer::View& view) const;
|
||||
|
||||
void setScreenNum(unsigned int sn) { _screenNum = sn; }
|
||||
unsigned int getScreenNum() const { return _screenNum; }
|
||||
|
||||
protected:
|
||||
|
||||
unsigned int _screenNum;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
57
include/osgViewer/config/SingleWindow
Normal file
57
include/osgViewer/config/SingleWindow
Normal file
@ -0,0 +1,57 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef OSGVIEWER_SingleWindow
|
||||
#define OSGVIEWER_SingleWindow 1
|
||||
|
||||
#include <osgViewer/Config>
|
||||
|
||||
namespace osgViewer {
|
||||
|
||||
/** single camera on a single window.*/
|
||||
class OSGVIEWER_EXPORT SingleWindow : public Config
|
||||
{
|
||||
public:
|
||||
|
||||
SingleWindow():_x(0),_y(0),_width(-1),_height(-1),_screenNum(0) {}
|
||||
SingleWindow(int x, int y, int width, int height, unsigned int screenNum=0):_x(x),_y(y),_width(width),_height(height),_screenNum(screenNum) {}
|
||||
SingleWindow(const SingleWindow& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):Config(rhs,copyop), _x(rhs._x),_y(rhs._y),_width(rhs._width),_height(rhs._height),_screenNum(rhs._screenNum) {}
|
||||
|
||||
META_Object(osgViewer,SingleWindow);
|
||||
|
||||
virtual void configure(osgViewer::View& view) const;
|
||||
|
||||
void setX(int x) { _x = x; }
|
||||
int getX() const { return _x; }
|
||||
|
||||
void setY(int y) { _y = y; }
|
||||
int getY() const { return _y; }
|
||||
|
||||
void setWidth(int w) { _width = w; }
|
||||
int getWidth() const { return _width; }
|
||||
|
||||
void setHeight(int h) { _height = h; }
|
||||
int getHeight() const { return _height; }
|
||||
|
||||
void setScreenNum(unsigned int sn) { _screenNum = sn; }
|
||||
unsigned int getScreenNum() const { return _screenNum; }
|
||||
|
||||
protected:
|
||||
|
||||
int _x, _y, _width, _height;
|
||||
unsigned int _screenNum;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
184
include/osgViewer/config/SphericalDisplay
Normal file
184
include/osgViewer/config/SphericalDisplay
Normal file
@ -0,0 +1,184 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef OSGVIEWER_SphericalDisplay
|
||||
#define OSGVIEWER_SphericalDisplay 1
|
||||
|
||||
#include <osgViewer/Config>
|
||||
|
||||
namespace osgViewer {
|
||||
|
||||
/** spherical display using 6 slave cameras rendering the 6 sides of a cube map, and 7th camera doing distortion correction to present on a spherical display.*/
|
||||
class OSGVIEWER_EXPORT SphericalDisplay : public Config
|
||||
{
|
||||
public:
|
||||
|
||||
SphericalDisplay(double radius=1.0, double collar=0.45, unsigned int screenNum=0, osg::Image* intensityMap=0, const osg::Matrixd& projectorMatrix = osg::Matrixd()):
|
||||
_radius(radius),
|
||||
_collar(collar),
|
||||
_screenNum(screenNum),
|
||||
_intensityMap(intensityMap),
|
||||
_projectorMatrix(projectorMatrix) {}
|
||||
|
||||
SphericalDisplay(const SphericalDisplay& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
|
||||
Config(rhs,copyop),
|
||||
_radius(rhs._radius),
|
||||
_collar(rhs._collar),
|
||||
_screenNum(rhs._screenNum),
|
||||
_intensityMap(rhs._intensityMap),
|
||||
_projectorMatrix(rhs._projectorMatrix) {}
|
||||
|
||||
META_Object(osgViewer,SphericalDisplay);
|
||||
|
||||
virtual void configure(osgViewer::View& view) const;
|
||||
|
||||
void setRadius(double r) { _radius = r; }
|
||||
double getRadius() const { return _radius; }
|
||||
|
||||
void setCollar(double r) { _collar = r; }
|
||||
double getCollar() const { return _collar; }
|
||||
|
||||
void setScreenNum(unsigned int n) { _screenNum = n; }
|
||||
unsigned int getScreenNum() const { return _screenNum; }
|
||||
|
||||
void setIntensityMap(osg::Image* im) { _intensityMap = im; }
|
||||
const osg::Image* getIntensityMap() const { return _intensityMap.get(); }
|
||||
|
||||
void setProjectionMatrix(const osg::Matrixd& m) { _projectorMatrix = m; }
|
||||
const osg::Matrixd& getProjectionMatrix() const { return _projectorMatrix; }
|
||||
|
||||
protected:
|
||||
|
||||
osg::Geometry* create3DSphericalDisplayDistortionMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector, double sphere_radius, double collar_radius,osg::Image* intensityMap, const osg::Matrix& projectorMatrix) const;
|
||||
|
||||
double _radius;
|
||||
double _collar;
|
||||
unsigned int _screenNum;
|
||||
osg::ref_ptr<osg::Image> _intensityMap;
|
||||
osg::Matrixd _projectorMatrix;
|
||||
};
|
||||
|
||||
#if 0
|
||||
/** spherical display by rendering main scene to a panoramic 2:1 texture and then doing distortion correction to present onto a spherical display.*/
|
||||
class OSGVIEWER_EXPORT ViewForPanoramicSphericalDisplay : public Config
|
||||
{
|
||||
public:
|
||||
|
||||
ViewForPanoramicSphericalDisplay(double radius=1.0, double collar=0.45, unsigned int screenNum=0, osg::Image* intensityMap=0, const osg::Matrixd& projectorMatrix = osg::Matrixd());
|
||||
ViewForPanoramicSphericalDisplay(const ViewForPanoramicSphericalDisplay& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Object(osgViewer,ViewOnSingleScreen);
|
||||
|
||||
virtual void configure(osgViewer::View& view) const;
|
||||
|
||||
void setRadius(double r) { _radius = r; }
|
||||
double getRadius() const { return _radius; }
|
||||
|
||||
void setCollar(double r) { _collar = r; }
|
||||
double getCollar() const { return _collar; }
|
||||
|
||||
void setScreenNum(unsigned int n) { _screenNum = n; }
|
||||
unsigned int getScreenNum() const { return _screenNum; }
|
||||
|
||||
void setIntensityMap(osg::Image* im) { _intensityMap = im; }
|
||||
const osg::Image* getIntensityMap() const { return _intensityMap; }
|
||||
|
||||
void setProjectionMatrix(const osg::Matrixd& m) { _projectorMatrix = m; }
|
||||
const osg::Matrixd& getProjectionMatrix() const { return _projectorMatrix; }
|
||||
|
||||
protected:
|
||||
|
||||
double _radius;
|
||||
double _collar;
|
||||
unsigned int _screenNum;
|
||||
osg::ref_ref<osg::Image> _intensityMap;
|
||||
osg::Matrixd _projectorMatrix;
|
||||
};
|
||||
|
||||
/** autostereoscopic Philips WoWvx display.*/
|
||||
class OSGVIEWER_EXPORT ViewForWoWVxDisplay : public Config
|
||||
{
|
||||
public:
|
||||
|
||||
ViewForWoWVxDisplay();
|
||||
ViewForWoWVxDisplay(unsigned int screenNum, unsigned char wow_content, unsigned char wow_factor, unsigned char wow_offset, float wow_disparity_Zd, float wow_disparity_vz, float wow_disparity_M, float wow_disparity_C);
|
||||
ViewForWoWVxDisplay(const ViewForWoWVxDisplay& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Object(osgViewer,ViewForWoWVxDisplay);
|
||||
|
||||
virtual void configure(osgViewer::View& view) const;
|
||||
|
||||
void setScreenNum(unsigned int n) { _screenNum = n; }
|
||||
unsigned int getScreenNum() const { return _screenNum; }
|
||||
|
||||
void set(unsigned char c) { _wow_content = c; }
|
||||
double get() const { return _wow_content; }
|
||||
|
||||
void set(unsigned char c) { _wow_factor = c; }
|
||||
double get() const { return _wow_factor; }
|
||||
|
||||
void set(unsigned char c) { _wow_offset = c; }
|
||||
double get() const { return _wow_offset; }
|
||||
|
||||
void setWowDisparityZD(float c) { _wow_disparity_Zd = c; }
|
||||
float getWowDisparityZD() const { return _wow_disparity_Zd; }
|
||||
|
||||
void setWowDisparityVZ(float c) { _wow_disparity_vz = c; }
|
||||
float getWowDisparityVZ() const { return _wow_disparity_vz; }
|
||||
|
||||
void setWowDisparityM(float c) { _wow_disparity_M = c; }
|
||||
float getWowDisparityM() const { return _wow_disparity_M; }
|
||||
|
||||
void setWowDisparityC(float c) { _wow_disparity_C = c; }
|
||||
float getWowDisparityC() const { return _wow_disparity_C; }
|
||||
|
||||
protected:
|
||||
|
||||
unsigned int _screenNum;
|
||||
unsigned char _wow_content;
|
||||
unsigned char _wow_factor;
|
||||
unsigned char _wow_offset;
|
||||
float _wow_disparity_Zd;
|
||||
float _wow_disparity_vz;
|
||||
float _wow_disparity_M;
|
||||
float _wow_disparity_C;
|
||||
};
|
||||
|
||||
/** Configure view with DepthPartition.*/
|
||||
class OSGVIEWER_EXPORT DepthPartition : public Config
|
||||
{
|
||||
public:
|
||||
|
||||
DepthPartition(DepthPartitionSettings* dsp=0);
|
||||
|
||||
DepthPartition(const ViewForWoWVxDisplay& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Object(osgViewer,DepthPartition);
|
||||
|
||||
void setDepthPartionSettings(DepthPartitionSettings* dsp) const { _dps = dps; }
|
||||
const DepthPartitionSettings* getDepthPartionSettings() const { return _dps; }
|
||||
|
||||
/** for setting up depth partitioning on the specified camera.*/
|
||||
bool setUpDepthPartitionForCamera(osg::Camera* cameraToPartition, DepthPartitionSettings* dps=0);
|
||||
|
||||
virtual void configure(osgViewer::View& view) const;
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
@ -23,7 +23,10 @@ SET(TARGET_H
|
||||
${HEADER_PATH}/ViewerEventHandlers
|
||||
)
|
||||
|
||||
FILE(GLOB LIB_COMMON_FILES config/*.cpp)
|
||||
|
||||
SET(LIB_COMMON_FILES
|
||||
${LIB_COMMON_FILES}
|
||||
CompositeViewer.cpp
|
||||
Config.cpp
|
||||
GraphicsWindow.cpp
|
||||
@ -41,6 +44,7 @@ SET(LIB_COMMON_FILES
|
||||
${OPENSCENEGRAPH_VERSIONINFO_RC}
|
||||
)
|
||||
|
||||
# Collect all the configuration files
|
||||
SET(LIB_EXTRA_LIBS)
|
||||
|
||||
IF(WIN32 AND NOT ANDROID)
|
||||
|
@ -12,29 +12,19 @@
|
||||
*/
|
||||
|
||||
#include <osgViewer/Config>
|
||||
#include <osgViewer/Renderer>
|
||||
#include <osgViewer/View>
|
||||
#include <osgViewer/GraphicsWindow>
|
||||
|
||||
#include <osg/io_utils>
|
||||
|
||||
#include <osg/TextureCubeMap>
|
||||
#include <osg/TextureRectangle>
|
||||
#include <osg/Texture1D>
|
||||
#include <osg/TexMat>
|
||||
#include <osg/Stencil>
|
||||
#include <osg/PolygonStipple>
|
||||
#include <osg/ValueObject>
|
||||
|
||||
#include <osgUtil/Optimizer>
|
||||
#include <osgUtil/ShaderGen>
|
||||
#include <osgUtil/IntersectionVisitor>
|
||||
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgDB/WriteFile>
|
||||
|
||||
using namespace osgViewer;
|
||||
|
||||
osg::DisplaySettings* Config::getActiveDisplaySetting(osgViewer::View& view) const
|
||||
{
|
||||
return view.getDisplaySettings() ? view.getDisplaySettings() : osg::DisplaySettings::instance().get();
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
void ViewAcrossAllScreens::configure(osgViewer::View& view) const
|
||||
{
|
||||
@ -45,7 +35,7 @@ void ViewAcrossAllScreens::configure(osgViewer::View& view) const
|
||||
return;
|
||||
}
|
||||
|
||||
osg::DisplaySettings* ds = view.getDisplaySettings()!=0 ? view.getDisplaySettings() : osg::DisplaySettings::instance().get();
|
||||
osg::DisplaySettings* ds = getActiveDisplaySetting(view);
|
||||
|
||||
double fovy, aspectRatio, zNear, zFar;
|
||||
view.getCamera()->getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar);
|
||||
@ -201,7 +191,7 @@ void ViewInWindow::configure(osgViewer::View& view) const
|
||||
return;
|
||||
}
|
||||
|
||||
osg::DisplaySettings* ds = view.getDisplaySettings() ? view.getDisplaySettings() : osg::DisplaySettings::instance().get();
|
||||
osg::DisplaySettings* ds = getActiveDisplaySetting(view);;
|
||||
|
||||
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits(ds);
|
||||
|
||||
@ -266,9 +256,7 @@ void ViewInWindow::configure(osgViewer::View& view) const
|
||||
view.getCamera()->setReadBuffer(buffer);
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
void View::setUpViewOnSingleScreen(unsigned int screenNum)
|
||||
void ViewOnSingleScreen::configure(osgViewer::View& view) const
|
||||
{
|
||||
osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
|
||||
if (!wsi)
|
||||
@ -277,7 +265,7 @@ void View::setUpViewOnSingleScreen(unsigned int screenNum)
|
||||
return;
|
||||
}
|
||||
|
||||
osg::DisplaySettings* ds = _displaySettings.valid() ? _displaySettings.get() : osg::DisplaySettings::instance().get();
|
||||
osg::DisplaySettings* ds = getActiveDisplaySetting(view);;
|
||||
|
||||
osg::GraphicsContext::ScreenIdentifier si;
|
||||
si.readDISPLAY();
|
||||
@ -285,7 +273,7 @@ void View::setUpViewOnSingleScreen(unsigned int screenNum)
|
||||
// displayNum has not been set so reset it to 0.
|
||||
if (si.displayNum<0) si.displayNum = 0;
|
||||
|
||||
si.screenNum = screenNum;
|
||||
si.screenNum = _screenNum;
|
||||
|
||||
unsigned int width, height;
|
||||
wsi->getScreenResolution(si, width, height);
|
||||
@ -335,7 +323,7 @@ void View::setUpViewOnSingleScreen(unsigned int screenNum)
|
||||
view.getCamera()->setReadBuffer(buffer);
|
||||
}
|
||||
|
||||
static osg::Geometry* create3DSphericalDisplayDistortionMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector, double sphere_radius, double collar_radius,osg::Image* intensityMap, const osg::Matrix& projectorMatrix)
|
||||
osg::Geometry* ViewFor3DSphericalDisplay::create3DSphericalDisplayDistortionMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector, double sphere_radius, double collar_radius,osg::Image* intensityMap, const osg::Matrix& projectorMatrix) const
|
||||
{
|
||||
osg::Vec3d center(0.0,0.0,0.0);
|
||||
osg::Vec3d eye(0.0,0.0,0.0);
|
||||
@ -488,9 +476,9 @@ static osg::Geometry* create3DSphericalDisplayDistortionMesh(const osg::Vec3& or
|
||||
return geometry;
|
||||
}
|
||||
|
||||
void View::setUpViewFor3DSphericalDisplay(double radius, double collar, unsigned int screenNum, osg::Image* intensityMap, const osg::Matrixd& projectorMatrix)
|
||||
void ViewFor3DSphericalDisplay::configure(osgViewer::View& view) const
|
||||
{
|
||||
OSG_INFO<<"View::setUpViewFor3DSphericalDisplay(rad="<<radius<<", cllr="<<collar<<", sn="<<screenNum<<", im="<<intensityMap<<")"<<std::endl;
|
||||
OSG_INFO<<"View::setUpViewFor3DSphericalDisplay(rad="<<_radius<<", cllr="<<_collar<<", sn="<<_screenNum<<", im="<<_intensityMap<<")"<<std::endl;
|
||||
osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
|
||||
if (!wsi)
|
||||
{
|
||||
@ -504,7 +492,7 @@ void View::setUpViewFor3DSphericalDisplay(double radius, double collar, unsigned
|
||||
// displayNum has not been set so reset it to 0.
|
||||
if (si.displayNum<0) si.displayNum = 0;
|
||||
|
||||
si.screenNum = screenNum;
|
||||
si.screenNum = _screenNum;
|
||||
|
||||
unsigned int width, height;
|
||||
wsi->getScreenResolution(si, width, height);
|
||||
@ -571,7 +559,7 @@ void View::setUpViewFor3DSphericalDisplay(double radius, double collar, unsigned
|
||||
// attach the texture and use it as the color buffer.
|
||||
camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::POSITIVE_Y);
|
||||
|
||||
addSlave(camera.get(), osg::Matrixd(), osg::Matrixd());
|
||||
view.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd());
|
||||
}
|
||||
|
||||
|
||||
@ -591,7 +579,7 @@ void View::setUpViewFor3DSphericalDisplay(double radius, double collar, unsigned
|
||||
// attach the texture and use it as the color buffer.
|
||||
camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::POSITIVE_Z);
|
||||
|
||||
addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(-90.0f), 1.0,0.0,0.0));
|
||||
view.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(-90.0f), 1.0,0.0,0.0));
|
||||
}
|
||||
|
||||
// left face
|
||||
@ -610,7 +598,7 @@ void View::setUpViewFor3DSphericalDisplay(double radius, double collar, unsigned
|
||||
// attach the texture and use it as the color buffer.
|
||||
camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::NEGATIVE_X);
|
||||
|
||||
addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(-90.0f), 0.0,1.0,0.0) * osg::Matrixd::rotate(osg::inDegrees(-90.0f), 0.0,0.0,1.0));
|
||||
view.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(-90.0f), 0.0,1.0,0.0) * osg::Matrixd::rotate(osg::inDegrees(-90.0f), 0.0,0.0,1.0));
|
||||
}
|
||||
|
||||
// right face
|
||||
@ -629,7 +617,7 @@ void View::setUpViewFor3DSphericalDisplay(double radius, double collar, unsigned
|
||||
// attach the texture and use it as the color buffer.
|
||||
camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::POSITIVE_X);
|
||||
|
||||
addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(90.0f), 0.0,1.0,0.0 ) * osg::Matrixd::rotate(osg::inDegrees(90.0f), 0.0,0.0,1.0));
|
||||
view.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(90.0f), 0.0,1.0,0.0 ) * osg::Matrixd::rotate(osg::inDegrees(90.0f), 0.0,0.0,1.0));
|
||||
}
|
||||
|
||||
// bottom face
|
||||
@ -648,7 +636,7 @@ void View::setUpViewFor3DSphericalDisplay(double radius, double collar, unsigned
|
||||
// attach the texture and use it as the color buffer.
|
||||
camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::NEGATIVE_Z);
|
||||
|
||||
addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(90.0f), 1.0,0.0,0.0) * osg::Matrixd::rotate(osg::inDegrees(180.0f), 0.0,0.0,1.0));
|
||||
view.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(90.0f), 1.0,0.0,0.0) * osg::Matrixd::rotate(osg::inDegrees(180.0f), 0.0,0.0,1.0));
|
||||
}
|
||||
|
||||
// back face
|
||||
@ -667,15 +655,15 @@ void View::setUpViewFor3DSphericalDisplay(double radius, double collar, unsigned
|
||||
// attach the texture and use it as the color buffer.
|
||||
camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::NEGATIVE_Y);
|
||||
|
||||
addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(180.0f), 1.0,0.0,0.0));
|
||||
view.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(180.0f), 1.0,0.0,0.0));
|
||||
}
|
||||
|
||||
getCamera()->setProjectionMatrixAsPerspective(90.0f, 1.0, 1, 1000.0);
|
||||
view.getCamera()->setProjectionMatrixAsPerspective(90.0f, 1.0, 1, 1000.0);
|
||||
|
||||
// distortion correction set up.
|
||||
{
|
||||
osg::Geode* geode = new osg::Geode();
|
||||
geode->addDrawable(create3DSphericalDisplayDistortionMesh(osg::Vec3(0.0f,0.0f,0.0f), osg::Vec3(width,0.0f,0.0f), osg::Vec3(0.0f,height,0.0f), radius, collar, applyIntensityMapAsColours ? intensityMap : 0, projectorMatrix));
|
||||
geode->addDrawable(create3DSphericalDisplayDistortionMesh(osg::Vec3(0.0f,0.0f,0.0f), osg::Vec3(width,0.0f,0.0f), osg::Vec3(0.0f,height,0.0f), _radius, _collar, applyIntensityMapAsColours ? _intensityMap.get() : 0, _projectorMatrix));
|
||||
|
||||
// new we need to add the texture to the mesh, we do so by creating a
|
||||
// StateSet to contain the Texture StateAttribute.
|
||||
@ -683,9 +671,9 @@ void View::setUpViewFor3DSphericalDisplay(double radius, double collar, unsigned
|
||||
stateset->setTextureAttributeAndModes(0, texture,osg::StateAttribute::ON);
|
||||
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
|
||||
|
||||
if (!applyIntensityMapAsColours && intensityMap)
|
||||
if (!applyIntensityMapAsColours && _intensityMap.valid())
|
||||
{
|
||||
stateset->setTextureAttributeAndModes(1, new osg::Texture2D(intensityMap), osg::StateAttribute::ON);
|
||||
stateset->setTextureAttributeAndModes(1, new osg::Texture2D(_intensityMap.get()), osg::StateAttribute::ON);
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
||||
@ -709,18 +697,19 @@ void View::setUpViewFor3DSphericalDisplay(double radius, double collar, unsigned
|
||||
|
||||
camera->setName("DistortionCorrectionCamera");
|
||||
|
||||
addSlave(camera.get(), osg::Matrixd(), osg::Matrixd(), false);
|
||||
view.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd(), false);
|
||||
}
|
||||
|
||||
getCamera()->setNearFarRatio(0.0001f);
|
||||
view.getCamera()->setNearFarRatio(0.0001f);
|
||||
|
||||
if (getLightingMode()==osg::View::HEADLIGHT)
|
||||
if (view.getLightingMode()==osg::View::HEADLIGHT)
|
||||
{
|
||||
// set a local light source for headlight to ensure that lighting is consistent across sides of cube.
|
||||
getLight()->setPosition(osg::Vec4(0.0f,0.0f,0.0f,1.0f));
|
||||
view.getLight()->setPosition(osg::Vec4(0.0f,0.0f,0.0f,1.0f));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static osg::Geometry* createParoramicSphericalDisplayDistortionMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector, double sphere_radius, double collar_radius, osg::Image* intensityMap, const osg::Matrix& projectorMatrix)
|
||||
{
|
||||
osg::Vec3d center(0.0,0.0,0.0);
|
||||
|
176
src/osgViewer/config/AcrossAllScreens.cpp
Normal file
176
src/osgViewer/config/AcrossAllScreens.cpp
Normal file
@ -0,0 +1,176 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* 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 <osgViewer/config/AcrossAllScreens>
|
||||
#include <osgViewer/Renderer>
|
||||
#include <osgViewer/View>
|
||||
#include <osgViewer/GraphicsWindow>
|
||||
|
||||
#include <osg/io_utils>
|
||||
|
||||
using namespace osgViewer;
|
||||
|
||||
void AcrossAllScreens::configure(osgViewer::View& view) const
|
||||
{
|
||||
osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
|
||||
if (!wsi)
|
||||
{
|
||||
OSG_NOTICE<<"AcrossAllScreens::configure() : Error, no WindowSystemInterface available, cannot create windows."<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
osg::DisplaySettings* ds = getActiveDisplaySetting(view);
|
||||
|
||||
double fovy, aspectRatio, zNear, zFar;
|
||||
view.getCamera()->getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar);
|
||||
|
||||
osg::GraphicsContext::ScreenIdentifier si;
|
||||
si.readDISPLAY();
|
||||
|
||||
// displayNum has not been set so reset it to 0.
|
||||
if (si.displayNum<0) si.displayNum = 0;
|
||||
|
||||
unsigned int numScreens = wsi->getNumScreens(si);
|
||||
if (numScreens==1)
|
||||
{
|
||||
if (si.screenNum<0) si.screenNum = 0;
|
||||
|
||||
unsigned int width, height;
|
||||
wsi->getScreenResolution(si, width, height);
|
||||
|
||||
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits(ds);
|
||||
traits->hostName = si.hostName;
|
||||
traits->displayNum = si.displayNum;
|
||||
traits->screenNum = si.screenNum;
|
||||
traits->x = 0;
|
||||
traits->y = 0;
|
||||
traits->width = width;
|
||||
traits->height = height;
|
||||
traits->windowDecoration = false;
|
||||
traits->doubleBuffer = true;
|
||||
traits->sharedContext = 0;
|
||||
|
||||
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
|
||||
|
||||
view.getCamera()->setGraphicsContext(gc.get());
|
||||
|
||||
osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(gc.get());
|
||||
if (gw)
|
||||
{
|
||||
OSG_INFO<<" GraphicsWindow has been created successfully."<<std::endl;
|
||||
gw->getEventQueue()->getCurrentEventState()->setWindowRectangle(0, 0, width, height );
|
||||
}
|
||||
else
|
||||
{
|
||||
OSG_NOTICE<<" GraphicsWindow has not been created successfully."<<std::endl;
|
||||
}
|
||||
|
||||
double newAspectRatio = double(traits->width) / double(traits->height);
|
||||
double aspectRatioChange = newAspectRatio / aspectRatio;
|
||||
if (aspectRatioChange != 1.0)
|
||||
{
|
||||
view.getCamera()->getProjectionMatrix() *= osg::Matrix::scale(1.0/aspectRatioChange,1.0,1.0);
|
||||
}
|
||||
|
||||
view.getCamera()->setViewport(new osg::Viewport(0, 0, traits->width, traits->height));
|
||||
|
||||
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
|
||||
|
||||
view.getCamera()->setDrawBuffer(buffer);
|
||||
view.getCamera()->setReadBuffer(buffer);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
double translate_x = 0.0;
|
||||
|
||||
for(unsigned int i=0; i<numScreens; ++i)
|
||||
{
|
||||
si.screenNum = i;
|
||||
|
||||
unsigned int width, height;
|
||||
wsi->getScreenResolution(si, width, height);
|
||||
translate_x += double(width) / (double(height) * aspectRatio);
|
||||
}
|
||||
|
||||
bool stereoSplitScreens = numScreens==2 &&
|
||||
ds->getStereoMode()==osg::DisplaySettings::HORIZONTAL_SPLIT &&
|
||||
ds->getStereo();
|
||||
|
||||
for(unsigned int i=0; i<numScreens; ++i)
|
||||
{
|
||||
si.screenNum = i;
|
||||
|
||||
unsigned int width, height;
|
||||
wsi->getScreenResolution(si, width, height);
|
||||
|
||||
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits(ds);
|
||||
traits->hostName = si.hostName;
|
||||
traits->displayNum = si.displayNum;
|
||||
traits->screenNum = si.screenNum;
|
||||
traits->screenNum = i;
|
||||
traits->x = 0;
|
||||
traits->y = 0;
|
||||
traits->width = width;
|
||||
traits->height = height;
|
||||
traits->windowDecoration = false;
|
||||
traits->doubleBuffer = true;
|
||||
traits->sharedContext = 0;
|
||||
|
||||
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
|
||||
|
||||
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
||||
camera->setGraphicsContext(gc.get());
|
||||
|
||||
osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(gc.get());
|
||||
if (gw)
|
||||
{
|
||||
OSG_INFO<<" GraphicsWindow has been created successfully."<<gw<<std::endl;
|
||||
|
||||
gw->getEventQueue()->getCurrentEventState()->setWindowRectangle(traits->x, traits->y, traits->width, traits->height );
|
||||
}
|
||||
else
|
||||
{
|
||||
OSG_NOTICE<<" GraphicsWindow has not been created successfully."<<std::endl;
|
||||
}
|
||||
|
||||
camera->setViewport(new osg::Viewport(0, 0, traits->width, traits->height));
|
||||
|
||||
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
|
||||
camera->setDrawBuffer(buffer);
|
||||
camera->setReadBuffer(buffer);
|
||||
|
||||
if (stereoSplitScreens)
|
||||
{
|
||||
unsigned int leftCameraNum = (ds->getSplitStereoHorizontalEyeMapping()==osg::DisplaySettings::LEFT_EYE_LEFT_VIEWPORT) ? 0 : 1;
|
||||
|
||||
osg::ref_ptr<osg::DisplaySettings> ds_local = new osg::DisplaySettings(*ds);
|
||||
ds_local->setStereoMode(leftCameraNum==i ? osg::DisplaySettings::LEFT_EYE : osg::DisplaySettings::RIGHT_EYE);
|
||||
camera->setDisplaySettings(ds_local.get());
|
||||
|
||||
view.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd() );
|
||||
}
|
||||
else
|
||||
{
|
||||
double newAspectRatio = double(traits->width) / double(traits->height);
|
||||
double aspectRatioChange = newAspectRatio / aspectRatio;
|
||||
|
||||
view.addSlave(camera.get(), osg::Matrixd::translate( translate_x - aspectRatioChange, 0.0, 0.0) * osg::Matrix::scale(1.0/aspectRatioChange,1.0,1.0), osg::Matrixd() );
|
||||
translate_x -= aspectRatioChange * 2.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
view.assignSceneDataToCameras();
|
||||
}
|
1643
src/osgViewer/config/PanormaicSphericalDisplay.cpp
Normal file
1643
src/osgViewer/config/PanormaicSphericalDisplay.cpp
Normal file
File diff suppressed because it is too large
Load Diff
88
src/osgViewer/config/SingleScreen.cpp
Normal file
88
src/osgViewer/config/SingleScreen.cpp
Normal file
@ -0,0 +1,88 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* 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 <osgViewer/config/SingleScreen>
|
||||
#include <osgViewer/Renderer>
|
||||
#include <osgViewer/View>
|
||||
#include <osgViewer/GraphicsWindow>
|
||||
|
||||
#include <osg/io_utils>
|
||||
|
||||
using namespace osgViewer;
|
||||
|
||||
void SingleScreen::configure(osgViewer::View& view) const
|
||||
{
|
||||
osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
|
||||
if (!wsi)
|
||||
{
|
||||
OSG_NOTICE<<"SingleScreen::configure() : Error, no WindowSystemInterface available, cannot create windows."<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
osg::DisplaySettings* ds = getActiveDisplaySetting(view);;
|
||||
|
||||
osg::GraphicsContext::ScreenIdentifier si;
|
||||
si.readDISPLAY();
|
||||
|
||||
// displayNum has not been set so reset it to 0.
|
||||
if (si.displayNum<0) si.displayNum = 0;
|
||||
|
||||
si.screenNum = _screenNum;
|
||||
|
||||
unsigned int width, height;
|
||||
wsi->getScreenResolution(si, width, height);
|
||||
|
||||
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits(ds);
|
||||
traits->hostName = si.hostName;
|
||||
traits->displayNum = si.displayNum;
|
||||
traits->screenNum = si.screenNum;
|
||||
traits->x = 0;
|
||||
traits->y = 0;
|
||||
traits->width = width;
|
||||
traits->height = height;
|
||||
traits->windowDecoration = false;
|
||||
traits->doubleBuffer = true;
|
||||
traits->sharedContext = 0;
|
||||
|
||||
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
|
||||
|
||||
view.getCamera()->setGraphicsContext(gc.get());
|
||||
|
||||
osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(gc.get());
|
||||
if (gw)
|
||||
{
|
||||
OSG_INFO<<"SingleScreen::configure() - GraphicsWindow has been created successfully."<<std::endl;
|
||||
gw->getEventQueue()->getCurrentEventState()->setWindowRectangle(0, 0, width, height );
|
||||
}
|
||||
else
|
||||
{
|
||||
OSG_NOTICE<<" GraphicsWindow has not been created successfully."<<std::endl;
|
||||
}
|
||||
|
||||
double fovy, aspectRatio, zNear, zFar;
|
||||
view.getCamera()->getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar);
|
||||
|
||||
double newAspectRatio = double(traits->width) / double(traits->height);
|
||||
double aspectRatioChange = newAspectRatio / aspectRatio;
|
||||
if (aspectRatioChange != 1.0)
|
||||
{
|
||||
view.getCamera()->getProjectionMatrix() *= osg::Matrix::scale(1.0/aspectRatioChange,1.0,1.0);
|
||||
}
|
||||
|
||||
view.getCamera()->setViewport(new osg::Viewport(0, 0, traits->width, traits->height));
|
||||
|
||||
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
|
||||
|
||||
view.getCamera()->setDrawBuffer(buffer);
|
||||
view.getCamera()->setReadBuffer(buffer);
|
||||
}
|
95
src/osgViewer/config/SingleWindow.cpp
Normal file
95
src/osgViewer/config/SingleWindow.cpp
Normal file
@ -0,0 +1,95 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* 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 <osgViewer/config/SingleWindow>
|
||||
#include <osgViewer/Renderer>
|
||||
#include <osgViewer/View>
|
||||
#include <osgViewer/GraphicsWindow>
|
||||
|
||||
#include <osg/io_utils>
|
||||
|
||||
using namespace osgViewer;
|
||||
|
||||
void SingleWindow::configure(osgViewer::View& view) const
|
||||
{
|
||||
osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
|
||||
if (!wsi)
|
||||
{
|
||||
OSG_NOTICE<<"SingleWindow::configure() : Error, no WindowSystemInterface available, cannot create windows."<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
osg::DisplaySettings* ds = getActiveDisplaySetting(view);;
|
||||
|
||||
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits(ds);
|
||||
|
||||
traits->readDISPLAY();
|
||||
if (traits->displayNum<0) traits->displayNum = 0;
|
||||
|
||||
traits->screenNum = _screenNum;
|
||||
traits->x = _x;
|
||||
traits->y = _y;
|
||||
traits->width = _width;
|
||||
traits->height = _height;
|
||||
traits->windowDecoration = true;
|
||||
traits->doubleBuffer = true;
|
||||
traits->sharedContext = 0;
|
||||
|
||||
if (traits->width<=0 || traits->height<=0 )
|
||||
{
|
||||
osg::GraphicsContext::ScreenIdentifier si;
|
||||
si.readDISPLAY();
|
||||
|
||||
// displayNum has not been set so reset it to 0.
|
||||
if (si.displayNum<0) si.displayNum = 0;
|
||||
|
||||
si.screenNum = _screenNum;
|
||||
|
||||
unsigned int width, height;
|
||||
wsi->getScreenResolution(si, width, height);
|
||||
if (traits->width<=0) traits->width = width;
|
||||
if (traits->height<=0) traits->height = height;
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
|
||||
|
||||
view.getCamera()->setGraphicsContext(gc.get());
|
||||
|
||||
osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(gc.get());
|
||||
if (gw)
|
||||
{
|
||||
OSG_INFO<<"View::setUpViewOnSingleScreen - GraphicsWindow has been created successfully."<<std::endl;
|
||||
gw->getEventQueue()->getCurrentEventState()->setWindowRectangle(traits->x, traits->y, traits->width, traits->height );
|
||||
}
|
||||
else
|
||||
{
|
||||
OSG_NOTICE<<" GraphicsWindow has not been created successfully."<<std::endl;
|
||||
}
|
||||
|
||||
double fovy, aspectRatio, zNear, zFar;
|
||||
view.getCamera()->getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar);
|
||||
|
||||
double newAspectRatio = double(traits->width) / double(traits->height);
|
||||
double aspectRatioChange = newAspectRatio / aspectRatio;
|
||||
if (aspectRatioChange != 1.0)
|
||||
{
|
||||
view.getCamera()->getProjectionMatrix() *= osg::Matrix::scale(1.0/aspectRatioChange,1.0,1.0);
|
||||
}
|
||||
|
||||
view.getCamera()->setViewport(new osg::Viewport(0, 0, traits->width, traits->height));
|
||||
|
||||
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
|
||||
|
||||
view.getCamera()->setDrawBuffer(buffer);
|
||||
view.getCamera()->setReadBuffer(buffer);
|
||||
}
|
416
src/osgViewer/config/SphericalDisplay.cpp
Normal file
416
src/osgViewer/config/SphericalDisplay.cpp
Normal file
@ -0,0 +1,416 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* 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 <osgViewer/config/SphericalDisplay>
|
||||
#include <osgViewer/Renderer>
|
||||
#include <osgViewer/View>
|
||||
#include <osgViewer/GraphicsWindow>
|
||||
|
||||
#include <osg/io_utils>
|
||||
|
||||
#include <osg/TextureCubeMap>
|
||||
#include <osg/TextureRectangle>
|
||||
#include <osg/Texture1D>
|
||||
#include <osg/Texture2D>
|
||||
#include <osg/TexMat>
|
||||
#include <osg/Stencil>
|
||||
#include <osg/PolygonStipple>
|
||||
#include <osg/ValueObject>
|
||||
|
||||
using namespace osgViewer;
|
||||
|
||||
osg::Geometry* SphericalDisplay::create3DSphericalDisplayDistortionMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector, double sphere_radius, double collar_radius,osg::Image* intensityMap, const osg::Matrix& projectorMatrix) const
|
||||
{
|
||||
osg::Vec3d center(0.0,0.0,0.0);
|
||||
osg::Vec3d eye(0.0,0.0,0.0);
|
||||
|
||||
double distance = sqrt(sphere_radius*sphere_radius - collar_radius*collar_radius);
|
||||
|
||||
bool centerProjection = false;
|
||||
|
||||
osg::Vec3d projector = eye - osg::Vec3d(0.0,0.0, distance);
|
||||
|
||||
OSG_INFO<<"create3DSphericalDisplayDistortionMesh : Projector position = "<<projector<<std::endl;
|
||||
OSG_INFO<<"create3DSphericalDisplayDistortionMesh : distance = "<<distance<<std::endl;
|
||||
|
||||
|
||||
// create the quad to visualize.
|
||||
osg::Geometry* geometry = new osg::Geometry();
|
||||
|
||||
geometry->setSupportsDisplayList(false);
|
||||
|
||||
osg::Vec3 xAxis(widthVector);
|
||||
float width = widthVector.length();
|
||||
xAxis /= width;
|
||||
|
||||
osg::Vec3 yAxis(heightVector);
|
||||
float height = heightVector.length();
|
||||
yAxis /= height;
|
||||
|
||||
int noSteps = 50;
|
||||
|
||||
osg::Vec3Array* vertices = new osg::Vec3Array;
|
||||
osg::Vec3Array* texcoords0 = new osg::Vec3Array;
|
||||
osg::Vec2Array* texcoords1 = intensityMap==0 ? new osg::Vec2Array : 0;
|
||||
osg::Vec4Array* colors = new osg::Vec4Array;
|
||||
|
||||
osg::Vec3 bottom = origin;
|
||||
osg::Vec3 dx = xAxis*(width/((float)(noSteps-1)));
|
||||
osg::Vec3 dy = yAxis*(height/((float)(noSteps-1)));
|
||||
|
||||
osg::Vec3d screenCenter = origin + widthVector*0.5f + heightVector*0.5f;
|
||||
float screenRadius = heightVector.length() * 0.5f;
|
||||
|
||||
int i,j;
|
||||
|
||||
if (centerProjection)
|
||||
{
|
||||
for(i=0;i<noSteps;++i)
|
||||
{
|
||||
osg::Vec3 cursor = bottom+dy*(float)i;
|
||||
for(j=0;j<noSteps;++j)
|
||||
{
|
||||
osg::Vec2 delta(cursor.x() - screenCenter.x(), cursor.y() - screenCenter.y());
|
||||
double theta = atan2(-delta.y(), delta.x());
|
||||
double phi = osg::PI_2 * delta.length() / screenRadius;
|
||||
if (phi > osg::PI_2) phi = osg::PI_2;
|
||||
|
||||
phi *= 2.0;
|
||||
|
||||
if (theta<0.0) theta += 2.0*osg::PI;
|
||||
|
||||
// OSG_NOTICE<<"theta = "<<theta<< "phi="<<phi<<std::endl;
|
||||
|
||||
osg::Vec3 texcoord(sin(phi) * cos(theta),
|
||||
sin(phi) * sin(theta),
|
||||
cos(phi));
|
||||
|
||||
vertices->push_back(cursor);
|
||||
texcoords0->push_back(texcoord * projectorMatrix);
|
||||
|
||||
osg::Vec2 texcoord1(theta/(2.0*osg::PI), 1.0f - phi/osg::PI_2);
|
||||
if (intensityMap)
|
||||
{
|
||||
colors->push_back(intensityMap->getColor(texcoord1));
|
||||
}
|
||||
else
|
||||
{
|
||||
colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
|
||||
if (texcoords1) texcoords1->push_back( texcoord1 );
|
||||
}
|
||||
|
||||
cursor += dx;
|
||||
}
|
||||
// OSG_NOTICE<<std::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(i=0;i<noSteps;++i)
|
||||
{
|
||||
osg::Vec3 cursor = bottom+dy*(float)i;
|
||||
for(j=0;j<noSteps;++j)
|
||||
{
|
||||
osg::Vec2 delta(cursor.x() - screenCenter.x(), cursor.y() - screenCenter.y());
|
||||
double theta = atan2(-delta.y(), delta.x());
|
||||
double phi = osg::PI_2 * delta.length() / screenRadius;
|
||||
if (phi > osg::PI_2) phi = osg::PI_2;
|
||||
if (theta<0.0) theta += 2.0*osg::PI;
|
||||
|
||||
// OSG_NOTICE<<"theta = "<<theta<< "phi="<<phi<<std::endl;
|
||||
|
||||
double f = distance * sin(phi);
|
||||
double e = distance * cos(phi) + sqrt( sphere_radius*sphere_radius - f*f);
|
||||
double l = e * cos(phi);
|
||||
double h = e * sin(phi);
|
||||
double z = l - distance;
|
||||
|
||||
osg::Vec3 texcoord(h * cos(theta) / sphere_radius,
|
||||
h * sin(theta) / sphere_radius,
|
||||
z / sphere_radius);
|
||||
|
||||
vertices->push_back(cursor);
|
||||
texcoords0->push_back(texcoord * projectorMatrix);
|
||||
|
||||
osg::Vec2 texcoord1(theta/(2.0*osg::PI), 1.0f - phi/osg::PI_2);
|
||||
if (intensityMap)
|
||||
{
|
||||
colors->push_back(intensityMap->getColor(texcoord1));
|
||||
}
|
||||
else
|
||||
{
|
||||
colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
|
||||
if (texcoords1) texcoords1->push_back( texcoord1 );
|
||||
}
|
||||
|
||||
cursor += dx;
|
||||
}
|
||||
// OSG_NOTICE<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// pass the created vertex array to the points geometry object.
|
||||
geometry->setVertexArray(vertices);
|
||||
|
||||
geometry->setColorArray(colors);
|
||||
geometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
|
||||
|
||||
geometry->setTexCoordArray(0,texcoords0);
|
||||
if (texcoords1) geometry->setTexCoordArray(1,texcoords1);
|
||||
|
||||
for(i=0;i<noSteps-1;++i)
|
||||
{
|
||||
osg::DrawElementsUShort* elements = new osg::DrawElementsUShort(osg::PrimitiveSet::QUAD_STRIP);
|
||||
for(j=0;j<noSteps;++j)
|
||||
{
|
||||
elements->push_back(j+(i+1)*noSteps);
|
||||
elements->push_back(j+(i)*noSteps);
|
||||
}
|
||||
geometry->addPrimitiveSet(elements);
|
||||
}
|
||||
|
||||
return geometry;
|
||||
}
|
||||
|
||||
void SphericalDisplay::configure(osgViewer::View& view) const
|
||||
{
|
||||
OSG_INFO<<"SphericalDisplay::configure(rad="<<_radius<<", cllr="<<_collar<<", sn="<<_screenNum<<", im="<<_intensityMap<<")"<<std::endl;
|
||||
osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
|
||||
if (!wsi)
|
||||
{
|
||||
OSG_NOTICE<<"Error, no WindowSystemInterface available, cannot create windows."<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
osg::GraphicsContext::ScreenIdentifier si;
|
||||
si.readDISPLAY();
|
||||
|
||||
// displayNum has not been set so reset it to 0.
|
||||
if (si.displayNum<0) si.displayNum = 0;
|
||||
|
||||
si.screenNum = _screenNum;
|
||||
|
||||
unsigned int width, height;
|
||||
wsi->getScreenResolution(si, width, height);
|
||||
|
||||
|
||||
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
|
||||
traits->hostName = si.hostName;
|
||||
traits->displayNum = si.displayNum;
|
||||
traits->screenNum = si.screenNum;
|
||||
traits->x = 0;
|
||||
traits->y = 0;
|
||||
traits->width = width;
|
||||
traits->height = height;
|
||||
traits->windowDecoration = false;
|
||||
traits->doubleBuffer = true;
|
||||
traits->sharedContext = 0;
|
||||
|
||||
|
||||
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
|
||||
if (!gc)
|
||||
{
|
||||
OSG_NOTICE<<"GraphicsWindow has not been created successfully."<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
bool applyIntensityMapAsColours = true;
|
||||
|
||||
int tex_width = 512;
|
||||
int tex_height = 512;
|
||||
|
||||
int camera_width = tex_width;
|
||||
int camera_height = tex_height;
|
||||
|
||||
osg::TextureCubeMap* texture = new osg::TextureCubeMap;
|
||||
|
||||
texture->setTextureSize(tex_width, tex_height);
|
||||
texture->setInternalFormat(GL_RGB);
|
||||
texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);
|
||||
texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);
|
||||
texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE);
|
||||
texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE);
|
||||
texture->setWrap(osg::Texture::WRAP_R,osg::Texture::CLAMP_TO_EDGE);
|
||||
|
||||
#if 0
|
||||
osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::SEPERATE_WINDOW;
|
||||
GLenum buffer = GL_FRONT;
|
||||
#else
|
||||
osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::FRAME_BUFFER_OBJECT;
|
||||
GLenum buffer = GL_FRONT;
|
||||
#endif
|
||||
|
||||
// front face
|
||||
{
|
||||
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
||||
camera->setName("Front face camera");
|
||||
camera->setGraphicsContext(gc.get());
|
||||
camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height));
|
||||
camera->setDrawBuffer(buffer);
|
||||
camera->setReadBuffer(buffer);
|
||||
camera->setAllowEventFocus(false);
|
||||
// tell the camera to use OpenGL frame buffer object where supported.
|
||||
camera->setRenderTargetImplementation(renderTargetImplementation);
|
||||
|
||||
// attach the texture and use it as the color buffer.
|
||||
camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::POSITIVE_Y);
|
||||
|
||||
view.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd());
|
||||
}
|
||||
|
||||
|
||||
// top face
|
||||
{
|
||||
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
||||
camera->setName("Top face camera");
|
||||
camera->setGraphicsContext(gc.get());
|
||||
camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height));
|
||||
camera->setDrawBuffer(buffer);
|
||||
camera->setReadBuffer(buffer);
|
||||
camera->setAllowEventFocus(false);
|
||||
|
||||
// tell the camera to use OpenGL frame buffer object where supported.
|
||||
camera->setRenderTargetImplementation(renderTargetImplementation);
|
||||
|
||||
// attach the texture and use it as the color buffer.
|
||||
camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::POSITIVE_Z);
|
||||
|
||||
view.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(-90.0f), 1.0,0.0,0.0));
|
||||
}
|
||||
|
||||
// left face
|
||||
{
|
||||
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
||||
camera->setName("Left face camera");
|
||||
camera->setGraphicsContext(gc.get());
|
||||
camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height));
|
||||
camera->setDrawBuffer(buffer);
|
||||
camera->setReadBuffer(buffer);
|
||||
camera->setAllowEventFocus(false);
|
||||
|
||||
// tell the camera to use OpenGL frame buffer object where supported.
|
||||
camera->setRenderTargetImplementation(renderTargetImplementation);
|
||||
|
||||
// attach the texture and use it as the color buffer.
|
||||
camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::NEGATIVE_X);
|
||||
|
||||
view.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(-90.0f), 0.0,1.0,0.0) * osg::Matrixd::rotate(osg::inDegrees(-90.0f), 0.0,0.0,1.0));
|
||||
}
|
||||
|
||||
// right face
|
||||
{
|
||||
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
||||
camera->setName("Right face camera");
|
||||
camera->setGraphicsContext(gc.get());
|
||||
camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height));
|
||||
camera->setDrawBuffer(buffer);
|
||||
camera->setReadBuffer(buffer);
|
||||
camera->setAllowEventFocus(false);
|
||||
|
||||
// tell the camera to use OpenGL frame buffer object where supported.
|
||||
camera->setRenderTargetImplementation(renderTargetImplementation);
|
||||
|
||||
// attach the texture and use it as the color buffer.
|
||||
camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::POSITIVE_X);
|
||||
|
||||
view.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(90.0f), 0.0,1.0,0.0 ) * osg::Matrixd::rotate(osg::inDegrees(90.0f), 0.0,0.0,1.0));
|
||||
}
|
||||
|
||||
// bottom face
|
||||
{
|
||||
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
||||
camera->setGraphicsContext(gc.get());
|
||||
camera->setName("Bottom face camera");
|
||||
camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height));
|
||||
camera->setDrawBuffer(buffer);
|
||||
camera->setReadBuffer(buffer);
|
||||
camera->setAllowEventFocus(false);
|
||||
|
||||
// tell the camera to use OpenGL frame buffer object where supported.
|
||||
camera->setRenderTargetImplementation(renderTargetImplementation);
|
||||
|
||||
// attach the texture and use it as the color buffer.
|
||||
camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::NEGATIVE_Z);
|
||||
|
||||
view.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(90.0f), 1.0,0.0,0.0) * osg::Matrixd::rotate(osg::inDegrees(180.0f), 0.0,0.0,1.0));
|
||||
}
|
||||
|
||||
// back face
|
||||
{
|
||||
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
||||
camera->setName("Back face camera");
|
||||
camera->setGraphicsContext(gc.get());
|
||||
camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height));
|
||||
camera->setDrawBuffer(buffer);
|
||||
camera->setReadBuffer(buffer);
|
||||
camera->setAllowEventFocus(false);
|
||||
|
||||
// tell the camera to use OpenGL frame buffer object where supported.
|
||||
camera->setRenderTargetImplementation(renderTargetImplementation);
|
||||
|
||||
// attach the texture and use it as the color buffer.
|
||||
camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::NEGATIVE_Y);
|
||||
|
||||
view.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(180.0f), 1.0,0.0,0.0));
|
||||
}
|
||||
|
||||
view.getCamera()->setProjectionMatrixAsPerspective(90.0f, 1.0, 1, 1000.0);
|
||||
|
||||
// distortion correction set up.
|
||||
{
|
||||
osg::Geode* geode = new osg::Geode();
|
||||
geode->addDrawable(create3DSphericalDisplayDistortionMesh(osg::Vec3(0.0f,0.0f,0.0f), osg::Vec3(width,0.0f,0.0f), osg::Vec3(0.0f,height,0.0f), _radius, _collar, applyIntensityMapAsColours ? _intensityMap.get() : 0, _projectorMatrix));
|
||||
|
||||
// new we need to add the texture to the mesh, we do so by creating a
|
||||
// StateSet to contain the Texture StateAttribute.
|
||||
osg::StateSet* stateset = geode->getOrCreateStateSet();
|
||||
stateset->setTextureAttributeAndModes(0, texture,osg::StateAttribute::ON);
|
||||
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
|
||||
|
||||
if (!applyIntensityMapAsColours && _intensityMap.valid())
|
||||
{
|
||||
stateset->setTextureAttributeAndModes(1, new osg::Texture2D(_intensityMap.get()), osg::StateAttribute::ON);
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
||||
camera->setGraphicsContext(gc.get());
|
||||
camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );
|
||||
camera->setClearColor( osg::Vec4(0.0,0.0,0.0,1.0) );
|
||||
camera->setViewport(new osg::Viewport(0, 0, width, height));
|
||||
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
|
||||
camera->setDrawBuffer(buffer);
|
||||
camera->setReadBuffer(buffer);
|
||||
camera->setReferenceFrame(osg::Camera::ABSOLUTE_RF);
|
||||
camera->setAllowEventFocus(true);
|
||||
camera->setInheritanceMask(camera->getInheritanceMask() & ~osg::CullSettings::CLEAR_COLOR & ~osg::CullSettings::COMPUTE_NEAR_FAR_MODE);
|
||||
//camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
|
||||
|
||||
camera->setProjectionMatrixAsOrtho2D(0,width,0,height);
|
||||
camera->setViewMatrix(osg::Matrix::identity());
|
||||
|
||||
// add subgraph to render
|
||||
camera->addChild(geode);
|
||||
|
||||
camera->setName("DistortionCorrectionCamera");
|
||||
|
||||
view.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd(), false);
|
||||
}
|
||||
|
||||
view.getCamera()->setNearFarRatio(0.0001f);
|
||||
|
||||
if (view.getLightingMode()==osg::View::HEADLIGHT)
|
||||
{
|
||||
// set a local light source for headlight to ensure that lighting is consistent across sides of cube.
|
||||
view.getLight()->setPosition(osg::Vec4(0.0f,0.0f,0.0f,1.0f));
|
||||
}
|
||||
}
|
12
src/osgWrappers/serializers/osgViewer/AcrossAllScreens.cpp
Normal file
12
src/osgWrappers/serializers/osgViewer/AcrossAllScreens.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
#include <osgViewer/config/AcrossAllScreens>
|
||||
|
||||
#include <osgDB/ObjectWrapper>
|
||||
#include <osgDB/InputStream>
|
||||
#include <osgDB/OutputStream>
|
||||
|
||||
REGISTER_OBJECT_WRAPPER( osgViewer_AcrossAllScreens,
|
||||
new osgViewer::AcrossAllScreens,
|
||||
osgViewer::AcrossAllScreens,
|
||||
"osg::Object osgViewer::Config osgViewer::AcrossAllScreens" )
|
||||
{
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
#include <osgViewer/config/PanoramicSphericalDisplay>
|
||||
|
||||
#include <osgDB/ObjectWrapper>
|
||||
#include <osgDB/InputStream>
|
||||
#include <osgDB/OutputStream>
|
||||
|
||||
REGISTER_OBJECT_WRAPPER( osgViewer_PanoramicSphericalDisplay,
|
||||
new osgViewer::PanoramicSphericalDisplay,
|
||||
osgViewer::PanoramicSphericalDisplay,
|
||||
"osg::Object osgViewer::Config osgViewer::PanoramicSphericalDisplay" )
|
||||
{
|
||||
ADD_DOUBLE_SERIALIZER(Radius, 1.0);
|
||||
ADD_DOUBLE_SERIALIZER(Collar, 0.45);
|
||||
ADD_UINT_SERIALIZER(ScreenNum, 0u);
|
||||
ADD_IMAGE_SERIALIZER(IntensityMap, osg::Image, NULL);
|
||||
ADD_MATRIXD_SERIALIZER(ProjectionMatrix, osg::Matrixd() );
|
||||
}
|
13
src/osgWrappers/serializers/osgViewer/SingleScreen.cpp
Normal file
13
src/osgWrappers/serializers/osgViewer/SingleScreen.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
#include <osgViewer/config/SingleScreen>
|
||||
|
||||
#include <osgDB/ObjectWrapper>
|
||||
#include <osgDB/InputStream>
|
||||
#include <osgDB/OutputStream>
|
||||
|
||||
REGISTER_OBJECT_WRAPPER( osgViewer_SingleScreen,
|
||||
new osgViewer::SingleScreen,
|
||||
osgViewer::SingleScreen,
|
||||
"osg::Object osgViewer::Config osgViewer::SingleScreen" )
|
||||
{
|
||||
ADD_UINT_SERIALIZER( ScreenNum, 0u);
|
||||
}
|
@ -1,13 +1,13 @@
|
||||
#include <osgViewer/Config>
|
||||
#include <osgViewer/config/SingleWindow>
|
||||
|
||||
#include <osgDB/ObjectWrapper>
|
||||
#include <osgDB/InputStream>
|
||||
#include <osgDB/OutputStream>
|
||||
|
||||
REGISTER_OBJECT_WRAPPER( osgViewer_ViewInWindow,
|
||||
new osgViewer::ViewInWindow,
|
||||
osgViewer::ViewInWindow,
|
||||
"osg::Object osgViewer::Config osgViewer::ViewInWindow" )
|
||||
REGISTER_OBJECT_WRAPPER( osgViewer_SingleWindow,
|
||||
new osgViewer::SingleWindow,
|
||||
osgViewer::SingleWindow,
|
||||
"osg::Object osgViewer::Config osgViewer::SingleWindow" )
|
||||
{
|
||||
ADD_INT_SERIALIZER( X, 0);
|
||||
ADD_INT_SERIALIZER( Y, 0);
|
17
src/osgWrappers/serializers/osgViewer/SphericalDisplay.cpp
Normal file
17
src/osgWrappers/serializers/osgViewer/SphericalDisplay.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
#include <osgViewer/config/SphericalDisplay>
|
||||
|
||||
#include <osgDB/ObjectWrapper>
|
||||
#include <osgDB/InputStream>
|
||||
#include <osgDB/OutputStream>
|
||||
|
||||
REGISTER_OBJECT_WRAPPER( osgViewer_SphericalDisplay,
|
||||
new osgViewer::SphericalDisplay,
|
||||
osgViewer::SphericalDisplay,
|
||||
"osg::Object osgViewer::Config osgViewer::SphericalDisplay" )
|
||||
{
|
||||
ADD_DOUBLE_SERIALIZER(Radius, 1.0);
|
||||
ADD_DOUBLE_SERIALIZER(Collar, 0.45);
|
||||
ADD_UINT_SERIALIZER(ScreenNum, 0u);
|
||||
ADD_IMAGE_SERIALIZER(IntensityMap, osg::Image, NULL);
|
||||
ADD_MATRIXD_SERIALIZER(ProjectionMatrix, osg::Matrixd() );
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
#include <osgViewer/Config>
|
||||
|
||||
#include <osgDB/ObjectWrapper>
|
||||
#include <osgDB/InputStream>
|
||||
#include <osgDB/OutputStream>
|
||||
|
||||
REGISTER_OBJECT_WRAPPER( osgViewer_ViewAcrossAllScreens,
|
||||
new osgViewer::ViewAcrossAllScreens,
|
||||
osgViewer::ViewAcrossAllScreens,
|
||||
"osg::Object osgViewer::Config osgViewer::ViewAcrossAllScreens" )
|
||||
{
|
||||
}
|
Loading…
Reference in New Issue
Block a user