2007-06-12 22:20:16 +08:00
|
|
|
/* OpenSceneGraph example, osgdistortion.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2003-12-28 06:17:41 +08:00
|
|
|
#include <osg/GLExtensions>
|
|
|
|
#include <osg/Node>
|
|
|
|
#include <osg/Geometry>
|
|
|
|
#include <osg/Notify>
|
|
|
|
#include <osg/MatrixTransform>
|
|
|
|
#include <osg/Texture2D>
|
|
|
|
#include <osg/Stencil>
|
|
|
|
#include <osg/ColorMask>
|
|
|
|
#include <osg/Depth>
|
|
|
|
#include <osg/Billboard>
|
|
|
|
#include <osg/Material>
|
|
|
|
#include <osg/Projection>
|
2007-02-21 05:06:24 +08:00
|
|
|
#include <osg/TextureCubeMap>
|
|
|
|
#include <osg/io_utils>
|
2003-12-28 06:17:41 +08:00
|
|
|
|
2007-02-22 03:41:03 +08:00
|
|
|
|
2003-12-28 06:17:41 +08:00
|
|
|
#include <osgGA/TrackballManipulator>
|
|
|
|
#include <osgGA/FlightManipulator>
|
|
|
|
#include <osgGA/DriveManipulator>
|
2007-02-22 03:41:03 +08:00
|
|
|
#include <osgGA/KeySwitchMatrixManipulator>
|
2007-02-21 05:06:24 +08:00
|
|
|
#include <osgGA/StateSetManipulator>
|
2007-02-22 03:41:03 +08:00
|
|
|
#include <osgGA/AnimationPathManipulator>
|
|
|
|
#include <osgGA/TerrainManipulator>
|
2003-12-28 06:17:41 +08:00
|
|
|
|
|
|
|
#include <osgUtil/SmoothingVisitor>
|
|
|
|
|
|
|
|
#include <osgDB/Registry>
|
|
|
|
#include <osgDB/ReadFile>
|
|
|
|
|
2007-01-07 05:35:57 +08:00
|
|
|
#include <osgViewer/Viewer>
|
2007-06-06 19:21:13 +08:00
|
|
|
#include <osgViewer/ViewerEventHandlers>
|
2003-12-28 06:17:41 +08:00
|
|
|
|
2007-06-08 20:13:33 +08:00
|
|
|
#include <iostream>
|
|
|
|
|
2004-01-29 23:47:51 +08:00
|
|
|
using namespace osg;
|
|
|
|
|
2015-03-16 20:13:44 +08:00
|
|
|
struct CommandLineOptions
|
2003-12-28 06:17:41 +08:00
|
|
|
{
|
2015-03-16 20:13:44 +08:00
|
|
|
unsigned int width;
|
|
|
|
unsigned int height;
|
|
|
|
unsigned int tex_width;
|
|
|
|
unsigned int tex_height;
|
|
|
|
double sphere_radius;
|
|
|
|
double collar_radius;
|
|
|
|
double distance;
|
|
|
|
|
|
|
|
CommandLineOptions():
|
|
|
|
width(1024),
|
|
|
|
height(1024),
|
|
|
|
tex_width(1024),
|
|
|
|
tex_height(1024),
|
|
|
|
sphere_radius(1.0),
|
|
|
|
collar_radius(0.45),
|
|
|
|
distance(1.0)
|
|
|
|
{
|
|
|
|
|
|
|
|
osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
|
|
|
|
if (!wsi)
|
|
|
|
{
|
|
|
|
osg::notify(osg::NOTICE)<<"Error, no WindowSystemInterface available, cannot create windows."<<std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-09-09 00:18:33 +08:00
|
|
|
osg::GraphicsContext::ScreenIdentifier main_screen_id;
|
|
|
|
|
|
|
|
main_screen_id.readDISPLAY();
|
|
|
|
main_screen_id.setUndefinedScreenDetailsToDefaultScreen();
|
|
|
|
wsi->getScreenResolution(main_screen_id, width, height);
|
2015-03-16 20:13:44 +08:00
|
|
|
distance = sqrt(sphere_radius*sphere_radius - collar_radius*collar_radius);
|
|
|
|
}
|
|
|
|
|
|
|
|
void read(osg::ArgumentParser& arguments)
|
|
|
|
{
|
|
|
|
while (arguments.read("--width",width)) {}
|
|
|
|
while (arguments.read("--height",height)) {}
|
|
|
|
while (arguments.read("--texture-width",tex_width) || arguments.read("--tx",tex_width) ) {}
|
|
|
|
while (arguments.read("--texture-height",tex_height) || arguments.read("--ty",tex_height) ) {}
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2015-03-16 20:13:44 +08:00
|
|
|
while (arguments.read("--radius", sphere_radius)) {}
|
|
|
|
while (arguments.read("--collar", collar_radius)) {}
|
|
|
|
|
|
|
|
distance = sqrt(sphere_radius*sphere_radius - collar_radius*collar_radius);
|
|
|
|
while (arguments.read("--distance", distance)) {}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-03-21 01:58:34 +08:00
|
|
|
|
|
|
|
class WindowResizedHandler : public osgGA::GUIEventHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
WindowResizedHandler()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-06-08 18:07:56 +08:00
|
|
|
virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& /*aa*/, osg::Object* object, osg::NodeVisitor* nv)
|
2015-03-21 01:58:34 +08:00
|
|
|
{
|
|
|
|
osg::Camera* camera = dynamic_cast<osg::Camera*>(object);
|
|
|
|
if (!camera) return false;
|
|
|
|
|
|
|
|
const osg::FrameStamp* fs = nv->getFrameStamp();
|
|
|
|
|
|
|
|
if (ea.getEventType()==osgGA::GUIEventAdapter::RESIZE)
|
|
|
|
{
|
|
|
|
OSG_NOTICE<<"Window resized event context="<<ea.getGraphicsContext()<<" frameNumber = "<<fs->getFrameNumber()<<std::endl;
|
|
|
|
OSG_NOTICE<<" WindowX="<<ea.getWindowX()<<std::endl;
|
|
|
|
OSG_NOTICE<<" WindowY="<<ea.getWindowY()<<std::endl;
|
|
|
|
OSG_NOTICE<<" WindowWidth="<<ea.getWindowWidth()<<std::endl;
|
|
|
|
OSG_NOTICE<<" WindowHeight="<<ea.getWindowHeight()<<std::endl;
|
|
|
|
|
2015-04-13 18:43:56 +08:00
|
|
|
// reset the Camera viewport and associated Texture's to make sure it tracks the new window size.
|
2015-04-01 00:23:43 +08:00
|
|
|
camera->resize(ea.getWindowWidth(), ea.getWindowHeight());
|
2015-03-21 01:58:34 +08:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2015-03-16 20:13:44 +08:00
|
|
|
osg::Node* createDistortionSubgraph(CommandLineOptions& options, osg::Node* subgraph, const osg::Vec4& clearColour)
|
|
|
|
{
|
|
|
|
osg::Group* distortionNode = new osg::Group;
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2005-07-09 22:35:35 +08:00
|
|
|
osg::Texture2D* texture = new osg::Texture2D;
|
2015-03-16 20:13:44 +08:00
|
|
|
texture->setTextureSize(options.tex_width, options.tex_height);
|
2005-07-09 22:35:35 +08:00
|
|
|
texture->setInternalFormat(GL_RGBA);
|
|
|
|
texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR);
|
|
|
|
texture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);
|
2015-03-19 18:49:17 +08:00
|
|
|
texture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::CLAMP_TO_EDGE);
|
|
|
|
texture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::CLAMP_TO_EDGE);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2005-07-09 22:35:35 +08:00
|
|
|
// set up the render to texture camera.
|
2003-12-28 06:17:41 +08:00
|
|
|
{
|
2006-11-27 22:52:07 +08:00
|
|
|
osg::Camera* camera = new osg::Camera;
|
2003-12-28 06:17:41 +08:00
|
|
|
|
2005-07-20 00:30:55 +08:00
|
|
|
// set clear the color and depth buffer
|
|
|
|
camera->setClearColor(clearColour);
|
|
|
|
camera->setClearMask(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
2005-07-09 22:35:35 +08:00
|
|
|
// just inherit the main cameras view
|
|
|
|
camera->setReferenceFrame(osg::Transform::RELATIVE_RF);
|
|
|
|
camera->setProjectionMatrix(osg::Matrixd::identity());
|
|
|
|
camera->setViewMatrix(osg::Matrixd::identity());
|
2003-12-28 06:17:41 +08:00
|
|
|
|
2005-07-09 22:35:35 +08:00
|
|
|
// set viewport
|
2015-03-16 20:13:44 +08:00
|
|
|
camera->setViewport(0,0,options.tex_width,options.tex_height);
|
2003-12-28 06:17:41 +08:00
|
|
|
|
2005-07-09 22:35:35 +08:00
|
|
|
// set the camera to render before the main camera.
|
2006-11-27 22:52:07 +08:00
|
|
|
camera->setRenderOrder(osg::Camera::PRE_RENDER);
|
2003-12-28 06:17:41 +08:00
|
|
|
|
2005-07-09 22:35:35 +08:00
|
|
|
// tell the camera to use OpenGL frame buffer object where supported.
|
2006-11-27 22:52:07 +08:00
|
|
|
camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
|
2003-12-28 06:17:41 +08:00
|
|
|
|
2005-07-09 22:35:35 +08:00
|
|
|
// attach the texture and use it as the color buffer.
|
2006-11-27 22:52:07 +08:00
|
|
|
camera->attach(osg::Camera::COLOR_BUFFER, texture);
|
2003-12-28 06:17:41 +08:00
|
|
|
|
2005-07-09 22:35:35 +08:00
|
|
|
// add subgraph to render
|
|
|
|
camera->addChild(subgraph);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2005-07-09 22:35:35 +08:00
|
|
|
distortionNode->addChild(camera);
|
2015-03-21 01:58:34 +08:00
|
|
|
|
|
|
|
camera->addEventCallback(new WindowResizedHandler());
|
2005-07-09 22:35:35 +08:00
|
|
|
}
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2007-02-21 05:06:24 +08:00
|
|
|
// set up the hud camera
|
2005-07-09 22:35:35 +08:00
|
|
|
{
|
|
|
|
// create the quad to visualize.
|
|
|
|
osg::Geometry* polyGeom = new osg::Geometry();
|
2003-12-28 06:17:41 +08:00
|
|
|
|
2005-07-09 22:35:35 +08:00
|
|
|
polyGeom->setSupportsDisplayList(false);
|
2003-12-28 06:17:41 +08:00
|
|
|
|
2005-07-09 22:35:35 +08:00
|
|
|
osg::Vec3 origin(0.0f,0.0f,0.0f);
|
|
|
|
osg::Vec3 xAxis(1.0f,0.0f,0.0f);
|
|
|
|
osg::Vec3 yAxis(0.0f,1.0f,0.0f);
|
|
|
|
float height = 1024.0f;
|
|
|
|
float width = 1280.0f;
|
|
|
|
int noSteps = 50;
|
2003-12-28 06:17:41 +08:00
|
|
|
|
2005-07-09 22:35:35 +08:00
|
|
|
osg::Vec3Array* vertices = new osg::Vec3Array;
|
|
|
|
osg::Vec2Array* texcoords = new osg::Vec2Array;
|
|
|
|
osg::Vec4Array* colors = new osg::Vec4Array;
|
2003-12-28 06:17:41 +08:00
|
|
|
|
2005-07-09 22:35:35 +08:00
|
|
|
osg::Vec3 bottom = origin;
|
|
|
|
osg::Vec3 dx = xAxis*(width/((float)(noSteps-1)));
|
|
|
|
osg::Vec3 dy = yAxis*(height/((float)(noSteps-1)));
|
2003-12-28 06:17:41 +08:00
|
|
|
|
2005-07-09 22:35:35 +08:00
|
|
|
osg::Vec2 bottom_texcoord(0.0f,0.0f);
|
|
|
|
osg::Vec2 dx_texcoord(1.0f/(float)(noSteps-1),0.0f);
|
|
|
|
osg::Vec2 dy_texcoord(0.0f,1.0f/(float)(noSteps-1));
|
2003-12-28 06:17:41 +08:00
|
|
|
|
2005-07-09 22:35:35 +08:00
|
|
|
int i,j;
|
|
|
|
for(i=0;i<noSteps;++i)
|
2003-12-28 06:17:41 +08:00
|
|
|
{
|
2005-07-09 22:35:35 +08:00
|
|
|
osg::Vec3 cursor = bottom+dy*(float)i;
|
|
|
|
osg::Vec2 texcoord = bottom_texcoord+dy_texcoord*(float)i;
|
|
|
|
for(j=0;j<noSteps;++j)
|
|
|
|
{
|
|
|
|
vertices->push_back(cursor);
|
|
|
|
texcoords->push_back(osg::Vec2((sin(texcoord.x()*osg::PI-osg::PI*0.5)+1.0f)*0.5f,(sin(texcoord.y()*osg::PI-osg::PI*0.5)+1.0f)*0.5f));
|
|
|
|
colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
|
|
|
|
|
|
|
|
cursor += dx;
|
|
|
|
texcoord += dx_texcoord;
|
|
|
|
}
|
2003-12-28 06:17:41 +08:00
|
|
|
}
|
|
|
|
|
2005-07-09 22:35:35 +08:00
|
|
|
// pass the created vertex array to the points geometry object.
|
|
|
|
polyGeom->setVertexArray(vertices);
|
2003-12-28 06:17:41 +08:00
|
|
|
|
2013-06-27 17:54:12 +08:00
|
|
|
polyGeom->setColorArray(colors, osg::Array::BIND_PER_VERTEX);
|
2003-12-28 06:17:41 +08:00
|
|
|
|
2005-07-09 22:35:35 +08:00
|
|
|
polyGeom->setTexCoordArray(0,texcoords);
|
2003-12-28 06:17:41 +08:00
|
|
|
|
|
|
|
|
2005-07-09 22:35:35 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
polyGeom->addPrimitiveSet(elements);
|
|
|
|
}
|
2003-12-28 06:17:41 +08:00
|
|
|
|
|
|
|
|
2013-06-27 17:54:12 +08:00
|
|
|
// new we need to add the texture to the Drawable, we do so by creating a
|
2005-07-09 22:35:35 +08:00
|
|
|
// StateSet to contain the Texture StateAttribute.
|
|
|
|
osg::StateSet* stateset = polyGeom->getOrCreateStateSet();
|
|
|
|
stateset->setTextureAttributeAndModes(0, texture,osg::StateAttribute::ON);
|
|
|
|
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
|
2003-12-28 06:17:41 +08:00
|
|
|
|
2005-07-09 22:35:35 +08:00
|
|
|
osg::Geode* geode = new osg::Geode();
|
|
|
|
geode->addDrawable(polyGeom);
|
2003-12-28 06:17:41 +08:00
|
|
|
|
2005-07-09 22:35:35 +08:00
|
|
|
// set up the camera to render the textured quad
|
2006-11-27 22:52:07 +08:00
|
|
|
osg::Camera* camera = new osg::Camera;
|
2003-12-28 06:17:41 +08:00
|
|
|
|
2005-07-09 22:35:35 +08:00
|
|
|
// just inherit the main cameras view
|
|
|
|
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
|
|
|
|
camera->setViewMatrix(osg::Matrix::identity());
|
|
|
|
camera->setProjectionMatrixAsOrtho2D(0,1280,0,1024);
|
2003-12-28 06:17:41 +08:00
|
|
|
|
2005-07-09 22:35:35 +08:00
|
|
|
// set the camera to render before the main camera.
|
2006-11-27 22:52:07 +08:00
|
|
|
camera->setRenderOrder(osg::Camera::NESTED_RENDER);
|
2003-12-28 06:17:41 +08:00
|
|
|
|
2005-07-09 22:35:35 +08:00
|
|
|
// add subgraph to render
|
|
|
|
camera->addChild(geode);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2005-07-09 22:35:35 +08:00
|
|
|
distortionNode->addChild(camera);
|
2003-12-28 06:17:41 +08:00
|
|
|
}
|
2005-07-09 22:35:35 +08:00
|
|
|
return distortionNode;
|
2003-12-28 06:17:41 +08:00
|
|
|
}
|
|
|
|
|
2015-03-16 20:13:44 +08:00
|
|
|
void setDomeFaces(osgViewer::Viewer& viewer, CommandLineOptions& options)
|
2007-02-20 19:44:10 +08:00
|
|
|
{
|
|
|
|
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
|
|
|
|
traits->x = 0;
|
|
|
|
traits->y = 0;
|
2015-03-16 20:13:44 +08:00
|
|
|
traits->width = options.width;
|
|
|
|
traits->height = options.height;
|
2007-02-20 19:44:10 +08:00
|
|
|
traits->windowDecoration = true;
|
|
|
|
traits->doubleBuffer = true;
|
|
|
|
traits->sharedContext = 0;
|
2018-09-09 00:18:33 +08:00
|
|
|
traits->readDISPLAY();
|
|
|
|
traits->setUndefinedScreenDetailsToDefaultScreen();
|
2007-02-20 19:44:10 +08:00
|
|
|
|
|
|
|
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
|
|
|
|
if (!gc)
|
|
|
|
{
|
|
|
|
osg::notify(osg::NOTICE)<<"GraphicsWindow has not been created successfully."<<std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-16 20:13:44 +08:00
|
|
|
int center_x = options.width/2;
|
|
|
|
int center_y = options.height/2;
|
2007-02-20 19:44:10 +08:00
|
|
|
int camera_width = 256;
|
|
|
|
int camera_height = 256;
|
|
|
|
|
|
|
|
// front face
|
|
|
|
{
|
|
|
|
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
|
|
|
camera->setGraphicsContext(gc.get());
|
|
|
|
camera->setViewport(new osg::Viewport(center_x-camera_width/2, center_y, camera_width, camera_height));
|
2007-02-22 03:41:03 +08:00
|
|
|
|
2007-02-20 19:44:10 +08:00
|
|
|
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
|
|
|
|
camera->setDrawBuffer(buffer);
|
|
|
|
camera->setReadBuffer(buffer);
|
|
|
|
|
|
|
|
viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd());
|
|
|
|
}
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2007-02-20 19:44:10 +08:00
|
|
|
// top face
|
|
|
|
{
|
|
|
|
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
|
|
|
camera->setGraphicsContext(gc.get());
|
|
|
|
camera->setViewport(new osg::Viewport(center_x-camera_width/2, center_y+camera_height, camera_width, camera_height));
|
|
|
|
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
|
|
|
|
camera->setDrawBuffer(buffer);
|
|
|
|
camera->setReadBuffer(buffer);
|
|
|
|
|
|
|
|
viewer.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->setGraphicsContext(gc.get());
|
|
|
|
camera->setViewport(new osg::Viewport(center_x-camera_width*3/2, center_y, camera_width, camera_height));
|
|
|
|
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
|
|
|
|
camera->setDrawBuffer(buffer);
|
|
|
|
camera->setReadBuffer(buffer);
|
|
|
|
|
|
|
|
viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(-90.0f), 0.0,1.0,0.0));
|
|
|
|
}
|
|
|
|
|
|
|
|
// right face
|
|
|
|
{
|
|
|
|
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
|
|
|
camera->setGraphicsContext(gc.get());
|
|
|
|
camera->setViewport(new osg::Viewport(center_x+camera_width/2, center_y, camera_width, camera_height));
|
|
|
|
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
|
|
|
|
camera->setDrawBuffer(buffer);
|
|
|
|
camera->setReadBuffer(buffer);
|
|
|
|
|
|
|
|
viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(90.0f), 0.0,1.0,0.0));
|
|
|
|
}
|
|
|
|
|
|
|
|
// bottom face
|
|
|
|
{
|
|
|
|
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
|
|
|
camera->setGraphicsContext(gc.get());
|
|
|
|
camera->setViewport(new osg::Viewport(center_x-camera_width/2, center_y-camera_height, camera_width, camera_height));
|
|
|
|
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
|
|
|
|
camera->setDrawBuffer(buffer);
|
|
|
|
camera->setReadBuffer(buffer);
|
|
|
|
|
|
|
|
viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(90.0f), 1.0,0.0,0.0));
|
|
|
|
}
|
|
|
|
|
|
|
|
// back face
|
|
|
|
{
|
|
|
|
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
|
|
|
camera->setGraphicsContext(gc.get());
|
|
|
|
camera->setViewport(new osg::Viewport(center_x-camera_width/2, center_y-2*camera_height, camera_width, camera_height));
|
|
|
|
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
|
|
|
|
camera->setDrawBuffer(buffer);
|
|
|
|
camera->setReadBuffer(buffer);
|
|
|
|
|
|
|
|
viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(-180.0f), 1.0,0.0,0.0));
|
|
|
|
}
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2007-02-20 19:44:10 +08:00
|
|
|
viewer.getCamera()->setProjectionMatrixAsPerspective(90.0f, 1.0, 1, 1000.0);
|
|
|
|
|
|
|
|
viewer.assignSceneDataToCameras();
|
|
|
|
}
|
2003-12-28 06:17:41 +08:00
|
|
|
|
2007-02-23 00:42:59 +08:00
|
|
|
osg::Geometry* createDomeDistortionMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector,
|
2015-03-16 20:13:44 +08:00
|
|
|
CommandLineOptions& options)
|
2007-02-22 19:17:45 +08:00
|
|
|
{
|
2007-02-23 00:42:59 +08:00
|
|
|
osg::Vec3d center(0.0,0.0,0.0);
|
|
|
|
osg::Vec3d eye(0.0,0.0,0.0);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2007-03-03 00:14:44 +08:00
|
|
|
bool centerProjection = false;
|
|
|
|
|
2015-03-16 20:13:44 +08:00
|
|
|
osg::Vec3d projector = eye - osg::Vec3d(0.0,0.0, options.distance);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
|
|
|
|
2007-02-23 00:42:59 +08:00
|
|
|
osg::notify(osg::NOTICE)<<"Projector position = "<<projector<<std::endl;
|
2015-03-16 20:13:44 +08:00
|
|
|
osg::notify(osg::NOTICE)<<"distance = "<<options.distance<<std::endl;
|
2007-02-23 00:42:59 +08:00
|
|
|
|
|
|
|
|
2007-02-22 19:17:45 +08:00
|
|
|
// 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;
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2007-03-03 00:14:44 +08:00
|
|
|
int noSteps = 50;
|
2007-02-22 19:17:45 +08:00
|
|
|
|
|
|
|
osg::Vec3Array* vertices = new osg::Vec3Array;
|
|
|
|
osg::Vec3Array* texcoords = new osg::Vec3Array;
|
|
|
|
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)));
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2007-02-23 00:42:59 +08:00
|
|
|
osg::Vec3d screenCenter = origin + widthVector*0.5f + heightVector*0.5f;
|
|
|
|
float screenRadius = heightVector.length() * 0.5f;
|
2007-02-22 19:17:45 +08:00
|
|
|
|
|
|
|
int i,j;
|
2007-03-03 00:14:44 +08:00
|
|
|
if (centerProjection)
|
2007-02-22 19:17:45 +08:00
|
|
|
{
|
2007-03-03 00:14:44 +08:00
|
|
|
for(i=0;i<noSteps;++i)
|
2007-02-22 19:17:45 +08:00
|
|
|
{
|
2007-03-03 00:14:44 +08:00
|
|
|
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;
|
|
|
|
|
|
|
|
// osg::notify(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);
|
|
|
|
colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
|
|
|
|
texcoords->push_back(texcoord);
|
|
|
|
|
|
|
|
cursor += dx;
|
|
|
|
}
|
|
|
|
// osg::notify(osg::NOTICE)<<std::endl;
|
2007-02-22 19:17:45 +08:00
|
|
|
}
|
|
|
|
}
|
2007-03-03 00:14:44 +08:00
|
|
|
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;
|
|
|
|
|
|
|
|
// osg::notify(osg::NOTICE)<<"theta = "<<theta<< "phi="<<phi<<std::endl;
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2015-03-16 20:13:44 +08:00
|
|
|
double f = options.distance * sin(phi);
|
|
|
|
double e = options.distance * cos(phi) + sqrt( options.sphere_radius*options.sphere_radius - f*f);
|
2007-03-03 00:14:44 +08:00
|
|
|
double l = e * cos(phi);
|
|
|
|
double h = e * sin(phi);
|
2015-03-16 20:13:44 +08:00
|
|
|
double z = l - options.distance;
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2015-03-16 20:13:44 +08:00
|
|
|
osg::Vec3 texcoord(h * cos(theta) / options.sphere_radius,
|
|
|
|
h * sin(theta) / options.sphere_radius,
|
|
|
|
z / options.sphere_radius);
|
2007-03-03 00:14:44 +08:00
|
|
|
|
|
|
|
vertices->push_back(cursor);
|
|
|
|
colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
|
|
|
|
texcoords->push_back(texcoord);
|
2007-02-22 19:17:45 +08:00
|
|
|
|
2007-03-03 00:14:44 +08:00
|
|
|
cursor += dx;
|
|
|
|
}
|
|
|
|
// osg::notify(osg::NOTICE)<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2007-02-22 19:17:45 +08:00
|
|
|
// pass the created vertex array to the points geometry object.
|
|
|
|
geometry->setVertexArray(vertices);
|
|
|
|
|
2013-06-27 17:54:12 +08:00
|
|
|
geometry->setColorArray(colors, osg::Array::BIND_PER_VERTEX);
|
2007-02-22 19:17:45 +08:00
|
|
|
|
|
|
|
geometry->setTexCoordArray(0,texcoords);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2007-02-22 19:17:45 +08:00
|
|
|
return geometry;
|
2007-04-06 23:36:13 +08:00
|
|
|
}
|
2007-02-22 19:17:45 +08:00
|
|
|
|
2015-03-16 20:13:44 +08:00
|
|
|
void setDomeCorrection(osgViewer::Viewer& viewer, CommandLineOptions& options)
|
2007-02-21 05:06:24 +08:00
|
|
|
{
|
|
|
|
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
|
|
|
|
traits->x = 0;
|
|
|
|
traits->y = 0;
|
2015-03-16 20:13:44 +08:00
|
|
|
traits->width = options.width;
|
|
|
|
traits->height = options.height;
|
2007-02-21 05:06:24 +08:00
|
|
|
traits->windowDecoration = false;
|
|
|
|
traits->doubleBuffer = true;
|
|
|
|
traits->sharedContext = 0;
|
2018-09-09 00:18:33 +08:00
|
|
|
traits->readDISPLAY();
|
|
|
|
traits->setUndefinedScreenDetailsToDefaultScreen();
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2007-02-21 05:06:24 +08:00
|
|
|
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
|
|
|
|
if (!gc)
|
|
|
|
{
|
|
|
|
osg::notify(osg::NOTICE)<<"GraphicsWindow has not been created successfully."<<std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-16 20:13:44 +08:00
|
|
|
int camera_width = options.tex_width;
|
|
|
|
int camera_height = options.tex_height;
|
2007-02-22 19:17:45 +08:00
|
|
|
|
2007-02-21 05:06:24 +08:00
|
|
|
osg::TextureCubeMap* texture = new osg::TextureCubeMap;
|
2007-02-22 19:17:45 +08:00
|
|
|
|
2015-03-16 20:13:44 +08:00
|
|
|
texture->setTextureSize(options.tex_width, options.tex_height);
|
2007-02-21 05:06:24 +08:00
|
|
|
texture->setInternalFormat(GL_RGB);
|
2007-02-22 03:41:03 +08:00
|
|
|
texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);
|
|
|
|
texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);
|
2015-03-16 20:13:44 +08:00
|
|
|
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);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
|
|
|
#if 0
|
2007-02-22 03:41:03 +08:00
|
|
|
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
|
2007-02-21 05:06:24 +08:00
|
|
|
|
|
|
|
// front face
|
|
|
|
{
|
|
|
|
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
|
|
|
camera->setName("Front face camera");
|
|
|
|
camera->setGraphicsContext(gc.get());
|
2007-02-22 03:41:03 +08:00
|
|
|
camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height));
|
2007-02-21 05:06:24 +08:00
|
|
|
camera->setDrawBuffer(buffer);
|
|
|
|
camera->setReadBuffer(buffer);
|
2007-02-22 03:41:03 +08:00
|
|
|
camera->setAllowEventFocus(false);
|
|
|
|
// tell the camera to use OpenGL frame buffer object where supported.
|
|
|
|
camera->setRenderTargetImplementation(renderTargetImplementation);
|
|
|
|
|
2007-02-21 05:06:24 +08:00
|
|
|
// attach the texture and use it as the color buffer.
|
2007-02-23 00:42:59 +08:00
|
|
|
camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::POSITIVE_Y);
|
2007-02-22 19:17:45 +08:00
|
|
|
|
2007-02-21 05:06:24 +08:00
|
|
|
viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd());
|
|
|
|
}
|
2007-02-22 03:41:03 +08:00
|
|
|
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2007-02-21 05:06:24 +08:00
|
|
|
// top face
|
|
|
|
{
|
|
|
|
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
|
|
|
camera->setName("Top face camera");
|
|
|
|
camera->setGraphicsContext(gc.get());
|
2007-02-22 03:41:03 +08:00
|
|
|
camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height));
|
2016-05-26 17:35:33 +08:00
|
|
|
GLenum cbuffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
|
|
|
|
camera->setDrawBuffer(cbuffer);
|
|
|
|
camera->setReadBuffer(cbuffer);
|
2007-02-22 03:41:03 +08:00
|
|
|
camera->setAllowEventFocus(false);
|
|
|
|
|
|
|
|
// tell the camera to use OpenGL frame buffer object where supported.
|
|
|
|
camera->setRenderTargetImplementation(renderTargetImplementation);
|
2007-02-21 05:06:24 +08:00
|
|
|
|
|
|
|
// attach the texture and use it as the color buffer.
|
2007-02-23 00:42:59 +08:00
|
|
|
camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::POSITIVE_Z);
|
2007-02-21 05:06:24 +08:00
|
|
|
|
|
|
|
viewer.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());
|
2007-02-22 03:41:03 +08:00
|
|
|
camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height));
|
2007-02-21 05:06:24 +08:00
|
|
|
camera->setDrawBuffer(buffer);
|
|
|
|
camera->setReadBuffer(buffer);
|
2007-02-22 03:41:03 +08:00
|
|
|
camera->setAllowEventFocus(false);
|
|
|
|
|
|
|
|
// tell the camera to use OpenGL frame buffer object where supported.
|
|
|
|
camera->setRenderTargetImplementation(renderTargetImplementation);
|
2007-02-21 05:06:24 +08:00
|
|
|
|
|
|
|
// attach the texture and use it as the color buffer.
|
|
|
|
camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::NEGATIVE_X);
|
|
|
|
|
2007-02-23 00:42:59 +08:00
|
|
|
viewer.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));
|
2007-02-21 05:06:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// right face
|
|
|
|
{
|
|
|
|
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
|
|
|
camera->setName("Right face camera");
|
|
|
|
camera->setGraphicsContext(gc.get());
|
2007-02-22 03:41:03 +08:00
|
|
|
camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height));
|
2007-02-21 05:06:24 +08:00
|
|
|
camera->setDrawBuffer(buffer);
|
|
|
|
camera->setReadBuffer(buffer);
|
2007-02-22 03:41:03 +08:00
|
|
|
camera->setAllowEventFocus(false);
|
|
|
|
|
|
|
|
// tell the camera to use OpenGL frame buffer object where supported.
|
|
|
|
camera->setRenderTargetImplementation(renderTargetImplementation);
|
2007-02-21 05:06:24 +08:00
|
|
|
|
|
|
|
// attach the texture and use it as the color buffer.
|
2007-02-23 00:42:59 +08:00
|
|
|
camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::POSITIVE_X);
|
2007-02-21 05:06:24 +08:00
|
|
|
|
2007-02-23 00:42:59 +08:00
|
|
|
viewer.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));
|
2007-02-21 05:06:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// bottom face
|
|
|
|
{
|
|
|
|
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
|
|
|
camera->setGraphicsContext(gc.get());
|
|
|
|
camera->setName("Bottom face camera");
|
2007-02-22 03:41:03 +08:00
|
|
|
camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height));
|
2007-02-21 05:06:24 +08:00
|
|
|
camera->setDrawBuffer(buffer);
|
|
|
|
camera->setReadBuffer(buffer);
|
2007-02-22 03:41:03 +08:00
|
|
|
camera->setAllowEventFocus(false);
|
|
|
|
|
|
|
|
// tell the camera to use OpenGL frame buffer object where supported.
|
|
|
|
camera->setRenderTargetImplementation(renderTargetImplementation);
|
2007-02-21 05:06:24 +08:00
|
|
|
|
|
|
|
// attach the texture and use it as the color buffer.
|
2007-02-23 00:42:59 +08:00
|
|
|
camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::NEGATIVE_Z);
|
2007-02-21 05:06:24 +08:00
|
|
|
|
2007-02-23 00:42:59 +08:00
|
|
|
viewer.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));
|
2007-02-21 05:06:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// back face
|
|
|
|
{
|
|
|
|
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
|
|
|
camera->setName("Back face camera");
|
|
|
|
camera->setGraphicsContext(gc.get());
|
2007-02-22 03:41:03 +08:00
|
|
|
camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height));
|
2007-02-21 05:06:24 +08:00
|
|
|
camera->setDrawBuffer(buffer);
|
|
|
|
camera->setReadBuffer(buffer);
|
2007-02-22 03:41:03 +08:00
|
|
|
camera->setAllowEventFocus(false);
|
|
|
|
|
|
|
|
// tell the camera to use OpenGL frame buffer object where supported.
|
|
|
|
camera->setRenderTargetImplementation(renderTargetImplementation);
|
2007-02-21 05:06:24 +08:00
|
|
|
|
|
|
|
// attach the texture and use it as the color buffer.
|
2007-02-23 00:42:59 +08:00
|
|
|
camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::NEGATIVE_Y);
|
2007-02-21 05:06:24 +08:00
|
|
|
|
2007-02-23 00:42:59 +08:00
|
|
|
viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(180.0f), 1.0,0.0,0.0));
|
2007-02-21 05:06:24 +08:00
|
|
|
}
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2007-02-21 05:06:24 +08:00
|
|
|
viewer.getCamera()->setProjectionMatrixAsPerspective(90.0f, 1.0, 1, 1000.0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// distortion correction set up.
|
|
|
|
{
|
2007-02-22 19:17:45 +08:00
|
|
|
osg::Geode* geode = new osg::Geode();
|
2015-03-16 20:13:44 +08:00
|
|
|
geode->addDrawable(createDomeDistortionMesh(osg::Vec3(0.0f,0.0f,0.0f), osg::Vec3(options.width,0.0f,0.0f), osg::Vec3(0.0f,options.height,0.0f), options));
|
2007-02-21 05:06:24 +08:00
|
|
|
|
2013-06-27 17:54:12 +08:00
|
|
|
// new we need to add the texture to the mesh, we do so by creating a
|
2007-02-21 05:06:24 +08:00
|
|
|
// StateSet to contain the Texture StateAttribute.
|
2007-02-22 19:17:45 +08:00
|
|
|
osg::StateSet* stateset = geode->getOrCreateStateSet();
|
2007-02-21 05:06:24 +08:00
|
|
|
stateset->setTextureAttributeAndModes(0, texture,osg::StateAttribute::ON);
|
|
|
|
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
|
|
|
|
|
|
|
|
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.1,0.1,1.0,1.0) );
|
2015-03-16 20:13:44 +08:00
|
|
|
camera->setViewport(new osg::Viewport(0, 0, options.width, options.height));
|
2016-05-26 17:35:33 +08:00
|
|
|
GLenum cbuffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
|
|
|
|
camera->setDrawBuffer(cbuffer);
|
|
|
|
camera->setReadBuffer(cbuffer);
|
2007-02-21 05:06:24 +08:00
|
|
|
camera->setReferenceFrame(osg::Camera::ABSOLUTE_RF);
|
2007-02-22 03:41:03 +08:00
|
|
|
camera->setAllowEventFocus(false);
|
2007-02-21 05:06:24 +08:00
|
|
|
//camera->setInheritanceMask(camera->getInheritanceMask() & ~osg::CullSettings::CLEAR_COLOR & ~osg::CullSettings::COMPUTE_NEAR_FAR_MODE);
|
|
|
|
//camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2015-03-16 20:13:44 +08:00
|
|
|
camera->setProjectionMatrixAsOrtho2D(0,options.width,0,options.height);
|
2007-02-21 05:06:24 +08:00
|
|
|
camera->setViewMatrix(osg::Matrix::identity());
|
|
|
|
|
|
|
|
// add subgraph to render
|
|
|
|
camera->addChild(geode);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2007-02-21 05:06:24 +08:00
|
|
|
camera->setName("DistortionCorrectionCamera");
|
|
|
|
|
2007-02-23 19:53:45 +08:00
|
|
|
viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd(), false);
|
2007-02-21 05:06:24 +08:00
|
|
|
}
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2007-02-23 00:42:59 +08:00
|
|
|
viewer.getCamera()->setNearFarRatio(0.0001f);
|
2007-02-21 05:06:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-07 05:35:57 +08:00
|
|
|
int main(int argc, char** argv)
|
2003-12-28 06:17:41 +08:00
|
|
|
{
|
|
|
|
// use an ArgumentParser object to manage the program arguments.
|
|
|
|
osg::ArgumentParser arguments(&argc,argv);
|
|
|
|
|
2015-03-16 20:13:44 +08:00
|
|
|
CommandLineOptions options;
|
|
|
|
options.read(arguments);
|
|
|
|
|
2003-12-28 06:17:41 +08:00
|
|
|
// construct the viewer.
|
2015-03-16 20:13:44 +08:00
|
|
|
osgViewer::Viewer viewer(arguments);
|
2007-06-08 20:13:33 +08:00
|
|
|
|
|
|
|
// load the nodes from the commandline arguments.
|
2015-10-22 21:42:19 +08:00
|
|
|
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFiles(arguments);
|
2007-06-08 20:13:33 +08:00
|
|
|
|
|
|
|
// if not loaded assume no arguments passed in, try use default mode instead.
|
2015-10-22 21:42:19 +08:00
|
|
|
if (!loadedModel) loadedModel = osgDB::readRefNodeFile("cow.osgt");
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2007-06-08 20:13:33 +08:00
|
|
|
if (!loadedModel)
|
|
|
|
{
|
|
|
|
std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2007-02-20 19:44:10 +08:00
|
|
|
|
2007-03-03 00:14:44 +08:00
|
|
|
if (arguments.read("--dome") || arguments.read("--puffer") )
|
2013-06-27 17:54:12 +08:00
|
|
|
{
|
2007-02-20 19:44:10 +08:00
|
|
|
|
2015-03-16 20:13:44 +08:00
|
|
|
setDomeCorrection(viewer, options);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2007-06-08 20:13:33 +08:00
|
|
|
viewer.setSceneData( loadedModel );
|
2007-02-21 05:06:24 +08:00
|
|
|
}
|
|
|
|
else if (arguments.read("--faces"))
|
2013-06-27 17:54:12 +08:00
|
|
|
{
|
2007-02-21 05:06:24 +08:00
|
|
|
|
2015-03-16 20:13:44 +08:00
|
|
|
setDomeFaces(viewer, options);
|
2007-03-03 00:14:44 +08:00
|
|
|
|
2007-06-08 20:13:33 +08:00
|
|
|
viewer.setSceneData( loadedModel );
|
2007-02-20 19:44:10 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-10-22 21:42:19 +08:00
|
|
|
osg::Node* distortionNode = createDistortionSubgraph( options, loadedModel.get(), viewer.getCamera()->getClearColor());
|
2007-03-22 00:34:04 +08:00
|
|
|
viewer.setSceneData( distortionNode );
|
2007-03-03 00:14:44 +08:00
|
|
|
}
|
|
|
|
|
2007-07-11 22:16:02 +08:00
|
|
|
while (arguments.read("--sky-light"))
|
|
|
|
{
|
|
|
|
viewer.setLightingMode(osg::View::SKY_LIGHT);
|
|
|
|
}
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2007-07-11 22:16:02 +08:00
|
|
|
if (viewer.getLightingMode()==osg::View::HEADLIGHT)
|
|
|
|
{
|
|
|
|
viewer.getLight()->setPosition(osg::Vec4(0.0f,0.0f,0.0f,1.0f));
|
|
|
|
}
|
|
|
|
|
2007-02-20 19:44:10 +08:00
|
|
|
|
2007-03-03 00:14:44 +08:00
|
|
|
// load the nodes from the commandline arguments.
|
|
|
|
if (!viewer.getSceneData())
|
|
|
|
{
|
|
|
|
osg::notify(osg::NOTICE)<<"Please specify a model filename on the command line."<<std::endl;
|
|
|
|
return 1;
|
2007-02-20 19:44:10 +08:00
|
|
|
}
|
2003-12-28 06:17:41 +08:00
|
|
|
|
2007-02-23 19:53:45 +08:00
|
|
|
|
2007-02-22 03:41:03 +08:00
|
|
|
// set up the camera manipulators.
|
|
|
|
{
|
|
|
|
osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator;
|
|
|
|
|
|
|
|
keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() );
|
|
|
|
keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() );
|
|
|
|
keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() );
|
|
|
|
keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() );
|
|
|
|
|
|
|
|
std::string pathfile;
|
|
|
|
char keyForAnimationPath = '5';
|
|
|
|
while (arguments.read("-p",pathfile))
|
|
|
|
{
|
|
|
|
osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile);
|
2013-06-27 17:54:12 +08:00
|
|
|
if (apm || !apm->valid())
|
2007-02-22 03:41:03 +08:00
|
|
|
{
|
|
|
|
unsigned int num = keyswitchManipulator->getNumMatrixManipulators();
|
|
|
|
keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm );
|
|
|
|
keyswitchManipulator->selectMatrixManipulator(num);
|
|
|
|
++keyForAnimationPath;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
viewer.setCameraManipulator( keyswitchManipulator.get() );
|
|
|
|
}
|
|
|
|
|
2007-03-03 00:14:44 +08:00
|
|
|
viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded);
|
2007-02-21 05:06:24 +08:00
|
|
|
|
2015-03-16 20:13:44 +08:00
|
|
|
// add window resize handler
|
|
|
|
viewer.addEventHandler(new osgViewer::WindowSizeHandler);
|
|
|
|
|
2007-02-21 05:06:24 +08:00
|
|
|
// add the state manipulator
|
|
|
|
viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) );
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2007-02-21 05:06:24 +08:00
|
|
|
// add the stats handler
|
|
|
|
viewer.addEventHandler(new osgViewer::StatsHandler);
|
|
|
|
|
2007-01-07 05:35:57 +08:00
|
|
|
return viewer.run();
|
2003-12-28 06:17:41 +08:00
|
|
|
}
|
2007-04-06 23:36:13 +08:00
|
|
|
|