2006-07-18 23:21:48 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2005-06-15 18:59:10 +08:00
|
|
|
*
|
|
|
|
* 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 <osgUtil/Optimizer>
|
|
|
|
#include <osgDB/ReadFile>
|
2007-01-08 18:00:16 +08:00
|
|
|
#include <osgViewer/Viewer>
|
2005-06-15 18:59:10 +08:00
|
|
|
|
|
|
|
#include <osg/Material>
|
|
|
|
#include <osg/Geode>
|
|
|
|
#include <osg/BlendFunc>
|
|
|
|
#include <osg/Depth>
|
|
|
|
#include <osg/Projection>
|
|
|
|
#include <osg/PolygonOffset>
|
|
|
|
#include <osg/MatrixTransform>
|
2006-11-27 22:52:07 +08:00
|
|
|
#include <osg/Camera>
|
2005-07-20 00:30:55 +08:00
|
|
|
#include <osg/FrontFace>
|
2005-06-15 18:59:10 +08:00
|
|
|
|
|
|
|
#include <osgText/Text>
|
|
|
|
|
|
|
|
|
2005-07-20 00:30:55 +08:00
|
|
|
osg::Node* createRearView(osg::Node* subgraph, const osg::Vec4& clearColour)
|
2005-06-15 18:59:10 +08:00
|
|
|
{
|
2006-11-27 22:52:07 +08:00
|
|
|
osg::Camera* camera = new osg::Camera;
|
2005-06-15 18:59:10 +08:00
|
|
|
|
2005-07-20 00:30:55 +08:00
|
|
|
// set the viewport
|
2005-11-02 22:22:31 +08:00
|
|
|
camera->setViewport(10,10,400,200);
|
2005-06-15 18:59:10 +08:00
|
|
|
|
|
|
|
// set the view matrix
|
|
|
|
camera->setCullingActive(false);
|
|
|
|
camera->setReferenceFrame(osg::Transform::RELATIVE_RF);
|
2006-11-27 22:52:07 +08:00
|
|
|
camera->setTransformOrder(osg::Camera::POST_MULTIPLY);
|
2005-07-20 00:30:55 +08:00
|
|
|
|
|
|
|
camera->setProjectionMatrix(osg::Matrixd::scale(-1.0f,1.0f,1.0f));
|
2005-06-15 18:59:10 +08:00
|
|
|
camera->setViewMatrix(osg::Matrixd::rotate(osg::inDegrees(180.0f),0.0f,1.0f,0.0f));
|
|
|
|
|
2005-07-20 00:30:55 +08:00
|
|
|
// set clear the color and depth buffer
|
|
|
|
camera->setClearColor(clearColour);
|
2005-06-15 18:59:10 +08:00
|
|
|
camera->setClearMask(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
|
|
|
// draw subgraph after main camera view.
|
2006-11-27 22:52:07 +08:00
|
|
|
camera->setRenderOrder(osg::Camera::POST_RENDER);
|
2005-06-15 18:59:10 +08:00
|
|
|
|
2005-07-20 00:30:55 +08:00
|
|
|
// add the subgraph to draw.
|
2005-06-15 18:59:10 +08:00
|
|
|
camera->addChild(subgraph);
|
|
|
|
|
2005-07-20 00:30:55 +08:00
|
|
|
// switch of back face culling as we've swapped over the projection matrix making back faces become front faces.
|
|
|
|
camera->getOrCreateStateSet()->setAttribute(new osg::FrontFace(osg::FrontFace::CLOCKWISE));
|
|
|
|
|
2005-06-15 18:59:10 +08:00
|
|
|
return camera;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main( int argc, char **argv )
|
|
|
|
{
|
|
|
|
|
|
|
|
// use an ArgumentParser object to manage the program arguments.
|
|
|
|
osg::ArgumentParser arguments(&argc,argv);
|
|
|
|
|
|
|
|
// construct the viewer.
|
2007-01-08 18:00:16 +08:00
|
|
|
osgViewer::Viewer viewer;
|
2005-06-15 18:59:10 +08:00
|
|
|
|
|
|
|
// read the scene from the list of file specified commandline args.
|
|
|
|
osg::ref_ptr<osg::Node> scene = osgDB::readNodeFiles(arguments);
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Group> group = new osg::Group;
|
|
|
|
|
|
|
|
// add the HUD subgraph.
|
|
|
|
if (scene.valid()) group->addChild(scene.get());
|
2005-11-02 22:22:31 +08:00
|
|
|
|
2007-01-08 18:00:16 +08:00
|
|
|
osg::Vec4 colour = viewer.getCamera()->getClearColor();
|
2005-11-02 22:22:31 +08:00
|
|
|
colour.r() *= 0.5f;
|
|
|
|
colour.g() *= 0.5f;
|
|
|
|
colour.b() *= 0.5f;
|
|
|
|
|
|
|
|
// note tone down the normal back ground colour to make it obvious that there is a seperate camera inserted.
|
|
|
|
group->addChild(createRearView(scene.get(), colour));
|
2005-06-15 18:59:10 +08:00
|
|
|
|
|
|
|
// set the scene to render
|
|
|
|
viewer.setSceneData(group.get());
|
|
|
|
|
2007-01-08 18:00:16 +08:00
|
|
|
return viewer.run();
|
2005-06-15 18:59:10 +08:00
|
|
|
}
|