Introduced CMake option OSG_PROVIDE_READFILE option that defaults to ON, but when switched to OFF disables the building of the osgDB::read*File() methods,
forcing users to use osgDB::readRef*File() methods. The later is preferable as it closes a potential threading bug when using paging databases in conjunction with the osgDB::Registry Object Cache. This threading bug occurs when one thread gets an object from the Cache via an osgDB::read*File() call where only a pointer to the object is passed back, so taking a reference to the object is delayed till it gets reassigned to a ref_ptr<>, but at the same time another thread calls a flush of the Object Cache deleting this object as it's referenceCount is now zero. Using osgDB::readREf*File() makes sure the a ref_ptr<> is passed back and the referenceCount never goes to zero. To ensure the OSG builds when OSG_PROVIDE_READFILE is to OFF the many cases of osgDB::read*File() usage had to be replaced with a ref_ptr<> osgDB::readRef*File() usage. The avoid this change causing lots of other client code to be rewritten to handle the use of ref_ptr<> in place of C pointer I introduced a serious of templte methods in various class to adapt ref_ptr<> to the underly C pointer to be passed to old OSG API's, example of this is found in include/osg/Group: bool addChild(Node* child); // old method which can only be used with a Node* tempalte<class T> bool addChild(const osg::ref_ptr<T>& child) { return addChild(child.get()); } // adapter template method These changes together cover 149 modified files, so it's a large submission. This extent of changes are warrent to make use of the Object Cache and multi-threaded loaded more robust. git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@15164 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
parent
79fb9abbbf
commit
dd996a3289
@ -398,6 +398,7 @@ ENDIF()
|
||||
OPTION(OSG_DISABLE_MSVC_WARNINGS "Set to OFF to not disable MSVC warnings generated by OSG headers." ON)
|
||||
MARK_AS_ADVANCED(OSG_DISABLE_MSVC_WARNINGS)
|
||||
|
||||
OPTION(OSG_PROVIDE_READFILE "Set to ON for include/osgDB/ReadFile to provide the osgDB::read*File(() methods. " ON)
|
||||
OPTION(OSG_USE_REF_PTR_IMPLICIT_OUTPUT_CONVERSION "Set to ON to use the ref_ptr<> T* operator() output conversion. " ON)
|
||||
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* This application is open source and may be redistributed and/or modified
|
||||
* This application is open source and may be redistributed and/or modified
|
||||
* freely and without restriction, both in commercial and non commercial applications,
|
||||
* as long as this copyright notice is maintained.
|
||||
*
|
||||
*
|
||||
* This application 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.
|
||||
@ -26,12 +26,12 @@ int main( int argc, char **argv )
|
||||
{
|
||||
// use an ArgumentParser object to manage the program arguments.
|
||||
osg::ArgumentParser arguments(&argc,argv);
|
||||
|
||||
|
||||
// set up the usage document, in case we need to print out how to use this program.
|
||||
arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName());
|
||||
arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is an application for collecting a set of separate files into a single archive file that can be later read in OSG applications..");
|
||||
arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...");
|
||||
|
||||
|
||||
// if user request help write it out to cout.
|
||||
if (arguments.read("-h") || arguments.read("--help"))
|
||||
{
|
||||
@ -49,14 +49,14 @@ int main( int argc, char **argv )
|
||||
{
|
||||
insert = true;
|
||||
}
|
||||
|
||||
|
||||
bool extract = false;
|
||||
while (arguments.read("-e") || arguments.read("--extract"))
|
||||
{
|
||||
extract = true;
|
||||
}
|
||||
|
||||
bool list = false;
|
||||
|
||||
bool list = false;
|
||||
while (arguments.read("-l") || arguments.read("--list"))
|
||||
{
|
||||
list = true;
|
||||
@ -93,7 +93,7 @@ int main( int argc, char **argv )
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// any option left unread are converted into errors to write out later.
|
||||
arguments.reportRemainingOptionsAsUnrecognized();
|
||||
|
||||
@ -103,7 +103,7 @@ int main( int argc, char **argv )
|
||||
arguments.writeErrorMessages(std::cout);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
if (archiveFilename.empty())
|
||||
{
|
||||
std::cout<<"Please specify an archive name using --archive filename"<<std::endl;
|
||||
@ -115,7 +115,7 @@ int main( int argc, char **argv )
|
||||
std::cout<<"Please specify an operation on the archive, either --insert, --extract or --list"<<std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
if (insert && extract)
|
||||
{
|
||||
std::cout<<"Cannot insert and extract files from the archive at one time, please use either --insert or --extract."<<std::endl;
|
||||
@ -127,7 +127,7 @@ int main( int argc, char **argv )
|
||||
if (insert)
|
||||
{
|
||||
archive = osgDB::openArchive(archiveFilename, osgDB::Archive::WRITE);
|
||||
|
||||
|
||||
if (archive.valid())
|
||||
{
|
||||
for (FileNameList::iterator itr=files.begin();
|
||||
@ -135,7 +135,7 @@ int main( int argc, char **argv )
|
||||
++itr)
|
||||
{
|
||||
std::cout<<"reading "<<*itr<<std::endl;
|
||||
osg::ref_ptr<osg::Object> obj = osgDB::readObjectFile(*itr);
|
||||
osg::ref_ptr<osg::Object> obj = osgDB::readRefObjectFile(*itr);
|
||||
if (obj.valid())
|
||||
{
|
||||
std::cout<<" write to archive "<<*itr<<std::endl;
|
||||
@ -152,10 +152,10 @@ int main( int argc, char **argv )
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
archive = osgDB::openArchive(archiveFilename, osgDB::Archive::READ);
|
||||
|
||||
|
||||
if (extract && archive.valid())
|
||||
{
|
||||
for (FileNameList::iterator itr=files.begin();
|
||||
@ -175,7 +175,7 @@ int main( int argc, char **argv )
|
||||
}
|
||||
|
||||
if (list && archive.valid())
|
||||
{
|
||||
{
|
||||
std::cout<<"List of files in archive:"<<std::endl;
|
||||
osgDB::Archive::FileNameList fileNames;
|
||||
if (archive->getFileNames(fileNames))
|
||||
@ -187,11 +187,11 @@ int main( int argc, char **argv )
|
||||
std::cout<<" "<<*itr<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::cout<<std::endl;
|
||||
std::cout<<"Master file "<<archive->getMasterFileName()<<std::endl;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -772,7 +772,7 @@ int main( int argc, char **argv )
|
||||
|
||||
osg::Timer_t startTick = osg::Timer::instance()->tick();
|
||||
|
||||
osg::ref_ptr<osg::Node> root = osgDB::readNodeFiles(fileNames);
|
||||
osg::ref_ptr<osg::Node> root = osgDB::readRefNodeFiles(fileNames);
|
||||
|
||||
if (root.valid())
|
||||
{
|
||||
|
@ -1,9 +1,9 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* This application is open source and may be redistributed and/or modified
|
||||
* This application is open source and may be redistributed and/or modified
|
||||
* freely and without restriction, both in commercial and non commercial applications,
|
||||
* as long as this copyright notice is maintained.
|
||||
*
|
||||
*
|
||||
* This application 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.
|
||||
@ -46,20 +46,20 @@ struct Extents
|
||||
_maxLevel(maxLevel),
|
||||
_min(minX, minY),
|
||||
_max(maxX, maxY) {}
|
||||
|
||||
|
||||
Extents(const Extents& extents):
|
||||
_maxLevel(extents._maxLevel),
|
||||
_min(extents._min),
|
||||
_max(extents._max) {}
|
||||
|
||||
|
||||
Extents& operator = (const Extents& rhs)
|
||||
{
|
||||
if (&rhs == this) return *this;
|
||||
|
||||
|
||||
_maxLevel = rhs._maxLevel;
|
||||
_min = rhs._min;
|
||||
_max = rhs._max;
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -69,10 +69,10 @@ struct Extents
|
||||
osg::notify(osg::INFO)<<" _maxLevel="<<_maxLevel<<", _min="<<_min<<" _max="<<_max<<std::endl;
|
||||
|
||||
if (level>_maxLevel) return false;
|
||||
|
||||
|
||||
osg::Vec2d union_min, union_max;
|
||||
|
||||
// handle mins
|
||||
// handle mins
|
||||
if (_min.x()!=DBL_MAX && in_min.x()!=DBL_MAX)
|
||||
{
|
||||
// both _min.x() and in_min.x() are defined so use max of two
|
||||
@ -95,7 +95,7 @@ struct Extents
|
||||
union_min.y() = _min.y()<in_min.y() ? _min.y() : in_min.y();
|
||||
}
|
||||
|
||||
// handle maxs
|
||||
// handle maxs
|
||||
if (_max.x()!=-DBL_MAX && in_max.x()!=-DBL_MAX)
|
||||
{
|
||||
// both _max.x() and in_max.x() are defined so use max of two
|
||||
@ -121,7 +121,7 @@ struct Extents
|
||||
bool result = union_min.x()<union_max.x() && union_min.y()<union_max.y() ;
|
||||
|
||||
osg::notify(osg::INFO)<<" union_min="<<union_min<<" union_max="<<union_max<<" result = "<<result<<std::endl;
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -140,7 +140,7 @@ public:
|
||||
_currentLevel(0) {}
|
||||
|
||||
void setFileCache(osgDB::FileCache* fileCache) { _fileCache = fileCache; }
|
||||
|
||||
|
||||
void addExtents(unsigned int maxLevel, double minX, double minY, double maxX, double maxY)
|
||||
{
|
||||
_extentsList.push_back(Extents(maxLevel, minX, minY, maxX, maxY));
|
||||
@ -154,16 +154,16 @@ public:
|
||||
void apply(osg::CoordinateSystemNode& cs)
|
||||
{
|
||||
_csnStack.push_back(&cs);
|
||||
|
||||
|
||||
if (!s_ExitApplication) traverse(cs);
|
||||
|
||||
_csnStack.pop_back();
|
||||
}
|
||||
|
||||
|
||||
void apply(osg::Group& group)
|
||||
{
|
||||
if (s_ExitApplication) return;
|
||||
|
||||
|
||||
osgTerrain::TerrainTile* terrainTile = dynamic_cast<osgTerrain::TerrainTile*>(&group);
|
||||
osgTerrain::Locator* locator = terrainTile ? terrainTile->getLocator() : 0;
|
||||
if (locator)
|
||||
@ -196,7 +196,7 @@ public:
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
traverse(group);
|
||||
}
|
||||
|
||||
@ -217,11 +217,11 @@ public:
|
||||
void apply(osg::PagedLOD& plod)
|
||||
{
|
||||
if (s_ExitApplication) return;
|
||||
|
||||
|
||||
++_currentLevel;
|
||||
|
||||
|
||||
initBound();
|
||||
|
||||
|
||||
// first compute the bounds of this subgraph
|
||||
for(unsigned int i=0; i<plod.getNumFileNames(); ++i)
|
||||
{
|
||||
@ -230,7 +230,7 @@ public:
|
||||
traverse(plod);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (intersects())
|
||||
{
|
||||
for(unsigned int i=0; i<plod.getNumFileNames(); ++i)
|
||||
@ -239,7 +239,7 @@ public:
|
||||
if (!plod.getFileName(i).empty())
|
||||
{
|
||||
std::string filename;
|
||||
if (!plod.getDatabasePath().empty())
|
||||
if (!plod.getDatabasePath().empty())
|
||||
{
|
||||
filename = plod.getDatabasePath() + plod.getFileName(i);
|
||||
}
|
||||
@ -255,10 +255,10 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
--_currentLevel;
|
||||
}
|
||||
|
||||
|
||||
void apply(osg::Geode& geode)
|
||||
{
|
||||
for(unsigned int i=0; i<geode.getNumDrawables(); ++i)
|
||||
@ -271,10 +271,10 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
osg::Node* readNodeFileAndWriteToCache(const std::string& filename)
|
||||
|
||||
osg::ref_ptr<osg::Node> readNodeFileAndWriteToCache(const std::string& filename)
|
||||
{
|
||||
osg::Node* node = 0;
|
||||
osg::ref_ptr<osg::Node> node = 0;
|
||||
if (_fileCache.valid() )
|
||||
{
|
||||
if (_fileCache->existsInCache(filename))
|
||||
@ -286,7 +286,7 @@ public:
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"reading : "<<filename<<std::endl;
|
||||
|
||||
node = osgDB::readNodeFile(filename);
|
||||
node = osgDB::readRefNodeFile(filename);
|
||||
if (node)
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"write to FileCache : "<<filename<<std::endl;
|
||||
@ -298,7 +298,7 @@ public:
|
||||
else
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"reading : "<<filename<<std::endl;
|
||||
node = osgDB::readNodeFile(filename);
|
||||
node = osgDB::readRefNodeFile(filename);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
@ -307,18 +307,18 @@ public:
|
||||
protected:
|
||||
|
||||
inline void pushMatrix(osg::Matrix& matrix) { _matrixStack.push_back(matrix); }
|
||||
|
||||
|
||||
inline void popMatrix() { _matrixStack.pop_back(); }
|
||||
|
||||
void convertXYZToLatLongHeight(osg::EllipsoidModel* em, osg::Vec3d& v)
|
||||
{
|
||||
em->convertXYZToLatLongHeight(v.x(), v.y(), v.z(),
|
||||
v.y(), v.x(), v.z());
|
||||
|
||||
|
||||
v.x() = osg::RadiansToDegrees(v.x());
|
||||
v.y() = osg::RadiansToDegrees(v.y());
|
||||
}
|
||||
|
||||
|
||||
void initBound()
|
||||
{
|
||||
_min.set(DBL_MAX, DBL_MAX);
|
||||
@ -332,16 +332,16 @@ protected:
|
||||
if (v.x() > _max.x()) _max.x() = v.x();
|
||||
if (v.y() > _max.y()) _max.y() = v.y();
|
||||
}
|
||||
|
||||
|
||||
void updateBound(osg::Vec3Array& vertices)
|
||||
{
|
||||
// set up matrix
|
||||
osg::Matrix matrix;
|
||||
if (!_matrixStack.empty()) matrix = _matrixStack.back();
|
||||
|
||||
|
||||
// set up ellipsoid model
|
||||
osg::EllipsoidModel* em = !_csnStack.empty() ? _csnStack.back()->getEllipsoidModel() : 0;
|
||||
|
||||
|
||||
for(osg::Vec3Array::iterator itr = vertices.begin();
|
||||
itr != vertices.end();
|
||||
++itr)
|
||||
@ -352,7 +352,7 @@ protected:
|
||||
updateBound(v);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool intersects()
|
||||
{
|
||||
osg::notify(osg::INFO)<<"intersects() _min = "<<_min<<" _max = "<<_max<<std::endl;
|
||||
@ -362,7 +362,7 @@ protected:
|
||||
{
|
||||
if (itr->intersects(_currentLevel, _min, _max)) return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -376,7 +376,7 @@ protected:
|
||||
unsigned int _currentLevel;
|
||||
MatrixStack _matrixStack;
|
||||
CSNStack _csnStack;
|
||||
|
||||
|
||||
osg::Vec2d _min;
|
||||
osg::Vec2d _max;
|
||||
};
|
||||
@ -403,7 +403,7 @@ int main( int argc, char **argv )
|
||||
|
||||
// use an ArgumentParser object to manage the program arguments.
|
||||
osg::ArgumentParser arguments(&argc,argv);
|
||||
|
||||
|
||||
// set up the usage document, in case we need to print out how to use this program.
|
||||
arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName());
|
||||
arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is an application for collecting a set of separate files into a single archive file that can be later read in OSG applications..");
|
||||
@ -412,21 +412,21 @@ int main( int argc, char **argv )
|
||||
arguments.getApplicationUsage()->addCommandLineOption("-e level minX minY maxX maxY","Read down to <level> across the extents minX, minY to maxY, maxY. Note, for geocentric datase X and Y are longitude and latitude respectively.");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("-c directory","Shorthand for --file-cache directory.");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--file-cache directory","Set directory as to place cache download files.");
|
||||
|
||||
|
||||
// if user request help write it out to cout.
|
||||
if (arguments.read("-h") || arguments.read("--help"))
|
||||
{
|
||||
arguments.getApplicationUsage()->write(std::cout);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
LoadDataVisitor ldv;
|
||||
|
||||
std::string fileCachePath;
|
||||
while(arguments.read("--file-cache",fileCachePath) || arguments.read("-c",fileCachePath)) {}
|
||||
|
||||
|
||||
if (fileCachePath.empty())
|
||||
{
|
||||
{
|
||||
const char* env_fileCachePath = getenv("OSG_FILE_CACHE");
|
||||
if (env_fileCachePath)
|
||||
{
|
||||
@ -439,7 +439,7 @@ int main( int argc, char **argv )
|
||||
std::cout<<"No path to the file cache defined, please set OSG_FILE_PATH env var, or use --file-cache <directory> to set a suitable directory for the file cache."<<std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
ldv.setFileCache(new osgDB::FileCache(fileCachePath));
|
||||
|
||||
unsigned int maxLevels = 0;
|
||||
@ -447,14 +447,14 @@ int main( int argc, char **argv )
|
||||
{
|
||||
ldv.addExtents(maxLevels);
|
||||
}
|
||||
|
||||
|
||||
double minX, maxX, minY, maxY;
|
||||
while(arguments.read("-e",maxLevels, minX, minY, maxX, maxY))
|
||||
{
|
||||
ldv.addExtents(maxLevels, minX, minY, maxX, maxY);
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string filename;
|
||||
for(int i=1; i<arguments.argc(); ++i)
|
||||
{
|
||||
@ -464,21 +464,21 @@ int main( int argc, char **argv )
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (filename.empty())
|
||||
|
||||
if (filename.empty())
|
||||
{
|
||||
std::cout<<"No file to load specified."<<std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
osg::ref_ptr<osg::Node> loadedModel = ldv.readNodeFileAndWriteToCache(filename);
|
||||
if (!loadedModel)
|
||||
{
|
||||
std::cout<<"No data loaded, please specify a database to load"<<std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
loadedModel->accept(ldv);
|
||||
|
||||
if (s_ExitApplication)
|
||||
|
@ -87,10 +87,10 @@ int main(int argc, char** argv)
|
||||
std::string device;
|
||||
while(arguments.read("--device", device))
|
||||
{
|
||||
osg::ref_ptr<osgGA::Device> dev = osgDB::readFile<osgGA::Device>(device);
|
||||
osg::ref_ptr<osgGA::Device> dev = osgDB::readRefFile<osgGA::Device>(device);
|
||||
if (dev.valid())
|
||||
{
|
||||
viewer.addDevice(dev.get());
|
||||
viewer.addDevice(dev);
|
||||
}
|
||||
}
|
||||
|
||||
@ -152,7 +152,7 @@ int main(int argc, char** argv)
|
||||
viewer.addEventHandler(new osgViewer::ScreenCaptureHandler);
|
||||
|
||||
// load the data
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFiles(arguments);
|
||||
if (!loadedModel)
|
||||
{
|
||||
std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl;
|
||||
@ -172,9 +172,9 @@ int main(int argc, char** argv)
|
||||
|
||||
// optimize the scene graph, remove redundant nodes and state etc.
|
||||
osgUtil::Optimizer optimizer;
|
||||
optimizer.optimize(loadedModel.get());
|
||||
optimizer.optimize(loadedModel);
|
||||
|
||||
viewer.setSceneData( loadedModel.get() );
|
||||
viewer.setSceneData(loadedModel);
|
||||
|
||||
viewer.realize();
|
||||
|
||||
|
@ -215,24 +215,24 @@ osg::ref_ptr<osg::Node> p3d::readShowFiles(osg::ArgumentParser& arguments,const
|
||||
std::string filename;
|
||||
while (arguments.read("--image",filename))
|
||||
{
|
||||
osg::ref_ptr<osg::Image> image = readImageFile(filename.c_str(), local_options.get());
|
||||
if (image.valid()) nodeList.push_back(osg::createGeodeForImage(image.get()));
|
||||
osg::ref_ptr<osg::Image> image = readRefImageFile(filename.c_str(), local_options.get());
|
||||
if (image.valid()) nodeList.push_back(osg::createGeodeForImage(image));
|
||||
}
|
||||
|
||||
while (arguments.read("--movie",filename))
|
||||
{
|
||||
osg::ref_ptr<osg::Image> image = readImageFile(filename.c_str(), local_options.get());
|
||||
osg::ref_ptr<osg::Image> image = readRefImageFile(filename.c_str(), local_options.get());
|
||||
osg::ref_ptr<osg::ImageStream> imageStream = dynamic_cast<osg::ImageStream*>(image.get());
|
||||
if (image.valid())
|
||||
{
|
||||
imageStream->play();
|
||||
nodeList.push_back(osg::createGeodeForImage(imageStream.get()));
|
||||
nodeList.push_back(osg::createGeodeForImage(imageStream));
|
||||
}
|
||||
}
|
||||
|
||||
while (arguments.read("--dem",filename))
|
||||
{
|
||||
osg::HeightField* hf = readHeightFieldFile(filename.c_str(), local_options.get());
|
||||
osg::ref_ptr<osg::HeightField> hf = readRefHeightFieldFile(filename.c_str(), local_options.get());
|
||||
if (hf)
|
||||
{
|
||||
osg::Geode* geode = new osg::Geode;
|
||||
@ -247,7 +247,7 @@ osg::ref_ptr<osg::Node> p3d::readShowFiles(osg::ArgumentParser& arguments,const
|
||||
if (!arguments.isOption(pos))
|
||||
{
|
||||
// not an option so assume string is a filename.
|
||||
osg::Node *node = osgDB::readNodeFile( arguments[pos], local_options.get());
|
||||
osg::ref_ptr<osg::Node> node = osgDB::readRefNodeFile( arguments[pos], local_options.get());
|
||||
|
||||
if(node)
|
||||
{
|
||||
|
@ -266,7 +266,7 @@ void processLoadedModel(osg::ref_ptr<osg::Node>& loadedModel, int optimizer_opti
|
||||
|
||||
void addDeviceTo(osgViewer::Viewer& viewer, const std::string& device_name, bool forward_mouse_events)
|
||||
{
|
||||
osg::ref_ptr<osgGA::Device> dev = osgDB::readFile<osgGA::Device>(device_name);
|
||||
osg::ref_ptr<osgGA::Device> dev = osgDB::readRefFile<osgGA::Device>(device_name);
|
||||
if (dev.valid())
|
||||
{
|
||||
OSG_INFO << "Adding Device : " << device_name << std::endl;
|
||||
@ -317,7 +317,7 @@ int main( int argc, char **argv )
|
||||
if (arguments.read("-devices") || arguments.read("--devices"))
|
||||
{
|
||||
// Force load QuickTime plugin, probe video capability, exit
|
||||
osgDB::readImageFile("devices.live");
|
||||
osgDB::readRefImageFile("devices.live");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -451,7 +451,7 @@ int main( int argc, char **argv )
|
||||
|
||||
osg::ref_ptr<osgDB::Options> device_options = new osgDB::Options("documentRegisteredHandlers");
|
||||
|
||||
osg::ref_ptr<osgGA::Device> rest_http_device = osgDB::readFile<osgGA::Device>(server_address+":"+server_port+"/"+document_root+".resthttp", device_options.get());
|
||||
osg::ref_ptr<osgGA::Device> rest_http_device = osgDB::readRefFile<osgGA::Device>(server_address+":"+server_port+"/"+document_root+".resthttp", device_options.get());
|
||||
if (rest_http_device.valid())
|
||||
{
|
||||
viewer.addDevice(rest_http_device.get());
|
||||
|
@ -85,7 +85,7 @@ int main( int argc, char **argv )
|
||||
std::string filename;
|
||||
if (arguments.read("--shader",filename))
|
||||
{
|
||||
osg::ref_ptr<osg::Shader> shader = osgDB::readShaderFile(filename);
|
||||
osg::ref_ptr<osg::Shader> shader = osgDB::readRefShaderFile(filename);
|
||||
if (shader.valid())
|
||||
{
|
||||
std::string name = osgDB::getStrippedName(filename);
|
||||
|
@ -311,7 +311,7 @@ public:
|
||||
//set OSG_FILE_PATH for loading axes.osgt
|
||||
void ComputeNode::addHelperGeometry()
|
||||
{
|
||||
_helperNode = osgDB::readNodeFile("axes.osgt");
|
||||
_helperNode = osgDB::readRefNodeFile("axes.osgt");
|
||||
|
||||
if (_helperNode.valid())
|
||||
{
|
||||
@ -464,8 +464,8 @@ void ComputeNode::addDataMonitor(osg::Vec3 placement, osg::Vec3 relativePlacemen
|
||||
ss->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
|
||||
|
||||
//add a label
|
||||
osgText::Text* text = new osgText::Text;
|
||||
osgText::Font* font = osgText::readFontFile("fonts/arial.ttf");
|
||||
osg::ref_ptr<osgText::Text> text = new osgText::Text;
|
||||
osg::ref_ptr<osgText::Font> font = osgText::readRefFontFile("fonts/arial.ttf");
|
||||
text->setFont(font);
|
||||
text->setColor(osg::Vec4(1, 1, 1, 1));
|
||||
text->setCharacterSize(0.1*scale);
|
||||
|
@ -557,7 +557,7 @@ public:
|
||||
osg::notify(osg::NOTICE)<<"LoadAndCompileOperation "<<_filename<<std::endl;
|
||||
|
||||
_modelReadyToMerge = false;
|
||||
_loadedModel = osgDB::readNodeFile(_filename);
|
||||
_loadedModel = osgDB::readRefNodeFile(_filename);
|
||||
|
||||
if (_loadedModel.valid())
|
||||
{
|
||||
|
@ -136,9 +136,9 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius)
|
||||
|
||||
osg::AnimationPath* animationPath = createAnimationPath(center,radius,animationLength);
|
||||
|
||||
osg::Group* model = new osg::Group;
|
||||
osg::ref_ptr<osg::Group> model = new osg::Group;
|
||||
|
||||
osg::Node* glider = osgDB::readNodeFile("glider.osgt");
|
||||
osg::ref_ptr<osg::Node> glider = osgDB::readRefNodeFile("glider.osgt");
|
||||
if (glider)
|
||||
{
|
||||
const osg::BoundingSphere& bs = glider->getBound();
|
||||
@ -159,7 +159,7 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius)
|
||||
model->addChild(xform);
|
||||
}
|
||||
|
||||
osg::Node* cessna = osgDB::readNodeFile("cessna.osgt");
|
||||
osg::ref_ptr<osg::Node> cessna = osgDB::readRefNodeFile("cessna.osgt");
|
||||
if (cessna)
|
||||
{
|
||||
const osg::BoundingSphere& bs = cessna->getBound();
|
||||
@ -173,26 +173,26 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius)
|
||||
|
||||
positioned->addChild(cessna);
|
||||
|
||||
osg::MatrixTransform* xform = new osg::MatrixTransform;
|
||||
osg::ref_ptr<osg::MatrixTransform> xform = new osg::MatrixTransform;
|
||||
xform->setUpdateCallback(new osg::AnimationPathCallback(animationPath,0.0f,2.0));
|
||||
xform->addChild(positioned);
|
||||
|
||||
model->addChild(xform);
|
||||
}
|
||||
|
||||
return model;
|
||||
return model.release();
|
||||
}
|
||||
|
||||
osg::Node* createModel(bool overlay, osgSim::OverlayNode::OverlayTechnique technique)
|
||||
osg::ref_ptr<osg::Group> createModel(bool overlay, osgSim::OverlayNode::OverlayTechnique technique)
|
||||
{
|
||||
osg::Vec3 center(0.0f,0.0f,0.0f);
|
||||
float radius = 100.0f;
|
||||
|
||||
osg::Group* root = new osg::Group;
|
||||
osg::ref_ptr<osg::Group> root = new osg::Group;
|
||||
|
||||
float baseHeight = center.z()-radius*0.5;
|
||||
osg::Node* baseModel = createBase(osg::Vec3(center.x(), center.y(), baseHeight),radius);
|
||||
osg::Node* movingModel = createMovingModel(center,radius*0.8f);
|
||||
osg::ref_ptr<osg::Node> baseModel = createBase(osg::Vec3(center.x(), center.y(), baseHeight),radius);
|
||||
osg::ref_ptr<osg::Node> movingModel = createMovingModel(center,radius*0.8f);
|
||||
|
||||
if (overlay)
|
||||
{
|
||||
@ -232,14 +232,14 @@ int main( int argc, char **argv )
|
||||
osgViewer::Viewer viewer;
|
||||
|
||||
// load the nodes from the commandline arguments.
|
||||
osg::Node* model = createModel(overlay, technique);
|
||||
osg::ref_ptr<osg::Group> model = createModel(overlay, technique);
|
||||
if (!model)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
// tilt the scene so the default eye position is looking down on the model.
|
||||
osg::MatrixTransform* rootnode = new osg::MatrixTransform;
|
||||
osg::ref_ptr<osg::MatrixTransform> rootnode = new osg::MatrixTransform;
|
||||
rootnode->setMatrix(osg::Matrix::rotate(osg::inDegrees(30.0f),1.0f,0.0f,0.0f));
|
||||
rootnode->addChild(model);
|
||||
|
||||
|
@ -1,14 +1,14 @@
|
||||
/* -*-c++-*-
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2009 Cedric Pinson <cedric.pinson@plopbyte.net>
|
||||
*
|
||||
* 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
|
||||
* 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
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
@ -110,7 +110,7 @@ struct MyRigTransformHardware : public osgAnimation::RigTransformHardware
|
||||
|
||||
osg::notify(osg::INFO) << "set vertex attrib " << ss.str() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < nbAttribs; i++)
|
||||
{
|
||||
std::stringstream ss;
|
||||
@ -134,7 +134,7 @@ struct SetupRigGeometry : public osg::NodeVisitor
|
||||
{
|
||||
bool _hardware;
|
||||
SetupRigGeometry( bool hardware = true) : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN), _hardware(hardware) {}
|
||||
|
||||
|
||||
void apply(osg::Geode& geode)
|
||||
{
|
||||
for (unsigned int i = 0; i < geode.getNumDrawables(); i++)
|
||||
@ -173,7 +173,7 @@ osg::Group* createCharacterInstance(osg::Group* character, bool hardware)
|
||||
anim->playAnimation(list[v].get());
|
||||
v = (v + 1)%list.size();
|
||||
}
|
||||
|
||||
|
||||
anim->playAnimation(list[v].get());
|
||||
|
||||
SetupRigGeometry switcher(hardware);
|
||||
@ -196,9 +196,9 @@ int main (int argc, char* argv[])
|
||||
while (psr.read("--software")) { hardware = false; }
|
||||
while (psr.read("--number", maxChar)) {}
|
||||
|
||||
|
||||
osg::ref_ptr<osg::Group> root = dynamic_cast<osg::Group*>(osgDB::readNodeFiles(psr));
|
||||
if (!root)
|
||||
osg::ref_ptr<osg::Node> node = osgDB::readRefNodeFiles(psr);
|
||||
osg::ref_ptr<osg::Group> root = dynamic_cast<osg::Group*>(node.get());
|
||||
if (!root)
|
||||
{
|
||||
std::cout << psr.getApplicationName() <<": No data loaded" << std::endl;
|
||||
return 1;
|
||||
@ -206,7 +206,7 @@ int main (int argc, char* argv[])
|
||||
|
||||
{
|
||||
osgAnimation::AnimationManagerBase* animationManager = dynamic_cast<osgAnimation::AnimationManagerBase*>(root->getUpdateCallback());
|
||||
if(!animationManager)
|
||||
if(!animationManager)
|
||||
{
|
||||
osg::notify(osg::FATAL) << "no AnimationManagerBase found, updateCallback need to animate elements" << std::endl;
|
||||
return 1;
|
||||
@ -218,13 +218,13 @@ int main (int argc, char* argv[])
|
||||
|
||||
// add the state manipulator
|
||||
viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) );
|
||||
|
||||
|
||||
// add the thread model handler
|
||||
viewer.addEventHandler(new osgViewer::ThreadingHandler);
|
||||
|
||||
// add the window size toggle handler
|
||||
viewer.addEventHandler(new osgViewer::WindowSizeHandler);
|
||||
|
||||
|
||||
// add the stats handler
|
||||
viewer.addEventHandler(new osgViewer::StatsHandler);
|
||||
|
||||
|
@ -1,14 +1,14 @@
|
||||
/* -*-c++-*-
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2008 Cedric Pinson <mornifle@plopbyte.net>
|
||||
*
|
||||
* 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
|
||||
* 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
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
@ -33,11 +33,11 @@ struct GeometryFinder : public osg::NodeVisitor
|
||||
{
|
||||
osg::ref_ptr<osg::Geometry> _geom;
|
||||
GeometryFinder() : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {}
|
||||
void apply(osg::Geode& geode)
|
||||
void apply(osg::Geode& geode)
|
||||
{
|
||||
if (_geom.valid())
|
||||
return;
|
||||
for (unsigned int i = 0; i < geode.getNumDrawables(); i++)
|
||||
for (unsigned int i = 0; i < geode.getNumDrawables(); i++)
|
||||
{
|
||||
osg::Geometry* geom = dynamic_cast<osg::Geometry*>(geode.getDrawable(i));
|
||||
if (geom) {
|
||||
@ -50,7 +50,7 @@ struct GeometryFinder : public osg::NodeVisitor
|
||||
|
||||
osg::ref_ptr<osg::Geometry> getShape(const std::string& name)
|
||||
{
|
||||
osg::ref_ptr<osg::Node> shape0 = osgDB::readNodeFile(name);
|
||||
osg::ref_ptr<osg::Node> shape0 = osgDB::readRefNodeFile(name);
|
||||
if (shape0)
|
||||
{
|
||||
GeometryFinder finder;
|
||||
@ -104,7 +104,7 @@ int main (int argc, char* argv[])
|
||||
|
||||
osg::Group* scene = new osg::Group;
|
||||
scene->addUpdateCallback(bam);
|
||||
|
||||
|
||||
osg::Geode* geode = new osg::Geode;
|
||||
geode->addDrawable(morph);
|
||||
geode->addUpdateCallback(new osgAnimation::UpdateMorph("MorphNodeCallback"));
|
||||
|
@ -163,7 +163,8 @@ int main (int argc, char* argv[])
|
||||
file = psr[1];
|
||||
|
||||
// replace the manager
|
||||
osg::Group* root = dynamic_cast<osg::Group*>(osgDB::readNodeFile(file));
|
||||
osg::ref_ptr<osg::Node> loadedmodel = osgDB::readRefNodeFile(file);
|
||||
osg::Group* root = dynamic_cast<osg::Group*>(loadedmodel.get());
|
||||
if (!root) {
|
||||
osg::notify(osg::FATAL) << "can't read file " << file << std::endl;
|
||||
return 1;
|
||||
|
@ -127,7 +127,8 @@ int main(int argc, char** argv)
|
||||
osgViewer::Viewer viewer(arguments);
|
||||
osg::ref_ptr<osg::Group> group = new osg::Group();
|
||||
|
||||
osg::Group* node = dynamic_cast<osg::Group*>(osgDB::readNodeFiles(arguments)); //dynamic_cast<osgAnimation::AnimationManager*>(osgDB::readNodeFile(psr[1]));
|
||||
osg::ref_ptr<osg::Node> loadedmodel = osgDB::readRefNodeFiles(arguments);
|
||||
osg::Group* node = dynamic_cast<osg::Group*>(loadedmodel.get());
|
||||
if(!node)
|
||||
{
|
||||
std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl;
|
||||
|
@ -165,7 +165,7 @@ int main(int argc, char** argv)
|
||||
viewer.addEventHandler(new osgViewer::ScreenCaptureHandler);
|
||||
|
||||
// load the data
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFiles(arguments);
|
||||
if (!loadedModel)
|
||||
{
|
||||
osg::Geometry * quad = osg::createTexturedQuadGeometry(osg::Vec3f(-2.0f, 0.0f, -2.0f),
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include <osgViewer/Viewer>
|
||||
#include <osgViewer/ViewerEventHandlers>
|
||||
#include <osgViewer/Renderer>
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
@ -41,7 +41,7 @@ public:
|
||||
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
|
||||
_foundNode(0)
|
||||
{}
|
||||
|
||||
|
||||
void apply(osg::Node& node)
|
||||
{
|
||||
T* result = dynamic_cast<T*>(&node);
|
||||
@ -50,7 +50,7 @@ public:
|
||||
else
|
||||
traverse(node);
|
||||
}
|
||||
|
||||
|
||||
T* _foundNode;
|
||||
};
|
||||
|
||||
@ -62,21 +62,21 @@ T* findTopMostNodeOfType(osg::Node* node)
|
||||
|
||||
FindTopMostNodeOfTypeVisitor<T> fnotv;
|
||||
node->accept(fnotv);
|
||||
|
||||
|
||||
return fnotv._foundNode;
|
||||
}
|
||||
|
||||
/** Capture the frame buffer and write image to disk*/
|
||||
class WindowCaptureCallback : public osg::Camera::DrawCallback
|
||||
{
|
||||
public:
|
||||
public:
|
||||
WindowCaptureCallback(GLenum readBuffer, const std::string& name):
|
||||
_readBuffer(readBuffer),
|
||||
_fileName(name)
|
||||
{
|
||||
_image = new osg::Image;
|
||||
}
|
||||
|
||||
|
||||
virtual void operator () (osg::RenderInfo& renderInfo) const
|
||||
{
|
||||
#if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE)
|
||||
@ -93,9 +93,9 @@ public:
|
||||
|
||||
if (gc->getTraits()->alpha)
|
||||
pixelFormat = GL_RGBA;
|
||||
else
|
||||
else
|
||||
pixelFormat = GL_RGB;
|
||||
|
||||
|
||||
#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE)
|
||||
if (pixelFormat == GL_RGB)
|
||||
{
|
||||
@ -118,7 +118,7 @@ public:
|
||||
|
||||
_image->readPixels(0, 0, width, height, pixelFormat, GL_UNSIGNED_BYTE);
|
||||
}
|
||||
|
||||
|
||||
if (!_fileName.empty())
|
||||
{
|
||||
std::cout << "Writing to: " << _fileName << std::endl;
|
||||
@ -126,7 +126,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
protected:
|
||||
GLenum _readBuffer;
|
||||
std::string _fileName;
|
||||
osg::ref_ptr<osg::Image> _image;
|
||||
@ -138,7 +138,7 @@ protected:
|
||||
class CustomRenderer : public osgViewer::Renderer
|
||||
{
|
||||
public:
|
||||
CustomRenderer(osg::Camera* camera)
|
||||
CustomRenderer(osg::Camera* camera)
|
||||
: osgViewer::Renderer(camera),
|
||||
_cullOnly(true)
|
||||
{
|
||||
@ -162,19 +162,19 @@ public:
|
||||
{
|
||||
osgUtil::SceneView* sceneView = _sceneView[0].get();
|
||||
if (!sceneView || _done ) return;
|
||||
|
||||
|
||||
updateSceneView(sceneView);
|
||||
|
||||
|
||||
osgViewer::View* view = dynamic_cast<osgViewer::View*>(_camera->getView());
|
||||
if (view) sceneView->setFusionDistance(view->getFusionDistanceMode(), view->getFusionDistanceValue());
|
||||
|
||||
sceneView->inheritCullSettings(*(sceneView->getCamera()));
|
||||
sceneView->cull();
|
||||
}
|
||||
|
||||
|
||||
bool _cullOnly;
|
||||
};
|
||||
|
||||
|
||||
|
||||
//===============================================================
|
||||
// MAIN
|
||||
@ -287,8 +287,8 @@ int main( int argc, char **argv )
|
||||
}
|
||||
|
||||
// load the data
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
|
||||
if (!loadedModel)
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFiles(arguments);
|
||||
if (!loadedModel)
|
||||
{
|
||||
std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl;
|
||||
return 1;
|
||||
@ -309,7 +309,7 @@ int main( int argc, char **argv )
|
||||
{
|
||||
osg::CoordinateSystemNode* csn = findTopMostNodeOfType<osg::CoordinateSystemNode>(loadedModel.get());
|
||||
if(!csn) return 1;
|
||||
|
||||
|
||||
// Compute eye point in world coordiantes
|
||||
osg::Vec3d eye;
|
||||
csn->getEllipsoidModel()->convertLatLongHeightToXYZ(lat, lon, alt, eye.x(), eye.y(), eye.z());
|
||||
@ -331,11 +331,11 @@ int main( int argc, char **argv )
|
||||
osg::Vec3d up_cross_tangent = up ^ tangent;
|
||||
osg::Matrixd incline_matrix = osg::Matrixd::rotate(incline, up_cross_tangent);
|
||||
osg::Vec3d target = incline_matrix.preMult(tangent);
|
||||
|
||||
|
||||
// Roll by rotating the up vector around the target vector ...
|
||||
osg::Matrixd roll_matrix = incline_matrix * osg::Matrixd::rotate(roll, target);
|
||||
up = roll_matrix.preMult(up);
|
||||
|
||||
|
||||
viewer.getCamera()->setViewMatrixAsLookAt(eye, eye+target, up);
|
||||
}
|
||||
else
|
||||
@ -349,10 +349,10 @@ int main( int argc, char **argv )
|
||||
keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() );
|
||||
keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() );
|
||||
|
||||
viewer.setCameraManipulator( keyswitchManipulator.get() );
|
||||
viewer.setCameraManipulator( keyswitchManipulator.get() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Optimize DatabasePager for auto-capture
|
||||
osgDB::DatabasePager* pager = viewer.getDatabasePager();
|
||||
pager->setDoPreCompile(false);
|
||||
@ -374,9 +374,9 @@ int main( int argc, char **argv )
|
||||
|
||||
// Initiate the first PagedLOD request
|
||||
viewer.frame();
|
||||
|
||||
|
||||
osg::Timer_t beforeLoadTick = osg::Timer::instance()->tick();
|
||||
|
||||
|
||||
// Keep updating and culling until full level of detail is reached
|
||||
while(!viewer.done() && pager->getRequestsInProgress())
|
||||
{
|
||||
@ -385,14 +385,14 @@ int main( int argc, char **argv )
|
||||
viewer.renderingTraversals();
|
||||
}
|
||||
// std::cout<<std::endl;
|
||||
|
||||
|
||||
osg::Timer_t afterLoadTick = osg::Timer::instance()->tick();
|
||||
std::cout<<"Load and Compile time = "<<osg::Timer::instance()->delta_s(beforeLoadTick, afterLoadTick)<<" seconds"<<std::endl;
|
||||
|
||||
// Do cull and draw to render the scene correctly
|
||||
customRenderer->setCullOnly(false);
|
||||
|
||||
|
||||
|
||||
|
||||
//--- Capture the image!!! ---
|
||||
if (!activeMode)
|
||||
{
|
||||
|
@ -42,10 +42,10 @@
|
||||
typedef std::vector< osg::ref_ptr<osg::Image> > ImageList;
|
||||
|
||||
/** create quad at specified position. */
|
||||
osg::Drawable* createSquare(const osg::Vec3& corner,const osg::Vec3& width,const osg::Vec3& height, osg::Image* image=NULL)
|
||||
osg::Drawable* createSquare(const osg::Vec3& corner,const osg::Vec3& width,const osg::Vec3& height, osg::ref_ptr<osg::Image> image)
|
||||
{
|
||||
// set up the Geometry.
|
||||
osg::Geometry* geom = new osg::Geometry;
|
||||
osg::ref_ptr<osg::Geometry> geom = new osg::Geometry;
|
||||
|
||||
osg::Vec3Array* coords = new osg::Vec3Array(4);
|
||||
(*coords)[0] = corner;
|
||||
@ -80,13 +80,13 @@ osg::Drawable* createSquare(const osg::Vec3& corner,const osg::Vec3& width,const
|
||||
geom->setStateSet(stateset);
|
||||
}
|
||||
|
||||
return geom;
|
||||
return geom.release();
|
||||
}
|
||||
|
||||
osg::Drawable* createAxis(const osg::Vec3& corner,const osg::Vec3& xdir,const osg::Vec3& ydir,const osg::Vec3& zdir)
|
||||
{
|
||||
// set up the Geometry.
|
||||
osg::Geometry* geom = new osg::Geometry;
|
||||
osg::ref_ptr<osg::Geometry> geom = new osg::Geometry;
|
||||
|
||||
osg::Vec3Array* coords = new osg::Vec3Array(6);
|
||||
(*coords)[0] = corner;
|
||||
@ -121,20 +121,20 @@ osg::Drawable* createAxis(const osg::Vec3& corner,const osg::Vec3& xdir,const os
|
||||
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
|
||||
geom->setStateSet(stateset);
|
||||
|
||||
return geom;
|
||||
return geom.release();
|
||||
}
|
||||
|
||||
osg::Node* createModel()
|
||||
osg::ref_ptr<osg::Node> createModel()
|
||||
{
|
||||
|
||||
// create the root node which will hold the model.
|
||||
osg::Group* root = new osg::Group();
|
||||
osg::ref_ptr<osg::Group> root = new osg::Group();
|
||||
|
||||
// add the drawable into a single geode to be shared...
|
||||
osg::Billboard* center = new osg::Billboard();
|
||||
center->setMode(osg::Billboard::POINT_ROT_EYE);
|
||||
center->addDrawable(
|
||||
createSquare(osg::Vec3(-0.5f,0.0f,-0.5f),osg::Vec3(1.0f,0.0f,0.0f),osg::Vec3(0.0f,0.0f,1.0f),osgDB::readImageFile("Images/reflect.rgb")),
|
||||
createSquare(osg::Vec3(-0.5f,0.0f,-0.5f),osg::Vec3(1.0f,0.0f,0.0f),osg::Vec3(0.0f,0.0f,1.0f),osgDB::readRefImageFile("Images/reflect.rgb")),
|
||||
osg::Vec3(0.0f,0.0f,0.0f));
|
||||
|
||||
osg::Billboard* x_arrow = new osg::Billboard();
|
||||
@ -142,7 +142,7 @@ osg::Node* createModel()
|
||||
x_arrow->setAxis(osg::Vec3(1.0f,0.0f,0.0f));
|
||||
x_arrow->setNormal(osg::Vec3(0.0f,-1.0f,0.0f));
|
||||
x_arrow->addDrawable(
|
||||
createSquare(osg::Vec3(-0.5f,0.0f,-0.5f),osg::Vec3(1.0f,0.0f,0.0f),osg::Vec3(0.0f,0.0f,1.0f),osgDB::readImageFile("Cubemap_axis/posx.png")),
|
||||
createSquare(osg::Vec3(-0.5f,0.0f,-0.5f),osg::Vec3(1.0f,0.0f,0.0f),osg::Vec3(0.0f,0.0f,1.0f),osgDB::readRefImageFile("Cubemap_axis/posx.png")),
|
||||
osg::Vec3(5.0f,0.0f,0.0f));
|
||||
|
||||
osg::Billboard* y_arrow = new osg::Billboard();
|
||||
@ -150,7 +150,7 @@ osg::Node* createModel()
|
||||
y_arrow->setAxis(osg::Vec3(0.0f,1.0f,0.0f));
|
||||
y_arrow->setNormal(osg::Vec3(1.0f,0.0f,0.0f));
|
||||
y_arrow->addDrawable(
|
||||
createSquare(osg::Vec3(0.0f,-0.5f,-0.5f),osg::Vec3(0.0f,1.0f,0.0f),osg::Vec3(0.0f,0.0f,1.0f),osgDB::readImageFile("Cubemap_axis/posy.png")),
|
||||
createSquare(osg::Vec3(0.0f,-0.5f,-0.5f),osg::Vec3(0.0f,1.0f,0.0f),osg::Vec3(0.0f,0.0f,1.0f),osgDB::readRefImageFile("Cubemap_axis/posy.png")),
|
||||
osg::Vec3(0.0f,5.0f,0.0f));
|
||||
|
||||
osg::Billboard* z_arrow = new osg::Billboard();
|
||||
@ -158,7 +158,7 @@ osg::Node* createModel()
|
||||
z_arrow->setAxis(osg::Vec3(0.0f,0.0f,1.0f));
|
||||
z_arrow->setNormal(osg::Vec3(0.0f,-1.0f,0.0f));
|
||||
z_arrow->addDrawable(
|
||||
createSquare(osg::Vec3(-0.5f,0.0f,-0.5f),osg::Vec3(1.0f,0.0f,0.0f),osg::Vec3(0.0f,0.0f,1.0f),osgDB::readImageFile("Cubemap_axis/posz.png")),
|
||||
createSquare(osg::Vec3(-0.5f,0.0f,-0.5f),osg::Vec3(1.0f,0.0f,0.0f),osg::Vec3(0.0f,0.0f,1.0f),osgDB::readRefImageFile("Cubemap_axis/posz.png")),
|
||||
osg::Vec3(0.0f,0.0f,5.0f));
|
||||
|
||||
|
||||
|
@ -71,9 +71,17 @@ int main( int argc, char **argv )
|
||||
bool useGlobalBlending = false;
|
||||
if ( arguments.read("--no-draw-buffers") ) useGlobalBlending = true;
|
||||
|
||||
|
||||
osg::ref_ptr<osg::Node> cessna = osgDB::readRefNodeFile("cessna.osgt");
|
||||
if (!cessna)
|
||||
{
|
||||
OSG_NOTICE<<"Cannot not find model 'cessna.osg' to render"<<std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Create a camera to output multi-rendering-targets (MRT)
|
||||
osg::Camera* mrtCam = createMRTCamera( textures );
|
||||
mrtCam->addChild( osgDB::readNodeFile("cessna.osgt") );
|
||||
osg::ref_ptr<osg::Camera> mrtCam = createMRTCamera( textures );
|
||||
mrtCam->addChild( cessna );
|
||||
|
||||
// Create shader program to be used
|
||||
const char* mrtFragmentCode = {
|
||||
@ -87,8 +95,8 @@ int main( int argc, char **argv )
|
||||
osg::ref_ptr<osg::Program> program = new osg::Program;
|
||||
program->addShader( new osg::Shader(osg::Shader::FRAGMENT, mrtFragmentCode) );
|
||||
|
||||
osg::StateSet* ss = mrtCam->getOrCreateStateSet();
|
||||
ss->setAttributeAndModes( program.get() );
|
||||
osg::ref_ptr<osg::StateSet> ss = mrtCam->getOrCreateStateSet();
|
||||
ss->setAttributeAndModes( program );
|
||||
|
||||
// Apply blending to the original scene in MRT
|
||||
if ( !useGlobalBlending )
|
||||
@ -103,8 +111,8 @@ int main( int argc, char **argv )
|
||||
// Accept different blend/colormask attributes on multiple render targets
|
||||
osg::ref_ptr<osg::BlendFunci> blend0 = new osg::BlendFunci(0, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
osg::ref_ptr<osg::ColorMaski> colormask3 = new osg::ColorMaski(3, false, true, false, true);
|
||||
ss->setAttribute( blend0.get() );
|
||||
ss->setAttributeAndModes( colormask3.get() );
|
||||
ss->setAttribute( blend0 );
|
||||
ss->setAttributeAndModes( colormask3 );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -139,10 +139,10 @@ int main( int argc, char **argv )
|
||||
osgViewer::Viewer viewer;
|
||||
|
||||
// load the nodes from the commandline arguments.
|
||||
osg::Node* loadedModel = osgDB::readNodeFiles(arguments);
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFiles(arguments);
|
||||
|
||||
// if not loaded assume no arguments passed in, try use default mode instead.
|
||||
if (!loadedModel) loadedModel = osgDB::readNodeFile("cessnafire.osgt");
|
||||
if (!loadedModel) loadedModel = osgDB::readRefNodeFile("cessnafire.osgt");
|
||||
|
||||
if (!loadedModel)
|
||||
{
|
||||
@ -150,11 +150,11 @@ int main( int argc, char **argv )
|
||||
return 1;
|
||||
}
|
||||
|
||||
osg::Group* root = new osg::Group;
|
||||
osg::ref_ptr<osg::Group> root = new osg::Group;
|
||||
root->addChild(loadedModel);
|
||||
|
||||
|
||||
osg::StateSet* stateset = new osg::StateSet;
|
||||
osg::ref_ptr<osg::StateSet> stateset = new osg::StateSet;
|
||||
stateset->setDataVariance(osg::Object::DYNAMIC);
|
||||
|
||||
osg::BlendEquation* blendEquation = new osg::BlendEquation(osg::BlendEquation::FUNC_ADD);
|
||||
|
@ -239,10 +239,10 @@ int main( int argc, char **argv )
|
||||
}
|
||||
else
|
||||
{
|
||||
rootnode = osgDB::readNodeFiles(arguments);
|
||||
rootnode = osgDB::readRefNodeFiles(arguments);
|
||||
|
||||
// if not loaded assume no arguments passed in, try use default mode instead.
|
||||
if (!rootnode) rootnode = osgDB::readNodeFile("cow.osgt");
|
||||
if (!rootnode) rootnode = osgDB::readRefNodeFile("cow.osgt");
|
||||
|
||||
if (!rootnode)
|
||||
{
|
||||
|
@ -25,50 +25,50 @@
|
||||
#include <osgGA/AnimationPathManipulator>
|
||||
#include <iostream>
|
||||
|
||||
class ModelHandler : public osgGA::GUIEventHandler
|
||||
class ModelHandler : public osgGA::GUIEventHandler
|
||||
{
|
||||
public:
|
||||
public:
|
||||
|
||||
ModelHandler():
|
||||
_position(0) {}
|
||||
|
||||
|
||||
typedef std::vector<std::string> Filenames;
|
||||
Filenames _filenames;
|
||||
unsigned int _position;
|
||||
|
||||
|
||||
void add(const std::string& filename) { _filenames.push_back(filename); }
|
||||
|
||||
|
||||
bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
|
||||
{
|
||||
osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(&aa);
|
||||
if (!viewer) return false;
|
||||
|
||||
|
||||
if (_filenames.empty()) return false;
|
||||
|
||||
|
||||
switch(ea.getEventType())
|
||||
{
|
||||
case(osgGA::GUIEventAdapter::KEYUP):
|
||||
{
|
||||
if (ea.getKey()=='l')
|
||||
{
|
||||
osg::ref_ptr<osg::Node> model = osgDB::readNodeFile( _filenames[_position] );
|
||||
{
|
||||
osg::ref_ptr<osg::Node> model = osgDB::readRefNodeFile( _filenames[_position] );
|
||||
++_position;
|
||||
if (_position>=_filenames.size()) _position = 0;
|
||||
|
||||
|
||||
if (model.valid())
|
||||
{
|
||||
viewer->setSceneData(model.get());
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool _done;
|
||||
};
|
||||
|
||||
@ -76,12 +76,12 @@ public:
|
||||
void singleWindowMultipleCameras(osgViewer::Viewer& viewer)
|
||||
{
|
||||
osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
|
||||
if (!wsi)
|
||||
if (!wsi)
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Error, no WindowSystemInterface available, cannot create windows."<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
unsigned int width, height;
|
||||
wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height);
|
||||
|
||||
@ -127,12 +127,12 @@ void singleWindowMultipleCameras(osgViewer::Viewer& viewer)
|
||||
void multipleWindowMultipleCameras(osgViewer::Viewer& viewer, bool multipleScreens)
|
||||
{
|
||||
osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
|
||||
if (!wsi)
|
||||
if (!wsi)
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Error, no WindowSystemInterface available, cannot create windows."<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
unsigned int width, height;
|
||||
wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height);
|
||||
|
||||
@ -198,7 +198,7 @@ int main( int argc, char **argv )
|
||||
// use an ArgumentParser object to manage the program arguments.
|
||||
osg::ArgumentParser arguments(&argc,argv);
|
||||
|
||||
if (argc<2)
|
||||
if (argc<2)
|
||||
{
|
||||
std::cout << argv[0] <<": requires filename argument." << std::endl;
|
||||
return 1;
|
||||
@ -214,7 +214,7 @@ int main( int argc, char **argv )
|
||||
osg::ref_ptr<osg::Node> model;
|
||||
if (sharedModel)
|
||||
{
|
||||
model = osgDB::readNodeFiles(arguments);
|
||||
model = osgDB::readRefNodeFiles(arguments);
|
||||
if (!model) return 0;
|
||||
|
||||
if (enableVBO)
|
||||
@ -242,7 +242,7 @@ int main( int argc, char **argv )
|
||||
if (sharedModel) viewer.setSceneData(model.get());
|
||||
else
|
||||
{
|
||||
osg::ref_ptr<osg::Node> node = osgDB::readNodeFiles(arguments);
|
||||
osg::ref_ptr<osg::Node> node = osgDB::readRefNodeFiles(arguments);
|
||||
if (!node) return 0;
|
||||
|
||||
if (enableVBO)
|
||||
@ -268,19 +268,19 @@ int main( int argc, char **argv )
|
||||
while (arguments.read("-p",pathfile))
|
||||
{
|
||||
apm = new osgGA::AnimationPathManipulator(pathfile);
|
||||
if (!apm.valid() || !(apm->valid()) )
|
||||
if (!apm.valid() || !(apm->valid()) )
|
||||
{
|
||||
apm = 0;
|
||||
}
|
||||
}
|
||||
|
||||
osgViewer::Viewer viewer(arguments);
|
||||
|
||||
|
||||
while (arguments.read("-s")) { viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded); }
|
||||
while (arguments.read("-g")) { viewer.setThreadingModel(osgViewer::Viewer::CullDrawThreadPerContext); }
|
||||
while (arguments.read("-d")) { viewer.setThreadingModel(osgViewer::Viewer::DrawThreadPerContext); }
|
||||
while (arguments.read("-c")) { viewer.setThreadingModel(osgViewer::Viewer::CullThreadPerCameraDrawThreadPerContext); }
|
||||
|
||||
|
||||
bool limitNumberOfFrames = false;
|
||||
unsigned int maxFrames = 10;
|
||||
while (arguments.read("--run-till-frame-number",maxFrames)) { limitNumberOfFrames = true; }
|
||||
@ -292,7 +292,7 @@ int main( int argc, char **argv )
|
||||
|
||||
if (apm.valid()) viewer.setCameraManipulator(apm.get());
|
||||
else viewer.setCameraManipulator( new osgGA::TrackballManipulator() );
|
||||
|
||||
|
||||
viewer.addEventHandler(new osgViewer::StatsHandler);
|
||||
viewer.addEventHandler(new osgViewer::ThreadingHandler);
|
||||
|
||||
@ -300,7 +300,7 @@ int main( int argc, char **argv )
|
||||
while (arguments.read("--config", configfile))
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Trying to read config file "<<configfile<<std::endl;
|
||||
osg::ref_ptr<osg::Object> object = osgDB::readObjectFile(configfile);
|
||||
osg::ref_ptr<osg::Object> object = osgDB::readRefObjectFile(configfile);
|
||||
osgViewer::View* view = dynamic_cast<osgViewer::View*>(object.get());
|
||||
if (view)
|
||||
{
|
||||
@ -329,19 +329,19 @@ int main( int argc, char **argv )
|
||||
else
|
||||
{
|
||||
// load the scene.
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFiles(arguments);
|
||||
|
||||
if (!loadedModel) loadedModel = osgDB::readNodeFile("cow.osgt");
|
||||
if (!loadedModel) loadedModel = osgDB::readRefNodeFile("cow.osgt");
|
||||
|
||||
if (!loadedModel)
|
||||
if (!loadedModel)
|
||||
{
|
||||
std::cout << argv[0] <<": No data loaded." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
viewer.setSceneData(loadedModel.get());
|
||||
viewer.setSceneData(loadedModel);
|
||||
}
|
||||
|
||||
|
||||
viewer.realize();
|
||||
|
||||
unsigned int numFrames = 0;
|
||||
|
@ -55,11 +55,11 @@ class Character : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
Character();
|
||||
|
||||
|
||||
void setCharacter(const std::string& filename, const std::string& name, const osg::Vec3& orgin, const osg::Vec3& width, const osg::Vec3& catchPos, float positionRatio);
|
||||
|
||||
|
||||
void setLives(const std::string& filename, const osg::Vec3& orgin, const osg::Vec3& delta, unsigned int numLives);
|
||||
|
||||
|
||||
void setCatches(const std::string& filename, const osg::Vec3& orgin, const osg::Vec3& delta, unsigned int numLives);
|
||||
|
||||
void moveLeft();
|
||||
@ -71,7 +71,7 @@ public:
|
||||
void resetCatches();
|
||||
|
||||
bool addCatch();
|
||||
|
||||
|
||||
bool looseLife();
|
||||
|
||||
osg::Vec3 getCurrentCenterOfBasket() const { return _character->getPosition()+_centerBasket; }
|
||||
@ -91,12 +91,12 @@ public:
|
||||
|
||||
unsigned int _numCatches;
|
||||
osg::ref_ptr<osg::Switch> _catchSwitch;
|
||||
|
||||
|
||||
osg::ref_ptr<osg::Group> _objectsGroup;
|
||||
|
||||
|
||||
osg::Vec3 _centerBasket;
|
||||
float _radiusBasket;
|
||||
|
||||
|
||||
};
|
||||
|
||||
Character::Character():
|
||||
@ -117,7 +117,7 @@ void Character::setCharacter(const std::string& filename, const std::string& nam
|
||||
|
||||
float _characterSize = _width.length()*0.2f;
|
||||
|
||||
osg::Image* image = osgDB::readImageFile(filename);
|
||||
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile(filename);
|
||||
if (image)
|
||||
{
|
||||
osg::Vec3 pos(-0.5f*_characterSize,0.0f,0.0f);
|
||||
@ -136,14 +136,14 @@ void Character::setCharacter(const std::string& filename, const std::string& nam
|
||||
_character = new osg::PositionAttitudeTransform;
|
||||
_character->setName(name);
|
||||
_character->addChild(geode);
|
||||
|
||||
|
||||
moveTo(positionRatio);
|
||||
|
||||
_centerBasket = width*catchPos.x() + height*catchPos.y() + pos;
|
||||
_radiusBasket = width.length()*catchPos.z();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Character::setLives(const std::string& filename, const osg::Vec3& origin, const osg::Vec3& delta, unsigned int numLives)
|
||||
@ -153,7 +153,7 @@ void Character::setLives(const std::string& filename, const osg::Vec3& origin, c
|
||||
_numLives = numLives;
|
||||
_livesSwitch = new osg::Switch;
|
||||
|
||||
osg::Image* image = osgDB::readImageFile(filename);
|
||||
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile(filename);
|
||||
if (image)
|
||||
{
|
||||
osg::StateSet* stateset = _livesSwitch->getOrCreateStateSet();
|
||||
@ -186,7 +186,7 @@ void Character::setCatches(const std::string& filename, const osg::Vec3& origin,
|
||||
_numCatches = 0;
|
||||
_catchSwitch = new osg::Switch;
|
||||
|
||||
osg::Image* image = osgDB::readImageFile(filename);
|
||||
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile(filename);
|
||||
if (image)
|
||||
{
|
||||
osg::StateSet* stateset = _catchSwitch->getOrCreateStateSet();
|
||||
@ -249,20 +249,20 @@ void Character::resetCatches()
|
||||
bool Character::addCatch()
|
||||
{
|
||||
if (!_catchSwitch || _numCatches>=_catchSwitch->getNumChildren()) return false;
|
||||
|
||||
|
||||
_catchSwitch->setValue(_numCatches,true);
|
||||
++_numCatches;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Character::looseLife()
|
||||
{
|
||||
if (!_livesSwitch || _numLives==0) return false;
|
||||
|
||||
|
||||
--_numLives;
|
||||
_livesSwitch->setValue(_numLives,false);
|
||||
|
||||
|
||||
return (_numLives!=0);
|
||||
}
|
||||
|
||||
@ -279,21 +279,21 @@ class CatchableObject : public osg::Referenced
|
||||
bool anyInside(const osg::Vec3& lower_left, const osg::Vec3& top_right);
|
||||
|
||||
bool centerInside(const osg::Vec3& center, float radius);
|
||||
|
||||
|
||||
void explode();
|
||||
|
||||
|
||||
bool dangerous() { return _dangerous; }
|
||||
|
||||
void stop() { _stopped = true; }
|
||||
|
||||
|
||||
bool stopped() { return _stopped; }
|
||||
|
||||
|
||||
void setTimeToRemove(double time) { _timeToRemove=time; }
|
||||
|
||||
|
||||
double getTimeToRemove() { return _timeToRemove; }
|
||||
|
||||
|
||||
bool needToRemove(double time) { return _timeToRemove>=0.0 && time>_timeToRemove; }
|
||||
|
||||
|
||||
osg::ref_ptr<osg::PositionAttitudeTransform> _object;
|
||||
osg::Vec3 _velocity;
|
||||
float _mass;
|
||||
@ -307,7 +307,7 @@ class CatchableObject : public osg::Referenced
|
||||
static void setUpCatchablesMap(const FileList& fileList);
|
||||
|
||||
public:
|
||||
|
||||
|
||||
// update position and velocity
|
||||
void update(double dt);
|
||||
|
||||
@ -317,7 +317,7 @@ class CatchableObject : public osg::Referenced
|
||||
_viscosity = v;
|
||||
_viscosityCoefficient = 6 * osg::PI * _viscosity;
|
||||
}
|
||||
|
||||
|
||||
/// Get the viscosity of the fluid.
|
||||
inline float getFluidViscosity() const { return _viscosity; }
|
||||
|
||||
@ -330,17 +330,17 @@ class CatchableObject : public osg::Referenced
|
||||
|
||||
/// Get the density of the fluid.
|
||||
inline float getFluidDensity() const { return _density; }
|
||||
|
||||
|
||||
|
||||
|
||||
/// Set the wind vector.
|
||||
inline void setWind(const osg::Vec3& wind) { _wind = wind; }
|
||||
|
||||
|
||||
/// Get the wind vector.
|
||||
inline const osg::Vec3& getWind() const { return _wind; }
|
||||
|
||||
|
||||
/// Set the acceleration vector.
|
||||
inline void setAcceleration(const osg::Vec3& v) { _acceleration = v; }
|
||||
|
||||
|
||||
/// Get the acceleration vector.
|
||||
inline const osg::Vec3& getAcceleration() const { return _acceleration; }
|
||||
|
||||
@ -356,7 +356,7 @@ class CatchableObject : public osg::Referenced
|
||||
setFluidDensity(1.2929f);
|
||||
setFluidViscosity(1.8e-5f);
|
||||
}
|
||||
|
||||
|
||||
/// Set the fluid parameters as for pure water (20°C temperature).
|
||||
inline void setFluidToWater()
|
||||
{
|
||||
@ -364,7 +364,7 @@ class CatchableObject : public osg::Referenced
|
||||
setFluidDensity(1.0f);
|
||||
setFluidViscosity(1.002e-3f);
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
@ -375,15 +375,15 @@ class CatchableObject : public osg::Referenced
|
||||
|
||||
float _viscosityCoefficient;
|
||||
float _densityCoefficeint;
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
CatchableObject::CatchableObject()
|
||||
{
|
||||
_stopped = false;
|
||||
_dangerous = false;
|
||||
|
||||
|
||||
_timeToRemove = -1.0; // do not remove.
|
||||
setFluidToAir();
|
||||
}
|
||||
@ -395,14 +395,14 @@ void CatchableObject::setUpCatchablesMap(const FileList& fileList)
|
||||
++itr)
|
||||
{
|
||||
const std::string& filename = *itr;
|
||||
osg::Image* image = osgDB::readImageFile(filename);
|
||||
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile(filename);
|
||||
if (image)
|
||||
{
|
||||
osg::ref_ptr<osg::StateSet> stateset = new osg::StateSet();
|
||||
stateset->setTextureAttributeAndModes(0,new osg::Texture2D(image),osg::StateAttribute::ON);
|
||||
stateset->setMode(GL_BLEND,osg::StateAttribute::ON);
|
||||
stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
|
||||
|
||||
|
||||
osg::Vec3 width((float)(image->s())/(float)(image->t()),0.0f,0.0);
|
||||
osg::Vec3 height(0.0f,0.0f,1.0f);
|
||||
osg::Vec3 pos = (width+height)*-0.5f;
|
||||
@ -455,8 +455,8 @@ void CatchableObject::update(double dt)
|
||||
osg::Vec3 force = _acceleration * (_mass - _density*Volume);
|
||||
|
||||
// compute force due to friction
|
||||
osg::Vec3 relative_wind = _velocity-_wind;
|
||||
force -= relative_wind * Area * (_viscosityCoefficient + _densityCoefficeint*relative_wind.length());
|
||||
osg::Vec3 relative_wind = _velocity-_wind;
|
||||
force -= relative_wind * Area * (_viscosityCoefficient + _densityCoefficeint*relative_wind.length());
|
||||
|
||||
// divide force by mass to get acceleration.
|
||||
_velocity += force*(dt/_mass);
|
||||
@ -466,7 +466,7 @@ void CatchableObject::update(double dt)
|
||||
bool CatchableObject::anyInside(const osg::Vec3& lower_left, const osg::Vec3& upper_right)
|
||||
{
|
||||
osg::Vec3 pos = _object->getPosition();
|
||||
|
||||
|
||||
if (pos.x()+_radius < lower_left.x()) return false;
|
||||
if (pos.x()-_radius > upper_right.x()) return false;
|
||||
if (pos.z()+_radius < lower_left.z()) return false;
|
||||
@ -513,20 +513,20 @@ class GameEventHandler : public osgGA::GUIEventHandler
|
||||
public:
|
||||
|
||||
GameEventHandler();
|
||||
|
||||
|
||||
META_Object(osgStereImageApp,GameEventHandler);
|
||||
|
||||
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&);
|
||||
|
||||
|
||||
virtual void getUsage(osg::ApplicationUsage& usage) const;
|
||||
|
||||
|
||||
osg::Matrix getCameraPosition();
|
||||
|
||||
|
||||
void compileGLObjects(osg::State& state)
|
||||
{
|
||||
osgUtil::GLObjectsVisitor compile;
|
||||
compile.setState(&state);
|
||||
|
||||
|
||||
for(ObjectMap::iterator itr = s_objectMap.begin();
|
||||
itr != s_objectMap.end();
|
||||
++itr)
|
||||
@ -534,14 +534,14 @@ public:
|
||||
itr->second->accept(compile);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
osg::Node* createScene();
|
||||
|
||||
|
||||
void setFOVY(float fovy) { _fovy = fovy; }
|
||||
float getFOVY() const { return _fovy; }
|
||||
|
||||
|
||||
void createNewCatchable();
|
||||
|
||||
|
||||
void clearCatchables()
|
||||
{
|
||||
for(CatchableObjectList::iterator itr=_catchableObjects.begin();
|
||||
@ -562,7 +562,7 @@ public:
|
||||
|
||||
_catchableObjects.clear();
|
||||
}
|
||||
|
||||
|
||||
void resetLevel()
|
||||
{
|
||||
_level = 0;
|
||||
@ -573,7 +573,7 @@ public:
|
||||
|
||||
_levelStartTick = osg::Timer::instance()->tick();
|
||||
}
|
||||
|
||||
|
||||
void nextLevel()
|
||||
{
|
||||
++_level;
|
||||
@ -596,12 +596,12 @@ public:
|
||||
void resetGame()
|
||||
{
|
||||
_currentScore = 0;
|
||||
|
||||
|
||||
updateTextWithScore();
|
||||
|
||||
clearCatchables();
|
||||
resetLevel();
|
||||
|
||||
|
||||
for(unsigned int i=0;i<_numberOfPlayers;++i)
|
||||
{
|
||||
_players[i].reset();
|
||||
@ -629,12 +629,12 @@ public:
|
||||
livesPosition = _originBaseLine+osg::Vec3(1000.0f,-0.5f,000.0f);
|
||||
catchesPosition = _originBaseLine+osg::Vec3(1100.0f,-0.5f,0.0f);
|
||||
}
|
||||
|
||||
|
||||
switch(player)
|
||||
{
|
||||
case PLAYER_GIRL:
|
||||
{
|
||||
std::string player_one = "Catch/girl.png";
|
||||
std::string player_one = "Catch/girl.png";
|
||||
osg::Vec3 catchPos(0.2, 0.57, 0.34);
|
||||
|
||||
_players[_numberOfPlayers].setCharacter(player_one,"girl", _originBaseLine + osg::Vec3(0.0f,-1.0f,0.0f), _widthBaseLine, catchPos, 0.5f);
|
||||
@ -646,7 +646,7 @@ public:
|
||||
}
|
||||
case PLAYER_BOY:
|
||||
{
|
||||
std::string player_two = "Catch/boy.png";
|
||||
std::string player_two = "Catch/boy.png";
|
||||
osg::Vec3 catchPos(0.8, 0.57, 0.34);
|
||||
|
||||
_players[_numberOfPlayers].setCharacter(player_two,"boy", _originBaseLine + osg::Vec3(0.0f,-2.0f,0.0f), _widthBaseLine, catchPos, 0.5f);
|
||||
@ -656,10 +656,10 @@ public:
|
||||
++_numberOfPlayers;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
typedef std::vector< osg::ref_ptr<osgText::Text> > TextList;
|
||||
|
||||
void updateScoreWithCatch()
|
||||
@ -673,8 +673,8 @@ public:
|
||||
osg::Timer_t newTick = osg::Timer::instance()->tick();
|
||||
double timeForLevel = osg::Timer::instance()->delta_s(_levelStartTick, newTick);
|
||||
|
||||
// a ten second level gets you 10 points,
|
||||
// a twenty second levels gets you 5 points.
|
||||
// a ten second level gets you 10 points,
|
||||
// a twenty second levels gets you 5 points.
|
||||
_currentScore += static_cast<unsigned int>(10000.0f/(timeForLevel*timeForLevel));
|
||||
|
||||
updateTextWithScore();
|
||||
@ -685,24 +685,24 @@ public:
|
||||
{
|
||||
std::ostringstream os;
|
||||
os<<"Score: "<<_currentScore;
|
||||
|
||||
|
||||
std::string textString = os.str();
|
||||
|
||||
|
||||
for(TextList::iterator itr = _scoreTextList.begin();
|
||||
itr != _scoreTextList.end();
|
||||
++itr)
|
||||
{
|
||||
(*itr)->setText(textString);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void updateLevelText()
|
||||
{
|
||||
std::ostringstream os;
|
||||
os<<"Level: "<<_level+1;
|
||||
_levelText->setText(os.str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
@ -715,45 +715,45 @@ protected:
|
||||
osg::Vec3 _originBaseLine;
|
||||
osg::Vec3 _widthBaseLine;
|
||||
float _characterSize;
|
||||
|
||||
|
||||
float _fovy;
|
||||
|
||||
unsigned _level;
|
||||
|
||||
|
||||
float _chanceOfExplodingAtStart;
|
||||
float _initialNumDropsPerSecond;
|
||||
|
||||
|
||||
osg::ref_ptr<osg::Switch> _gameSwitch;
|
||||
osg::ref_ptr<osg::Group> _gameGroup;
|
||||
osg::ref_ptr<osg::Switch> _levelSwitch;
|
||||
|
||||
|
||||
unsigned int _currentIndex;
|
||||
unsigned int _welcomeIndex;
|
||||
unsigned int _lostIndex;
|
||||
unsigned int _wonIndex;
|
||||
unsigned int _gameIndex;
|
||||
|
||||
|
||||
osg::Timer_t _levelStartTick;
|
||||
unsigned int _currentScore;
|
||||
|
||||
|
||||
osg::ref_ptr<osgText::Text> _levelText;
|
||||
TextList _scoreTextList;
|
||||
|
||||
|
||||
unsigned int _numberOfPlayers;
|
||||
Character _players[2];
|
||||
|
||||
typedef std::list< osg::ref_ptr<CatchableObject> > CatchableObjectList;
|
||||
CatchableObjectList _catchableObjects;
|
||||
|
||||
|
||||
FileList _backgroundFiles;
|
||||
FileList _benignCatachables;
|
||||
|
||||
bool _leftKeyPressed;
|
||||
bool _rightKeyPressed;
|
||||
|
||||
|
||||
osg::ref_ptr<CatchableObject> _dummyCatchable;
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -791,11 +791,11 @@ GameEventHandler::GameEventHandler()
|
||||
_benignCatachables.push_back("Catch/t.png");
|
||||
_benignCatachables.push_back("Catch/u.png");
|
||||
_benignCatachables.push_back("Catch/ball.png");
|
||||
|
||||
|
||||
CatchableObject::setUpCatchablesMap(_benignCatachables);
|
||||
|
||||
|
||||
_currentScore = 0;
|
||||
|
||||
|
||||
setFOVY(osg::DegreesToRadians(60.0));
|
||||
|
||||
}
|
||||
@ -817,7 +817,7 @@ bool GameEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else if (_currentIndex==_lostIndex)
|
||||
{
|
||||
@ -834,7 +834,7 @@ bool GameEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else if (_currentIndex==_wonIndex)
|
||||
{
|
||||
@ -851,7 +851,7 @@ bool GameEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else if (_currentIndex==_gameIndex)
|
||||
{
|
||||
@ -888,7 +888,7 @@ bool GameEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA
|
||||
for(unsigned int i=0;i<_numberOfPlayers;++i)
|
||||
{
|
||||
bool inBasket = ((*itr)->centerInside(_players[i].getCurrentCenterOfBasket(),_players[i].getCurrentRadiusOfBasket()));
|
||||
|
||||
|
||||
if ((*itr)->dangerous())
|
||||
{
|
||||
if ((*itr)->anyInside(_players[i].getLowerLeft(),_players[i].getUpperRight()) || inBasket)
|
||||
@ -912,7 +912,7 @@ bool GameEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA
|
||||
{
|
||||
// player has caught a safe object.
|
||||
updateScoreWithCatch();
|
||||
|
||||
|
||||
if (!_players[i].addCatch())
|
||||
{
|
||||
_players[i].resetCatches();
|
||||
@ -930,7 +930,7 @@ bool GameEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA
|
||||
}
|
||||
}
|
||||
|
||||
if (!(*itr)->anyInside(_origin, _origin+_width+_height) ||
|
||||
if (!(*itr)->anyInside(_origin, _origin+_width+_height) ||
|
||||
(*itr)->needToRemove(ea.getTime()) ||
|
||||
removeEntry)
|
||||
{
|
||||
@ -968,7 +968,7 @@ bool GameEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA
|
||||
float numDropsPerSecond = _initialNumDropsPerSecond * (_level+1);
|
||||
float r = (float)rand()/(float)RAND_MAX;
|
||||
if (r < deltaTime*numDropsPerSecond)
|
||||
{
|
||||
{
|
||||
createNewCatchable();
|
||||
}
|
||||
|
||||
@ -1015,7 +1015,7 @@ bool GameEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
void GameEventHandler::getUsage(osg::ApplicationUsage&) const
|
||||
@ -1026,9 +1026,9 @@ osg::Matrix GameEventHandler::getCameraPosition()
|
||||
{
|
||||
osg::Matrix cameraPosition;
|
||||
osg::Vec3 center = _origin+(_width+_height)*0.5f;
|
||||
|
||||
|
||||
float distance = _height.length()/(2.0f*tanf(_fovy*0.5f));
|
||||
|
||||
|
||||
cameraPosition.makeLookAt(center-osg::Vec3(0.0f,distance,0.0f),center,osg::Vec3(0.0f,0.0f,1.0f));
|
||||
return cameraPosition;
|
||||
}
|
||||
@ -1036,8 +1036,8 @@ osg::Matrix GameEventHandler::getCameraPosition()
|
||||
osg::Node* GameEventHandler::createScene()
|
||||
{
|
||||
_gameSwitch = new osg::Switch;
|
||||
|
||||
// create a dummy catchable to load all the particule textures to reduce
|
||||
|
||||
// create a dummy catchable to load all the particule textures to reduce
|
||||
// latency later on..
|
||||
_dummyCatchable = new CatchableObject;
|
||||
_dummyCatchable->setObject("Catch/a.png","a",osg::Vec3(0.0f,0.0,0.0f),1.0f,osg::Vec3(0.0f,0.0,0.0f));
|
||||
@ -1045,10 +1045,10 @@ osg::Node* GameEventHandler::createScene()
|
||||
|
||||
// set up welcome subgraph
|
||||
{
|
||||
osg::Geode* geode = new osg::Geode;
|
||||
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
|
||||
|
||||
// set up the background
|
||||
osg::Image* image = osgDB::readImageFile("Catch/Welcome.jpg");
|
||||
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile("Catch/Welcome.jpg");
|
||||
if (image)
|
||||
{
|
||||
osg::Geometry* geometry = osg::createTexturedQuadGeometry(_origin,_width,_height);
|
||||
@ -1057,7 +1057,7 @@ osg::Node* GameEventHandler::createScene()
|
||||
|
||||
geode->addDrawable(geometry);
|
||||
}
|
||||
|
||||
|
||||
// set up the text
|
||||
osg::Vec3 textPosition = _origin+_width*0.5f+_height*0.8f -osg::Vec3(0.0f,0.1f,0.0f);
|
||||
{
|
||||
@ -1072,7 +1072,7 @@ osg::Node* GameEventHandler::createScene()
|
||||
|
||||
geode->addDrawable(text);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
textPosition -= _height*0.25f;
|
||||
osgText::Text* text = new osgText::Text;
|
||||
@ -1121,9 +1121,9 @@ osg::Node* GameEventHandler::createScene()
|
||||
|
||||
// set up you've lost subgraph
|
||||
{
|
||||
osg::Geode* geode = new osg::Geode;
|
||||
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
|
||||
|
||||
osg::Image* image = osgDB::readImageFile("Catch/YouLost.jpg");
|
||||
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile("Catch/YouLost.jpg");
|
||||
if (image)
|
||||
{
|
||||
osg::Geometry* geometry = osg::createTexturedQuadGeometry(_origin,_width,_height);
|
||||
@ -1132,7 +1132,7 @@ osg::Node* GameEventHandler::createScene()
|
||||
|
||||
geode->addDrawable(geometry);
|
||||
}
|
||||
|
||||
|
||||
// set up the text
|
||||
osg::Vec3 textPosition = _origin+_width*0.5f+_height*0.75f -osg::Vec3(0.0f,0.1f,0.0f);
|
||||
{
|
||||
@ -1147,7 +1147,7 @@ osg::Node* GameEventHandler::createScene()
|
||||
|
||||
geode->addDrawable(text);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
textPosition -= _height*0.25f;
|
||||
osgText::Text* text = new osgText::Text;
|
||||
@ -1184,9 +1184,9 @@ osg::Node* GameEventHandler::createScene()
|
||||
|
||||
// set up you've won subgraph
|
||||
{
|
||||
osg::Geode* geode = new osg::Geode;
|
||||
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
|
||||
|
||||
osg::Image* image = osgDB::readImageFile("Catch/YouWon.jpg");
|
||||
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile("Catch/YouWon.jpg");
|
||||
if (image)
|
||||
{
|
||||
osg::Geometry* geometry = osg::createTexturedQuadGeometry(_origin,_width,_height);
|
||||
@ -1195,7 +1195,7 @@ osg::Node* GameEventHandler::createScene()
|
||||
|
||||
geode->addDrawable(geometry);
|
||||
}
|
||||
|
||||
|
||||
// set up the text
|
||||
osg::Vec3 textPosition = _origin+_width*0.5f+_height*0.75f -osg::Vec3(0.0f,0.1f,0.0f);
|
||||
{
|
||||
@ -1210,7 +1210,7 @@ osg::Node* GameEventHandler::createScene()
|
||||
|
||||
geode->addDrawable(text);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
textPosition -= _height*0.25f;
|
||||
osgText::Text* text = new osgText::Text;
|
||||
@ -1258,7 +1258,7 @@ osg::Node* GameEventHandler::createScene()
|
||||
_gameGroup->addChild(_players[i]._character.get());
|
||||
_gameGroup->addChild(_players[i]._livesSwitch.get());
|
||||
_gameGroup->addChild(_players[i]._catchSwitch.get());
|
||||
}
|
||||
}
|
||||
|
||||
// background
|
||||
{
|
||||
@ -1269,7 +1269,7 @@ osg::Node* GameEventHandler::createScene()
|
||||
++itr)
|
||||
{
|
||||
|
||||
osg::Image* image = osgDB::readImageFile(*itr);
|
||||
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile(*itr);
|
||||
if (image)
|
||||
{
|
||||
osg::Geometry* geometry = osg::createTexturedQuadGeometry(_origin,_width,_height);
|
||||
@ -1305,7 +1305,7 @@ osg::Node* GameEventHandler::createScene()
|
||||
osg::Geode* geode = new osg::Geode;
|
||||
geode->addDrawable(text);
|
||||
_scoreTextList.push_back(text);
|
||||
|
||||
|
||||
textPosition -= _height*0.05f;
|
||||
_levelText = new osgText::Text;
|
||||
_levelText->setText("Level : 0");
|
||||
@ -1317,7 +1317,7 @@ osg::Node* GameEventHandler::createScene()
|
||||
_levelText->setAxisAlignment(osgText::Text::XZ_PLANE);
|
||||
|
||||
geode->addDrawable(_levelText.get());
|
||||
|
||||
|
||||
|
||||
|
||||
_gameGroup->addChild(geode);
|
||||
@ -1325,7 +1325,7 @@ osg::Node* GameEventHandler::createScene()
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
_currentIndex = _welcomeIndex;
|
||||
_gameSwitch->setSingleChildOn(_currentIndex);
|
||||
|
||||
@ -1338,7 +1338,7 @@ void GameEventHandler::createNewCatchable()
|
||||
|
||||
unsigned int catachableIndex = (unsigned int)((float)_benignCatachables.size()*(float)rand()/(float)RAND_MAX);
|
||||
if (catachableIndex>=_benignCatachables.size()) catachableIndex = _benignCatachables.size()-1;
|
||||
|
||||
|
||||
const std::string& filename = _benignCatachables[catachableIndex];
|
||||
|
||||
float ratio = ((float)rand() / (float)RAND_MAX);
|
||||
@ -1356,7 +1356,7 @@ void GameEventHandler::createNewCatchable()
|
||||
float r = (float)rand() / (float)RAND_MAX;
|
||||
if (r < _chanceOfExplodingAtStart)
|
||||
{
|
||||
catchableObject->explode();
|
||||
catchableObject->explode();
|
||||
}
|
||||
|
||||
_gameGroup->addChild(catchableObject->_object.get());
|
||||
@ -1369,7 +1369,7 @@ class CompileStateCallback : public osg::Operation
|
||||
osg::Referenced(true),
|
||||
osg::Operation("CompileStateCallback", false),
|
||||
_gameEventHandler(eh) {}
|
||||
|
||||
|
||||
virtual void operator () (osg::Object* object)
|
||||
{
|
||||
osg::GraphicsContext* context = dynamic_cast<osg::GraphicsContext*>(object);
|
||||
@ -1380,7 +1380,7 @@ class CompileStateCallback : public osg::Operation
|
||||
_gameEventHandler->compileGLObjects(*(context->getState()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
OpenThreads::Mutex _mutex;
|
||||
GameEventHandler* _gameEventHandler;
|
||||
};
|
||||
@ -1390,7 +1390,7 @@ int main( int argc, char **argv )
|
||||
|
||||
// use an ArgumentParser object to manage the program arguments.
|
||||
osg::ArgumentParser arguments(&argc,argv);
|
||||
|
||||
|
||||
// set up the usage document, in case we need to print out how to use this program.
|
||||
arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates use node masks to create stereo images.");
|
||||
arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] image_file_left_eye image_file_right_eye");
|
||||
@ -1410,8 +1410,8 @@ int main( int argc, char **argv )
|
||||
|
||||
while (arguments.read("--boy")) seh->addPlayer(GameEventHandler::PLAYER_BOY);
|
||||
while (arguments.read("--girl")) seh->addPlayer(GameEventHandler::PLAYER_GIRL);
|
||||
|
||||
|
||||
|
||||
|
||||
// if user request help write it out to cout.
|
||||
if (arguments.read("-h") || arguments.read("--help"))
|
||||
{
|
||||
@ -1428,8 +1428,8 @@ int main( int argc, char **argv )
|
||||
arguments.writeErrorMessages(std::cout);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// enable the image cache so we don't need to keep loading the particle files
|
||||
osgDB::ReaderWriter::Options* options = new osgDB::ReaderWriter::Options;
|
||||
options->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_IMAGES);
|
||||
@ -1454,7 +1454,7 @@ int main( int argc, char **argv )
|
||||
|
||||
double fovy, aspectRatio, zNear, zFar;
|
||||
viewer.getCamera()->getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar);
|
||||
seh->setFOVY(osg::DegreesToRadians(fovy));
|
||||
seh->setFOVY(osg::DegreesToRadians(fovy));
|
||||
|
||||
// todo for osgViewer - create default set up.
|
||||
viewer.setUpViewAcrossAllScreens();
|
||||
@ -1472,7 +1472,7 @@ int main( int argc, char **argv )
|
||||
}
|
||||
|
||||
// todo for osgViewer - implement warp pointer that can be done relative to different coordinate frames
|
||||
// viewer.requestWarpPointer(0.5f,0.5f);
|
||||
// viewer.requestWarpPointer(0.5f,0.5f);
|
||||
|
||||
while( !viewer.done() )
|
||||
{
|
||||
@ -1480,8 +1480,8 @@ int main( int argc, char **argv )
|
||||
|
||||
// fire off the cull and draw traversals of the scene.
|
||||
viewer.frame();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -40,10 +40,9 @@
|
||||
#include <osgUtil/Optimizer>
|
||||
|
||||
|
||||
osg::Node* decorate_with_clip_node(osg::Node* subgraph)
|
||||
osg::ref_ptr<osg::Node> decorate_with_clip_node(const osg::ref_ptr<osg::Node>& subgraph)
|
||||
{
|
||||
osg::Group* rootnode = new osg::Group;
|
||||
|
||||
osg::ref_ptr<osg::Group> rootnode = new osg::Group;
|
||||
|
||||
// create wireframe view of the model so the user can see
|
||||
// what parts are being culled away.
|
||||
@ -52,7 +51,7 @@ osg::Node* decorate_with_clip_node(osg::Node* subgraph)
|
||||
osg::PolygonMode* polymode = new osg::PolygonMode;
|
||||
polymode->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::LINE);
|
||||
stateset->setAttributeAndModes(polymode,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
|
||||
|
||||
osg::Group* wireframe_subgraph = new osg::Group;
|
||||
wireframe_subgraph->setStateSet(stateset);
|
||||
wireframe_subgraph->addChild(subgraph);
|
||||
@ -80,7 +79,7 @@ osg::Node* decorate_with_clip_node(osg::Node* subgraph)
|
||||
// more complex approach to managing ClipNode, allowing
|
||||
// ClipNode node to be transformed independently from the subgraph
|
||||
// that it is clipping.
|
||||
|
||||
|
||||
osg::MatrixTransform* transform= new osg::MatrixTransform;
|
||||
|
||||
osg::NodeCallback* nc = new osg::AnimationPathCallback(subgraph->getBound().center(),osg::Vec3(0.0f,0.0f,1.0f),osg::inDegrees(45.0f));
|
||||
@ -117,11 +116,11 @@ int main( int argc, char **argv )
|
||||
osg::ArgumentParser arguments(&argc,argv);
|
||||
|
||||
// load the nodes from the commandline arguments.
|
||||
osg::Node* loadedModel = osgDB::readNodeFiles(arguments);
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFiles(arguments);
|
||||
|
||||
|
||||
// if not loaded assume no arguments passed in, try use default mode instead.
|
||||
if (!loadedModel) loadedModel = osgDB::readNodeFile("cow.osgt");
|
||||
if (!loadedModel) loadedModel = osgDB::readRefNodeFile("cow.osgt");
|
||||
|
||||
|
||||
if (!loadedModel)
|
||||
@ -129,16 +128,16 @@ int main( int argc, char **argv )
|
||||
osg::notify(osg::NOTICE)<<"Please specify a filename on the command line"<<std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// decorate the scenegraph with a clip node.
|
||||
osg::Node* rootnode = decorate_with_clip_node(loadedModel);
|
||||
|
||||
osg::ref_ptr<osg::Node> rootnode = decorate_with_clip_node(loadedModel);
|
||||
|
||||
// run optimization over the scene graph
|
||||
osgUtil::Optimizer optimzer;
|
||||
optimzer.optimize(rootnode);
|
||||
|
||||
|
||||
osgViewer::Viewer viewer;
|
||||
|
||||
|
||||
// set the scene to render
|
||||
viewer.setSceneData(rootnode);
|
||||
|
||||
|
@ -505,7 +505,7 @@ int main( int argc, char **argv )
|
||||
}
|
||||
|
||||
// load model.
|
||||
osg::ref_ptr<osg::Node> rootnode = osgDB::readNodeFiles(arguments);
|
||||
osg::ref_ptr<osg::Node> rootnode = osgDB::readRefNodeFiles(arguments);
|
||||
|
||||
// set the scene to render
|
||||
viewer.setSceneData(rootnode.get());
|
||||
|
@ -133,7 +133,7 @@ int main( int argc, char **argv )
|
||||
osg::ArgumentParser arguments(&argc,argv);
|
||||
|
||||
// read the scene from the list of file specified commandline args.
|
||||
osg::ref_ptr<osg::Node> scene = osgDB::readNodeFiles(arguments);
|
||||
osg::ref_ptr<osg::Node> scene = osgDB::readRefNodeFiles(arguments);
|
||||
|
||||
if (!scene)
|
||||
{
|
||||
@ -149,7 +149,7 @@ int main( int argc, char **argv )
|
||||
{
|
||||
osgViewer::View* view = new osgViewer::View;
|
||||
view->setName("Single view");
|
||||
view->setSceneData(osgDB::readNodeFile("fountain.osgt"));
|
||||
view->setSceneData(osgDB::readRefNodeFile("fountain.osgt"));
|
||||
|
||||
view->addEventHandler( new osgViewer::StatsHandler );
|
||||
|
||||
@ -283,7 +283,7 @@ int main( int argc, char **argv )
|
||||
view->setName("View three");
|
||||
viewer.addView(view);
|
||||
|
||||
view->setSceneData(osgDB::readNodeFile("cessnafire.osgt"));
|
||||
view->setSceneData(osgDB::readRefNodeFile("cessnafire.osgt"));
|
||||
|
||||
view->getCamera()->setName("Cam three");
|
||||
view->getCamera()->setProjectionMatrixAsPerspective(30.0, double(traits->width) / double(traits->height/2), 1.0, 1000.0);
|
||||
|
@ -43,7 +43,7 @@ static const char* computeSrc = {
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
osg::ArgumentParser arguments( &argc, argv );
|
||||
|
||||
|
||||
// Create the texture as both the output of compute shader and the input of a normal quad
|
||||
osg::ref_ptr<osg::Texture2D> tex2D = new osg::Texture2D;
|
||||
tex2D->setTextureSize( 512, 512 );
|
||||
@ -53,23 +53,23 @@ int main( int argc, char** argv )
|
||||
tex2D->setSourceFormat( GL_RED );
|
||||
tex2D->setSourceType( GL_FLOAT );
|
||||
tex2D->bindToImageUnit( 0, osg::Texture::WRITE_ONLY ); // So we can use 'image2D' in the compute shader
|
||||
|
||||
|
||||
// The compute shader can't work with other kinds of shaders
|
||||
// It also requires the work group numbers. Setting them to 0 will disable the compute shader
|
||||
osg::ref_ptr<osg::Program> computeProg = new osg::Program;
|
||||
computeProg->setComputeGroups( 512/16, 512/16, 1 );
|
||||
computeProg->addShader( new osg::Shader(osg::Shader::COMPUTE, computeSrc) );
|
||||
|
||||
|
||||
// Create a node for outputting to the texture.
|
||||
// It is OK to have just an empty node here, but seems inbuilt uniforms like osg_FrameTime won't work then.
|
||||
// TODO: maybe we can have a custom drawable which also will implement glMemoryBarrier?
|
||||
osg::Node* sourceNode = osgDB::readNodeFile("axes.osgt");
|
||||
osg::ref_ptr<osg::Node> sourceNode = osgDB::readRefNodeFile("axes.osgt");
|
||||
if ( !sourceNode ) sourceNode = new osg::Node;
|
||||
sourceNode->setDataVariance( osg::Object::DYNAMIC );
|
||||
sourceNode->getOrCreateStateSet()->setAttributeAndModes( computeProg.get() );
|
||||
sourceNode->getOrCreateStateSet()->addUniform( new osg::Uniform("targetTex", (int)0) );
|
||||
sourceNode->getOrCreateStateSet()->setTextureAttributeAndModes( 0, tex2D.get() );
|
||||
|
||||
|
||||
// Display the texture on a quad. We will also be able to operate on the data if reading back to CPU side
|
||||
osg::Geometry* geom = osg::createTexturedQuadGeometry(
|
||||
osg::Vec3(), osg::Vec3(1.0f,0.0f,0.0f), osg::Vec3(0.0f,0.0f,1.0f) );
|
||||
@ -77,12 +77,12 @@ int main( int argc, char** argv )
|
||||
quad->addDrawable( geom );
|
||||
quad->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
|
||||
quad->getOrCreateStateSet()->setTextureAttributeAndModes( 0, tex2D.get() );
|
||||
|
||||
|
||||
// Create the scene graph and start the viewer
|
||||
osg::ref_ptr<osg::Group> scene = new osg::Group;
|
||||
scene->addChild( sourceNode );
|
||||
scene->addChild( quad.get() );
|
||||
|
||||
|
||||
osgViewer::Viewer viewer;
|
||||
viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) );
|
||||
viewer.addEventHandler( new osgViewer::StatsHandler );
|
||||
|
@ -33,12 +33,12 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
// Customize the CopyOp so that we add our own verbose
|
||||
// Customize the CopyOp so that we add our own verbose
|
||||
// output of what's being copied.
|
||||
class MyCopyOp : public osg::CopyOp
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
inline MyCopyOp(CopyFlags flags=SHALLOW_COPY):
|
||||
osg::CopyOp(flags),
|
||||
_indent(0),
|
||||
@ -46,11 +46,11 @@ class MyCopyOp : public osg::CopyOp
|
||||
|
||||
inline void moveIn() const { _indent += _step; }
|
||||
inline void moveOut() const { _indent -= _step; }
|
||||
inline void writeIndent() const
|
||||
inline void writeIndent() const
|
||||
{
|
||||
for(int i=0;i<_indent;++i) std::cout << " ";
|
||||
}
|
||||
|
||||
|
||||
virtual osg::Referenced* operator() (const osg::Referenced* ref) const
|
||||
{
|
||||
writeIndent(); std::cout << "copying Referenced "<<ref<<std::endl;
|
||||
@ -59,7 +59,7 @@ class MyCopyOp : public osg::CopyOp
|
||||
moveOut();
|
||||
return ret_ref;
|
||||
}
|
||||
|
||||
|
||||
virtual osg::Object* operator() (const osg::Object* obj) const
|
||||
{
|
||||
writeIndent(); std::cout << "copying Object "<<obj;
|
||||
@ -70,7 +70,7 @@ class MyCopyOp : public osg::CopyOp
|
||||
moveOut();
|
||||
return ret_obj;
|
||||
}
|
||||
|
||||
|
||||
virtual osg::Node* operator() (const osg::Node* node) const
|
||||
{
|
||||
writeIndent(); std::cout << "copying Node "<<node;
|
||||
@ -136,25 +136,25 @@ class MyCopyOp : public osg::CopyOp
|
||||
moveOut();
|
||||
return ret_image;
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
// must be mutable since CopyOp is passed around as const to
|
||||
// the various clone/copy constructors.
|
||||
mutable int _indent;
|
||||
mutable int _step;
|
||||
};
|
||||
|
||||
// this CopyOp class will preserve the multi-parent structure of the copied
|
||||
// object, instead of expanding it into a tree. Works with the
|
||||
// this CopyOp class will preserve the multi-parent structure of the copied
|
||||
// object, instead of expanding it into a tree. Works with the
|
||||
// DEEP_COPY_NODES flag.
|
||||
class GraphCopyOp : public osg::CopyOp
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
inline GraphCopyOp(CopyFlags flags=SHALLOW_COPY):
|
||||
osg::CopyOp(flags) { _nodeCopyMap.clear();}
|
||||
|
||||
|
||||
virtual osg::Node* operator() (const osg::Node* node) const
|
||||
{
|
||||
if (node && _flags&DEEP_COPY_NODES)
|
||||
@ -180,9 +180,9 @@ class GraphCopyOp : public osg::CopyOp
|
||||
else
|
||||
return const_cast<osg::Node*>(node);
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
// must be mutable since CopyOp is passed around as const to
|
||||
// the various clone/copy constructors.
|
||||
mutable std::map<const osg::Node*,osg::Node*> _nodeCopyMap;
|
||||
@ -198,19 +198,19 @@ int main( int argc, char **argv )
|
||||
osgViewer::Viewer viewer;
|
||||
|
||||
// load the nodes from the commandline arguments.
|
||||
osg::Node* rootnode = osgDB::readNodeFiles(arguments);
|
||||
osg::ref_ptr<osg::Node> rootnode = osgDB::readRefNodeFiles(arguments);
|
||||
if (!rootnode)
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Please specify a model filename on the command line."<<std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// run optimization over the scene graph
|
||||
osgUtil::Optimizer optimzer;
|
||||
optimzer.optimize(rootnode);
|
||||
|
||||
|
||||
// ------------- Start of copy specific code -------------------------------------------------------
|
||||
|
||||
|
||||
// do a deep copy, using MyCopyOp to reveal whats going on under the hood,
|
||||
// in your own code you'd typically just use the basic osg::CopyOp something like
|
||||
osg::ref_ptr<osg::Node> mycopy = dynamic_cast<osg::Node*>(rootnode->clone(osg::CopyOp::DEEP_COPY_ALL));
|
||||
@ -219,7 +219,7 @@ int main( int argc, char **argv )
|
||||
// note, we need the dyanmic_cast because MS Visual Studio can't handle covarient
|
||||
// return types, so that clone has return just Object*. bahh hum bug
|
||||
osg::ref_ptr<osg::Node> deep_copy = dynamic_cast<osg::Node*>(rootnode->clone(MyCopyOp(osg::CopyOp::DEEP_COPY_ALL)));
|
||||
|
||||
|
||||
std::cout << "----------------------------------------------------------------"<<std::endl;
|
||||
|
||||
// do a graph preserving deep copy.
|
||||
@ -260,18 +260,18 @@ int main( int argc, char **argv )
|
||||
// DEEP_COPY_IMAGES = 64,
|
||||
// DEEP_COPY_ALL = 0xffffffff
|
||||
// };
|
||||
//
|
||||
//
|
||||
// These options you can use together such as :
|
||||
// osg::Node* mycopy = dynamic_cast<osg::Node*>(rootnode->clone(osg::CopyOp::DEEP_COPY_NODES | DEEP_COPY_DRAWABLES));
|
||||
// Which shares state but creates copies of all nodes and drawables (which contain the geometry).
|
||||
//
|
||||
//
|
||||
// You may also want to subclass from CopyOp to provide finer grained control of what gets shared (shallow copy) vs
|
||||
// cloned (deep copy).
|
||||
|
||||
|
||||
|
||||
|
||||
// ------------- End of copy specific code -------------------------------------------------------
|
||||
|
||||
|
||||
// set the scene to render
|
||||
viewer.setSceneData(rootnode);
|
||||
|
||||
|
@ -95,10 +95,10 @@ int main(int argc, char *argv[])
|
||||
osgViewer::Viewer viewer;
|
||||
|
||||
// load the nodes from the commandline arguments.
|
||||
osg::Node* rootnode = osgDB::readNodeFiles(arguments);
|
||||
osg::ref_ptr<osg::Node> rootnode = osgDB::readRefNodeFiles(arguments);
|
||||
|
||||
// if not loaded assume no arguments passed in, try use default mode instead.
|
||||
if (!rootnode) rootnode = osgDB::readNodeFile("cessna.osgt");
|
||||
if (!rootnode) rootnode = osgDB::readRefNodeFile("cessna.osgt");
|
||||
|
||||
if (!rootnode)
|
||||
{
|
||||
@ -107,7 +107,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
// create specular highlights
|
||||
create_specular_highlights(rootnode);
|
||||
create_specular_highlights(rootnode.get());
|
||||
|
||||
// run optimization over the scene graph
|
||||
osgUtil::Optimizer optimzer;
|
||||
|
@ -1,9 +1,9 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* This application is open source and may be redistributed and/or modified
|
||||
* This application is open source and may be redistributed and/or modified
|
||||
* freely and without restriction, both in commercial and non commercial applications,
|
||||
* as long as this copyright notice is maintained.
|
||||
*
|
||||
*
|
||||
* This application 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.
|
||||
@ -50,7 +50,7 @@ int main(int argc, char** argv)
|
||||
arguments.getApplicationUsage()->write(std::cout, helpType);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// report any errors if they have occurred when parsing the program arguments.
|
||||
if (arguments.errors())
|
||||
{
|
||||
@ -81,7 +81,7 @@ int main(int argc, char** argv)
|
||||
while (arguments.read("-p",pathfile))
|
||||
{
|
||||
osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile);
|
||||
if (apm || !apm->valid())
|
||||
if (apm || !apm->valid())
|
||||
{
|
||||
unsigned int num = keyswitchManipulator->getNumMatrixManipulators();
|
||||
keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm );
|
||||
@ -95,13 +95,13 @@ int main(int argc, char** argv)
|
||||
|
||||
// add the state manipulator
|
||||
viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) );
|
||||
|
||||
|
||||
// add the thread model handler
|
||||
viewer.addEventHandler(new osgViewer::ThreadingHandler);
|
||||
|
||||
// add the window size toggle handler
|
||||
viewer.addEventHandler(new osgViewer::WindowSizeHandler);
|
||||
|
||||
|
||||
// add the stats handler
|
||||
viewer.addEventHandler(new osgViewer::StatsHandler);
|
||||
|
||||
@ -129,8 +129,8 @@ int main(int argc, char** argv)
|
||||
|
||||
|
||||
// load the data
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFile(file);
|
||||
if (!loadedModel)
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFile(file);
|
||||
if (!loadedModel)
|
||||
{
|
||||
std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl;
|
||||
return 1;
|
||||
|
@ -224,7 +224,7 @@ public:
|
||||
osg::StateSet *dstate= gm->getOrCreateStateSet( );
|
||||
dstate->setMode( GL_LIGHTING, osg::StateAttribute::ON );
|
||||
|
||||
osg::Image* image = osgDB::readImageFile("Images/Brick-Std-Orange.TGA");
|
||||
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile("Images/Brick-Std-Orange.TGA");
|
||||
if (image)
|
||||
{
|
||||
osg::Texture2D* txt = new osg::Texture2D;
|
||||
@ -354,7 +354,7 @@ osg::Group *makedelaunay(const int ndcs)
|
||||
|
||||
osg::Vec3Array *points=new osg::Vec3Array;
|
||||
|
||||
osg::Image* image = osgDB::readImageFile("Images/blueFlowers.png");
|
||||
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile("Images/blueFlowers.png");
|
||||
if (image)
|
||||
{
|
||||
osg::Texture2D* texture = new osg::Texture2D;
|
||||
@ -817,7 +817,7 @@ osg::Geometry *WallConstraint::makeWallGeometry() const
|
||||
{
|
||||
osg::ref_ptr<osg::Geometry> gm=new osg::Geometry; // the wall
|
||||
if (texture!="") {
|
||||
osg::Image* image = osgDB::readImageFile(texture.c_str());
|
||||
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile(texture.c_str());
|
||||
if (image)
|
||||
{
|
||||
osg::Texture2D* txt = new osg::Texture2D;
|
||||
@ -1005,7 +1005,7 @@ deprecated_osg::Geometry *ArealConstraint::makeWallGeometry( osg::Vec3Array *pt)
|
||||
tscx->retessellatePolygons(*(edges)); // find all edges
|
||||
|
||||
if (walltexture!="") {
|
||||
osg::Image* image = osgDB::readImageFile(walltexture.c_str());
|
||||
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile(walltexture.c_str());
|
||||
if (image)
|
||||
{
|
||||
osg::Texture2D* txt = new osg::Texture2D;
|
||||
@ -1062,7 +1062,7 @@ deprecated_osg::Geometry * ArealConstraint::makeAreal( osg::Vec3Array *points)
|
||||
gm->setNormalArray(getCanopyNormals(points));
|
||||
gm->setNormalBinding(deprecated_osg::Geometry::BIND_PER_PRIMITIVE);
|
||||
gm->setTexCoordArray(0,getCanopyTexcoords(points));
|
||||
osg::Image* image = osgDB::readImageFile(texture);
|
||||
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile(texture);
|
||||
if (image)
|
||||
{
|
||||
osg::Texture2D* txt = new osg::Texture2D;
|
||||
@ -1238,7 +1238,7 @@ deprecated_osg::Geometry * LinearConstraint::makeGeometry(const osg::Vec3Array *
|
||||
if (_midline->size()>0) {
|
||||
osg::ref_ptr<osg::Vec3Array> locpts=getPoints(points);
|
||||
if (texture!="") {
|
||||
osg::Image* image = osgDB::readImageFile(texture.c_str());
|
||||
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile(texture.c_str());
|
||||
if (image)
|
||||
{
|
||||
osg::Texture2D* txt = new osg::Texture2D;
|
||||
|
@ -139,7 +139,7 @@ int main( int argc, char **argv )
|
||||
bool needToSetHomePosition = false;
|
||||
|
||||
// read the scene from the list of file specified commandline args.
|
||||
osg::ref_ptr<osg::Node> scene = osgDB::readNodeFiles(arguments);
|
||||
osg::ref_ptr<osg::Node> scene = osgDB::readRefNodeFiles(arguments);
|
||||
|
||||
// if one hasn't been loaded create an earth and sun test model.
|
||||
if (!scene)
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "DePee.h"
|
||||
#include "DePee.h"
|
||||
|
||||
/*!
|
||||
Handles keyboard events.
|
||||
@ -28,7 +28,7 @@
|
||||
class KeyboardEventHandler : public osgGA::GUIEventHandler
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
KeyboardEventHandler(DePee* dePee)
|
||||
{
|
||||
_apc = 0;
|
||||
@ -41,12 +41,12 @@ public:
|
||||
_dePee->setSketchy(_sketchy);
|
||||
_dePee->setColored(_colored);
|
||||
}
|
||||
|
||||
|
||||
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&)
|
||||
{
|
||||
switch(ea.getEventType())
|
||||
{
|
||||
|
||||
|
||||
case(osgGA::GUIEventAdapter::KEYDOWN):
|
||||
{
|
||||
if (ea.getKey()==osgGA::GUIEventAdapter::KEY_Space)
|
||||
@ -77,7 +77,7 @@ public:
|
||||
_dePee->setSketchy(_sketchy);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
else if (ea.getKey() == 'e')
|
||||
{
|
||||
_edgy = !_edgy;
|
||||
@ -106,13 +106,13 @@ public:
|
||||
_crayon = !_crayon;
|
||||
_dePee->setCrayon(_crayon);
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -139,12 +139,12 @@ private:
|
||||
class MouseEventHandler : public osgGA::GUIEventHandler
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
MouseEventHandler(DePee* dePee)
|
||||
{
|
||||
_dePee = dePee;
|
||||
}
|
||||
|
||||
|
||||
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&)
|
||||
{
|
||||
switch(ea.getEventType())
|
||||
@ -152,17 +152,17 @@ public:
|
||||
//mouse
|
||||
case(osgGA::GUIEventAdapter::DRAG):
|
||||
{
|
||||
rotate(ea.getXnormalized(), ea.getYnormalized());
|
||||
rotate(ea.getXnormalized(), ea.getYnormalized());
|
||||
break;
|
||||
}
|
||||
case(osgGA::GUIEventAdapter::MOVE):
|
||||
_prevX = ea.getXnormalized();
|
||||
_prevX = ea.getXnormalized();
|
||||
_prevY = ea.getYnormalized();
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -175,25 +175,25 @@ private:
|
||||
void rotate(float x, float y)
|
||||
{
|
||||
osg::Matrix baseMatrix = _modelGroupTransform->getMatrix();
|
||||
|
||||
|
||||
baseMatrix.preMultTranslate(_rotCenter);
|
||||
baseMatrix.preMultRotate(osg::Quat((x - _prevX) * 3, osg::Vec3d(0.0, 0.0, 1.0)));
|
||||
baseMatrix.preMultRotate(osg::Quat(-(y - _prevY) * 3, (baseMatrix * osg::Vec3d(1.0, 0.0, 0.0))));
|
||||
baseMatrix.preMultTranslate(-_rotCenter);
|
||||
|
||||
|
||||
_modelGroupTransform->setMatrix(baseMatrix);
|
||||
|
||||
_prevX = x;
|
||||
_prevX = x;
|
||||
_prevY = y;
|
||||
};
|
||||
|
||||
|
||||
DePee* _dePee;
|
||||
|
||||
float _prevX;
|
||||
|
||||
float _prevX;
|
||||
float _prevY;
|
||||
|
||||
|
||||
osg::Vec3 _rotCenter;
|
||||
osg::MatrixTransform* _modelGroupTransform;
|
||||
osg::MatrixTransform* _modelGroupTransform;
|
||||
};
|
||||
|
||||
|
||||
@ -202,25 +202,25 @@ int main( int argc, char **argv )
|
||||
{
|
||||
// use an ArgumentParser object to manage the program arguments.
|
||||
osg::ArgumentParser arguments(&argc,argv);
|
||||
|
||||
|
||||
// set up the usage document, in case we need to print out how to use this program.
|
||||
arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates Depth Peeling");
|
||||
arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" filename");
|
||||
|
||||
|
||||
|
||||
|
||||
// construct the viewer
|
||||
osgViewer::Viewer viewer(arguments);
|
||||
|
||||
|
||||
// any option left unread are converted into errors to write out later.
|
||||
arguments.reportRemainingOptionsAsUnrecognized();
|
||||
|
||||
|
||||
// report any errors if they have occurred when parsing the program arguments.
|
||||
if (arguments.errors())
|
||||
{
|
||||
arguments.writeErrorMessages(std::cout);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
if (arguments.argc()<=1 || arguments.argc() > 3)
|
||||
{
|
||||
arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION);
|
||||
@ -232,29 +232,29 @@ int main( int argc, char **argv )
|
||||
viewer.getCamera()->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
|
||||
|
||||
// read the model to do depth peeling with
|
||||
osg::Node* loadedModel = osgDB::readNodeFile(arguments.argv()[1]);
|
||||
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFile(arguments.argv()[1]);
|
||||
|
||||
if (!loadedModel)
|
||||
return 1;
|
||||
|
||||
|
||||
// create a transform to spin the model.
|
||||
osg::MatrixTransform* modelGroupTransform = new osg::MatrixTransform;
|
||||
osg::Group* modelGroup = new osg::Group;
|
||||
modelGroupTransform->addChild(modelGroup);
|
||||
modelGroup->addChild(loadedModel);
|
||||
|
||||
|
||||
osg::Group* rootNode = new osg::Group();
|
||||
|
||||
|
||||
// add model to the viewer.
|
||||
viewer.setSceneData(rootNode);
|
||||
|
||||
|
||||
// Depth peel example only works on a single graphics context right now
|
||||
// so open up viewer on single screen to prevent problems
|
||||
viewer.setUpViewOnSingleScreen(0);
|
||||
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize();
|
||||
|
||||
|
||||
unsigned int width = 1280;
|
||||
unsigned int height = 1280;
|
||||
osgViewer::Viewer::Windows windows;
|
||||
@ -266,11 +266,11 @@ int main( int argc, char **argv )
|
||||
}
|
||||
|
||||
|
||||
osg::ref_ptr<DePee> dePee = new DePee(rootNode,
|
||||
modelGroupTransform,
|
||||
osg::ref_ptr<DePee> dePee = new DePee(rootNode,
|
||||
modelGroupTransform,
|
||||
width,
|
||||
height);
|
||||
|
||||
|
||||
//create event handlers
|
||||
KeyboardEventHandler* keyboardEventHandler = new KeyboardEventHandler(dePee.get());
|
||||
MouseEventHandler* mouseEventHandler = new MouseEventHandler(dePee.get());
|
||||
@ -278,7 +278,7 @@ int main( int argc, char **argv )
|
||||
viewer.addEventHandler(mouseEventHandler);
|
||||
|
||||
//viewer.setCameraManipulator(new osgGA::TrackballManipulator);
|
||||
|
||||
|
||||
osg::StateSet* stateset = modelGroupTransform->getOrCreateStateSet();
|
||||
|
||||
stateset->setMode(GL_BLEND, osg::StateAttribute::OFF);
|
||||
@ -287,15 +287,15 @@ int main( int argc, char **argv )
|
||||
osg::AnimationPathCallback* apc = new osg::AnimationPathCallback(modelGroupTransform->getBound().center(),osg::Vec3(0.0f,0.0f,1.0f),osg::inDegrees(45.0f));
|
||||
apc->setPause(true);
|
||||
modelGroupTransform->setUpdateCallback(apc);
|
||||
|
||||
|
||||
keyboardEventHandler->registerAnimationPathCallback(apc);
|
||||
mouseEventHandler->registerModelGroupTransform(modelGroupTransform);
|
||||
|
||||
|
||||
//setup stuff that is necessary for measuring fps
|
||||
osg::Timer_t current_tick, previous_tick = 1;
|
||||
double* fps = new double;
|
||||
dePee->setFPS(fps);
|
||||
|
||||
|
||||
while(!viewer.done())
|
||||
{
|
||||
current_tick = osg::Timer::instance()->tick();
|
||||
|
@ -703,10 +703,10 @@ int main(int argc, char** argv)
|
||||
osgViewer::Viewer viewer(arguments);
|
||||
|
||||
// load the nodes from the commandline arguments.
|
||||
osg::Node* loadedModel = osgDB::readNodeFiles(arguments);
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFiles(arguments);
|
||||
|
||||
// if not loaded assume no arguments passed in, try use default mode instead.
|
||||
if (!loadedModel) loadedModel = osgDB::readNodeFile("cow.osgt");
|
||||
if (!loadedModel) loadedModel = osgDB::readRefNodeFile("cow.osgt");
|
||||
|
||||
if (!loadedModel)
|
||||
{
|
||||
@ -731,7 +731,7 @@ int main(int argc, char** argv)
|
||||
}
|
||||
else
|
||||
{
|
||||
osg::Node* distortionNode = createDistortionSubgraph( options, loadedModel, viewer.getCamera()->getClearColor());
|
||||
osg::Node* distortionNode = createDistortionSubgraph( options, loadedModel.get(), viewer.getCamera()->getClearColor());
|
||||
viewer.setSceneData( distortionNode );
|
||||
}
|
||||
|
||||
|
@ -97,7 +97,7 @@ createStateSet()
|
||||
ss->setAttribute( program.get(),
|
||||
osg::StateAttribute::ON | osg::StateAttribute::PROTECTED );
|
||||
|
||||
osg::ref_ptr< osg::Image> iLogo = osgDB::readImageFile( "Images/osg128.png" );
|
||||
osg::ref_ptr< osg::Image> iLogo = osgDB::readRefImageFile( "Images/osg128.png" );
|
||||
if( !iLogo.valid() )
|
||||
{
|
||||
osg::notify( osg::ALWAYS ) << "Can't open image file osg128.png" << std::endl;
|
||||
|
@ -44,21 +44,21 @@ osg::Node* createEarth()
|
||||
osg::TessellationHints* hints = new osg::TessellationHints;
|
||||
hints->setDetailRatio(5.0f);
|
||||
|
||||
|
||||
|
||||
osg::ShapeDrawable* sd = new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0.0,0.0,0.0), osg::WGS_84_RADIUS_POLAR), hints);
|
||||
|
||||
|
||||
osg::Geode* geode = new osg::Geode;
|
||||
geode->addDrawable(sd);
|
||||
|
||||
|
||||
std::string filename = osgDB::findDataFile("Images/land_shallow_topo_2048.jpg");
|
||||
geode->getOrCreateStateSet()->setTextureAttributeAndModes(0, new osg::Texture2D(osgDB::readImageFile(filename)));
|
||||
|
||||
geode->getOrCreateStateSet()->setTextureAttributeAndModes(0, new osg::Texture2D(osgDB::readRefImageFile(filename)));
|
||||
|
||||
osg::CoordinateSystemNode* csn = new osg::CoordinateSystemNode;
|
||||
csn->setEllipsoidModel(new osg::EllipsoidModel());
|
||||
csn->addChild(geode);
|
||||
|
||||
|
||||
return csn;
|
||||
|
||||
|
||||
}
|
||||
|
||||
osgText::Text* createText(osg::EllipsoidModel* ellipsoid, double latitude, double longitude, double height, const std::string& str)
|
||||
@ -78,7 +78,7 @@ osgText::Text* createText(osg::EllipsoidModel* ellipsoid, double latitude, doubl
|
||||
text->setCharacterSize(300000.0f);
|
||||
text->setCharacterSizeMode(osgText::Text::OBJECT_COORDS_WITH_MAXIMUM_SCREEN_SIZE_CAPPED_BY_FONT_HEIGHT);
|
||||
text->setAutoRotateToScreen(true);
|
||||
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
@ -87,10 +87,10 @@ osg::Node* createFadeText(osg::EllipsoidModel* ellipsoid)
|
||||
osg::Group* group = new osg::Group;
|
||||
|
||||
group->getOrCreateStateSet()->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
|
||||
|
||||
|
||||
osg::Geode* geode = new osg::Geode;
|
||||
group->addChild(geode);
|
||||
|
||||
|
||||
std::vector<std::string> textList;
|
||||
textList.push_back("Town");
|
||||
textList.push_back("City");
|
||||
@ -99,7 +99,7 @@ osg::Node* createFadeText(osg::EllipsoidModel* ellipsoid)
|
||||
textList.push_back("Mountain");
|
||||
textList.push_back("Road");
|
||||
textList.push_back("Lake");
|
||||
|
||||
|
||||
unsigned int numLat = 15;
|
||||
unsigned int numLong = 20;
|
||||
double latitude = 0.0;
|
||||
@ -118,7 +118,7 @@ osg::Node* createFadeText(osg::EllipsoidModel* ellipsoid)
|
||||
}
|
||||
|
||||
return group;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int, char**)
|
||||
@ -128,10 +128,10 @@ int main(int, char**)
|
||||
|
||||
viewer.getCamera()->setComputeNearFarMode(osg::CullSettings::COMPUTE_NEAR_FAR_USING_PRIMITIVES);
|
||||
viewer.getCamera()->setNearFarRatio(0.00001f);
|
||||
|
||||
|
||||
// read the scene from the list of file specified commandline args.
|
||||
osg::ref_ptr<osg::Node> root = createEarth();
|
||||
|
||||
|
||||
if (!root) return 0;
|
||||
|
||||
// add a viewport to the viewer and attach the scene graph.
|
||||
@ -142,7 +142,7 @@ int main(int, char**)
|
||||
{
|
||||
// add fade text around the globe
|
||||
csn->addChild(createFadeText(csn->getEllipsoidModel()));
|
||||
}
|
||||
}
|
||||
|
||||
viewer.setCameraManipulator(new osgGA::TerrainManipulator);
|
||||
|
||||
|
@ -62,7 +62,7 @@ osgText::Text* createLabel(const std::string& l, const char* f, unsigned int siz
|
||||
static osg::Vec3 pos(10.0f, 10.0f, 0.0f);
|
||||
|
||||
osgText::Text* label = new osgText::Text();
|
||||
osgText::Font* font = osgText::readFontFile(f);
|
||||
osg::ref_ptr<osgText::Font> font = osgText::readRefFontFile(f);
|
||||
|
||||
label->setFont(font);
|
||||
label->setCharacterSize(size);
|
||||
|
@ -388,7 +388,7 @@ osg::Geode* ForestTechniqueManager::createTerrain(const osg::Vec3& origin, const
|
||||
// ---------------------------------------
|
||||
osg::StateSet* stateset = new osg::StateSet();
|
||||
|
||||
osg::Image* image = osgDB::readImageFile("Images/lz.rgb");
|
||||
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile("Images/lz.rgb");
|
||||
if (image)
|
||||
{
|
||||
osg::Texture2D* texture = new osg::Texture2D;
|
||||
@ -1182,7 +1182,7 @@ osg::Node* ForestTechniqueManager::createScene(unsigned int numTreesToCreates, u
|
||||
osg::Texture2D *tex = new osg::Texture2D;
|
||||
tex->setWrap( osg::Texture2D::WRAP_S, osg::Texture2D::CLAMP );
|
||||
tex->setWrap( osg::Texture2D::WRAP_T, osg::Texture2D::CLAMP );
|
||||
tex->setImage(osgDB::readImageFile("Images/tree0.rgba"));
|
||||
tex->setImage(osgDB::readRefImageFile("Images/tree0.rgba"));
|
||||
|
||||
osg::StateSet *dstate = new osg::StateSet;
|
||||
{
|
||||
|
@ -961,7 +961,7 @@ int main(int argc, char **argv)
|
||||
arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION);
|
||||
return 1;
|
||||
}
|
||||
ref_ptr<Node> loadedModel = osgDB::readNodeFiles(arguments);
|
||||
ref_ptr<Node> loadedModel = osgDB::readRefNodeFiles(arguments);
|
||||
if (!loadedModel) {
|
||||
cerr << "couldn't load " << argv[1] << "\n";
|
||||
return 1;
|
||||
|
@ -127,7 +127,7 @@ public:
|
||||
for (osgFX::Registry::EffectMap::const_iterator i=emap.begin(); i!=emap.end(); ++i) {
|
||||
std::cout << "INFO: \t" << i->first << "\n";
|
||||
osg::ref_ptr<osgFX::Effect> effect = static_cast<osgFX::Effect *>(i->second->cloneType());
|
||||
_effects.push_back(effect.get());
|
||||
_effects.push_back(effect.get());
|
||||
}
|
||||
|
||||
std::cout << "INFO: " << emap.size() << " effect(s) ready.\n";
|
||||
@ -144,9 +144,9 @@ public:
|
||||
inline void setScene(osg::Node* node) { _scene = node; }
|
||||
|
||||
inline bool getEffectsEnabled() const { return _fxen; }
|
||||
inline void setEffectsEnabled(bool v)
|
||||
{
|
||||
_fxen = v;
|
||||
inline void setEffectsEnabled(bool v)
|
||||
{
|
||||
_fxen = v;
|
||||
if (getSelectedEffect()) {
|
||||
getSelectedEffect()->setEnabled(_fxen);
|
||||
}
|
||||
@ -156,7 +156,7 @@ public:
|
||||
inline void setEffectIndex(int i)
|
||||
{
|
||||
if (i >= static_cast<int>(_effects.size())) i = 0;
|
||||
if (i < 0) i = static_cast<int>(_effects.size()-1);
|
||||
if (i < 0) i = static_cast<int>(_effects.size()-1);
|
||||
_selected_fx = i;
|
||||
rebuild();
|
||||
}
|
||||
@ -174,11 +174,11 @@ protected:
|
||||
{
|
||||
float zPos = -0.1; // note from Robert, was 0.1f, but now must be -0.1f to keep text visible??#!? due
|
||||
// to some other change in the OSG not tracked down yet...
|
||||
|
||||
osg::ref_ptr<osgText::Font> arial = osgText::readFontFile("fonts/arial.ttf");
|
||||
|
||||
osg::ref_ptr<osgText::Font> arial = osgText::readRefFontFile("fonts/arial.ttf");
|
||||
|
||||
osg::ref_ptr<osgText::Text> hints = new osgText::Text;
|
||||
hints->setFont(arial.get());
|
||||
hints->setFont(arial);
|
||||
hints->setColor(_hints_color);
|
||||
hints->setAlignment(osgText::Text::CENTER_BOTTOM);
|
||||
hints->setCharacterSize(13);
|
||||
@ -195,7 +195,7 @@ protected:
|
||||
if (!author_name.empty()) {
|
||||
effect_description = author_name = "AUTHOR: " + std::string(_effects[_selected_fx]->effectAuthor()) + std::string("\n\n");
|
||||
}
|
||||
effect_description += "DESCRIPTION:\n" + std::string(_effects[_selected_fx]->effectDescription());
|
||||
effect_description += "DESCRIPTION:\n" + std::string(_effects[_selected_fx]->effectDescription());
|
||||
|
||||
if (_scene.valid() && _root.valid()) {
|
||||
_root->removeChildren(0, _root->getNumChildren());
|
||||
@ -268,7 +268,7 @@ EffectPanel* build_gui(osg::Group* root)
|
||||
|
||||
osg::ref_ptr<EffectPanel> effect_panel = new EffectPanel;
|
||||
effect_panel->setCaption("osgFX Effect Browser");
|
||||
effect_panel->setRect(osgfxbrowser::Rect(20, 20, 1000, 280));
|
||||
effect_panel->setRect(osgfxbrowser::Rect(20, 20, 1000, 280));
|
||||
|
||||
hud->addChild(effect_panel.get());
|
||||
|
||||
@ -325,7 +325,7 @@ int main(int argc, char *argv[])
|
||||
unsigned int clearMask = viewer.getCamera()->getClearMask();
|
||||
viewer.getCamera()->setClearMask(clearMask | GL_STENCIL_BUFFER_BIT);
|
||||
viewer.getCamera()->setClearStencil(0);
|
||||
|
||||
|
||||
// any option left unread are converted into errors to write out later.
|
||||
arguments.reportRemainingOptionsAsUnrecognized();
|
||||
|
||||
@ -336,11 +336,11 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
// read the scene from the list of file specified commandline args.
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFiles(arguments);
|
||||
|
||||
// if not loaded assume no arguments passed in, try use default mode instead.
|
||||
if (!loadedModel) loadedModel = osgDB::readNodeFile("dumptruck.osgt");
|
||||
|
||||
if (!loadedModel) loadedModel = osgDB::readRefNodeFile("dumptruck.osgt");
|
||||
|
||||
if (!loadedModel)
|
||||
{
|
||||
std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl;
|
||||
|
@ -117,14 +117,14 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
// load the image
|
||||
osg::ref_ptr<osg::Image> startIm = osgDB::readImageFile(startName);
|
||||
osg::ref_ptr<osg::Image> startIm = osgDB::readRefImageFile(startName);
|
||||
|
||||
if (!startIm) {
|
||||
std::cout << "Could not load start image.\n";
|
||||
return(1);
|
||||
}
|
||||
|
||||
osg::Node* scene = createScene(startIm.get());
|
||||
osg::ref_ptr<osg::Node> scene = createScene(startIm.get());
|
||||
|
||||
// construct the viewer.
|
||||
osgViewer::Viewer viewer;
|
||||
|
@ -550,7 +550,7 @@ osg::Node* createBackground()
|
||||
{
|
||||
|
||||
// we'll create a texture mapped quad to sit behind the Geometry
|
||||
osg::Image* image = osgDB::readImageFile("Images/primitives.gif");
|
||||
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile("Images/primitives.gif");
|
||||
if (!image) return NULL;
|
||||
|
||||
|
||||
|
@ -434,8 +434,8 @@ int main(int argv, char **argc)
|
||||
|
||||
osg::ref_ptr<osg::Group> group = new osg::Group;
|
||||
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
|
||||
if (loadedModel.valid()) group->addChild(loadedModel.get());
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFiles(arguments);
|
||||
if (loadedModel.valid()) group->addChild(loadedModel);
|
||||
|
||||
for(Tracks::iterator itr = tracks.begin();
|
||||
itr != tracks.end();
|
||||
|
@ -52,12 +52,12 @@ int main(int argc, char** argv)
|
||||
osgViewer::Viewer viewer(arguments);
|
||||
|
||||
|
||||
osg::ref_ptr<osg::Node> node = osgDB::readNodeFiles(arguments);
|
||||
osg::ref_ptr<osg::Node> node = osgDB::readRefNodeFiles(arguments);
|
||||
if (!node) return 0;
|
||||
|
||||
osg::ref_ptr<osg::GraphicsCostEstimator> gce = new osg::GraphicsCostEstimator;
|
||||
|
||||
viewer.setSceneData(node.get());
|
||||
viewer.setSceneData(node);
|
||||
|
||||
viewer.realize();
|
||||
|
||||
|
@ -67,7 +67,7 @@ Node *makeBase( void )
|
||||
|
||||
Texture2D *tex = new Texture2D;
|
||||
|
||||
tex->setImage(osgDB::readImageFile("Images/water.rgb"));
|
||||
tex->setImage(osgDB::readRefImageFile("Images/water.rgb"));
|
||||
tex->setWrap( Texture2D::WRAP_S, Texture2D::REPEAT );
|
||||
tex->setWrap( Texture2D::WRAP_T, Texture2D::REPEAT );
|
||||
|
||||
|
@ -112,7 +112,7 @@ Node *makeSky( void )
|
||||
|
||||
|
||||
Texture2D *tex = new Texture2D;
|
||||
tex->setImage(osgDB::readImageFile("Images/white.rgb"));
|
||||
tex->setImage(osgDB::readRefImageFile("Images/white.rgb"));
|
||||
|
||||
StateSet *dstate = new StateSet;
|
||||
|
||||
|
@ -161,7 +161,7 @@ Node *makeTank( void )
|
||||
|
||||
for( i = 0; i < c; i++ )
|
||||
conv( vc[i], mat, vc[i] );
|
||||
|
||||
|
||||
gset->addPrimitiveSet(new DrawArrays(PrimitiveSet::TRIANGLE_FAN,prev_c,c-prev_c));
|
||||
|
||||
|
||||
@ -171,7 +171,7 @@ Node *makeTank( void )
|
||||
|
||||
tex->setWrap( Texture2D::WRAP_S, Texture2D::REPEAT );
|
||||
tex->setWrap( Texture2D::WRAP_T, Texture2D::REPEAT );
|
||||
tex->setImage(osgDB::readImageFile("Images/tank.rgb"));
|
||||
tex->setImage(osgDB::readRefImageFile("Images/tank.rgb"));
|
||||
|
||||
StateSet *dstate = new StateSet;
|
||||
dstate->setTextureAttributeAndModes(0, tex, StateAttribute::ON );
|
||||
|
@ -131,7 +131,7 @@ Node *makeTerrain( void )
|
||||
|
||||
Texture2D *tex = new Texture2D;
|
||||
|
||||
tex->setImage(osgDB::readImageFile("Images/lz.rgb"));
|
||||
tex->setImage(osgDB::readRefImageFile("Images/lz.rgb"));
|
||||
|
||||
StateSet *dstate = new StateSet;
|
||||
dstate->setMode( GL_LIGHTING, StateAttribute::OFF );
|
||||
|
@ -234,7 +234,7 @@ Node *makeTrees( void )
|
||||
struct _tree *t;
|
||||
|
||||
Texture2D *tex = new Texture2D;
|
||||
tex->setImage(osgDB::readImageFile("Images/tree0.rgba"));
|
||||
tex->setImage(osgDB::readRefImageFile("Images/tree0.rgba"));
|
||||
|
||||
StateSet *dstate = new StateSet;
|
||||
|
||||
|
@ -248,7 +248,7 @@ struct SnapeImageHandler : public osgGA::GUIEventHandler
|
||||
{
|
||||
osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa);
|
||||
osg::Node* node = view ? view->getSceneData() : 0;
|
||||
if (node)
|
||||
if (node)
|
||||
{
|
||||
osgDB::writeNodeFile(*node, "hud.osgt");
|
||||
osgDB::writeNodeFile(*node, "hud.osgb");
|
||||
@ -284,10 +284,10 @@ int main( int argc, char **argv )
|
||||
|
||||
|
||||
// read the scene from the list of file specified commandline args.
|
||||
osg::ref_ptr<osg::Node> scene = osgDB::readNodeFiles(arguments);
|
||||
osg::ref_ptr<osg::Node> scene = osgDB::readRefNodeFiles(arguments);
|
||||
|
||||
// if not loaded assume no arguments passed in, try use default model instead.
|
||||
if (!scene) scene = osgDB::readNodeFile("dumptruck.osgt");
|
||||
if (!scene) scene = osgDB::readRefNodeFile("dumptruck.osgt");
|
||||
|
||||
|
||||
if (!scene)
|
||||
@ -320,7 +320,7 @@ int main( int argc, char **argv )
|
||||
viewer.addSlave(hudCamera, false);
|
||||
|
||||
// set the scene to render
|
||||
viewer.setSceneData(scene.get());
|
||||
viewer.setSceneData(scene);
|
||||
|
||||
return viewer.run();
|
||||
|
||||
@ -334,7 +334,7 @@ int main( int argc, char **argv )
|
||||
osgViewer::View* view = new osgViewer::View;
|
||||
viewer.addView(view);
|
||||
|
||||
view->setSceneData(scene.get());
|
||||
view->setSceneData(scene);
|
||||
view->setUpViewAcrossAllScreens();;
|
||||
view->setCameraManipulator(new osgGA::TrackballManipulator);
|
||||
|
||||
@ -375,11 +375,11 @@ int main( int argc, char **argv )
|
||||
osg::ref_ptr<osg::Group> group = new osg::Group;
|
||||
|
||||
// add the HUD subgraph.
|
||||
if (scene.valid()) group->addChild(scene.get());
|
||||
if (scene.valid()) group->addChild(scene);
|
||||
group->addChild(createHUD());
|
||||
|
||||
// set the scene to render
|
||||
viewer.setSceneData(group.get());
|
||||
viewer.setSceneData(group);
|
||||
|
||||
return viewer.run();
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ static osgDB::DirectoryContents getSuitableFiles(osg::ArgumentParser& arguments)
|
||||
{
|
||||
const std::string& directory = arguments[i];
|
||||
osgDB::DirectoryContents dc = osgDB::getSortedDirectoryContents(directory);
|
||||
|
||||
|
||||
for(osgDB::DirectoryContents::iterator itr = dc.begin(); itr != dc.end(); ++itr)
|
||||
{
|
||||
std::string full_file_name = directory + "/" + (*itr);
|
||||
@ -76,28 +76,28 @@ osg::StateSet* createState(osg::ArgumentParser& arguments)
|
||||
osg::ref_ptr<osg::ImageSequence> imageSequence = new osg::ImageSequence;
|
||||
|
||||
bool preLoad = true;
|
||||
|
||||
|
||||
while (arguments.read("--page-and-discard"))
|
||||
{
|
||||
imageSequence->setMode(osg::ImageSequence::PAGE_AND_DISCARD_USED_IMAGES);
|
||||
preLoad = false;
|
||||
}
|
||||
|
||||
|
||||
while (arguments.read("--page-and-retain"))
|
||||
{
|
||||
imageSequence->setMode(osg::ImageSequence::PAGE_AND_RETAIN_IMAGES);
|
||||
preLoad = false;
|
||||
}
|
||||
|
||||
|
||||
while (arguments.read("--preload"))
|
||||
{
|
||||
imageSequence->setMode(osg::ImageSequence::PRE_LOAD_ALL_IMAGES);
|
||||
preLoad = true;
|
||||
}
|
||||
|
||||
|
||||
double length = -1.0;
|
||||
while (arguments.read("--length",length)) {}
|
||||
|
||||
|
||||
double fps = 30.0;
|
||||
while (arguments.read("--fps",fps)) {}
|
||||
|
||||
@ -111,7 +111,7 @@ osg::StateSet* createState(osg::ArgumentParser& arguments)
|
||||
const std::string& filename = *itr;
|
||||
if (preLoad)
|
||||
{
|
||||
osg::ref_ptr<osg::Image> image = osgDB::readImageFile(filename);
|
||||
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile(filename);
|
||||
if (image.valid())
|
||||
{
|
||||
imageSequence->addImage(image.get());
|
||||
@ -123,7 +123,7 @@ osg::StateSet* createState(osg::ArgumentParser& arguments)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (length>0.0)
|
||||
{
|
||||
imageSequence->setLength(length);
|
||||
@ -144,14 +144,14 @@ osg::StateSet* createState(osg::ArgumentParser& arguments)
|
||||
{
|
||||
imageSequence->setLength(4.0);
|
||||
}
|
||||
imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/posx.png"));
|
||||
imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/negx.png"));
|
||||
imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/posy.png"));
|
||||
imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/negy.png"));
|
||||
imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/posz.png"));
|
||||
imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/negz.png"));
|
||||
imageSequence->addImage(osgDB::readRefImageFile("Cubemap_axis/posx.png"));
|
||||
imageSequence->addImage(osgDB::readRefImageFile("Cubemap_axis/negx.png"));
|
||||
imageSequence->addImage(osgDB::readRefImageFile("Cubemap_axis/posy.png"));
|
||||
imageSequence->addImage(osgDB::readRefImageFile("Cubemap_axis/negy.png"));
|
||||
imageSequence->addImage(osgDB::readRefImageFile("Cubemap_axis/posz.png"));
|
||||
imageSequence->addImage(osgDB::readRefImageFile("Cubemap_axis/negz.png"));
|
||||
}
|
||||
|
||||
|
||||
// start the image sequence playing
|
||||
imageSequence->play();
|
||||
|
||||
@ -163,7 +163,7 @@ osg::StateSet* createState(osg::ArgumentParser& arguments)
|
||||
texture->setResizeNonPowerOfTwoHint(false);
|
||||
texture->setImage(imageSequence.get());
|
||||
//texture->setTextureSize(512,512);
|
||||
#else
|
||||
#else
|
||||
osg::TextureRectangle* texture = new osg::TextureRectangle;
|
||||
texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);
|
||||
texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);
|
||||
@ -183,12 +183,12 @@ osg::StateSet* createState(osg::ArgumentParser& arguments)
|
||||
osg::Node* createModel(osg::ArgumentParser& arguments)
|
||||
{
|
||||
|
||||
// create the geometry of the model, just a simple 2d quad right now.
|
||||
// create the geometry of the model, just a simple 2d quad right now.
|
||||
osg::Geode* geode = new osg::Geode;
|
||||
geode->addDrawable(osg::createTexturedQuadGeometry(osg::Vec3(0.0f,0.0f,0.0), osg::Vec3(1.0f,0.0f,0.0), osg::Vec3(0.0f,0.0f,1.0f)));
|
||||
|
||||
geode->setStateSet(createState(arguments));
|
||||
|
||||
|
||||
return geode;
|
||||
|
||||
}
|
||||
@ -200,10 +200,10 @@ class MovieEventHandler : public osgGA::GUIEventHandler
|
||||
public:
|
||||
|
||||
MovieEventHandler():_playToggle(true),_trackMouse(false) {}
|
||||
|
||||
|
||||
void setMouseTracking(bool track) { _trackMouse = track; }
|
||||
bool getMouseTracking() const { return _trackMouse; }
|
||||
|
||||
|
||||
void set(osg::Node* node);
|
||||
|
||||
void setTrackMouse(bool tm)
|
||||
@ -233,20 +233,20 @@ public:
|
||||
bool getTrackMouse() const { return _trackMouse; }
|
||||
|
||||
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor* nv);
|
||||
|
||||
|
||||
virtual void getUsage(osg::ApplicationUsage& usage) const;
|
||||
|
||||
typedef std::vector< osg::observer_ptr<osg::ImageStream> > ImageStreamList;
|
||||
|
||||
|
||||
struct ImageStreamPlaybackSpeedData {
|
||||
double fps;
|
||||
unsigned char* lastData;
|
||||
double timeStamp, lastOutput;
|
||||
|
||||
|
||||
ImageStreamPlaybackSpeedData() : fps(0), lastData(NULL), timeStamp(0), lastOutput(0) {}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
typedef std::vector< ImageStreamPlaybackSpeedData > ImageStreamPlayBackSpeedList;
|
||||
|
||||
protected:
|
||||
@ -258,7 +258,7 @@ protected:
|
||||
public:
|
||||
FindImageStreamsVisitor(ImageStreamList& imageStreamList):
|
||||
_imageStreamList(imageStreamList) {}
|
||||
|
||||
|
||||
virtual void apply(osg::Geode& geode)
|
||||
{
|
||||
apply(geode.getStateSet());
|
||||
@ -267,7 +267,7 @@ protected:
|
||||
{
|
||||
apply(geode.getDrawable(i)->getStateSet());
|
||||
}
|
||||
|
||||
|
||||
traverse(geode);
|
||||
}
|
||||
|
||||
@ -276,11 +276,11 @@ protected:
|
||||
apply(node.getStateSet());
|
||||
traverse(node);
|
||||
}
|
||||
|
||||
|
||||
inline void apply(osg::StateSet* stateset)
|
||||
{
|
||||
if (!stateset) return;
|
||||
|
||||
|
||||
osg::StateAttribute* attr = stateset->getTextureAttribute(0,osg::StateAttribute::TEXTURE);
|
||||
if (attr)
|
||||
{
|
||||
@ -291,20 +291,20 @@ protected:
|
||||
if (textureRec) apply(dynamic_cast<osg::ImageStream*>(textureRec->getImage()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline void apply(osg::ImageStream* imagestream)
|
||||
{
|
||||
if (imagestream)
|
||||
{
|
||||
_imageStreamList.push_back(imagestream);
|
||||
_imageStreamList.push_back(imagestream);
|
||||
s_imageStream = imagestream;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ImageStreamList& _imageStreamList;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
FindImageStreamsVisitor& operator = (const FindImageStreamsVisitor&) { return *this; }
|
||||
};
|
||||
|
||||
@ -313,7 +313,7 @@ protected:
|
||||
bool _trackMouse;
|
||||
ImageStreamList _imageStreamList;
|
||||
ImageStreamPlayBackSpeedList _imageStreamPlayBackSpeedList;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -338,7 +338,7 @@ bool MovieEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIAction
|
||||
{
|
||||
double t = ea.getTime();
|
||||
bool printed(false);
|
||||
|
||||
|
||||
ImageStreamPlayBackSpeedList::iterator fps_itr = _imageStreamPlayBackSpeedList.begin();
|
||||
for(ImageStreamList::iterator itr=_imageStreamList.begin();
|
||||
itr!=_imageStreamList.end();
|
||||
@ -351,17 +351,17 @@ bool MovieEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIAction
|
||||
data.lastData = (*itr)->data();
|
||||
data.fps = (*fps_itr).fps * 0.8 + 0.2 * (1/dt);
|
||||
data.timeStamp = t;
|
||||
|
||||
|
||||
if (t-data.lastOutput > 1)
|
||||
{
|
||||
std::cout << data.fps << " ";
|
||||
data.lastOutput = t;
|
||||
printed = true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
if (printed)
|
||||
if (printed)
|
||||
std::cout << std::endl;
|
||||
}
|
||||
break;
|
||||
@ -380,7 +380,7 @@ bool MovieEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIAction
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
case(osgGA::GUIEventAdapter::KEYDOWN):
|
||||
{
|
||||
if (ea.getKey()=='p')
|
||||
@ -434,11 +434,11 @@ bool MovieEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIAction
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if (ea.getKey() == 'i')
|
||||
else if (ea.getKey() == 'i')
|
||||
{
|
||||
setTrackMouse(!_trackMouse);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -479,7 +479,7 @@ int main(int argc, char **argv)
|
||||
meh->set( viewer.getSceneData() );
|
||||
|
||||
if (arguments.read("--track-mouse")) meh->setTrackMouse(true);
|
||||
|
||||
|
||||
viewer.addEventHandler( meh );
|
||||
|
||||
viewer.addEventHandler( new osgViewer::StatsHandler());
|
||||
|
@ -244,7 +244,7 @@ int main( int argc, char **argv )
|
||||
|
||||
|
||||
// load the nodes from the commandline arguments.
|
||||
osg::ref_ptr<osg::Node> model = osgDB::readNodeFiles(arguments);
|
||||
osg::ref_ptr<osg::Node> model = osgDB::readRefNodeFiles(arguments);
|
||||
if (model)
|
||||
{
|
||||
// the osgSim::InsertImpostorsVisitor used lower down to insert impostors
|
||||
@ -280,7 +280,7 @@ int main( int argc, char **argv )
|
||||
// on it right now as it requires a getRoots() method to be added to
|
||||
// osg::Node, and we're about to make a release so no new features!
|
||||
osg::ref_ptr<osg::Group> rootnode = new osg::Group;
|
||||
rootnode->addChild(model.get());
|
||||
rootnode->addChild(model);
|
||||
|
||||
|
||||
// now insert impostors in the model using the InsertImpostorsVisitor.
|
||||
@ -304,7 +304,7 @@ int main( int argc, char **argv )
|
||||
}
|
||||
|
||||
// add model to viewer.
|
||||
viewer.setSceneData(model.get());
|
||||
viewer.setSceneData(model);
|
||||
|
||||
return viewer.run();
|
||||
}
|
||||
|
@ -36,9 +36,15 @@
|
||||
|
||||
struct MyReadCallback : public osgUtil::IntersectionVisitor::ReadCallback
|
||||
{
|
||||
#if 0
|
||||
virtual osg::Node* readNodeFile(const std::string& filename)
|
||||
{
|
||||
return osgDB::readNodeFile(filename);
|
||||
return osgDB::readRefNodeFile(filename).release();
|
||||
}
|
||||
#endif
|
||||
virtual osg::ref_ptr<osg::Node> readNodeFile(const std::string& filename)
|
||||
{
|
||||
return osgDB::readRefNodeFile(filename);
|
||||
}
|
||||
};
|
||||
|
||||
@ -47,37 +53,37 @@ int main(int argc, char **argv)
|
||||
{
|
||||
// use an ArgumentParser object to manage the program arguments.
|
||||
osg::ArgumentParser arguments(&argc,argv);
|
||||
|
||||
osg::ref_ptr<osg::Node> scene = osgDB::readNodeFiles(arguments);
|
||||
|
||||
if (!scene)
|
||||
|
||||
osg::ref_ptr<osg::Node> scene = osgDB::readRefNodeFiles(arguments);
|
||||
|
||||
if (!scene)
|
||||
{
|
||||
std::cout<<"No model loaded, please specify a valid model on the command line."<<std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
std::cout<<"Intersection "<<std::endl;
|
||||
|
||||
|
||||
|
||||
|
||||
osg::BoundingSphere bs = scene->getBound();
|
||||
|
||||
|
||||
bool useIntersectorGroup = true;
|
||||
bool useLineOfSight = true;
|
||||
|
||||
|
||||
//osg::CoordinateSystemNode* csn = dynamic_cast<osg::CoordinateSystemNode*>(scene.get());
|
||||
//osg::EllipsoidModel* em = csn ? csn->getEllipsoidModel() : 0;
|
||||
|
||||
if (useLineOfSight)
|
||||
{
|
||||
|
||||
|
||||
osg::Vec3d start = bs.center() + osg::Vec3d(0.0,bs.radius(),0.0);
|
||||
osg::Vec3d end = bs.center() - osg::Vec3d(0.0, bs.radius(),0.0);
|
||||
osg::Vec3d deltaRow( 0.0, 0.0, bs.radius()*0.01);
|
||||
osg::Vec3d deltaColumn( bs.radius()*0.01, 0.0, 0.0);
|
||||
|
||||
osgSim::LineOfSight los;
|
||||
|
||||
|
||||
#if 1
|
||||
unsigned int numRows = 20;
|
||||
unsigned int numColumns = 20;
|
||||
@ -118,7 +124,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
// now do a second traversal to test performance of cache.
|
||||
osg::Timer_t startTick = osg::Timer::instance()->tick();
|
||||
@ -173,7 +179,7 @@ int main(int argc, char **argv)
|
||||
else if (useIntersectorGroup)
|
||||
{
|
||||
osg::Timer_t startTick = osg::Timer::instance()->tick();
|
||||
|
||||
|
||||
osg::Vec3d start = bs.center() + osg::Vec3d(0.0,bs.radius(),0.0);
|
||||
osg::Vec3d end = bs.center();// - osg::Vec3d(0.0, bs.radius(),0.0);
|
||||
osg::Vec3d deltaRow( 0.0, 0.0, bs.radius()*0.01);
|
||||
@ -194,7 +200,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
osgUtil::IntersectionVisitor intersectVisitor( intersectorGroup.get(), new MyReadCallback );
|
||||
scene->accept(intersectVisitor);
|
||||
|
||||
@ -229,7 +235,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -272,6 +278,6 @@ int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include <osgDB/ReadFile>
|
||||
|
||||
#include <osg/ArgumentParser>
|
||||
@ -47,24 +47,24 @@ int main(int argc, char **argv)
|
||||
{
|
||||
// use an ArgumentParser object to manage the program arguments.
|
||||
osg::ArgumentParser arguments(&argc,argv);
|
||||
|
||||
|
||||
int maxNumLevels = 16;
|
||||
int targetNumIndicesPerLeaf = 16;
|
||||
|
||||
while (arguments.read("--max", maxNumLevels)) {}
|
||||
while (arguments.read("--leaf", targetNumIndicesPerLeaf)) {}
|
||||
|
||||
|
||||
osgDB::Registry::instance()->setBuildKdTreesHint(osgDB::ReaderWriter::Options::BUILD_KDTREES);
|
||||
|
||||
osg::ref_ptr<osg::Node> scene = osgDB::readNodeFiles(arguments);
|
||||
|
||||
if (!scene)
|
||||
|
||||
osg::ref_ptr<osg::Node> scene = osgDB::readRefNodeFiles(arguments);
|
||||
|
||||
if (!scene)
|
||||
{
|
||||
std::cout<<"No model loaded, please specify a valid model on the command line."<<std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
osgViewer::Viewer viewer;
|
||||
viewer.setSceneData(scene.get());
|
||||
viewer.setSceneData(scene);
|
||||
return viewer.run();
|
||||
}
|
||||
|
@ -341,10 +341,10 @@ int main( int argc, char **argv )
|
||||
osg::ref_ptr<osg::Node> loadedModel;
|
||||
|
||||
// load the scene.
|
||||
if (argc>1) loadedModel = osgDB::readNodeFile(argv[1]);
|
||||
if (argc>1) loadedModel = osgDB::readRefNodeFile(argv[1]);
|
||||
|
||||
// if not loaded assume no arguments passed in, try use default mode instead.
|
||||
if (!loadedModel) loadedModel = osgDB::readNodeFile("dumptruck.osgt");
|
||||
if (!loadedModel) loadedModel = osgDB::readRefNodeFile("dumptruck.osgt");
|
||||
|
||||
if (!loadedModel)
|
||||
{
|
||||
@ -374,7 +374,7 @@ int main( int argc, char **argv )
|
||||
osgViewer::Viewer viewer;
|
||||
viewer.getCamera()->setGraphicsContext(gc.get());
|
||||
viewer.getCamera()->setViewport(0,0,800,600);
|
||||
viewer.setSceneData(loadedModel.get());
|
||||
viewer.setSceneData(loadedModel);
|
||||
|
||||
// create a tracball manipulator to move the camera around in response to keyboard/mouse events
|
||||
viewer.setCameraManipulator( new osgGA::TrackballManipulator );
|
||||
|
@ -38,14 +38,14 @@
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
osg::ArgumentParser arguments(&argc,argv);
|
||||
|
||||
|
||||
// initialize the viewer.
|
||||
osgViewer::Viewer viewer(arguments);
|
||||
|
||||
|
||||
osg::DisplaySettings* ds = viewer.getDisplaySettings() ? viewer.getDisplaySettings() : osg::DisplaySettings::instance().get();
|
||||
ds->readCommandLine(arguments);
|
||||
|
||||
osg::ref_ptr<osg::Node> model = osgDB::readNodeFiles(arguments);
|
||||
osg::ref_ptr<osg::Node> model = osgDB::readRefNodeFiles(arguments);
|
||||
|
||||
if (!model)
|
||||
{
|
||||
@ -57,8 +57,8 @@ int main( int argc, char **argv )
|
||||
OSG_NOTICE<<"Stereo "<<ds->getStereo()<<std::endl;
|
||||
OSG_NOTICE<<"StereoMode "<<ds->getStereoMode()<<std::endl;
|
||||
|
||||
viewer.setSceneData(model.get());
|
||||
|
||||
viewer.setSceneData(model);
|
||||
|
||||
// add the state manipulator
|
||||
viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) );
|
||||
|
||||
@ -77,7 +77,7 @@ int main( int argc, char **argv )
|
||||
}
|
||||
|
||||
ds->setKeystoneHint(true);
|
||||
|
||||
|
||||
if (!ds->getKeystoneFileNames().empty())
|
||||
{
|
||||
for(osg::DisplaySettings::Objects::iterator itr = ds->getKeystones().begin();
|
||||
@ -85,19 +85,19 @@ int main( int argc, char **argv )
|
||||
++itr)
|
||||
{
|
||||
osgViewer::Keystone* keystone = dynamic_cast<osgViewer::Keystone*>(itr->get());
|
||||
if (keystone)
|
||||
if (keystone)
|
||||
{
|
||||
std::string filename;
|
||||
keystone->getUserValue("filename",filename);
|
||||
OSG_NOTICE<<"Loaded keystone "<<filename<<", "<<keystone<<std::endl;
|
||||
|
||||
|
||||
ds->getKeystones().push_back(keystone);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
viewer.apply(new osgViewer::SingleScreen(0));
|
||||
|
||||
|
||||
viewer.realize();
|
||||
|
||||
while(!viewer.done())
|
||||
|
@ -53,23 +53,23 @@ int runApp(std::string xapp);
|
||||
|
||||
// class to handle events with a pick
|
||||
class PickHandler : public osgGA::GUIEventHandler {
|
||||
public:
|
||||
public:
|
||||
|
||||
PickHandler(osgViewer::Viewer* viewer,osgText::Text* updateText):
|
||||
_viewer(viewer),
|
||||
_updateText(updateText) {}
|
||||
|
||||
|
||||
~PickHandler() {}
|
||||
|
||||
|
||||
bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us);
|
||||
|
||||
std::string pick(const osgGA::GUIEventAdapter& event);
|
||||
|
||||
|
||||
void highlight(const std::string& name)
|
||||
{
|
||||
if (_updateText.get()) _updateText->setText(name);
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
osgViewer::Viewer* _viewer;
|
||||
@ -133,14 +133,14 @@ osg::Node* createHUD(osgText::Text* updateText)
|
||||
osg::MatrixTransform* modelview_abs = new osg::MatrixTransform;
|
||||
modelview_abs->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
|
||||
modelview_abs->setMatrix(osg::Matrix::identity());
|
||||
|
||||
|
||||
osg::Projection* projection = new osg::Projection;
|
||||
projection->setMatrix(osg::Matrix::ortho2D(0,1280,0,1024));
|
||||
projection->addChild(modelview_abs);
|
||||
|
||||
|
||||
|
||||
|
||||
std::string timesFont("fonts/times.ttf");
|
||||
|
||||
|
||||
// turn lighting off for the text and disable depth test to ensure its always ontop.
|
||||
osg::Vec3 position(50.0f,510.0f,0.0f);
|
||||
osg::Vec3 delta(0.0f,-60.0f,0.0f);
|
||||
@ -153,16 +153,16 @@ osg::Node* createHUD(osgText::Text* updateText)
|
||||
geode->setName("The text label");
|
||||
geode->addDrawable( updateText );
|
||||
modelview_abs->addChild(geode);
|
||||
|
||||
|
||||
updateText->setCharacterSize(20.0f);
|
||||
updateText->setFont(timesFont);
|
||||
updateText->setColor(osg::Vec4(1.0f,1.0f,0.0f,1.0f));
|
||||
updateText->setText("");
|
||||
updateText->setPosition(position);
|
||||
|
||||
|
||||
position += delta;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return projection;
|
||||
|
||||
} // end create HUDf
|
||||
@ -179,13 +179,13 @@ class Xample
|
||||
std::string app;
|
||||
public:
|
||||
Xample(std::string image, std::string prog)
|
||||
{
|
||||
{
|
||||
texture = image;
|
||||
app = prog;
|
||||
osg::notify(osg::INFO) << "New Xample!" << std::endl;
|
||||
};
|
||||
~Xample() { };
|
||||
|
||||
|
||||
std::string getTexture()
|
||||
{
|
||||
return texture;
|
||||
@ -225,11 +225,11 @@ int runApp(std::string xapp)
|
||||
if(!xapp.compare(x.getApp()))
|
||||
{
|
||||
osg::notify(osg::INFO) << "app found!" << std::endl;
|
||||
|
||||
|
||||
const char* cxapp = xapp.c_str();
|
||||
|
||||
|
||||
osg::notify(osg::INFO) << "char* = " << cxapp <<std::endl;
|
||||
|
||||
|
||||
return system(cxapp);
|
||||
}
|
||||
}
|
||||
@ -241,14 +241,14 @@ int runApp(std::string xapp)
|
||||
void readConfFile(const char* confFile) // read confFile 1
|
||||
{
|
||||
osg::notify(osg::INFO) << "Start reading confFile" << std::endl;
|
||||
|
||||
|
||||
std::string fileName = osgDB::findDataFile(confFile);
|
||||
if (fileName.empty())
|
||||
{
|
||||
osg::notify(osg::INFO) << "Config file not found"<<confFile << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
osgDB::ifstream in(fileName.c_str());
|
||||
if (!in)
|
||||
@ -258,7 +258,7 @@ void readConfFile(const char* confFile)
|
||||
}
|
||||
std::string imageBuffer;
|
||||
std::string appBuffer;
|
||||
|
||||
|
||||
while (!in.eof())
|
||||
{
|
||||
std::getline(in, imageBuffer);
|
||||
@ -269,18 +269,18 @@ void readConfFile(const char* confFile)
|
||||
osg::notify(osg::INFO) << "imageBuffer: " << imageBuffer << std::endl;
|
||||
osg::notify(osg::INFO) << "appBuffer: " << appBuffer << std::endl;
|
||||
// jeweils checken ob image vorhanden ist.
|
||||
|
||||
|
||||
Xample tmp(imageBuffer, appBuffer); // create Xample objects 2
|
||||
|
||||
|
||||
Xamplelist.push_back(tmp); // store objects in list 2
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
in.close();
|
||||
|
||||
|
||||
osg::notify(osg::INFO) << "End reading confFile" << std::endl;
|
||||
|
||||
|
||||
printList();
|
||||
} // end readConfFile
|
||||
|
||||
@ -291,8 +291,8 @@ void SetObjectTextureState(osg::Geode *geodeCurrent, std::string texture)
|
||||
osg::StateSet* stateTexture = geodeCurrent->getOrCreateStateSet();
|
||||
|
||||
// load texture.jpg as an image
|
||||
osg::Image* imgTexture = osgDB::readImageFile( texture );
|
||||
|
||||
osg::ref_ptr<osg::Image> imgTexture = osgDB::readRefImageFile( texture );
|
||||
|
||||
// if the image is successfully loaded
|
||||
if (imgTexture)
|
||||
{
|
||||
@ -338,11 +338,11 @@ osg::PositionAttitudeTransform* getPATransformation(osg::Node* object, osg::Vec3
|
||||
{
|
||||
osg::PositionAttitudeTransform* tmpTrans = new osg::PositionAttitudeTransform();
|
||||
tmpTrans->addChild( object );
|
||||
|
||||
|
||||
tmpTrans->setPosition( position );
|
||||
tmpTrans->setScale( scale );
|
||||
tmpTrans->setPivotPoint( pivot );
|
||||
|
||||
|
||||
return tmpTrans;
|
||||
}
|
||||
|
||||
@ -352,7 +352,7 @@ void printBoundings(osg::Node* current, std::string name)
|
||||
osg::notify(osg::INFO) << name << std::endl;
|
||||
osg::notify(osg::INFO) << "center = " << currentBound.center() << std::endl;
|
||||
osg::notify(osg::INFO) << "radius = " << currentBound.radius() << std::endl;
|
||||
|
||||
|
||||
// return currentBound.radius();
|
||||
}
|
||||
|
||||
@ -361,7 +361,7 @@ osg::Group* setupGraph()
|
||||
{
|
||||
osg::Group* xGroup = new osg::Group();
|
||||
|
||||
|
||||
|
||||
// positioning and sizes
|
||||
float defaultRadius = 0.8f;
|
||||
|
||||
@ -375,20 +375,20 @@ osg::Group* setupGraph()
|
||||
float xjump = (2*bs);
|
||||
float zjump = xjump;
|
||||
osg::Vec3 vScale( 0.5f, 0.5f, 0.5f );
|
||||
osg::Vec3 vPivot( 0.0f, 0.0f, 0.0f );
|
||||
osg::Vec3 vPivot( 0.0f, 0.0f, 0.0f );
|
||||
|
||||
// run through Xampleliste
|
||||
int z = 1;
|
||||
for (OP i = Xamplelist.begin() ; i != Xamplelist.end() ; ++i, ++z)
|
||||
{
|
||||
Xample& x = *i;
|
||||
|
||||
|
||||
osg::Node* tmpCube = createTexturedCube(defaultRadius, defaultPos, x.getTexture(), x.getApp());
|
||||
printBoundings(tmpCube, x.getApp());
|
||||
osg::Vec3 vPosition( xnext, 0.0f, znext );
|
||||
osg::PositionAttitudeTransform* transX = getPATransformation(tmpCube, vPosition, vScale, vPivot);
|
||||
xGroup->addChild( transX );
|
||||
|
||||
|
||||
// line feed
|
||||
if(z < itemsInLine)
|
||||
xnext += xjump;
|
||||
@ -398,8 +398,8 @@ osg::Group* setupGraph()
|
||||
znext -= zjump;
|
||||
z = 0;
|
||||
}
|
||||
} // end run through list
|
||||
|
||||
} // end run through list
|
||||
|
||||
return xGroup;
|
||||
} // end setupGraph
|
||||
|
||||
@ -414,7 +414,7 @@ int main( int argc, char **argv )
|
||||
{
|
||||
readConfFile(argv[1]); // read ConfigFile 1
|
||||
}
|
||||
|
||||
|
||||
// construct the viewer.
|
||||
osgViewer::Viewer viewer;
|
||||
|
||||
@ -428,9 +428,9 @@ int main( int argc, char **argv )
|
||||
|
||||
root->addChild( setupGraph() );
|
||||
|
||||
// add the HUD subgraph.
|
||||
// add the HUD subgraph.
|
||||
root->addChild(createHUD(updateText.get()));
|
||||
|
||||
|
||||
// add model to viewer.
|
||||
viewer.setSceneData( root );
|
||||
|
||||
@ -438,13 +438,13 @@ int main( int argc, char **argv )
|
||||
lookAt.makeLookAt(osg::Vec3(0.0f, -4.0f, 0.0f), centerScope, osg::Vec3(0.0f, 0.0f, 1.0f));
|
||||
|
||||
viewer.getCamera()->setViewMatrix(lookAt);
|
||||
|
||||
|
||||
viewer.realize();
|
||||
|
||||
while( !viewer.done() )
|
||||
{
|
||||
// fire off the cull and draw traversals of the scene.
|
||||
viewer.frame();
|
||||
viewer.frame();
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -226,7 +226,7 @@ osg::Geometry* createWall(const osg::Vec3& v1,const osg::Vec3& v2,const osg::Vec
|
||||
}
|
||||
|
||||
|
||||
osg::Node* createRoom(osg::Node* loadedModel)
|
||||
osg::ref_ptr<osg::Node> createRoom(const osg::ref_ptr<osg::Node>& loadedModel)
|
||||
{
|
||||
// default scale for this model.
|
||||
osg::BoundingSphere bs(osg::Vec3(0.0f,0.0f,0.0f),1.0f);
|
||||
@ -323,20 +323,20 @@ int main( int argc, char **argv )
|
||||
osgViewer::Viewer viewer;
|
||||
|
||||
// load the nodes from the commandline arguments.
|
||||
osg::Node* loadedModel = osgDB::readNodeFiles(arguments);
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFiles(arguments);
|
||||
|
||||
// if not loaded assume no arguments passed in, try use default mode instead.
|
||||
if (!loadedModel) loadedModel = osgDB::readNodeFile("glider.osgt");
|
||||
if (!loadedModel) loadedModel = osgDB::readRefNodeFile("glider.osgt");
|
||||
|
||||
// create a room made of foor walls, a floor, a roof, and swinging light fitting.
|
||||
osg::Node* rootnode = createRoom(loadedModel);
|
||||
osg::ref_ptr<osg::Node> rootnode = createRoom(loadedModel);
|
||||
|
||||
// run optimization over the scene graph
|
||||
osgUtil::Optimizer optimzer;
|
||||
optimzer.optimize(rootnode);
|
||||
|
||||
// add a viewport to the viewer and attach the scene graph.
|
||||
viewer.setSceneData( rootnode );
|
||||
viewer.setSceneData(rootnode);
|
||||
|
||||
|
||||
// create the windows and run the threads.
|
||||
|
@ -47,12 +47,12 @@ void addToLightPointNode(osgSim::LightPointNode& lpn,osgSim::LightPoint& start,o
|
||||
lpn.addLightPoint(start);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
float rend = 0.0f;
|
||||
float rdelta = 1.0f/((float)noSteps-1.0f);
|
||||
|
||||
|
||||
lpn.getLightPointList().reserve(noSteps);
|
||||
|
||||
|
||||
for(unsigned int i=0;i<noSteps;++i,rend+=rdelta)
|
||||
{
|
||||
float rstart = 1.0f-rend;
|
||||
@ -63,7 +63,7 @@ void addToLightPointNode(osgSim::LightPointNode& lpn,osgSim::LightPoint& start,o
|
||||
INTERPOLATE(_radius);
|
||||
|
||||
lpn.addLightPoint(lp);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,12 +78,12 @@ osg::Node* createLightPointsDatabase()
|
||||
|
||||
start._position.set(-500.0f,-500.0f,0.0f);
|
||||
start._color.set(1.0f,0.0f,0.0f,1.0f);
|
||||
|
||||
|
||||
end._position.set(500.0f,-500.0f,0.0f);
|
||||
end._color.set(1.0f,1.0f,1.0f,1.0f);
|
||||
|
||||
|
||||
osg::MatrixTransform* transform = new osg::MatrixTransform;
|
||||
|
||||
|
||||
transform->setDataVariance(osg::Object::STATIC);
|
||||
transform->setMatrix(osg::Matrix::scale(0.1,0.1,0.1));
|
||||
|
||||
@ -100,7 +100,7 @@ osg::Node* createLightPointsDatabase()
|
||||
// bs->addPulse(0.5,osg::Vec4(0.0f,0.0f,0.0f,0.0f)); // off
|
||||
// bs->addPulse(1.0,osg::Vec4(1.0f,1.0f,1.0f,1.0f));
|
||||
// bs->addPulse(0.5,osg::Vec4(0.0f,0.0f,0.0f,0.0f)); // off
|
||||
|
||||
|
||||
|
||||
// osgSim::Sector* sector = new osgSim::ConeSector(osg::Vec3(0.0f,0.0f,1.0f),osg::inDegrees(45.0),osg::inDegrees(45.0));
|
||||
// osgSim::Sector* sector = new osgSim::ElevationSector(-osg::inDegrees(45.0),osg::inDegrees(45.0),osg::inDegrees(45.0));
|
||||
@ -113,7 +113,7 @@ osg::Node* createLightPointsDatabase()
|
||||
{
|
||||
|
||||
// osgSim::BlinkSequence* local_bs = new osgSim::BlinkSequence(*bs);
|
||||
// local_bs->setSequenceGroup(new osgSim::BlinkSequence::SequenceGroup((double)i*0.1));
|
||||
// local_bs->setSequenceGroup(new osgSim::BlinkSequence::SequenceGroup((double)i*0.1));
|
||||
// start._blinkSequence = local_bs;
|
||||
|
||||
// start._sector = sector;
|
||||
@ -129,7 +129,7 @@ osg::Node* createLightPointsDatabase()
|
||||
|
||||
// Set point sprite texture in LightPointNode StateSet.
|
||||
osg::Texture2D *tex = new osg::Texture2D();
|
||||
tex->setImage(osgDB::readImageFile("Images/particle.rgb"));
|
||||
tex->setImage(osgDB::readRefImageFile("Images/particle.rgb"));
|
||||
set->setTextureAttributeAndModes(0, tex, osg::StateAttribute::ON);
|
||||
}
|
||||
|
||||
@ -140,17 +140,17 @@ osg::Node* createLightPointsDatabase()
|
||||
//
|
||||
|
||||
addToLightPointNode(*lpn,start,end,noStepsX);
|
||||
|
||||
|
||||
start._position += start_delta;
|
||||
end._position += end_delta;
|
||||
|
||||
transform->addChild(lpn);
|
||||
|
||||
transform->addChild(lpn);
|
||||
}
|
||||
|
||||
|
||||
osg::Group* group = new osg::Group;
|
||||
group->addChild(transform);
|
||||
|
||||
|
||||
|
||||
|
||||
return group;
|
||||
}
|
||||
|
||||
@ -232,16 +232,16 @@ int main( int argc, char **argv )
|
||||
osg::Group* rootnode = new osg::Group;
|
||||
|
||||
// load the nodes from the commandline arguments.
|
||||
rootnode->addChild(osgDB::readNodeFiles(arguments));
|
||||
rootnode->addChild(osgDB::readRefNodeFiles(arguments));
|
||||
rootnode->addChild(createLightPointsDatabase());
|
||||
rootnode->addChild(CreateBlinkSequenceLightNode());
|
||||
|
||||
|
||||
// run optimization over the scene graph
|
||||
osgUtil::Optimizer optimzer;
|
||||
optimzer.optimize(rootnode);
|
||||
|
||||
|
||||
// add a viewport to the viewer and attach the scene graph.
|
||||
viewer.setSceneData( rootnode );
|
||||
|
||||
|
||||
return viewer.run();
|
||||
}
|
||||
|
@ -32,7 +32,7 @@
|
||||
|
||||
const int _ops_nb=16;
|
||||
const osg::LogicOp::Opcode _operations[_ops_nb]=
|
||||
{
|
||||
{
|
||||
osg::LogicOp::CLEAR,
|
||||
osg::LogicOp::SET,
|
||||
osg::LogicOp::COPY,
|
||||
@ -52,7 +52,7 @@ const osg::LogicOp::Opcode _operations[_ops_nb]=
|
||||
};
|
||||
|
||||
const char* _ops_name[_ops_nb]=
|
||||
{
|
||||
{
|
||||
"osg::LogicOp::CLEAR",
|
||||
"osg::LogicOp::SET",
|
||||
"osg::LogicOp::COPY",
|
||||
@ -142,22 +142,22 @@ int main( int argc, char **argv )
|
||||
osg::ArgumentParser arguments(&argc,argv);
|
||||
|
||||
// load the nodes from the commandline arguments.
|
||||
osg::Node* loadedModel = osgDB::readNodeFiles(arguments);
|
||||
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFiles(arguments);
|
||||
|
||||
// if not loaded assume no arguments passed in, try use default mode instead.
|
||||
if (!loadedModel) loadedModel = osgDB::readNodeFile("glider.osgt");
|
||||
|
||||
if (!loadedModel) loadedModel = osgDB::readRefNodeFile("glider.osgt");
|
||||
|
||||
if (!loadedModel)
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Please specify model filename on the command line."<<std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
osg::Group* root = new osg::Group;
|
||||
|
||||
osg::ref_ptr<osg::Group> root = new osg::Group;
|
||||
root->addChild(loadedModel);
|
||||
|
||||
osg::StateSet* stateset = new osg::StateSet;
|
||||
osg::LogicOp* logicOp = new osg::LogicOp(osg::LogicOp::OR_INVERTED);
|
||||
|
||||
osg::ref_ptr<osg::StateSet> stateset = new osg::StateSet;
|
||||
osg::ref_ptr<osg::LogicOp> logicOp = new osg::LogicOp(osg::LogicOp::OR_INVERTED);
|
||||
|
||||
stateset->setAttributeAndModes(logicOp,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
|
||||
@ -170,14 +170,14 @@ int main( int argc, char **argv )
|
||||
// construct the viewer.
|
||||
osgViewer::Viewer viewer;
|
||||
|
||||
viewer.addEventHandler(new TechniqueEventHandler(logicOp));
|
||||
|
||||
viewer.addEventHandler(new TechniqueEventHandler(logicOp.get()));
|
||||
|
||||
// run optimization over the scene graph
|
||||
osgUtil::Optimizer optimzer;
|
||||
optimzer.optimize(root);
|
||||
|
||||
|
||||
// add a viewport to the viewer and attach the scene graph.
|
||||
viewer.setSceneData( root );
|
||||
|
||||
|
||||
return viewer.run();
|
||||
}
|
||||
|
@ -234,7 +234,7 @@ osg:: Node* createGlobe(const osg::BoundingBox& bb,float ratio, const std::strin
|
||||
osg::MatrixTransform* xform = new osg::MatrixTransform;
|
||||
xform->setUpdateCallback(new osg::AnimationPathCallback(bb.center(),osg::Vec3(0.0f,0.0f,1.0f),osg::inDegrees(10.0f)));
|
||||
|
||||
osg::Node* bluemarble = filename.empty() ? 0 : osgDB::readNodeFile(filename.c_str());
|
||||
osg::ref_ptr<osg::Node> bluemarble = filename.empty() ? 0 : osgDB::readRefNodeFile(filename.c_str());
|
||||
if (bluemarble)
|
||||
{
|
||||
const osg::BoundingSphere& bs = bluemarble->getBound();
|
||||
@ -252,7 +252,7 @@ osg:: Node* createGlobe(const osg::BoundingBox& bb,float ratio, const std::strin
|
||||
|
||||
osg::StateSet* stateset = geode->getOrCreateStateSet();
|
||||
|
||||
osg::Image* image = osgDB::readImageFile("Images/land_shallow_topo_2048.jpg");
|
||||
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile("Images/land_shallow_topo_2048.jpg");
|
||||
if (image)
|
||||
{
|
||||
osg::Texture2D* texture = new osg::Texture2D;
|
||||
|
@ -453,7 +453,7 @@ int main( int argc, char **argv )
|
||||
osg::Timer_t start_tick = osg::Timer::instance()->tick();
|
||||
|
||||
// read the scene from the list of file specified command line args.
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFiles(arguments);
|
||||
|
||||
// if no model has been successfully loaded report failure.
|
||||
bool tragger2Scene(true);
|
||||
@ -481,14 +481,14 @@ int main( int argc, char **argv )
|
||||
|
||||
// optimize the scene graph, remove redundant nodes and state etc.
|
||||
osgUtil::Optimizer optimizer;
|
||||
optimizer.optimize(loadedModel.get());
|
||||
optimizer.optimize(loadedModel);
|
||||
|
||||
|
||||
// pass the loaded scene graph to the viewer.
|
||||
if ( tragger2Scene ) {
|
||||
viewer.setSceneData(addDraggerToScene(loadedModel.get(), dragger_name, fixedSizeInScreen));
|
||||
} else {
|
||||
viewer.setSceneData(loadedModel.get());
|
||||
viewer.setSceneData(loadedModel);
|
||||
}
|
||||
|
||||
|
||||
|
@ -37,7 +37,7 @@ public:
|
||||
{
|
||||
osg::GraphicsContext* gc = dynamic_cast<osg::GraphicsContext*>(object);
|
||||
if (!gc) return;
|
||||
|
||||
|
||||
double t = gc->getState()->getFrameStamp()->getSimulationTime();
|
||||
|
||||
if (!cleared_)
|
||||
@ -73,14 +73,14 @@ int main( int argc, char **argv )
|
||||
|
||||
// use an ArgumentParser object to manage the program arguments.
|
||||
osg::ArgumentParser arguments(&argc,argv);
|
||||
|
||||
|
||||
// set up the usage document, in case we need to print out how to use this program.
|
||||
arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName());
|
||||
arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is an OpenSceneGraph example that shows how to use the accumulation buffer to achieve a simple motion blur effect.");
|
||||
arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("-P or --persistence","Set the motion blur persistence time");
|
||||
|
||||
|
||||
|
||||
// construct the viewer.
|
||||
osgViewer::Viewer viewer;
|
||||
@ -96,13 +96,13 @@ int main( int argc, char **argv )
|
||||
arguments.read("-P", persistence) || arguments.read("--persistence", persistence);
|
||||
|
||||
// read the scene from the list of file specified commandline args.
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
|
||||
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFiles(arguments);
|
||||
|
||||
// if not loaded assume no arguments passed in, try use default mode instead.
|
||||
if (!loadedModel) loadedModel = osgDB::readNodeFile("cow.osgt");
|
||||
if (!loadedModel) loadedModel = osgDB::readRefNodeFile("cow.osgt");
|
||||
|
||||
// if no model has been successfully loaded report failure.
|
||||
if (!loadedModel)
|
||||
if (!loadedModel)
|
||||
{
|
||||
std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl;
|
||||
return 1;
|
||||
|
@ -520,8 +520,8 @@ int main(int argc, char** argv)
|
||||
{
|
||||
if (arguments.isString(i))
|
||||
{
|
||||
osg::Image* image = osgDB::readImageFile(arguments[i]);
|
||||
osg::ImageStream* imagestream = dynamic_cast<osg::ImageStream*>(image);
|
||||
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile(arguments[i]);
|
||||
osg::ImageStream* imagestream = dynamic_cast<osg::ImageStream*>(image.get());
|
||||
if (imagestream)
|
||||
{
|
||||
osg::ImageStream::AudioStreams& audioStreams = imagestream->getAudioStreams();
|
||||
@ -550,7 +550,7 @@ int main(int argc, char** argv)
|
||||
float width = image->s() * image->getPixelAspectRatio();
|
||||
float height = image->t();
|
||||
|
||||
osg::ref_ptr<osg::Drawable> drawable = myCreateTexturedQuadGeometry(pos, width, height,image, useTextureRectangle, xyPlane, flip);
|
||||
osg::ref_ptr<osg::Drawable> drawable = myCreateTexturedQuadGeometry(pos, width, height, image.get(), useTextureRectangle, xyPlane, flip);
|
||||
|
||||
if (image->isImageTranslucent())
|
||||
{
|
||||
|
@ -362,7 +362,7 @@ private:
|
||||
|
||||
static osg::Node* readImageStream(const std::string& file_name, osg::Vec3& p, float desired_height, osgDB::Options* options)
|
||||
{
|
||||
osg::ref_ptr<osg::Object> obj = osgDB::readObjectFile(file_name, options);
|
||||
osg::ref_ptr<osg::Object> obj = osgDB::readRefObjectFile(file_name, options);
|
||||
osg::ref_ptr<osg::Texture> tex = dynamic_cast<osg::Texture*>(obj.get());
|
||||
osg::Geometry* geo(NULL);
|
||||
float w(0);
|
||||
@ -374,7 +374,7 @@ static osg::Node* readImageStream(const std::string& file_name, osg::Vec3& p, fl
|
||||
// try readImageFile if readObjectFile failed
|
||||
if (!img_stream)
|
||||
{
|
||||
img_stream = dynamic_cast<osg::ImageStream*>(osgDB::readImageFile(file_name, options));
|
||||
img_stream = osgDB::readRefFile<osg::ImageStream>(file_name, options);
|
||||
}
|
||||
|
||||
if (img_stream)
|
||||
@ -531,7 +531,9 @@ private:
|
||||
if (!tex) {
|
||||
osg::ref_ptr<osg::ImageStream> stream = dynamic_cast<osg::ImageStream*>(obj.get());
|
||||
if (!stream)
|
||||
stream = dynamic_cast<osg::ImageStream*>(osgDB::readImageFile(_files[_currentFile], _options.get()));
|
||||
{
|
||||
stream = osgDB::readRefFile<osg::ImageStream>(_files[_currentFile], _options.get());
|
||||
}
|
||||
|
||||
if (stream)
|
||||
{
|
||||
|
@ -44,10 +44,10 @@ int main( int argc, char **argv )
|
||||
osgViewer::Viewer viewer;
|
||||
|
||||
// load the nodes from the commandline arguments.
|
||||
osg::Node* rootnode = osgDB::readNodeFiles(arguments);
|
||||
osg::ref_ptr<osg::Node> rootnode = osgDB::readRefNodeFiles(arguments);
|
||||
|
||||
// if not loaded assume no arguments passed in, try use default mode instead.
|
||||
if (!rootnode) rootnode = osgDB::readNodeFile("cessnafire.osgt");
|
||||
if (!rootnode) rootnode = osgDB::readRefNodeFile("cessnafire.osgt");
|
||||
|
||||
if (!rootnode)
|
||||
{
|
||||
@ -55,7 +55,7 @@ int main( int argc, char **argv )
|
||||
return 1;
|
||||
}
|
||||
|
||||
osg::Image* image = osgDB::readImageFile("Images/reflect.rgb");
|
||||
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile("Images/reflect.rgb");
|
||||
if (image)
|
||||
{
|
||||
osg::Texture2D* texture = new osg::Texture2D;
|
||||
|
@ -55,7 +55,7 @@ public:
|
||||
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
|
||||
_foundNode(0)
|
||||
{}
|
||||
|
||||
|
||||
void apply(osg::Node& node)
|
||||
{
|
||||
T* result = dynamic_cast<T*>(&node);
|
||||
@ -68,18 +68,18 @@ public:
|
||||
traverse(node);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
T* _foundNode;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
T* findTopMostNodeOfType(osg::Node* node)
|
||||
template<class T, class R>
|
||||
T* findTopMostNodeOfType(R node)
|
||||
{
|
||||
if (!node) return 0;
|
||||
|
||||
FindTopMostNodeOfTypeVisitor<T> fnotv;
|
||||
node->accept(fnotv);
|
||||
|
||||
|
||||
return fnotv._foundNode;
|
||||
}
|
||||
|
||||
@ -87,7 +87,7 @@ T* findTopMostNodeOfType(osg::Node* node)
|
||||
class ElevationLayerBlendingCallback : public osg::NodeCallback
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
typedef std::vector<double> Elevations;
|
||||
|
||||
ElevationLayerBlendingCallback(osgFX::MultiTextureControl* mtc, const Elevations& elevations, float animationTime=4.0f):
|
||||
@ -97,7 +97,7 @@ class ElevationLayerBlendingCallback : public osg::NodeCallback
|
||||
_currentElevation(0.0),
|
||||
_mtc(mtc),
|
||||
_elevations(elevations) {}
|
||||
|
||||
|
||||
/** Callback method called by the NodeVisitor when visiting a node.*/
|
||||
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
|
||||
{
|
||||
@ -118,7 +118,7 @@ class ElevationLayerBlendingCallback : public osg::NodeCallback
|
||||
unsigned int index = _mtc->getNumTextureWeights()-1;
|
||||
for(unsigned int i=0; i<_elevations.size(); ++i)
|
||||
{
|
||||
if (_currentElevation>_elevations[i])
|
||||
if (_currentElevation>_elevations[i])
|
||||
{
|
||||
index = i;
|
||||
break;
|
||||
@ -153,7 +153,7 @@ class ElevationLayerBlendingCallback : public osg::NodeCallback
|
||||
_currentElevation = nv->getViewPoint().z();
|
||||
|
||||
osg::CoordinateSystemNode* csn = dynamic_cast<osg::CoordinateSystemNode*>(node);
|
||||
if (csn)
|
||||
if (csn)
|
||||
{
|
||||
osg::EllipsoidModel* em = csn->getEllipsoidModel();
|
||||
if (em)
|
||||
@ -175,7 +175,7 @@ class ElevationLayerBlendingCallback : public osg::NodeCallback
|
||||
double _previousTime;
|
||||
float _animationTime;
|
||||
double _currentElevation;
|
||||
|
||||
|
||||
osg::observer_ptr<osgFX::MultiTextureControl> _mtc;
|
||||
Elevations _elevations;
|
||||
};
|
||||
@ -183,17 +183,17 @@ class ElevationLayerBlendingCallback : public osg::NodeCallback
|
||||
|
||||
// class to handle events with a pick
|
||||
class TerrainHandler : public osgGA::GUIEventHandler {
|
||||
public:
|
||||
public:
|
||||
|
||||
TerrainHandler(osgTerrain::Terrain* terrain):
|
||||
_terrain(terrain) {}
|
||||
|
||||
|
||||
bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa)
|
||||
{
|
||||
switch(ea.getEventType())
|
||||
{
|
||||
case(osgGA::GUIEventAdapter::KEYDOWN):
|
||||
{
|
||||
{
|
||||
if (ea.getKey()=='r')
|
||||
{
|
||||
_terrain->setSampleRatio(_terrain->getSampleRatio()*0.5);
|
||||
@ -220,12 +220,12 @@ public:
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
~TerrainHandler() {}
|
||||
@ -240,7 +240,7 @@ int main( int argc, char **argv )
|
||||
arguments.getApplicationUsage()->addCommandLineOption("-v","Set the terrain vertical scale.");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("-r","Set the terrain sample ratio.");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--login <url> <username> <password>","Provide authentication information for http file access.");
|
||||
|
||||
|
||||
// construct the viewer.
|
||||
osgViewer::Viewer viewer(arguments);
|
||||
|
||||
@ -262,7 +262,7 @@ int main( int argc, char **argv )
|
||||
// obtain the vertical scale
|
||||
float verticalScale = 1.0f;
|
||||
while(arguments.read("-v",verticalScale)) {}
|
||||
|
||||
|
||||
// obtain the sample ratio
|
||||
float sampleRatio = 1.0f;
|
||||
while(arguments.read("-r",sampleRatio)) {}
|
||||
@ -322,7 +322,7 @@ int main( int argc, char **argv )
|
||||
while (arguments.read("-p",pathfile))
|
||||
{
|
||||
osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile);
|
||||
if (apm || !apm->valid())
|
||||
if (apm || !apm->valid())
|
||||
{
|
||||
num = keyswitchManipulator->getNumMatrixManipulators();
|
||||
keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm );
|
||||
@ -338,7 +338,7 @@ int main( int argc, char **argv )
|
||||
// set up the scene graph
|
||||
{
|
||||
// load the nodes from the commandline arguments.
|
||||
osg::Node* rootnode = osgDB::readNodeFiles(arguments);
|
||||
osg::ref_ptr<osg::Node> rootnode = osgDB::readRefNodeFiles(arguments);
|
||||
|
||||
if (!rootnode)
|
||||
{
|
||||
@ -410,7 +410,7 @@ int main( int argc, char **argv )
|
||||
// add a viewport to the viewer and attach the scene graph.
|
||||
viewer.setSceneData( rootnode );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// create the windows and run the threads.
|
||||
|
@ -52,7 +52,7 @@ osg::Camera* createHUD(unsigned int w, unsigned int h)
|
||||
// set the projection matrix
|
||||
camera->setProjectionMatrix(osg::Matrix::ortho2D(0,w,0,h));
|
||||
|
||||
// set the view matrix
|
||||
// set the view matrix
|
||||
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
|
||||
camera->setViewMatrix(osg::Matrix::identity());
|
||||
|
||||
@ -64,7 +64,7 @@ osg::Camera* createHUD(unsigned int w, unsigned int h)
|
||||
|
||||
// we don't want the camera to grab event focus from the viewers main camera(s).
|
||||
camera->setAllowEventFocus(false);
|
||||
|
||||
|
||||
|
||||
|
||||
// add to this camera a subgraph to render
|
||||
@ -87,7 +87,7 @@ osg::Camera* createHUD(unsigned int w, unsigned int h)
|
||||
text->setFont(timesFont);
|
||||
text->setPosition(position);
|
||||
text->setText("A simple multi-touch-example\n1 touch = rotate, \n2 touches = drag + scale, \n3 touches = home");
|
||||
}
|
||||
}
|
||||
|
||||
camera->addChild(geode);
|
||||
}
|
||||
@ -106,49 +106,49 @@ public:
|
||||
{
|
||||
createTouchRepresentations(parent_group, 10);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
void createTouchRepresentations(osg::Group* parent_group, unsigned int num_objects)
|
||||
void createTouchRepresentations(osg::Group* parent_group, unsigned int num_objects)
|
||||
{
|
||||
// create some geometry which is shown for every touch-point
|
||||
for(unsigned int i = 0; i != num_objects; ++i)
|
||||
for(unsigned int i = 0; i != num_objects; ++i)
|
||||
{
|
||||
std::ostringstream ss;
|
||||
|
||||
|
||||
osg::Geode* geode = new osg::Geode();
|
||||
|
||||
|
||||
osg::ShapeDrawable* drawable = new osg::ShapeDrawable(new osg::Box(osg::Vec3(0,0,0), 100));
|
||||
drawable->setColor(osg::Vec4(0.5, 0.5, 0.5,1));
|
||||
geode->addDrawable(drawable);
|
||||
|
||||
|
||||
ss << "Touch " << i;
|
||||
|
||||
|
||||
osgText::Text* text = new osgText::Text;
|
||||
geode->addDrawable( text );
|
||||
drawable->setDataVariance(osg::Object::DYNAMIC);
|
||||
_drawables.push_back(drawable);
|
||||
|
||||
|
||||
|
||||
|
||||
text->setFont("fonts/arial.ttf");
|
||||
text->setPosition(osg::Vec3(110,0,0));
|
||||
text->setText(ss.str());
|
||||
_texts.push_back(text);
|
||||
text->setDataVariance(osg::Object::DYNAMIC);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
osg::MatrixTransform* mat = new osg::MatrixTransform();
|
||||
mat->addChild(geode);
|
||||
mat->setNodeMask(0x0);
|
||||
|
||||
|
||||
_mats.push_back(mat);
|
||||
|
||||
|
||||
parent_group->addChild(mat);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
parent_group->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
|
||||
}
|
||||
|
||||
|
||||
virtual bool handle (const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa, osg::Object *, osg::NodeVisitor *)
|
||||
{
|
||||
if (ea.getEventType() != osgGA::GUIEventAdapter::FRAME) {
|
||||
@ -162,7 +162,7 @@ private:
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
|
||||
switch(ea.getEventType())
|
||||
{
|
||||
case osgGA::GUIEventAdapter::FRAME:
|
||||
@ -171,7 +171,7 @@ private:
|
||||
_cleanupOnNextFrame = false;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case osgGA::GUIEventAdapter::PUSH:
|
||||
case osgGA::GUIEventAdapter::DRAG:
|
||||
case osgGA::GUIEventAdapter::RELEASE:
|
||||
@ -179,74 +179,74 @@ private:
|
||||
// is this a multi-touch event?
|
||||
if (!ea.isMultiTouchEvent())
|
||||
return false;
|
||||
|
||||
|
||||
unsigned int j(0);
|
||||
|
||||
|
||||
// iterate over all touch-points and update the geometry
|
||||
unsigned num_touch_ended(0);
|
||||
|
||||
|
||||
for(osgGA::GUIEventAdapter::TouchData::iterator i = ea.getTouchData()->begin(); i != ea.getTouchData()->end(); ++i, ++j)
|
||||
{
|
||||
const osgGA::GUIEventAdapter::TouchData::TouchPoint& tp = (*i);
|
||||
float x = ea.getTouchPointNormalizedX(j);
|
||||
float y = ea.getTouchPointNormalizedY(j);
|
||||
|
||||
|
||||
// std::cout << j << ": " << tp.x << "/" << tp.y <<" "<< x << " " << y << " " << _w << " " << _h << std::endl;
|
||||
|
||||
|
||||
_mats[j]->setMatrix(osg::Matrix::translate((1+x) * 0.5 * _w, (1+y) * 0.5 * _h, 0));
|
||||
_mats[j]->setNodeMask(0xffff);
|
||||
|
||||
|
||||
std::ostringstream ss;
|
||||
ss << "Touch " << tp.id;
|
||||
_texts[j]->setText(ss.str());
|
||||
|
||||
switch (tp.phase)
|
||||
|
||||
switch (tp.phase)
|
||||
{
|
||||
case osgGA::GUIEventAdapter::TOUCH_BEGAN:
|
||||
_drawables[j]->setColor(osg::Vec4(0,1,0,1));
|
||||
break;
|
||||
|
||||
|
||||
case osgGA::GUIEventAdapter::TOUCH_MOVED:
|
||||
_drawables[j]->setColor(osg::Vec4(1,1,1,1));
|
||||
break;
|
||||
|
||||
|
||||
case osgGA::GUIEventAdapter::TOUCH_ENDED:
|
||||
_drawables[j]->setColor(osg::Vec4(1,0,0,1));
|
||||
++num_touch_ended;
|
||||
break;
|
||||
|
||||
|
||||
case osgGA::GUIEventAdapter::TOUCH_STATIONERY:
|
||||
_drawables[j]->setColor(osg::Vec4(0.8,0.8,0.8,1));
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// hide unused geometry
|
||||
cleanup(j);
|
||||
|
||||
|
||||
//check if all touches ended
|
||||
if ((ea.getTouchData()->getNumTouchPoints() > 0) && (ea.getTouchData()->getNumTouchPoints() == num_touch_ended))
|
||||
{
|
||||
_cleanupOnNextFrame = true;
|
||||
}
|
||||
|
||||
|
||||
// reposition mouse-pointer
|
||||
aa.requestWarpPointer((ea.getWindowX() + ea.getWindowWidth()) / 2.0, (ea.getWindowY() + ea.getWindowHeight()) / 2.0);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void cleanup(unsigned int j)
|
||||
|
||||
void cleanup(unsigned int j)
|
||||
{
|
||||
for(unsigned k = j; k < _mats.size(); ++k) {
|
||||
_mats[k]->setNodeMask(0x0);
|
||||
@ -257,7 +257,7 @@ private:
|
||||
std::vector<osg::MatrixTransform*> _mats;
|
||||
std::vector<osgText::Text*> _texts;
|
||||
bool _cleanupOnNextFrame;
|
||||
|
||||
|
||||
float _w, _h;
|
||||
|
||||
};
|
||||
@ -267,7 +267,7 @@ int main( int argc, char **argv )
|
||||
{
|
||||
// use an ArgumentParser object to manage the program arguments.
|
||||
osg::ArgumentParser arguments(&argc,argv);
|
||||
|
||||
|
||||
|
||||
unsigned int helpType = 0;
|
||||
if ((helpType = arguments.readHelpType()))
|
||||
@ -284,12 +284,12 @@ int main( int argc, char **argv )
|
||||
}
|
||||
|
||||
// read the scene from the list of file specified commandline args.
|
||||
osg::ref_ptr<osg::Node> scene = osgDB::readNodeFiles(arguments);
|
||||
|
||||
osg::ref_ptr<osg::Node> scene = osgDB::readRefNodeFiles(arguments);
|
||||
|
||||
// if not loaded assume no arguments passed in, try use default model instead.
|
||||
if (!scene) scene = osgDB::readNodeFile("dumptruck.osgt");
|
||||
|
||||
if (!scene)
|
||||
if (!scene) scene = osgDB::readRefNodeFile("dumptruck.osgt");
|
||||
|
||||
if (!scene)
|
||||
{
|
||||
osg::Geode* geode = new osg::Geode();
|
||||
osg::ShapeDrawable* drawable = new osg::ShapeDrawable(new osg::Box(osg::Vec3(0,0,0), 100));
|
||||
@ -301,43 +301,43 @@ int main( int argc, char **argv )
|
||||
|
||||
// construct the viewer.
|
||||
osgViewer::Viewer viewer(arguments);
|
||||
|
||||
|
||||
|
||||
|
||||
//opening devices
|
||||
std::string device;
|
||||
while(arguments.read("--device", device))
|
||||
{
|
||||
osg::ref_ptr<osgGA::Device> dev = osgDB::readFile<osgGA::Device>(device);
|
||||
osg::ref_ptr<osgGA::Device> dev = osgDB::readRefFile<osgGA::Device>(device);
|
||||
if (dev.valid())
|
||||
{
|
||||
viewer.addDevice(dev.get());
|
||||
viewer.addDevice(dev);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
osg::ref_ptr<osg::Group> group = new osg::Group;
|
||||
|
||||
// add the HUD subgraph.
|
||||
if (scene.valid()) group->addChild(scene.get());
|
||||
|
||||
// add the HUD subgraph.
|
||||
if (scene) group->addChild(scene);
|
||||
|
||||
viewer.setCameraManipulator(new osgGA::MultiTouchTrackballManipulator());
|
||||
viewer.realize();
|
||||
|
||||
|
||||
osg::GraphicsContext* gc = viewer.getCamera()->getGraphicsContext();
|
||||
|
||||
|
||||
#ifdef __APPLE__
|
||||
// as multitouch is disabled by default, enable it now
|
||||
osgViewer::GraphicsWindowCocoa* win = dynamic_cast<osgViewer::GraphicsWindowCocoa*>(gc);
|
||||
if (win) win->setMultiTouchEnabled(true);
|
||||
#endif
|
||||
|
||||
|
||||
std::cout << "creating hud with " << gc->getTraits()->width << "x" << gc->getTraits()->height << std::endl;
|
||||
osg::Camera* hud_camera = createHUD(gc->getTraits()->width, gc->getTraits()->height);
|
||||
|
||||
|
||||
|
||||
|
||||
viewer.addEventHandler(new TestMultiTouchEventHandler(hud_camera, gc->getTraits()->width, gc->getTraits()->height));
|
||||
|
||||
|
||||
|
||||
|
||||
group->addChild(hud_camera);
|
||||
|
||||
// set the scene to render
|
||||
@ -345,5 +345,5 @@ int main( int argc, char **argv )
|
||||
|
||||
return viewer.run();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -64,11 +64,11 @@ int main( int argc, char **argv )
|
||||
osg::ArgumentParser arguments(&argc,argv);
|
||||
|
||||
// read the scene from the list of file specified commandline args.
|
||||
osg::ref_ptr<osg::Node> scene = osgDB::readNodeFiles(arguments);
|
||||
osg::ref_ptr<osg::Node> scene = osgDB::readRefNodeFiles(arguments);
|
||||
|
||||
if (!scene)
|
||||
{
|
||||
scene = osgDB::readNodeFile("http://www.openscenegraph.org/data/earth_bayarea/earth.ive");
|
||||
scene = osgDB::readRefNodeFile("http://www.openscenegraph.org/data/earth_bayarea/earth.ive");
|
||||
}
|
||||
|
||||
if (!scene)
|
||||
@ -123,7 +123,7 @@ int main( int argc, char **argv )
|
||||
view->setName("View one");
|
||||
viewer.addView(view);
|
||||
|
||||
view->setSceneData(scene.get());
|
||||
view->setSceneData(scene);
|
||||
view->getCamera()->setName("Cam one");
|
||||
view->getCamera()->setViewport(new osg::Viewport(0,0, traits->width/2, traits->height/2));
|
||||
view->getCamera()->setGraphicsContext(gc.get());
|
||||
@ -148,7 +148,7 @@ int main( int argc, char **argv )
|
||||
view->setName("View two");
|
||||
viewer.addView(view);
|
||||
|
||||
view->setSceneData(scene.get());
|
||||
view->setSceneData(scene);
|
||||
view->getCamera()->setName("Cam two");
|
||||
view->getCamera()->setViewport(new osg::Viewport(traits->width/2,0, traits->width/2, traits->height/2));
|
||||
view->getCamera()->setGraphicsContext(gc.get());
|
||||
@ -162,7 +162,7 @@ int main( int argc, char **argv )
|
||||
view->setName("View three");
|
||||
viewer.addView(view);
|
||||
|
||||
view->setSceneData(scene.get());
|
||||
view->setSceneData(scene);
|
||||
|
||||
view->getCamera()->setName("Cam three");
|
||||
view->getCamera()->setProjectionMatrixAsPerspective(30.0, double(traits->width) / double(traits->height/2), 1.0, 1000.0);
|
||||
|
@ -311,10 +311,10 @@ int main( int argc, char **argv )
|
||||
}
|
||||
|
||||
// load the nodes from the commandline arguments.
|
||||
osg::Node* loadedmodel = osgDB::readNodeFiles(arguments);
|
||||
osg::ref_ptr<osg::Node> loadedmodel = osgDB::readRefNodeFiles(arguments);
|
||||
|
||||
// if not loaded assume no arguments passed in, try using default mode instead.
|
||||
if (!loadedmodel) loadedmodel = osgDB::readNodeFile("glider.osgt");
|
||||
if (!loadedmodel) loadedmodel = osgDB::readRefNodeFile("glider.osgt");
|
||||
|
||||
if (!loadedmodel)
|
||||
{
|
||||
@ -336,12 +336,12 @@ int main( int argc, char **argv )
|
||||
}
|
||||
else
|
||||
{
|
||||
rootnode = createOccludersAroundModel(loadedmodel);
|
||||
rootnode = createOccludersAroundModel(loadedmodel.get());
|
||||
}
|
||||
|
||||
|
||||
// add a viewport to the viewer and attach the scene graph.
|
||||
viewer.setSceneData( rootnode.get() );
|
||||
viewer.setSceneData( rootnode );
|
||||
|
||||
return viewer.run();
|
||||
}
|
||||
|
@ -749,8 +749,8 @@ int main(int argc, char** argv)
|
||||
|
||||
if (arguments.argc()>1)
|
||||
{
|
||||
root = osgDB::readNodeFiles( arguments );
|
||||
if (root.valid())
|
||||
root = osgDB::readRefNodeFiles( arguments );
|
||||
if (root)
|
||||
{
|
||||
// Run a NodeVisitor to insert OcclusionQueryNodes in the scene graph.
|
||||
OcclusionQueryVisitor oqv;
|
||||
@ -787,10 +787,10 @@ int main(int argc, char** argv)
|
||||
if (optimize)
|
||||
{
|
||||
osgUtil::Optimizer optimizer;
|
||||
optimizer.optimize( root.get() );
|
||||
optimizer.optimize( root );
|
||||
}
|
||||
|
||||
viewer.setSceneData( root.get() );
|
||||
viewer.setSceneData( root );
|
||||
|
||||
KeyHandler* kh = new KeyHandler( *root );
|
||||
viewer.addEventHandler( kh );
|
||||
|
@ -55,23 +55,23 @@ int main(int argc, char** argv)
|
||||
|
||||
osg::DisplaySettings* displaySettings = new osg::DisplaySettings;
|
||||
viewer.setDisplaySettings(displaySettings);
|
||||
|
||||
|
||||
// Add the stats handler
|
||||
viewer.addEventHandler(new osgViewer::StatsHandler);
|
||||
|
||||
|
||||
// add the help handler
|
||||
viewer.addEventHandler(new osgViewer::HelpHandler(arguments.getApplicationUsage()));
|
||||
|
||||
// any option left unread are converted into errors to write out later.
|
||||
arguments.reportRemainingOptionsAsUnrecognized();
|
||||
|
||||
|
||||
// read the dump truck, we will need it twice
|
||||
osg::ref_ptr<osg::Node> dt = osgDB::readNodeFile("dumptruck.osg");
|
||||
osg::ref_ptr<osg::Node> dt = osgDB::readRefNodeFile("dumptruck.osg");
|
||||
|
||||
// display a solid version of the dump truck
|
||||
osg::ref_ptr<osg::PositionAttitudeTransform> solidModel = new osg::PositionAttitudeTransform;
|
||||
solidModel->setPosition(osg::Vec3f(7.0f, -2.0f, 7.0f));
|
||||
solidModel->addChild(dt.get());
|
||||
solidModel->addChild(dt);
|
||||
|
||||
// generate the 3D heatmap surface to display
|
||||
osg::ref_ptr<Heatmap> hm = new Heatmap(30, 30, 10, 30, 30, 1.0, 0.25);
|
||||
|
@ -200,7 +200,7 @@ private:
|
||||
|
||||
bool UserEventHandler::handle(osgGA::Event* event, osg::Object* object, osg::NodeVisitor* nv)
|
||||
{
|
||||
|
||||
|
||||
OSG_ALWAYS << "handle user-event: " << event->getName() << std::endl;
|
||||
|
||||
if (event->getName() == "/pick-result")
|
||||
@ -215,7 +215,7 @@ bool UserEventHandler::handle(osgGA::Event* event, osg::Object* object, osg::Nod
|
||||
ss << "x: " << y << " y: " << y << std::endl;
|
||||
|
||||
_text->setText(ss.str());
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
else if(event->getName() == "/osgga")
|
||||
@ -231,7 +231,7 @@ bool UserEventHandler::handle(osgGA::Event* event, osg::Object* object, osg::Nod
|
||||
if (win)
|
||||
win->setWindowRectangle(rect[2] + 10 + rect[0], rect[1], rect[2], rect[3]);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
@ -251,7 +251,7 @@ bool UserEventHandler::handle(osgGA::Event* event, osg::Object* object, osg::Nod
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -377,8 +377,8 @@ public:
|
||||
|
||||
std::ostringstream ss ;
|
||||
ss << host << ":" << port << ".sender.osc";
|
||||
_device = osgDB::readFile<osgGA::Device>(ss.str());
|
||||
|
||||
_device = osgDB::readRefFile<osgGA::Device>(ss.str());
|
||||
|
||||
osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(nv);
|
||||
osgViewer::View* view = ev ? dynamic_cast<osgViewer::View*>(ev->getActionAdapter()) : NULL;
|
||||
if (view)
|
||||
@ -403,14 +403,14 @@ int main( int argc, char **argv )
|
||||
|
||||
|
||||
// read the scene from the list of file specified commandline args.
|
||||
osg::ref_ptr<osg::Node> scene = osgDB::readNodeFiles(arguments);
|
||||
osg::ref_ptr<osg::Node> scene = osgDB::readRefNodeFiles(arguments);
|
||||
|
||||
if (!scene)
|
||||
{
|
||||
osg::Geode* geode = new osg::Geode();
|
||||
osg::ShapeDrawable* drawable = new osg::ShapeDrawable(new osg::Box());
|
||||
geode->addDrawable(drawable);
|
||||
|
||||
|
||||
scene = geode;
|
||||
}
|
||||
|
||||
@ -463,15 +463,15 @@ int main( int argc, char **argv )
|
||||
view->addEventHandler( new osgViewer::StatsHandler );
|
||||
view->addEventHandler( new UserEventHandler(text) );
|
||||
|
||||
osg::ref_ptr<osgGA::Device> device = osgDB::readFile<osgGA::Device>("0.0.0.0:9000.receiver.osc");
|
||||
osg::ref_ptr<osgGA::Device> device = osgDB::readRefFile<osgGA::Device>("0.0.0.0:9000.receiver.osc");
|
||||
if (device.valid() && (device->getCapabilities() & osgGA::Device::RECEIVE_EVENTS))
|
||||
{
|
||||
view->addDevice(device.get());
|
||||
view->addDevice(device);
|
||||
|
||||
// add a zeroconf device, advertising the osc-device
|
||||
if(use_zeroconf)
|
||||
{
|
||||
osgGA::Device* zeroconf_device = osgDB::readFile<osgGA::Device>("_osc._udp:9000.advertise.zeroconf");
|
||||
osg::ref_ptr<osgGA::Device> zeroconf_device = osgDB::readRefFile<osgGA::Device>("_osc._udp:9000.advertise.zeroconf");
|
||||
if (zeroconf_device)
|
||||
{
|
||||
view->addDevice(zeroconf_device);
|
||||
@ -496,8 +496,8 @@ int main( int argc, char **argv )
|
||||
traits->windowName = "Sender / view one";
|
||||
|
||||
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef __APPLE__
|
||||
// as multitouch is disabled by default, enable it now
|
||||
osgViewer::GraphicsWindowCocoa* win = dynamic_cast<osgViewer::GraphicsWindowCocoa*>(gc.get());
|
||||
@ -527,7 +527,7 @@ int main( int argc, char **argv )
|
||||
|
||||
if (use_zeroconf)
|
||||
{
|
||||
osgGA::Device* zeroconf_device = osgDB::readFile<osgGA::Device>("_osc._udp.discover.zeroconf");
|
||||
osg::ref_ptr<osgGA::Device> zeroconf_device = osgDB::readRefFile<osgGA::Device>("_osc._udp.discover.zeroconf");
|
||||
if(zeroconf_device) {
|
||||
view->addDevice(zeroconf_device);
|
||||
view->getEventHandlers().push_front(new OscServiceDiscoveredEventHandler());
|
||||
@ -536,7 +536,7 @@ int main( int argc, char **argv )
|
||||
}
|
||||
else
|
||||
{
|
||||
osg::ref_ptr<osgGA::Device> device = osgDB::readFile<osgGA::Device>("localhost:9000.sender.osc");
|
||||
osg::ref_ptr<osgGA::Device> device = osgDB::readRefFile<osgGA::Device>("localhost:9000.sender.osc");
|
||||
if (device.valid() && (device->getCapabilities() & osgGA::Device::SEND_EVENTS))
|
||||
{
|
||||
// add as first event handler, so it gets ALL events ...
|
||||
|
@ -25,7 +25,7 @@ int main(int argc, char** argv)
|
||||
|
||||
// load outlined object
|
||||
std::string modelFilename = arguments.argc() > 1 ? arguments[1] : "dumptruck.osgt";
|
||||
osg::ref_ptr<osg::Node> outlineModel = osgDB::readNodeFile(modelFilename);
|
||||
osg::ref_ptr<osg::Node> outlineModel = osgDB::readRefNodeFile(modelFilename);
|
||||
if (!outlineModel)
|
||||
{
|
||||
osg::notify(osg::FATAL) << "Unable to load model '" << modelFilename << "'\n";
|
||||
@ -38,18 +38,18 @@ int main(int argc, char** argv)
|
||||
{
|
||||
// create outline effect
|
||||
osg::ref_ptr<osgFX::Outline> outline = new osgFX::Outline;
|
||||
root->addChild(outline.get());
|
||||
root->addChild(outline);
|
||||
|
||||
outline->setWidth(8);
|
||||
outline->setColor(osg::Vec4(1,1,0,1));
|
||||
outline->addChild(outlineModel.get());
|
||||
outline->addChild(outlineModel);
|
||||
}
|
||||
|
||||
if (testOcclusion)
|
||||
{
|
||||
// load occluder
|
||||
std::string occludedModelFilename = "cow.osgt";
|
||||
osg::ref_ptr<osg::Node> occludedModel = osgDB::readNodeFile(occludedModelFilename);
|
||||
osg::ref_ptr<osg::Node> occludedModel = osgDB::readRefNodeFile(occludedModelFilename);
|
||||
if (!occludedModel)
|
||||
{
|
||||
osg::notify(osg::FATAL) << "Unable to load model '" << occludedModelFilename << "'\n";
|
||||
@ -63,14 +63,14 @@ int main(int argc, char** argv)
|
||||
// occluder behind outlined model
|
||||
osg::ref_ptr<osg::PositionAttitudeTransform> modelTransform0 = new osg::PositionAttitudeTransform;
|
||||
modelTransform0->setPosition(bsphere.center() + occluderOffset);
|
||||
modelTransform0->addChild(occludedModel.get());
|
||||
root->addChild(modelTransform0.get());
|
||||
modelTransform0->addChild(occludedModel);
|
||||
root->addChild(modelTransform0);
|
||||
|
||||
// occluder in front of outlined model
|
||||
osg::ref_ptr<osg::PositionAttitudeTransform> modelTransform1 = new osg::PositionAttitudeTransform;
|
||||
modelTransform1->setPosition(bsphere.center() - occluderOffset);
|
||||
modelTransform1->addChild(occludedModel.get());
|
||||
root->addChild(modelTransform1.get());
|
||||
modelTransform1->addChild(occludedModel);
|
||||
root->addChild(modelTransform1);
|
||||
}
|
||||
|
||||
// must have stencil buffer...
|
||||
@ -78,7 +78,7 @@ int main(int argc, char** argv)
|
||||
|
||||
// construct the viewer
|
||||
osgViewer::Viewer viewer;
|
||||
viewer.setSceneData(root.get());
|
||||
viewer.setSceneData(root);
|
||||
|
||||
// must clear stencil buffer...
|
||||
unsigned int clearMask = viewer.getCamera()->getClearMask();
|
||||
|
@ -43,17 +43,17 @@ public:
|
||||
_count(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
virtual void apply(osg::Node& node)
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << node.className() << "_"<<_count++;
|
||||
|
||||
node.setName(os.str());
|
||||
|
||||
|
||||
traverse(node);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
unsigned int _count;
|
||||
};
|
||||
|
||||
@ -64,7 +64,7 @@ public:
|
||||
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
virtual void apply(osg::PagedLOD& plod)
|
||||
{
|
||||
std::cout<<"PagedLOD "<<plod.getName()<<" numRanges = "<< plod.getNumRanges()<<" numFiles = "<<plod.getNumFileNames()<<std::endl;
|
||||
@ -72,7 +72,7 @@ public:
|
||||
{
|
||||
std::cout<<" files = '"<<plod.getFileName(i)<<"'"<<std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -83,7 +83,7 @@ public:
|
||||
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
virtual void apply(osg::PagedLOD& plod)
|
||||
{
|
||||
|
||||
@ -98,9 +98,9 @@ public:
|
||||
osgDB::writeNodeFile(*child,filename);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
traverse(plod);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class ConvertToPageLODVistor : public osg::NodeVisitor
|
||||
@ -113,7 +113,7 @@ public:
|
||||
_makeAllChildrenPaged(makeAllChildrenPaged)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
virtual ~ConvertToPageLODVistor()
|
||||
{
|
||||
}
|
||||
@ -121,9 +121,9 @@ public:
|
||||
virtual void apply(osg::LOD& lod)
|
||||
{
|
||||
_lodSet.insert(&lod);
|
||||
|
||||
|
||||
traverse(lod);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void apply(osg::PagedLOD& plod)
|
||||
{
|
||||
@ -139,7 +139,7 @@ public:
|
||||
++itr, ++lodNum)
|
||||
{
|
||||
osg::ref_ptr<osg::LOD> lod = const_cast<osg::LOD*>(itr->get());
|
||||
|
||||
|
||||
if (lod->getNumParents()==0)
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Warning can't operator on root node."<<std::endl;
|
||||
@ -153,9 +153,9 @@ public:
|
||||
}
|
||||
|
||||
osg::notify(osg::NOTICE)<<"Converting LOD to PagedLOD."<<std::endl;
|
||||
|
||||
|
||||
osg::PagedLOD* plod = new osg::PagedLOD;
|
||||
|
||||
|
||||
const osg::LOD::RangeList& originalRangeList = lod->getRangeList();
|
||||
typedef std::multimap< osg::LOD::MinMaxPair , unsigned int > MinMaxPairMap;
|
||||
MinMaxPairMap rangeMap;
|
||||
@ -166,7 +166,7 @@ public:
|
||||
{
|
||||
rangeMap.insert(std::multimap< osg::LOD::MinMaxPair , unsigned int >::value_type(*ritr, pos));
|
||||
}
|
||||
|
||||
|
||||
pos = 0;
|
||||
for(MinMaxPairMap::reverse_iterator mitr = rangeMap.rbegin();
|
||||
mitr != rangeMap.rend();
|
||||
@ -181,11 +181,11 @@ public:
|
||||
std::string filename = _basename;
|
||||
std::ostringstream os;
|
||||
os << _basename << "_"<<lodNum<<"_"<<pos<<_extension;
|
||||
|
||||
|
||||
plod->addChild(lod->getChild(mitr->second), mitr->first.first, mitr->first.second, os.str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
osg::Node::ParentList parents = lod->getParents();
|
||||
for(osg::Node::ParentList::iterator pitr=parents.begin();
|
||||
pitr!=parents.end();
|
||||
@ -195,12 +195,12 @@ public:
|
||||
}
|
||||
|
||||
plod->setCenter(plod->getBound().center());
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
typedef std::set< osg::ref_ptr<osg::LOD> > LODSet;
|
||||
LODSet _lodSet;
|
||||
std::string _basename;
|
||||
@ -214,7 +214,7 @@ int main( int argc, char **argv )
|
||||
|
||||
// use an ArgumentParser object to manage the program arguments.
|
||||
osg::ArgumentParser arguments(&argc,argv);
|
||||
|
||||
|
||||
// set up the usage document, in case we need to print out how to use this program.
|
||||
arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName());
|
||||
arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" creates a hierarchy of files for paging which can be later loaded by viewers.");
|
||||
@ -232,8 +232,8 @@ int main( int argc, char **argv )
|
||||
|
||||
std::string outputfile("output.ive");
|
||||
while (arguments.read("-o",outputfile)) {}
|
||||
|
||||
|
||||
|
||||
|
||||
bool makeAllChildrenPaged = false;
|
||||
while (arguments.read("--makeAllChildrenPaged")) { makeAllChildrenPaged = true; }
|
||||
|
||||
@ -246,7 +246,7 @@ int main( int argc, char **argv )
|
||||
arguments.writeErrorMessages(std::cout);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// if (arguments.argc()<=1)
|
||||
// {
|
||||
// arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION);
|
||||
@ -254,21 +254,21 @@ int main( int argc, char **argv )
|
||||
// }
|
||||
|
||||
|
||||
osg::ref_ptr<osg::Node> model = osgDB::readNodeFiles(arguments);
|
||||
|
||||
osg::ref_ptr<osg::Node> model = osgDB::readRefNodeFiles(arguments);
|
||||
|
||||
if (!model)
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"No model loaded."<<std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
std::string basename( osgDB::getNameLessExtension(outputfile) );
|
||||
std::string ext = '.'+ osgDB::getFileExtension(outputfile);
|
||||
|
||||
|
||||
ConvertToPageLODVistor converter(basename,ext, makeAllChildrenPaged);
|
||||
model->accept(converter);
|
||||
converter.convert();
|
||||
|
||||
|
||||
NameVistor nameNodes;
|
||||
model->accept(nameNodes);
|
||||
|
||||
@ -278,7 +278,7 @@ int main( int argc, char **argv )
|
||||
if (model.valid())
|
||||
{
|
||||
osgDB::writeNodeFile(*model,outputfile);
|
||||
|
||||
|
||||
WriteOutPagedLODSubgraphsVistor woplsv;
|
||||
model->accept(woplsv);
|
||||
}
|
||||
|
@ -40,7 +40,7 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// vertex shader using just Vec4 coefficients
|
||||
char vertexShaderSource_simple[] =
|
||||
char vertexShaderSource_simple[] =
|
||||
"uniform vec4 coeff; \n"
|
||||
"\n"
|
||||
"void main(void) \n"
|
||||
@ -52,11 +52,11 @@ char vertexShaderSource_simple[] =
|
||||
" gl_Vertex.y*coeff[2] + gl_Vertex.y*gl_Vertex.y* coeff[3]; \n"
|
||||
" gl_Position = gl_ModelViewProjectionMatrix * vert;\n"
|
||||
"}\n";
|
||||
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// vertex shader using full Matrix4 coefficients
|
||||
char vertexShaderSource_matrix[] =
|
||||
char vertexShaderSource_matrix[] =
|
||||
"uniform vec4 origin; \n"
|
||||
"uniform mat4 coeffMatrix; \n"
|
||||
"\n"
|
||||
@ -70,7 +70,7 @@ char vertexShaderSource_matrix[] =
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// vertex shader using texture read
|
||||
char vertexShaderSource_texture[] =
|
||||
char vertexShaderSource_texture[] =
|
||||
"uniform sampler2D vertexTexture; \n"
|
||||
"\n"
|
||||
"void main(void) \n"
|
||||
@ -86,7 +86,7 @@ char vertexShaderSource_texture[] =
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// fragment shader
|
||||
//
|
||||
char fragmentShaderSource[] =
|
||||
char fragmentShaderSource[] =
|
||||
"uniform sampler2D baseTexture; \n"
|
||||
"\n"
|
||||
"void main(void) \n"
|
||||
@ -109,17 +109,17 @@ class UniformVarying : public osg::UniformCallback
|
||||
osg::Node* createModel(const std::string& shader, const std::string& textureFileName, const std::string& terrainFileName, bool dynamic, bool useVBO)
|
||||
{
|
||||
osg::Geode* geode = new osg::Geode;
|
||||
|
||||
|
||||
osg::Geometry* geom = new osg::Geometry;
|
||||
geode->addDrawable(geom);
|
||||
|
||||
|
||||
// dimensions for ~one million triangles :-)
|
||||
unsigned int num_x = 708;
|
||||
unsigned int num_y = 708;
|
||||
|
||||
// set up state
|
||||
{
|
||||
|
||||
|
||||
osg::StateSet* stateset = geom->getOrCreateStateSet();
|
||||
|
||||
osg::Program* program = new osg::Program;
|
||||
@ -131,7 +131,7 @@ osg::Node* createModel(const std::string& shader, const std::string& textureFile
|
||||
program->addShader(vertex_shader);
|
||||
|
||||
osg::Uniform* coeff = new osg::Uniform("coeff",osg::Vec4(1.0,-1.0f,-1.0f,1.0f));
|
||||
|
||||
|
||||
stateset->addUniform(coeff);
|
||||
|
||||
if (dynamic)
|
||||
@ -140,7 +140,7 @@ osg::Node* createModel(const std::string& shader, const std::string& textureFile
|
||||
coeff->setDataVariance(osg::Object::DYNAMIC);
|
||||
stateset->setDataVariance(osg::Object::DYNAMIC);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else if (shader=="matrix")
|
||||
{
|
||||
@ -163,7 +163,7 @@ osg::Node* createModel(const std::string& shader, const std::string& textureFile
|
||||
osg::Shader* vertex_shader = new osg::Shader(osg::Shader::VERTEX, vertexShaderSource_texture);
|
||||
program->addShader(vertex_shader);
|
||||
|
||||
osg::Image* image = 0;
|
||||
osg::ref_ptr<osg::Image> image;
|
||||
|
||||
if (terrainFileName.empty())
|
||||
{
|
||||
@ -184,7 +184,7 @@ osg::Node* createModel(const std::string& shader, const std::string& textureFile
|
||||
}
|
||||
else
|
||||
{
|
||||
image = osgDB::readImageFile(terrainFileName);
|
||||
image = osgDB::readRefImageFile(terrainFileName);
|
||||
|
||||
num_x = image->s();
|
||||
num_y = image->t();
|
||||
@ -206,7 +206,7 @@ osg::Node* createModel(const std::string& shader, const std::string& textureFile
|
||||
osg::Shader* fragment_shader = new osg::Shader(osg::Shader::FRAGMENT, fragmentShaderSource);
|
||||
program->addShader(fragment_shader);
|
||||
|
||||
osg::Texture2D* texture = new osg::Texture2D(osgDB::readImageFile(textureFileName));
|
||||
osg::Texture2D* texture = new osg::Texture2D(osgDB::readRefImageFile(textureFileName));
|
||||
stateset->setTextureAttributeAndModes(0,texture);
|
||||
|
||||
osg::Uniform* baseTextureSampler = new osg::Uniform("baseTexture",0);
|
||||
@ -218,11 +218,11 @@ osg::Node* createModel(const std::string& shader, const std::string& textureFile
|
||||
// set up geometry data.
|
||||
|
||||
osg::Vec3Array* vertices = new osg::Vec3Array( num_x * num_y );
|
||||
|
||||
|
||||
float dx = 1.0f/(float)(num_x-1);
|
||||
float dy = 1.0f/(float)(num_y-1);
|
||||
osg::Vec3 row(0.0f,0.0f,0.0);
|
||||
|
||||
|
||||
unsigned int vert_no = 0;
|
||||
unsigned int iy;
|
||||
for(iy=0; iy<num_y; ++iy)
|
||||
@ -232,7 +232,7 @@ osg::Node* createModel(const std::string& shader, const std::string& textureFile
|
||||
{
|
||||
(*vertices)[vert_no++] = column;
|
||||
column.x() += dx;
|
||||
}
|
||||
}
|
||||
row.y() += dy;
|
||||
}
|
||||
|
||||
@ -240,7 +240,7 @@ osg::Node* createModel(const std::string& shader, const std::string& textureFile
|
||||
|
||||
osg::VertexBufferObject* vbo = useVBO ? new osg::VertexBufferObject : 0;
|
||||
if (vbo) vertices->setVertexBufferObject(vbo);
|
||||
|
||||
|
||||
osg::ElementBufferObject* ebo = useVBO ? new osg::ElementBufferObject : 0;
|
||||
|
||||
for(iy=0; iy<num_y-1; ++iy)
|
||||
@ -253,11 +253,11 @@ osg::Node* createModel(const std::string& shader, const std::string& textureFile
|
||||
(*elements)[element_no++] = index + num_x;
|
||||
(*elements)[element_no++] = index++;
|
||||
}
|
||||
geom->addPrimitiveSet(elements);
|
||||
|
||||
geom->addPrimitiveSet(elements);
|
||||
|
||||
if (ebo) elements->setElementBufferObject(ebo);
|
||||
}
|
||||
|
||||
|
||||
geom->setUseVertexBufferObjects(useVBO);
|
||||
|
||||
return geode;
|
||||
@ -272,7 +272,7 @@ int main(int argc, char *argv[])
|
||||
arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrate support for ARB_vertex_program.");
|
||||
arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");
|
||||
|
||||
|
||||
// construct the viewer.
|
||||
osgViewer::Viewer viewer;
|
||||
|
||||
@ -281,7 +281,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
std::string shader("simple");
|
||||
while(arguments.read("-s",shader)) {}
|
||||
|
||||
|
||||
std::string textureFileName("Images/lz.rgb");
|
||||
while(arguments.read("-t",textureFileName)) {}
|
||||
|
||||
@ -300,14 +300,14 @@ int main(int argc, char *argv[])
|
||||
arguments.getApplicationUsage()->write(std::cout);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// load the nodes from the commandline arguments.
|
||||
osg::Node* model = createModel(shader,textureFileName,terrainFileName, dynamic, vbo);
|
||||
if (!model)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
viewer.setSceneData(model);
|
||||
|
||||
return viewer.run();
|
||||
|
@ -77,9 +77,9 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius)
|
||||
|
||||
osg::AnimationPath* animationPath = createAnimationPath(center,radius,animationLength);
|
||||
|
||||
osg::Group* model = new osg::Group;
|
||||
osg::ref_ptr<osg::Group> model = new osg::Group;
|
||||
|
||||
osg::Node* glider = osgDB::readNodeFile("glider.osgt");
|
||||
osg::ref_ptr<osg::Node> glider = osgDB::readRefNodeFile("glider.osgt");
|
||||
if (glider)
|
||||
{
|
||||
const osg::BoundingSphere& bs = glider->getBound();
|
||||
@ -102,7 +102,7 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius)
|
||||
model->addChild(xform);
|
||||
}
|
||||
|
||||
osg::Node* cessna = osgDB::readNodeFile("cessna.osgt");
|
||||
osg::ref_ptr<osg::Node> cessna = osgDB::readRefNodeFile("cessna.osgt");
|
||||
if (cessna)
|
||||
{
|
||||
const osg::BoundingSphere& bs = cessna->getBound();
|
||||
@ -126,7 +126,7 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius)
|
||||
model->addChild(xform);
|
||||
}
|
||||
|
||||
return model;
|
||||
return model.release();
|
||||
}
|
||||
|
||||
|
||||
@ -162,8 +162,8 @@ void build_world(osg::Group *root)
|
||||
osg::Geode* terrainGeode = new osg::Geode;
|
||||
// create terrain
|
||||
{
|
||||
osg::StateSet* stateset = new osg::StateSet();
|
||||
osg::Image* image = osgDB::readImageFile("Images/lz.rgb");
|
||||
osg::ref_ptr<osg::StateSet> stateset = new osg::StateSet();
|
||||
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile("Images/lz.rgb");
|
||||
if (image)
|
||||
{
|
||||
osg::Texture2D* texture = new osg::Texture2D;
|
||||
|
@ -75,21 +75,20 @@ std::string ImageReaderWriter::local_insertReference(const std::string& fileName
|
||||
return myReference;
|
||||
}
|
||||
|
||||
osg::Image* ImageReaderWriter::readImage_Archive(DataReference& dr, float& s,float& t)
|
||||
osg::ref_ptr<osg::Image> ImageReaderWriter::readImage_Archive(DataReference& dr, float& s,float& t)
|
||||
{
|
||||
for(PhotoArchiveList::iterator itr=_photoArchiveList.begin();
|
||||
itr!=_photoArchiveList.end();
|
||||
++itr)
|
||||
{
|
||||
osg::Image* image = (*itr)->readImage(dr._fileName,dr._resolutionX,dr._resolutionY,s,t);
|
||||
osg::ref_ptr<osg::Image> image = (*itr)->readImage(dr._fileName,dr._resolutionX,dr._resolutionY,s,t);
|
||||
if (image) return image;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
osg::Image* ImageReaderWriter::readImage_DynamicSampling(DataReference& dr, float& s,float& t)
|
||||
osg::ref_ptr<osg::Image> ImageReaderWriter::readImage_DynamicSampling(DataReference& dr, float& s,float& t)
|
||||
{
|
||||
|
||||
// record previous options.
|
||||
osg::ref_ptr<osgDB::ReaderWriter::Options> previousOptions = osgDB::Registry::instance()->getOptions();
|
||||
|
||||
@ -99,7 +98,7 @@ osg::Image* ImageReaderWriter::readImage_DynamicSampling(DataReference& dr, floa
|
||||
|
||||
osgDB::Registry::instance()->setOptions(options.get());
|
||||
|
||||
osg::Image* image = osgDB::readImageFile(dr._fileName);
|
||||
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile(dr._fileName);
|
||||
|
||||
// restore previous options.
|
||||
osgDB::Registry::instance()->setOptions(previousOptions.get());
|
||||
@ -119,7 +118,7 @@ osgDB::ReaderWriter::ReadResult ImageReaderWriter::local_readNode(const std::str
|
||||
|
||||
DataReference& dr = itr->second;
|
||||
|
||||
osg::Image* image = 0;
|
||||
osg::ref_ptr<osg::Image> image;
|
||||
float s=1.0f,t=1.0f;
|
||||
|
||||
// try to load photo from any loaded PhotoArchives
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* -*-c++-*-
|
||||
/* -*-c++-*-
|
||||
*
|
||||
* OpenSceneGraph example, osgphotoalbum.
|
||||
*
|
||||
@ -30,14 +30,14 @@
|
||||
|
||||
#include "PhotoArchive.h"
|
||||
|
||||
#define SERIALIZER() OpenThreads::ScopedLock<OpenThreads::ReentrantMutex> lock(_serializerMutex)
|
||||
#define SERIALIZER() OpenThreads::ScopedLock<OpenThreads::ReentrantMutex> lock(_serializerMutex)
|
||||
|
||||
class ImageReaderWriter : public osgDB::ReaderWriter
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
ImageReaderWriter();
|
||||
|
||||
|
||||
virtual const char* className() const { return "ImageReader"; }
|
||||
|
||||
void addPhotoArchive(PhotoArchive* archive) { _photoArchiveList.push_back(archive); }
|
||||
@ -54,7 +54,7 @@ class ImageReaderWriter : public osgDB::ReaderWriter
|
||||
return const_cast<ImageReaderWriter*>(this)->local_readNode(fileName, options);
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
std::string local_insertReference(const std::string& fileName, unsigned int res, float width, float height, bool backPage);
|
||||
@ -73,16 +73,16 @@ class ImageReaderWriter : public osgDB::ReaderWriter
|
||||
unsigned int _resolutionX;
|
||||
unsigned int _resolutionY;
|
||||
osg::Vec3 _center;
|
||||
osg::Vec3 _maximumWidth;
|
||||
osg::Vec3 _maximumWidth;
|
||||
osg::Vec3 _maximumHeight;
|
||||
unsigned int _numPointsAcross;
|
||||
unsigned int _numPointsAcross;
|
||||
unsigned int _numPointsUp;
|
||||
bool _backPage;
|
||||
};
|
||||
|
||||
osg::Image* readImage_Archive(DataReference& dr, float& s,float& t);
|
||||
|
||||
osg::Image* readImage_DynamicSampling(DataReference& dr, float& s,float& t);
|
||||
|
||||
osg::ref_ptr<osg::Image> readImage_Archive(DataReference& dr, float& s,float& t);
|
||||
|
||||
osg::ref_ptr<osg::Image> readImage_DynamicSampling(DataReference& dr, float& s,float& t);
|
||||
|
||||
typedef std::map< std::string,DataReference > DataReferenceMap;
|
||||
typedef std::vector< osg::ref_ptr<PhotoArchive> > PhotoArchiveList;
|
||||
|
@ -38,7 +38,7 @@ PhotoArchive::PhotoArchive(const std::string& filename)
|
||||
bool PhotoArchive::readPhotoIndex(const std::string& filename)
|
||||
{
|
||||
osgDB::ifstream in(filename.c_str());
|
||||
|
||||
|
||||
char* fileIndentifier = new char [FILE_IDENTIFER.size()];
|
||||
in.read(fileIndentifier,FILE_IDENTIFER.size());
|
||||
if (FILE_IDENTIFER!=fileIndentifier)
|
||||
@ -47,17 +47,17 @@ bool PhotoArchive::readPhotoIndex(const std::string& filename)
|
||||
return false;
|
||||
}
|
||||
delete [] fileIndentifier;
|
||||
|
||||
|
||||
unsigned int numPhotos;
|
||||
in.read((char*)&numPhotos,sizeof(numPhotos));
|
||||
|
||||
_photoIndex.resize(numPhotos);
|
||||
|
||||
in.read((char*)&_photoIndex.front(),sizeof(PhotoHeader)*numPhotos);
|
||||
|
||||
|
||||
// success record filename.
|
||||
_archiveFileName = filename;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -69,10 +69,10 @@ void PhotoArchive::getImageFileNameList(FileNameList& filenameList)
|
||||
{
|
||||
filenameList.push_back(std::string(itr->filename));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
osg::Image* PhotoArchive::readImage(const std::string& filename,
|
||||
osg::ref_ptr<osg::Image> PhotoArchive::readImage(const std::string& filename,
|
||||
unsigned int target_s, unsigned target_t,
|
||||
float& original_s, float& original_t)
|
||||
{
|
||||
@ -83,56 +83,56 @@ osg::Image* PhotoArchive::readImage(const std::string& filename,
|
||||
if (filename==itr->filename)
|
||||
{
|
||||
const PhotoHeader& photoHeader = *itr;
|
||||
|
||||
|
||||
if (target_s <= photoHeader.thumbnail_s &&
|
||||
target_t <= photoHeader.thumbnail_t &&
|
||||
photoHeader.thumbnail_position != 0)
|
||||
{
|
||||
osgDB::ifstream in(_archiveFileName.c_str(),std::ios::in | std::ios::binary);
|
||||
|
||||
|
||||
// find image
|
||||
in.seekg(photoHeader.thumbnail_position);
|
||||
|
||||
|
||||
// read image header
|
||||
ImageHeader imageHeader;
|
||||
in.read((char*)&imageHeader,sizeof(ImageHeader));
|
||||
unsigned char* data = new unsigned char[imageHeader.size];
|
||||
in.read((char*)data,imageHeader.size);
|
||||
|
||||
osg::Image* image = new osg::Image;
|
||||
|
||||
osg::ref_ptr<osg::Image> image = new osg::Image;
|
||||
image->setImage(photoHeader.thumbnail_s,photoHeader.thumbnail_t,1,
|
||||
imageHeader.pixelFormat,imageHeader.pixelFormat,imageHeader.type,
|
||||
data,osg::Image::USE_NEW_DELETE);
|
||||
|
||||
|
||||
original_s = photoHeader.original_s;
|
||||
original_t = photoHeader.original_t;
|
||||
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
if (photoHeader.fullsize_s &&
|
||||
photoHeader.fullsize_t &&
|
||||
photoHeader.fullsize_position != 0)
|
||||
{
|
||||
osgDB::ifstream in(_archiveFileName.c_str(),std::ios::in | std::ios::binary);
|
||||
|
||||
|
||||
// find image
|
||||
in.seekg(photoHeader.fullsize_position);
|
||||
|
||||
|
||||
// read image header
|
||||
ImageHeader imageHeader;
|
||||
in.read((char*)&imageHeader,sizeof(ImageHeader));
|
||||
unsigned char* data = new unsigned char[imageHeader.size];
|
||||
in.read((char*)data,imageHeader.size);
|
||||
|
||||
osg::Image* image = new osg::Image;
|
||||
|
||||
osg::ref_ptr<osg::Image> image = new osg::Image;
|
||||
image->setImage(photoHeader.fullsize_s,photoHeader.fullsize_t,1,
|
||||
imageHeader.pixelFormat,imageHeader.pixelFormat,imageHeader.type,
|
||||
data,osg::Image::USE_NEW_DELETE);
|
||||
|
||||
|
||||
original_s = photoHeader.original_s;
|
||||
original_t = photoHeader.original_t;
|
||||
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
@ -152,21 +152,21 @@ void PhotoArchive::buildArchive(const std::string& filename, const FileNameList&
|
||||
++fitr)
|
||||
{
|
||||
PhotoHeader header;
|
||||
|
||||
|
||||
// set name
|
||||
strncpy(header.filename,fitr->c_str(),255);
|
||||
header.filename[255]=0;
|
||||
|
||||
|
||||
header.thumbnail_s = thumbnailSize;
|
||||
header.thumbnail_t = thumbnailSize;
|
||||
header.thumbnail_position = 0;
|
||||
|
||||
|
||||
header.fullsize_s = thumbnailSize;
|
||||
header.fullsize_t = thumbnailSize;
|
||||
header.fullsize_position = 0;
|
||||
|
||||
photoIndex.push_back(header);
|
||||
|
||||
|
||||
}
|
||||
|
||||
std::cout<<"Building photo archive containing "<<photoIndex.size()<<" pictures"<<std::endl;
|
||||
@ -185,21 +185,21 @@ void PhotoArchive::buildArchive(const std::string& filename, const FileNameList&
|
||||
unsigned int startOfPhotoIndex = out.tellp();
|
||||
out.write((char*)&photoIndex.front(),sizeof(PhotoHeader)*photoIndex.size());
|
||||
|
||||
unsigned int photoCount=1;
|
||||
unsigned int photoCount=1;
|
||||
for(PhotoIndexList::iterator pitr=photoIndex.begin();
|
||||
pitr!=photoIndex.end();
|
||||
++pitr,++photoCount)
|
||||
{
|
||||
PhotoHeader& photoHeader = *pitr;
|
||||
|
||||
|
||||
|
||||
|
||||
std::cout<<"Processing image "<<photoCount<<" of "<< photoIndex.size()<<" filename="<< photoHeader.filename << std::endl;
|
||||
std::cout<<" reading image...";std::cout.flush();
|
||||
|
||||
osg::ref_ptr<osg::Image> image = osgDB::readImageFile(photoHeader.filename);
|
||||
|
||||
|
||||
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile(photoHeader.filename);
|
||||
|
||||
std::cout<<"done."<< std::endl;
|
||||
|
||||
|
||||
photoHeader.original_s = image->s();
|
||||
photoHeader.original_t = image->t();
|
||||
|
||||
@ -207,7 +207,7 @@ void PhotoArchive::buildArchive(const std::string& filename, const FileNameList&
|
||||
|
||||
std::cout<<" creating thumbnail image...";
|
||||
// first need to rescale image to the require thumbnail size
|
||||
unsigned int newTotalSize =
|
||||
unsigned int newTotalSize =
|
||||
image->computeRowWidthInBytes(thumbnailSize,image->getPixelFormat(),image->getDataType(),image->getPacking())*
|
||||
thumbnailSize;
|
||||
|
||||
@ -241,7 +241,7 @@ void PhotoArchive::buildArchive(const std::string& filename, const FileNameList&
|
||||
osg::notify(osg::WARN) << "Error scaleImage() did not succeed : errorString = "<<osg::gluErrorString((GLenum)status)<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// now set up the photo header.
|
||||
photoHeader.thumbnail_s = thumbnailSize;
|
||||
photoHeader.thumbnail_t = thumbnailSize;
|
||||
@ -259,13 +259,13 @@ void PhotoArchive::buildArchive(const std::string& filename, const FileNameList&
|
||||
// write out image header and image data.
|
||||
out.write((char*)&imageHeader,sizeof(ImageHeader));
|
||||
out.write((char*)newData,imageHeader.size);
|
||||
|
||||
|
||||
delete [] newData;
|
||||
|
||||
std::cout<<"done."<< std::endl;
|
||||
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
std::cout<<" creating fullsize image...";std::cout.flush();
|
||||
|
||||
@ -275,7 +275,7 @@ void PhotoArchive::buildArchive(const std::string& filename, const FileNameList&
|
||||
photoHeader.fullsize_position = (unsigned int)out.tellp();
|
||||
|
||||
// first need to rescale image to the require thumbnail size
|
||||
unsigned int newTotalSize =
|
||||
unsigned int newTotalSize =
|
||||
image->computeRowWidthInBytes(photoHeader.fullsize_s,image->getPixelFormat(),image->getDataType(),image->getPacking())*
|
||||
photoHeader.fullsize_t;
|
||||
|
||||
@ -326,7 +326,7 @@ void PhotoArchive::buildArchive(const std::string& filename, const FileNameList&
|
||||
|
||||
std::cout<<"done."<< std::endl;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// rewrite photo index now it has the correct sizes set
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* -*-c++-*-
|
||||
/* -*-c++-*-
|
||||
*
|
||||
* OpenSceneGraph example, osgphotoalbum.
|
||||
*
|
||||
@ -35,19 +35,19 @@ public:
|
||||
}
|
||||
|
||||
typedef std::vector<std::string> FileNameList;
|
||||
|
||||
|
||||
bool empty() { return _photoIndex.empty(); }
|
||||
|
||||
void getImageFileNameList(FileNameList& filenameList);
|
||||
|
||||
|
||||
static void buildArchive(const std::string& filename, const FileNameList& imageList, unsigned int thumbnailSize=256, unsigned int maximumSize=1024, bool compressed=true);
|
||||
|
||||
osg::Image* readImage(const std::string& filename,
|
||||
osg::ref_ptr<osg::Image> readImage(const std::string& filename,
|
||||
unsigned int target_s, unsigned target_t,
|
||||
float& original_s, float& original_t);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
PhotoArchive(const std::string& filename);
|
||||
@ -55,7 +55,7 @@ protected:
|
||||
virtual ~PhotoArchive() {}
|
||||
|
||||
bool readPhotoIndex(const std::string& filename);
|
||||
|
||||
|
||||
struct PhotoHeader
|
||||
{
|
||||
PhotoHeader():
|
||||
@ -70,7 +70,7 @@ protected:
|
||||
{
|
||||
filename[0]='\0';
|
||||
}
|
||||
|
||||
|
||||
char filename[256];
|
||||
unsigned int original_s;
|
||||
unsigned int original_t;
|
||||
@ -84,7 +84,7 @@ protected:
|
||||
unsigned int fullsize_position;
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct ImageHeader
|
||||
{
|
||||
ImageHeader():
|
||||
@ -94,7 +94,7 @@ protected:
|
||||
pixelFormat(0),
|
||||
type(0),
|
||||
size(0) {}
|
||||
|
||||
|
||||
unsigned int s;
|
||||
unsigned int t;
|
||||
GLint internalTextureformat;
|
||||
@ -107,7 +107,7 @@ protected:
|
||||
typedef std::vector<PhotoHeader> PhotoIndexList;
|
||||
|
||||
std::string _archiveFileName;
|
||||
PhotoIndexList _photoIndex;
|
||||
PhotoIndexList _photoIndex;
|
||||
|
||||
};
|
||||
|
||||
|
@ -239,7 +239,7 @@ int main( int argc, char **argv )
|
||||
osg::ArgumentParser arguments(&argc,argv);
|
||||
|
||||
// read the scene from the list of file specified commandline args.
|
||||
osg::ref_ptr<osg::Node> scene = osgDB::readNodeFiles(arguments);
|
||||
osg::ref_ptr<osg::Node> scene = osgDB::readRefNodeFiles(arguments);
|
||||
|
||||
if (!scene && arguments.read("--relative-camera-scene"))
|
||||
{
|
||||
@ -271,7 +271,7 @@ int main( int argc, char **argv )
|
||||
}
|
||||
|
||||
// if not loaded assume no arguments passed in, try use default mode instead.
|
||||
if (!scene) scene = osgDB::readNodeFile("fountain.osgt");
|
||||
if (!scene) scene = osgDB::readRefNodeFile("fountain.osgt");
|
||||
|
||||
osg::ref_ptr<osg::Group> group = dynamic_cast<osg::Group*>(scene.get());
|
||||
if (!group)
|
||||
|
@ -366,7 +366,7 @@ osg::Geode* SolarSystem::createSpace( const std::string& name, const std::string
|
||||
|
||||
if( !textureName.empty() )
|
||||
{
|
||||
osg::Image* image = osgDB::readImageFile( textureName );
|
||||
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile( textureName );
|
||||
if ( image )
|
||||
{
|
||||
sSpaceSphere->getOrCreateStateSet()->setTextureAttributeAndModes( 0, new osg::Texture2D( image ), osg::StateAttribute::ON );
|
||||
@ -467,7 +467,7 @@ osg::Geode* SolarSystem::createPlanet( double radius, const std::string& name, c
|
||||
|
||||
if( !textureName.empty() )
|
||||
{
|
||||
osg::Image* image = osgDB::readImageFile( textureName );
|
||||
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile( textureName );
|
||||
if ( image )
|
||||
{
|
||||
osg::Texture2D* tex2d = new osg::Texture2D( image );
|
||||
@ -493,7 +493,7 @@ osg::Geode* SolarSystem::createPlanet( double radius, const std::string& name, c
|
||||
|
||||
if( !textureName2.empty() )
|
||||
{
|
||||
osg::Image* image = osgDB::readImageFile( textureName2 );
|
||||
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile( textureName2 );
|
||||
if ( image )
|
||||
{
|
||||
osg::StateSet* stateset = geodePlanet->getOrCreateStateSet();
|
||||
|
@ -31,7 +31,7 @@
|
||||
class KeyboardEventHandler : public osgGA::GUIEventHandler
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
KeyboardEventHandler(osg::StateSet* stateset):
|
||||
_stateset(stateset)
|
||||
{
|
||||
@ -39,7 +39,7 @@ public:
|
||||
_point->setDistanceAttenuation(osg::Vec3(0.0,0.0000,0.05f));
|
||||
_stateset->setAttribute(_point.get());
|
||||
}
|
||||
|
||||
|
||||
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&)
|
||||
{
|
||||
switch(ea.getEventType())
|
||||
@ -73,13 +73,13 @@ public:
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
float getPointSize() const
|
||||
{
|
||||
return _point->getSize();
|
||||
}
|
||||
|
||||
|
||||
void setPointSize(float psize)
|
||||
{
|
||||
if (psize>0.0)
|
||||
@ -98,10 +98,10 @@ public:
|
||||
{
|
||||
_point->setDistanceAttenuation(_point->getDistanceAttenuation()*scale);
|
||||
}
|
||||
|
||||
|
||||
osg::ref_ptr<osg::StateSet> _stateset;
|
||||
osg::ref_ptr<osg::Point> _point;
|
||||
|
||||
|
||||
};
|
||||
|
||||
int main( int argc, char **argv )
|
||||
@ -109,7 +109,7 @@ int main( int argc, char **argv )
|
||||
|
||||
// use an ArgumentParser object to manage the program arguments.
|
||||
osg::ArgumentParser arguments(&argc,argv);
|
||||
|
||||
|
||||
// set up the usage document, in case we need to print out how to use this program.
|
||||
arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName());
|
||||
arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" example provides an interactive viewer for visualising point clouds..");
|
||||
@ -131,7 +131,7 @@ int main( int argc, char **argv )
|
||||
arguments.getApplicationUsage()->write(std::cout);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
bool usePointSprites = false;
|
||||
while (arguments.read("--sprites")) { usePointSprites = true; };
|
||||
|
||||
@ -145,10 +145,10 @@ int main( int argc, char **argv )
|
||||
}
|
||||
|
||||
// read the scene from the list of file specified commandline args.
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFiles(arguments);
|
||||
|
||||
// if no model has been successfully loaded report failure.
|
||||
if (!loadedModel)
|
||||
if (!loadedModel)
|
||||
{
|
||||
std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl;
|
||||
return 1;
|
||||
@ -161,10 +161,10 @@ int main( int argc, char **argv )
|
||||
|
||||
// set the scene to render
|
||||
viewer.setSceneData(loadedModel.get());
|
||||
|
||||
|
||||
|
||||
osg::StateSet* stateset = loadedModel->getOrCreateStateSet();
|
||||
if (usePointSprites)
|
||||
if (usePointSprites)
|
||||
{
|
||||
/// Setup cool blending
|
||||
osg::BlendFunc *fn = new osg::BlendFunc();
|
||||
@ -176,7 +176,7 @@ int main( int argc, char **argv )
|
||||
|
||||
/// The texture for the sprites
|
||||
osg::Texture2D *tex = new osg::Texture2D();
|
||||
tex->setImage(osgDB::readImageFile("Images/particle.rgb"));
|
||||
tex->setImage(osgDB::readRefImageFile("Images/particle.rgb"));
|
||||
stateset->setTextureAttributeAndModes(0, tex, osg::StateAttribute::ON);
|
||||
}
|
||||
|
||||
@ -187,7 +187,7 @@ int main( int argc, char **argv )
|
||||
osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::POINT );
|
||||
stateset->setAttributeAndModes( pm, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// register the handler for modifying the point size
|
||||
viewer.addEventHandler(new KeyboardEventHandler(viewer.getCamera()->getOrCreateStateSet()));
|
||||
@ -196,10 +196,10 @@ int main( int argc, char **argv )
|
||||
if (shader)
|
||||
{
|
||||
osg::StateSet* stateset = loadedModel->getOrCreateStateSet();
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// vertex shader using just Vec4 coefficients
|
||||
char vertexShaderSource[] =
|
||||
char vertexShaderSource[] =
|
||||
"void main(void) \n"
|
||||
"{ \n"
|
||||
"\n"
|
||||
@ -218,7 +218,7 @@ int main( int argc, char **argv )
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// fragment shader
|
||||
//
|
||||
char fragmentShaderSource[] =
|
||||
char fragmentShaderSource[] =
|
||||
"void main(void) \n"
|
||||
"{ \n"
|
||||
" gl_FragColor = gl_Color; \n"
|
||||
|
@ -86,7 +86,7 @@ osg::StateSet* makeStateSet(float size)
|
||||
|
||||
/// The texture for the sprites
|
||||
osg::Texture2D *tex = new osg::Texture2D();
|
||||
tex->setImage(osgDB::readImageFile("Images/particle.rgb"));
|
||||
tex->setImage(osgDB::readRefImageFile("Images/particle.rgb"));
|
||||
set->setTextureAttributeAndModes(0, tex, osg::StateAttribute::ON);
|
||||
|
||||
return set;
|
||||
|
@ -9,9 +9,9 @@
|
||||
/* PagedLoadingCallback: Callback for loading paged nodes while doing intersecting test */
|
||||
struct PagedLoadingCallback : public osgUtil::IntersectionVisitor::ReadCallback
|
||||
{
|
||||
virtual osg::Node* readNodeFile( const std::string& filename )
|
||||
virtual osg::ref_ptr<osg::Node> readNodeFile( const std::string& filename )
|
||||
{
|
||||
return osgDB::readNodeFile( filename );
|
||||
return osgDB::readRefNodeFile( filename );
|
||||
}
|
||||
};
|
||||
static osg::ref_ptr<PagedLoadingCallback> g_pagedLoadingCallback = new PagedLoadingCallback;
|
||||
|
@ -38,14 +38,14 @@ public:
|
||||
: osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
|
||||
_foundNode(0)
|
||||
{}
|
||||
|
||||
|
||||
void apply( osg::Node& node )
|
||||
{
|
||||
T* result = dynamic_cast<T*>( &node );
|
||||
if ( result ) _foundNode = result;
|
||||
else traverse( node );
|
||||
}
|
||||
|
||||
|
||||
T* _foundNode;
|
||||
};
|
||||
|
||||
@ -53,7 +53,7 @@ template<class T>
|
||||
T* findTopMostNodeOfType( osg::Node* node )
|
||||
{
|
||||
if ( !node ) return 0;
|
||||
|
||||
|
||||
FindTopMostNodeOfTypeVisitor<T> fnotv;
|
||||
node->accept( fnotv );
|
||||
return fnotv._foundNode;
|
||||
@ -75,31 +75,31 @@ void computeViewMatrixOnEarth( osg::Camera* camera, osg::Node* scene,
|
||||
{
|
||||
osg::CoordinateSystemNode* csn = findTopMostNodeOfType<osg::CoordinateSystemNode>(scene);
|
||||
if ( !csn ) return;
|
||||
|
||||
|
||||
// Compute eye point in world coordiantes
|
||||
osg::Vec3d eye;
|
||||
csn->getEllipsoidModel()->convertLatLongHeightToXYZ(
|
||||
latLongHeight.x(), latLongHeight.y(), latLongHeight.z(), eye.x(), eye.y(), eye.z() );
|
||||
|
||||
|
||||
// Build matrix for computing target vector
|
||||
osg::Matrixd target_matrix =
|
||||
osg::Matrixd::rotate( -hpr.x(), osg::Vec3d(1,0,0),
|
||||
-latLongHeight.x(), osg::Vec3d(0,1,0),
|
||||
latLongHeight.y(), osg::Vec3d(0,0,1) );
|
||||
|
||||
|
||||
// Compute tangent vector
|
||||
osg::Vec3d tangent = target_matrix.preMult( osg::Vec3d(0,0,1) );
|
||||
|
||||
|
||||
// Compute non-inclined, non-rolled up vector
|
||||
osg::Vec3d up( eye );
|
||||
up.normalize();
|
||||
|
||||
|
||||
// Incline by rotating the target- and up vector around the tangent/up-vector
|
||||
// cross-product
|
||||
osg::Vec3d up_cross_tangent = up ^ tangent;
|
||||
osg::Matrixd incline_matrix = osg::Matrixd::rotate( hpr.y(), up_cross_tangent );
|
||||
osg::Vec3d target = incline_matrix.preMult( tangent );
|
||||
|
||||
|
||||
// Roll by rotating the up vector around the target vector
|
||||
osg::Matrixd roll_matrix = incline_matrix * osg::Matrixd::rotate( hpr.z(), target );
|
||||
up = roll_matrix.preMult( up );
|
||||
@ -114,7 +114,7 @@ public:
|
||||
: osgViewer::Renderer(camera), _cullOnly(true)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void setCullOnly(bool on) { _cullOnly = on; }
|
||||
|
||||
virtual void operator ()( osg::GraphicsContext* )
|
||||
@ -125,22 +125,22 @@ public:
|
||||
else cull_draw();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
virtual void cull()
|
||||
{
|
||||
osgUtil::SceneView* sceneView = _sceneView[0].get();
|
||||
if ( !sceneView || _done || _graphicsThreadDoesCull )
|
||||
return;
|
||||
|
||||
|
||||
updateSceneView( sceneView );
|
||||
|
||||
|
||||
osgViewer::View* view = dynamic_cast<osgViewer::View*>( _camera->getView() );
|
||||
if ( view )
|
||||
sceneView->setFusionDistance( view->getFusionDistanceMode(), view->getFusionDistanceValue() );
|
||||
sceneView->inheritCullSettings( *(sceneView->getCamera()) );
|
||||
sceneView->cull();
|
||||
}
|
||||
|
||||
|
||||
bool _cullOnly;
|
||||
};
|
||||
|
||||
@ -150,12 +150,12 @@ class PrintPosterHandler : public osgGA::GUIEventHandler
|
||||
public:
|
||||
PrintPosterHandler( PosterPrinter* printer )
|
||||
: _printer(printer), _started(false) {}
|
||||
|
||||
|
||||
bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
|
||||
{
|
||||
osgViewer::View* view = dynamic_cast<osgViewer::View*>( &aa );
|
||||
if ( !view ) return false;
|
||||
|
||||
|
||||
switch( ea.getEventType() )
|
||||
{
|
||||
case osgGA::GUIEventAdapter::FRAME:
|
||||
@ -165,7 +165,7 @@ public:
|
||||
if ( view->getDatabasePager()->getRequestsInProgress() )
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if ( _printer.valid() )
|
||||
{
|
||||
_printer->frame( view->getFrameStamp(), view->getSceneData() );
|
||||
@ -183,7 +183,7 @@ public:
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case osgGA::GUIEventAdapter::KEYDOWN:
|
||||
if ( ea.getKey()=='p' || ea.getKey()=='P' )
|
||||
{
|
||||
@ -196,14 +196,14 @@ public:
|
||||
root->setValue( 0, false );
|
||||
root->setValue( 1, true );
|
||||
}
|
||||
|
||||
|
||||
_printer->init( view->getCamera() );
|
||||
_started = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -241,13 +241,13 @@ int main( int argc, char** argv )
|
||||
usage->addCommandLineOption( "--camera-eye <x> <y> <z>", "Set eye position in inactive mode." );
|
||||
usage->addCommandLineOption( "--camera-latlongheight <lat> <lon> <h>", "Set eye position on earth in inactive mode." );
|
||||
usage->addCommandLineOption( "--camera-hpr <h> <p> <r>", "Set eye rotation in inactive mode." );
|
||||
|
||||
|
||||
if ( arguments.read("-h") || arguments.read("--help") )
|
||||
{
|
||||
usage->write( std::cout );
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// Poster arguments
|
||||
bool activeMode = true;
|
||||
bool outputPoster = true;
|
||||
@ -257,7 +257,7 @@ int main( int argc, char** argv )
|
||||
std::string posterName = "poster.bmp", extName = "bmp";
|
||||
osg::Vec4 bgColor(0.2f, 0.2f, 0.6f, 1.0f);
|
||||
osg::Camera::RenderTargetImplementation renderImplementation = osg::Camera::FRAME_BUFFER_OBJECT;
|
||||
|
||||
|
||||
while ( arguments.read("--inactive") ) { activeMode = false; }
|
||||
while ( arguments.read("--color", bgColor.r(), bgColor.g(), bgColor.b()) ) {}
|
||||
while ( arguments.read("--tilesize", tileWidth, tileHeight) ) {}
|
||||
@ -272,7 +272,7 @@ int main( int argc, char** argv )
|
||||
while ( arguments.read("--use-pbuffer")) { renderImplementation = osg::Camera::PIXEL_BUFFER; }
|
||||
while ( arguments.read("--use-pbuffer-rtt")) { renderImplementation = osg::Camera::PIXEL_BUFFER_RTT; }
|
||||
while ( arguments.read("--use-fb")) { renderImplementation = osg::Camera::FRAME_BUFFER; }
|
||||
|
||||
|
||||
// Camera settings for inactive screenshot
|
||||
bool useLatLongHeight = true;
|
||||
osg::Vec3d eye;
|
||||
@ -296,16 +296,16 @@ int main( int argc, char** argv )
|
||||
hpr.y() = osg::DegreesToRadians( hpr.y() );
|
||||
hpr.z() = osg::DegreesToRadians( hpr.z() );
|
||||
}
|
||||
|
||||
|
||||
// Construct scene graph
|
||||
osg::Node* scene = osgDB::readNodeFiles( arguments );
|
||||
if ( !scene ) scene = osgDB::readNodeFile( "cow.osgt" );
|
||||
osg::ref_ptr<osg::Node> scene = osgDB::readRefNodeFiles( arguments );
|
||||
if ( !scene ) scene = osgDB::readRefNodeFile( "cow.osgt" );
|
||||
if ( !scene )
|
||||
{
|
||||
std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// Create camera for rendering tiles offscreen. FrameBuffer is recommended because it requires less memory.
|
||||
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
||||
camera->setClearColor( bgColor );
|
||||
@ -315,13 +315,13 @@ int main( int argc, char** argv )
|
||||
camera->setRenderTargetImplementation( renderImplementation );
|
||||
camera->setViewport( 0, 0, tileWidth, tileHeight );
|
||||
camera->addChild( scene );
|
||||
|
||||
|
||||
// Set the printer
|
||||
osg::ref_ptr<PosterPrinter> printer = new PosterPrinter;
|
||||
printer->setTileSize( tileWidth, tileHeight );
|
||||
printer->setPosterSize( posterWidth, posterHeight );
|
||||
printer->setCamera( camera.get() );
|
||||
|
||||
|
||||
osg::ref_ptr<osg::Image> posterImage = 0;
|
||||
if ( outputPoster )
|
||||
{
|
||||
@ -330,7 +330,7 @@ int main( int argc, char** argv )
|
||||
printer->setFinalPoster( posterImage.get() );
|
||||
printer->setOutputPosterName( posterName );
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
// While recording sub-images of the poster, the scene will always be traversed twice, from its two
|
||||
// parent node: root and camera. Sometimes this may not be so comfortable.
|
||||
@ -345,11 +345,11 @@ int main( int argc, char** argv )
|
||||
root->addChild( scene );
|
||||
root->addChild( camera.get() );
|
||||
#endif
|
||||
|
||||
|
||||
osgViewer::Viewer viewer;
|
||||
viewer.setSceneData( root.get() );
|
||||
viewer.getDatabasePager()->setDoPreCompile( false );
|
||||
|
||||
|
||||
if ( renderImplementation==osg::Camera::FRAME_BUFFER )
|
||||
{
|
||||
// FRAME_BUFFER requires the window resolution equal or greater than the to-be-copied size
|
||||
@ -360,7 +360,7 @@ int main( int argc, char** argv )
|
||||
// We want to see the console output, so just render in a window
|
||||
viewer.setUpViewInWindow( 100, 100, 800, 600 );
|
||||
}
|
||||
|
||||
|
||||
if ( activeMode )
|
||||
{
|
||||
viewer.addEventHandler( new PrintPosterHandler(printer.get()) );
|
||||
@ -373,21 +373,21 @@ int main( int argc, char** argv )
|
||||
{
|
||||
osg::Camera* camera = viewer.getCamera();
|
||||
if ( !useLatLongHeight ) computeViewMatrix( camera, eye, hpr );
|
||||
else computeViewMatrixOnEarth( camera, scene, latLongHeight, hpr );
|
||||
|
||||
else computeViewMatrixOnEarth( camera, scene.get(), latLongHeight, hpr );
|
||||
|
||||
osg::ref_ptr<CustomRenderer> renderer = new CustomRenderer( camera );
|
||||
camera->setRenderer( renderer.get() );
|
||||
viewer.setThreadingModel( osgViewer::Viewer::SingleThreaded );
|
||||
|
||||
|
||||
// Realize and initiate the first PagedLOD request
|
||||
viewer.realize();
|
||||
viewer.frame();
|
||||
|
||||
|
||||
printer->init( camera );
|
||||
while ( !printer->done() )
|
||||
{
|
||||
viewer.advance();
|
||||
|
||||
|
||||
// Keep updating and culling until full level of detail is reached
|
||||
renderer->setCullOnly( true );
|
||||
while ( viewer.getDatabasePager()->getRequestsInProgress() )
|
||||
@ -395,7 +395,7 @@ int main( int argc, char** argv )
|
||||
viewer.updateTraversal();
|
||||
viewer.renderingTraversals();
|
||||
}
|
||||
|
||||
|
||||
renderer->setCullOnly( false );
|
||||
printer->frame( viewer.getFrameStamp(), viewer.getSceneData() );
|
||||
viewer.renderingTraversals();
|
||||
|
@ -49,7 +49,7 @@ class MyGustCallback : public osg::NodeCallback
|
||||
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
|
||||
{
|
||||
osgParticle::PrecipitationEffect* pe = dynamic_cast<osgParticle::PrecipitationEffect*>(node);
|
||||
|
||||
|
||||
float value = sin(nv->getFrameStamp()->getSimulationTime());
|
||||
if (value<-0.5)
|
||||
{
|
||||
@ -59,7 +59,7 @@ class MyGustCallback : public osg::NodeCallback
|
||||
{
|
||||
pe->rain(0.5);
|
||||
}
|
||||
|
||||
|
||||
traverse(node, nv);
|
||||
}
|
||||
};
|
||||
@ -70,7 +70,7 @@ int main( int argc, char **argv )
|
||||
|
||||
// use an ArgumentParser object to manage the program arguments.
|
||||
osg::ArgumentParser arguments(&argc,argv);
|
||||
|
||||
|
||||
// set up the usage document, in case we need to print out how to use this program.
|
||||
arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName());
|
||||
arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" example provides an interactive viewer for visualising point clouds..");
|
||||
@ -89,7 +89,7 @@ int main( int argc, char **argv )
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--fogDensity <density>","Set the fog density");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--fogColour <red> <green> <blue> <alpha>","Set fog colour.");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("-useFarLineSegments","Switch on the use of line segments");
|
||||
|
||||
|
||||
|
||||
// construct the viewer.
|
||||
osgViewer::Viewer viewer;
|
||||
@ -108,7 +108,7 @@ int main( int argc, char **argv )
|
||||
while (arguments.read("-p",pathfile))
|
||||
{
|
||||
osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile);
|
||||
if (apm || !apm->valid())
|
||||
if (apm || !apm->valid())
|
||||
{
|
||||
unsigned int num = keyswitchManipulator->getNumMatrixManipulators();
|
||||
keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm );
|
||||
@ -135,7 +135,7 @@ int main( int argc, char **argv )
|
||||
|
||||
osg::Vec3 wind;
|
||||
while (arguments.read("--wind", wind.x(), wind.y(), wind.z())) precipitationEffect->setWind(wind);
|
||||
|
||||
|
||||
while (arguments.read("--particleSpeed", value)) precipitationEffect->setParticleSpeed(value);
|
||||
|
||||
while (arguments.read("--nearTransition", value )) precipitationEffect->setNearTransition(value);
|
||||
@ -144,7 +144,7 @@ int main( int argc, char **argv )
|
||||
while (arguments.read("--particleDensity", value )) precipitationEffect->setMaximumParticleDensity(value);
|
||||
|
||||
osg::Vec3 cellSize;
|
||||
while (arguments.read("--cellSize", cellSize.x(), cellSize.y(), cellSize.z())) precipitationEffect->setCellSize(cellSize);
|
||||
while (arguments.read("--cellSize", cellSize.x(), cellSize.y(), cellSize.z())) precipitationEffect->setCellSize(cellSize);
|
||||
|
||||
double clipDistance = 0.0;
|
||||
while (arguments.read("--clip",clipDistance)) {}
|
||||
@ -160,10 +160,10 @@ int main( int argc, char **argv )
|
||||
while (arguments.read("--fogDensity", value )) precipitationEffect->getFog()->setDensity(value);
|
||||
while (arguments.read("--fogColor", color.r(), color.g(), color.b(), color.a() )) precipitationEffect->getFog()->setColor(color);
|
||||
while (arguments.read("--fogColour", color.r(), color.g(), color.b(), color.a() )) precipitationEffect->getFog()->setColor(color);
|
||||
|
||||
|
||||
while (arguments.read("--useFarLineSegments")) { precipitationEffect->setUseFarLineSegments(true); }
|
||||
|
||||
|
||||
|
||||
viewer.getCamera()->setClearColor( precipitationEffect->getFog()->getColor() );
|
||||
|
||||
|
||||
@ -173,21 +173,21 @@ int main( int argc, char **argv )
|
||||
arguments.getApplicationUsage()->write(std::cout);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// read the scene from the list of file specified commandline args.
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
|
||||
if (!loadedModel)
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFiles(arguments);
|
||||
if (!loadedModel)
|
||||
{
|
||||
std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// precipitationEffect->setUpdateCallback(new MyGustCallback);
|
||||
|
||||
|
||||
osg::ref_ptr<osg::Group> group = new osg::Group;
|
||||
|
||||
|
||||
if (clipDistance!=0.0)
|
||||
{
|
||||
{
|
||||
osg::ref_ptr<osg::ClipNode> clipNode = new osg::ClipNode;
|
||||
clipNode->addClipPlane( new osg::ClipPlane( 0 ) );
|
||||
clipNode->getClipPlane(0)->setClipPlane( 0.0, 0.0, -1.0, -clipDistance );
|
||||
@ -200,12 +200,12 @@ int main( int argc, char **argv )
|
||||
{
|
||||
group->addChild(precipitationEffect.get());
|
||||
}
|
||||
|
||||
|
||||
group->addChild(loadedModel.get());
|
||||
|
||||
loadedModel->getOrCreateStateSet()->setAttributeAndModes(precipitationEffect->getFog());
|
||||
|
||||
// create the light
|
||||
|
||||
// create the light
|
||||
osg::LightSource* lightSource = new osg::LightSource;
|
||||
group->addChild(lightSource);
|
||||
|
||||
|
@ -463,10 +463,10 @@ int main( int argc, char **argv )
|
||||
|
||||
|
||||
// load the nodes from the commandline arguments.
|
||||
osg::Node* loadedModel = osgDB::readNodeFiles(arguments);
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFiles(arguments);
|
||||
|
||||
// if not loaded assume no arguments passed in, try use default mode instead.
|
||||
if (!loadedModel) loadedModel = osgDB::readNodeFile("cessna.osgt");
|
||||
if (!loadedModel) loadedModel = osgDB::readRefNodeFile("cessna.osgt");
|
||||
|
||||
if (!loadedModel)
|
||||
{
|
||||
|
@ -63,7 +63,7 @@ osg::StateSet* createMirrorTexturedState(const std::string& filename)
|
||||
dstate->setMode(GL_CULL_FACE,osg::StateAttribute::OFF|osg::StateAttribute::PROTECTED);
|
||||
|
||||
// set up the texture.
|
||||
osg::Image* image = osgDB::readImageFile(filename.c_str());
|
||||
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile(filename.c_str());
|
||||
if (image)
|
||||
{
|
||||
osg::Texture2D* texture = new osg::Texture2D;
|
||||
@ -335,10 +335,10 @@ int main( int argc, char **argv )
|
||||
osgViewer::Viewer viewer;
|
||||
|
||||
// read the scene from the list of file specified commandline args.
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFiles(arguments);
|
||||
|
||||
// if not loaded assume no arguments passed in, try use default mode instead.
|
||||
if (!loadedModel) loadedModel = osgDB::readNodeFile("cessna.osgt");
|
||||
if (!loadedModel) loadedModel = osgDB::readRefNodeFile("cessna.osgt");
|
||||
|
||||
// if no model has been successfully loaded report failure.
|
||||
if (!loadedModel)
|
||||
@ -350,11 +350,11 @@ int main( int argc, char **argv )
|
||||
|
||||
// optimize the scene graph, remove redundant nodes and state etc.
|
||||
osgUtil::Optimizer optimizer;
|
||||
optimizer.optimize(loadedModel.get());
|
||||
optimizer.optimize(loadedModel);
|
||||
|
||||
// add a transform with a callback to animate the loaded model.
|
||||
osg::ref_ptr<osg::MatrixTransform> loadedModelTransform = new osg::MatrixTransform;
|
||||
loadedModelTransform->addChild(loadedModel.get());
|
||||
loadedModelTransform->addChild(loadedModel);
|
||||
|
||||
osg::ref_ptr<osg::NodeCallback> nc = new osg::AnimationPathCallback(loadedModelTransform->getBound().center(),osg::Vec3(0.0f,0.0f,1.0f),osg::inDegrees(45.0f));
|
||||
loadedModelTransform->setUpdateCallback(nc.get());
|
||||
@ -364,7 +364,7 @@ int main( int argc, char **argv )
|
||||
osg::ref_ptr<osg::Node> rootNode = createMirroredScene(loadedModelTransform.get());
|
||||
|
||||
// set the scene to render
|
||||
viewer.setSceneData(rootNode.get());
|
||||
viewer.setSceneData(rootNode);
|
||||
|
||||
// hint to tell viewer to request stencil buffer when setting up windows
|
||||
osg::DisplaySettings::instance()->setMinimumNumStencilBits(8);
|
||||
|
@ -726,7 +726,7 @@ int main(int argc, char** argv)
|
||||
}
|
||||
|
||||
// load the data
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFiles(arguments);
|
||||
if (!loadedModel)
|
||||
{
|
||||
std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl;
|
||||
@ -746,9 +746,9 @@ int main(int argc, char** argv)
|
||||
|
||||
// optimize the scene graph, remove redundant nodes and state etc.
|
||||
osgUtil::Optimizer optimizer;
|
||||
optimizer.optimize(loadedModel.get());
|
||||
optimizer.optimize(loadedModel);
|
||||
|
||||
viewer.setSceneData( loadedModel.get() );
|
||||
viewer.setSceneData(loadedModel);
|
||||
|
||||
|
||||
if (pbuffer.valid())
|
||||
|
@ -40,55 +40,55 @@ int main( int argc, char **argv )
|
||||
osgViewer::Viewer viewer;
|
||||
|
||||
// load the nodes from the commandline arguments.
|
||||
osg::Node* loadedModel = osgDB::readNodeFiles(arguments);
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFiles(arguments);
|
||||
|
||||
// if not loaded assume no arguments passed in, try use default mode instead.
|
||||
if (!loadedModel) loadedModel = osgDB::readNodeFile("cow.osgt");
|
||||
|
||||
if (!loadedModel) loadedModel = osgDB::readRefNodeFile("cow.osgt");
|
||||
|
||||
if (!loadedModel)
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Please specify a model filename on the command line."<<std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// to do scribe mode we create a top most group to contain the
|
||||
// original model, and then a second group contains the same model
|
||||
// but overrides various state attributes, so that the second instance
|
||||
// is rendered as wireframe.
|
||||
|
||||
osg::Group* rootnode = new osg::Group;
|
||||
|
||||
osg::Group* decorator = new osg::Group;
|
||||
|
||||
osg::ref_ptr<osg::Group> rootnode = new osg::Group;
|
||||
|
||||
osg::ref_ptr<osg::Group> decorator = new osg::Group;
|
||||
|
||||
rootnode->addChild(loadedModel);
|
||||
|
||||
|
||||
|
||||
|
||||
rootnode->addChild(decorator);
|
||||
|
||||
decorator->addChild(loadedModel);
|
||||
|
||||
decorator->addChild(loadedModel);
|
||||
|
||||
// set up the state so that the underlying color is not seen through
|
||||
// and that the drawing mode is changed to wireframe, and a polygon offset
|
||||
// is added to ensure that we see the wireframe itself, and turn off
|
||||
// is added to ensure that we see the wireframe itself, and turn off
|
||||
// so texturing too.
|
||||
osg::StateSet* stateset = new osg::StateSet;
|
||||
osg::PolygonOffset* polyoffset = new osg::PolygonOffset;
|
||||
osg::ref_ptr<osg::StateSet> stateset = new osg::StateSet;
|
||||
osg::ref_ptr<osg::PolygonOffset> polyoffset = new osg::PolygonOffset;
|
||||
polyoffset->setFactor(-1.0f);
|
||||
polyoffset->setUnits(-1.0f);
|
||||
osg::PolygonMode* polymode = new osg::PolygonMode;
|
||||
osg::ref_ptr<osg::PolygonMode> polymode = new osg::PolygonMode;
|
||||
polymode->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::LINE);
|
||||
stateset->setAttributeAndModes(polyoffset,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
stateset->setAttributeAndModes(polymode,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
|
||||
#if 1
|
||||
osg::Material* material = new osg::Material;
|
||||
osg::ref_ptr<osg::Material> material = new osg::Material;
|
||||
stateset->setAttributeAndModes(material,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF);
|
||||
#else
|
||||
// version which sets the color of the wireframe.
|
||||
osg::Material* material = new osg::Material;
|
||||
material->setColorMode(osg::Material::OFF); // switch glColor usage off
|
||||
// turn all lighting off
|
||||
// turn all lighting off
|
||||
material->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0,0.0f,0.0f,1.0f));
|
||||
material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0,0.0f,0.0f,1.0f));
|
||||
material->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0,0.0f,0.0f,1.0f));
|
||||
@ -99,21 +99,21 @@ int main( int argc, char **argv )
|
||||
#endif
|
||||
|
||||
stateset->setTextureMode(0,GL_TEXTURE_2D,osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF);
|
||||
|
||||
|
||||
// osg::LineStipple* linestipple = new osg::LineStipple;
|
||||
// linestipple->setFactor(1);
|
||||
// linestipple->setPattern(0xf0f0);
|
||||
// stateset->setAttributeAndModes(linestipple,osg::StateAttribute::OVERRIDE_ON);
|
||||
|
||||
|
||||
decorator->setStateSet(stateset);
|
||||
|
||||
|
||||
|
||||
|
||||
// run optimization over the scene graph
|
||||
osgUtil::Optimizer optimzer;
|
||||
optimzer.optimize(rootnode);
|
||||
|
||||
|
||||
// add a viewport to the viewer and attach the scene graph.
|
||||
viewer.setSceneData( rootnode );
|
||||
|
||||
|
||||
return viewer.run();
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ osg::Sequence* createSequence(osg::ArgumentParser& arguments)
|
||||
|
||||
typedef std::vector<std::string> Filenames;
|
||||
Filenames filenames;
|
||||
|
||||
|
||||
if (arguments.argc() > 1)
|
||||
{
|
||||
for (int i = 1; i < arguments.argc(); ++i)
|
||||
@ -139,17 +139,17 @@ osg::Sequence* createSequence(osg::ArgumentParser& arguments)
|
||||
filenames.push_back("cessna.osgt");
|
||||
filenames.push_back("glider.osgt");
|
||||
}
|
||||
|
||||
|
||||
for(Filenames::iterator itr = filenames.begin();
|
||||
itr != filenames.end();
|
||||
++itr)
|
||||
++itr)
|
||||
{
|
||||
// load model
|
||||
osg::Node* node = osgDB::readNodeFile(*itr);
|
||||
osg::ref_ptr<osg::Node> node = osgDB::readRefNodeFile(*itr);
|
||||
|
||||
if (node)
|
||||
{
|
||||
seq->addChild(createScaledNode(node, 100.0f));
|
||||
seq->addChild(createScaledNode(node.get(), 100.0f));
|
||||
seq->setTime(seq->getNumChildren()-1, 1.0f);
|
||||
}
|
||||
}
|
||||
@ -231,7 +231,7 @@ int main( int argc, char **argv )
|
||||
{
|
||||
// use an ArgumentParser object to manage the program arguments.
|
||||
osg::ArgumentParser arguments(&argc,argv);
|
||||
|
||||
|
||||
// construct the viewer.
|
||||
osgViewer::Viewer viewer;
|
||||
// root
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
osg::Node* createOldShaderCompositionScene(osg::ArgumentParser& arguments)
|
||||
{
|
||||
osg::Node* node = osgDB::readNodeFiles(arguments);
|
||||
osg::ref_ptr<osg::Node> node = osgDB::readRefNodeFiles(arguments);
|
||||
if (!node) return 0;
|
||||
|
||||
osg::Group* group = new osg::Group;
|
||||
|
@ -25,7 +25,7 @@ extern osg::Node* createOldShaderCompositionScene(osg::ArgumentParser& arguments
|
||||
|
||||
osg::Node* createNewShaderCompositionScene(osg::ArgumentParser& arguments)
|
||||
{
|
||||
osg::ref_ptr<osg::Node> node = osgDB::readNodeFiles(arguments);
|
||||
osg::ref_ptr<osg::Node> node = osgDB::readRefNodeFiles(arguments);
|
||||
if (!node) return 0;
|
||||
|
||||
osg::ref_ptr<osg::Group> group = new osg::Group;
|
||||
@ -34,21 +34,21 @@ osg::Node* createNewShaderCompositionScene(osg::ArgumentParser& arguments)
|
||||
osg::ref_ptr<osg::Program> program = new osg::Program;
|
||||
stateset->setAttribute(program.get());
|
||||
|
||||
osg::ref_ptr<osg::Shader> lighting_shader = osgDB::readShaderFile("shaders/lighting.vert");
|
||||
osg::ref_ptr<osg::Shader> lighting_shader = osgDB::readRefShaderFile("shaders/lighting.vert");
|
||||
if (lighting_shader.valid())
|
||||
{
|
||||
program->addShader(lighting_shader.get());
|
||||
OSG_NOTICE<<"Adding lighting shader"<<std::endl;
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::Shader> vertex_shader = osgDB::readShaderFile("shaders/osgshadercomposition.vert");
|
||||
osg::ref_ptr<osg::Shader> vertex_shader = osgDB::readRefShaderFile("shaders/osgshadercomposition.vert");
|
||||
if (vertex_shader.valid())
|
||||
{
|
||||
program->addShader(vertex_shader.get());
|
||||
OSG_NOTICE<<"Adding vertex shader"<<std::endl;
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::Shader> fragment_shader = osgDB::readShaderFile("shaders/osgshadercomposition.frag");
|
||||
osg::ref_ptr<osg::Shader> fragment_shader = osgDB::readRefShaderFile("shaders/osgshadercomposition.frag");
|
||||
if (fragment_shader.valid())
|
||||
{
|
||||
program->addShader(fragment_shader.get());
|
||||
|
@ -1,9 +1,9 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* This application is open source and may be redistributed and/or modified
|
||||
* This application is open source and may be redistributed and/or modified
|
||||
* freely and without restriction, both in commercial and non commercial applications,
|
||||
* as long as this copyright notice is maintained.
|
||||
*
|
||||
*
|
||||
* This application 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.
|
||||
@ -70,14 +70,14 @@ int main(int argc, char** argv)
|
||||
arguments.getApplicationUsage()->write(std::cout, helpType);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// report any errors if they have occurred when parsing the program arguments.
|
||||
if (arguments.errors())
|
||||
{
|
||||
arguments.writeErrorMessages(std::cout);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
if (arguments.argc()<=1)
|
||||
{
|
||||
arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION);
|
||||
@ -98,7 +98,7 @@ int main(int argc, char** argv)
|
||||
while (arguments.read("-p",pathfile))
|
||||
{
|
||||
osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile);
|
||||
if (apm || !apm->valid())
|
||||
if (apm || !apm->valid())
|
||||
{
|
||||
unsigned int num = keyswitchManipulator->getNumMatrixManipulators();
|
||||
keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm );
|
||||
@ -112,13 +112,13 @@ int main(int argc, char** argv)
|
||||
|
||||
// add the state manipulator
|
||||
viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) );
|
||||
|
||||
|
||||
// add the thread model handler
|
||||
viewer.addEventHandler(new osgViewer::ThreadingHandler);
|
||||
|
||||
// add the window size toggle handler
|
||||
viewer.addEventHandler(new osgViewer::WindowSizeHandler);
|
||||
|
||||
|
||||
// add the stats handler
|
||||
viewer.addEventHandler(new osgViewer::StatsHandler);
|
||||
|
||||
@ -133,7 +133,7 @@ int main(int argc, char** argv)
|
||||
|
||||
// add the screen capture handler
|
||||
viewer.addEventHandler(new osgViewer::ScreenCaptureHandler);
|
||||
|
||||
|
||||
// Register shader generator callback
|
||||
ShaderGenReadFileCallback *readFileCallback = new ShaderGenReadFileCallback;
|
||||
// All read nodes will inherit root state set.
|
||||
@ -141,8 +141,8 @@ int main(int argc, char** argv)
|
||||
osgDB::Registry::instance()->setReadFileCallback(readFileCallback);
|
||||
|
||||
// load the data
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
|
||||
if (!loadedModel)
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFiles(arguments);
|
||||
if (!loadedModel)
|
||||
{
|
||||
std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl;
|
||||
return 1;
|
||||
|
@ -121,7 +121,7 @@ osg::Node* createScene()
|
||||
stateset->setTextureAttributeAndModes(0,terrainTexture,osg::StateAttribute::ON);
|
||||
|
||||
|
||||
osg::Image* image = osgDB::readImageFile("Images/lz.rgb");
|
||||
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile("Images/lz.rgb");
|
||||
if (image)
|
||||
{
|
||||
osg::Texture2D* texture = new osg::Texture2D;
|
||||
|
@ -390,7 +390,7 @@ namespace ModelTwo
|
||||
|
||||
// set up the texture of the base.
|
||||
osg::StateSet* stateset = new osg::StateSet();
|
||||
osg::Image* image = osgDB::readImageFile("Images/lz.rgb");
|
||||
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile("Images/lz.rgb");
|
||||
if (image)
|
||||
{
|
||||
osg::Texture2D* texture = new osg::Texture2D;
|
||||
@ -451,7 +451,7 @@ namespace ModelTwo
|
||||
|
||||
osg::Group* model = new osg::Group;
|
||||
|
||||
osg::Node* cessna = osgDB::readNodeFile("cessna.osgt");
|
||||
osg::ref_ptr<osg::Node> cessna = osgDB::readRefNodeFile("cessna.osgt");
|
||||
if (cessna)
|
||||
{
|
||||
const osg::BoundingSphere& bs = cessna->getBound();
|
||||
@ -571,7 +571,7 @@ namespace ModelThree
|
||||
|
||||
if (withBaseTexture)
|
||||
{
|
||||
scene->getOrCreateStateSet()->setTextureAttributeAndModes( 0, new osg::Texture2D(osgDB::readImageFile("Images/lz.rgb")), osg::StateAttribute::ON);
|
||||
scene->getOrCreateStateSet()->setTextureAttributeAndModes( 0, new osg::Texture2D(osgDB::readRefImageFile("Images/lz.rgb")), osg::StateAttribute::ON);
|
||||
}
|
||||
|
||||
return scene;
|
||||
@ -626,13 +626,13 @@ namespace ModelFive
|
||||
{
|
||||
// Set the ground (only receives shadow)
|
||||
osg::ref_ptr<osg::MatrixTransform> groundNode = new osg::MatrixTransform;
|
||||
groundNode->addChild( osgDB::readNodeFile("lz.osg") );
|
||||
groundNode->addChild( osgDB::readRefNodeFile("lz.osg") );
|
||||
groundNode->setMatrix( osg::Matrix::translate(200.0f, 200.0f,-200.0f) );
|
||||
groundNode->setNodeMask( ReceivesShadowTraversalMask );
|
||||
|
||||
// Set the cessna (only casts shadow)
|
||||
osg::ref_ptr<osg::MatrixTransform> cessnaNode = new osg::MatrixTransform;
|
||||
cessnaNode->addChild( osgDB::readNodeFile("cessna.osg.0,0,90.rot") );
|
||||
cessnaNode->addChild( osgDB::readRefNodeFile("cessna.osg.0,0,90.rot") );
|
||||
cessnaNode->addUpdateCallback( createAnimationPathCallback(50.0f, 6.0f) );
|
||||
cessnaNode->setNodeMask( CastsShadowTraversalMask );
|
||||
|
||||
@ -1025,7 +1025,7 @@ int main(int argc, char** argv)
|
||||
|
||||
OSG_INFO<<"shadowedScene->getShadowTechnique()="<<shadowedScene->getShadowTechnique()<<std::endl;
|
||||
|
||||
osg::ref_ptr<osg::Node> model = osgDB::readNodeFiles(arguments);
|
||||
osg::ref_ptr<osg::Node> model = osgDB::readRefNodeFiles(arguments);
|
||||
if (model.valid())
|
||||
{
|
||||
model->setNodeMask(CastsShadowTraversalMask | ReceivesShadowTraversalMask);
|
||||
@ -1061,7 +1061,7 @@ int main(int argc, char** argv)
|
||||
|
||||
geode->setNodeMask(shadowedScene->getReceivesShadowTraversalMask());
|
||||
|
||||
geode->getOrCreateStateSet()->setTextureAttributeAndModes(0, new osg::Texture2D(osgDB::readImageFile("Images/lz.rgb")));
|
||||
geode->getOrCreateStateSet()->setTextureAttributeAndModes(0, new osg::Texture2D(osgDB::readRefImageFile("Images/lz.rgb")));
|
||||
|
||||
shadowedScene->addChild(geode);
|
||||
}
|
||||
|
@ -36,13 +36,13 @@ osg::Geode* createShapes()
|
||||
{
|
||||
osg::Geode* geode = new osg::Geode();
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------
|
||||
// Set up a StateSet to texture the objects
|
||||
// ---------------------------------------
|
||||
osg::StateSet* stateset = new osg::StateSet();
|
||||
|
||||
osg::Image* image = osgDB::readImageFile( "Images/lz.rgb" );
|
||||
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile( "Images/lz.rgb" );
|
||||
if (image)
|
||||
{
|
||||
osg::Texture2D* texture = new osg::Texture2D;
|
||||
@ -50,18 +50,18 @@ osg::Geode* createShapes()
|
||||
texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR);
|
||||
stateset->setTextureAttributeAndModes(0,texture, osg::StateAttribute::ON);
|
||||
}
|
||||
|
||||
|
||||
stateset->setMode(GL_LIGHTING, osg::StateAttribute::ON);
|
||||
|
||||
|
||||
geode->setStateSet( stateset );
|
||||
|
||||
|
||||
|
||||
float radius = 0.8f;
|
||||
float height = 1.0f;
|
||||
|
||||
|
||||
osg::TessellationHints* hints = new osg::TessellationHints;
|
||||
hints->setDetailRatio(0.5f);
|
||||
|
||||
|
||||
geode->addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0.0f,0.0f,0.0f),radius),hints));
|
||||
geode->addDrawable(new osg::ShapeDrawable(new osg::Box(osg::Vec3(2.0f,0.0f,0.0f),2*radius),hints));
|
||||
geode->addDrawable(new osg::ShapeDrawable(new osg::Cone(osg::Vec3(4.0f,0.0f,0.0f),radius,height),hints));
|
||||
@ -72,7 +72,7 @@ osg::Geode* createShapes()
|
||||
grid->allocate(38,39);
|
||||
grid->setXInterval(0.28f);
|
||||
grid->setYInterval(0.28f);
|
||||
|
||||
|
||||
for(unsigned int r=0;r<39;++r)
|
||||
{
|
||||
for(unsigned int c=0;c<38;++c)
|
||||
@ -81,7 +81,7 @@ osg::Geode* createShapes()
|
||||
}
|
||||
}
|
||||
geode->addDrawable(new osg::ShapeDrawable(grid));
|
||||
|
||||
|
||||
osg::ConvexHull* mesh = new osg::ConvexHull;
|
||||
osg::Vec3Array* vertices = new osg::Vec3Array(4);
|
||||
(*vertices)[0].set(9.0+0.0f,-1.0f+2.0f,-1.0f+0.0f);
|
||||
|
@ -41,7 +41,7 @@ using namespace osg;
|
||||
using namespace osgGA;
|
||||
|
||||
|
||||
class SwitchDOFVisitor : public osg::NodeVisitor, public osgGA::GUIEventHandler
|
||||
class SwitchDOFVisitor : public osg::NodeVisitor, public osgGA::GUIEventHandler
|
||||
{
|
||||
public:
|
||||
SwitchDOFVisitor():
|
||||
@ -52,11 +52,11 @@ public:
|
||||
SwitchDOFVisitor(const SwitchDOFVisitor& sdfv, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) {}
|
||||
|
||||
META_Object(osg, SwitchDOFVisitor)
|
||||
|
||||
|
||||
virtual void apply(Group& node)
|
||||
{
|
||||
osgSim::MultiSwitch* pMSwitch = dynamic_cast<osgSim::MultiSwitch*>(&node);
|
||||
|
||||
|
||||
if (pMSwitch)
|
||||
{
|
||||
mSwitches.push_back(pMSwitch);
|
||||
@ -64,11 +64,11 @@ public:
|
||||
|
||||
osg::NodeVisitor::apply(node);
|
||||
}
|
||||
|
||||
|
||||
virtual void apply(Transform& node)
|
||||
{
|
||||
osgSim::DOFTransform* pDof = dynamic_cast<osgSim::DOFTransform*>(&node);
|
||||
|
||||
|
||||
if (pDof)
|
||||
{
|
||||
mDofs.push_back(pDof);
|
||||
@ -159,12 +159,12 @@ private:
|
||||
void singleWindowSideBySideCameras(osgViewer::Viewer& viewer)
|
||||
{
|
||||
osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
|
||||
if (!wsi)
|
||||
if (!wsi)
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Error, no WindowSystemInterface available, cannot create windows."<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
unsigned int width, height;
|
||||
wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height);
|
||||
|
||||
@ -237,14 +237,14 @@ int main( int argc, char **argv )
|
||||
// use an ArgumentParser object to manage the program arguments.
|
||||
osg::ArgumentParser arguments(&argc,argv);
|
||||
|
||||
if (argc<2)
|
||||
if (argc<2)
|
||||
{
|
||||
std::cout << argv[0] <<": requires filename argument." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
osgViewer::Viewer viewer(arguments);
|
||||
|
||||
|
||||
std::string outputfile("output.osgt");
|
||||
while (arguments.read("-o",outputfile)) {}
|
||||
|
||||
@ -252,7 +252,7 @@ int main( int argc, char **argv )
|
||||
while (arguments.read("-g")) { viewer.setThreadingModel(osgViewer::Viewer::CullDrawThreadPerContext); }
|
||||
while (arguments.read("-d")) { viewer.setThreadingModel(osgViewer::Viewer::DrawThreadPerContext); }
|
||||
while (arguments.read("-c")) { viewer.setThreadingModel(osgViewer::Viewer::CullThreadPerCameraDrawThreadPerContext); }
|
||||
|
||||
|
||||
singleWindowSideBySideCameras(viewer);
|
||||
|
||||
viewer.setCameraManipulator( new osgGA::TrackballManipulator() );
|
||||
@ -264,30 +264,26 @@ int main( int argc, char **argv )
|
||||
|
||||
SwitchDOFVisitor* visit = new SwitchDOFVisitor;
|
||||
viewer.addEventHandler(visit);
|
||||
|
||||
osg::ref_ptr<osg::Node> loadedModel;
|
||||
// load the scene.
|
||||
loadedModel = osgDB::readNodeFiles(arguments);
|
||||
|
||||
if (!loadedModel)
|
||||
// load the scene.
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFiles(arguments);
|
||||
if (!loadedModel)
|
||||
{
|
||||
std::cout << argv[0] <<": No data loaded." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
osg::Group* group = new osg::Group;
|
||||
|
||||
|
||||
osg::Group* group1 = new osg::Group;
|
||||
group1->addChild(loadedModel.get());
|
||||
group1->addChild(loadedModel);
|
||||
group1->setNodeMask(1);
|
||||
|
||||
// Uncomment these lines if you like to compare the loaded model to the resulting model in a merge/diff tool
|
||||
//osgDB::writeNodeFile(*loadedModel.get(), "dummy1.osgt");
|
||||
|
||||
osgDB::writeNodeFile(*loadedModel.get(), outputfile);
|
||||
osg::ref_ptr<osg::Node> convertedModel = osgDB::readNodeFile(outputfile);
|
||||
|
||||
//osgDB::writeNodeFile(*convertedModel.get(), "dummy2.osgt");
|
||||
osgDB::writeNodeFile(*loadedModel, outputfile);
|
||||
osg::ref_ptr<osg::Node> convertedModel = osgDB::readRefNodeFile(outputfile);
|
||||
|
||||
osg::Group* group2 = new osg::Group;
|
||||
group2->addChild(convertedModel.get());
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user