Replaced deprecated osg::Geometry::set*Binding() usage.

This commit is contained in:
Robert Osfield 2013-06-27 09:59:33 +00:00
parent 87add5f508
commit 592c580721
6 changed files with 132 additions and 146 deletions

View File

@ -1,14 +1,14 @@
/* -*-c++-*-
/* -*-c++-*-
* Copyright (C) 2010 Jeremy Moles <cubicool@gmail.com>
*
* 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.
*/
@ -50,8 +50,7 @@ osg::Geometry* createEaseMotionGeometry(osgAnimation::Motion* motion) {
geom->setUseDisplayList(false);
geom->setVertexArray(v);
geom->setColorArray(cols);
geom->setColorBinding(osg::Geometry::BIND_OVERALL);
geom->setColorArray(cols, osg::Array::BIND_OVERALL);
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP, 0, v->size()));
return geom;
@ -105,11 +104,11 @@ struct ColorLabel: public osgWidget::Label {
setFont("fonts/VeraMono.ttf");
setFontSize(14);
setFontColor(1.0f, 1.0f, 1.0f, 1.0f);
setColor(0.3f, 0.3f, 0.3f, 1.0f);
setPadding(2.0f);
setCanFill(true);
addSize(150.0f, 25.0f);
setLabel(label);
@ -118,9 +117,9 @@ struct ColorLabel: public osgWidget::Label {
bool mousePush(double, double, const osgWidget::WindowManager*) {
osgWidget::Table* p = dynamic_cast<osgWidget::Table*>(_parent);
if(!p) return false;
p->hide();
const std::string& name = getName();
@ -232,7 +231,7 @@ struct ColorLabel: public osgWidget::Label {
else if(!name.compare("InOutExpoMotion"))
EASE_MOTION_SAMPLER->setMotion<osgAnimation::InOutExpoMotion>()
;
else EASE_MOTION_SAMPLER->setMotion<osgAnimation::LinearMotion>();
return true;
@ -240,13 +239,13 @@ struct ColorLabel: public osgWidget::Label {
bool mouseEnter(double, double, const osgWidget::WindowManager*) {
setColor(0.9f, 0.6f, 0.1f, 1.0f);
return true;
}
bool mouseLeave(double, double, const osgWidget::WindowManager*) {
setColor(0.3f, 0.3f, 0.3f, 1.0f);
return true;
}
};
@ -286,7 +285,7 @@ public:
_window->addWidget(new ColorLabel("OutCircMotion"), 3, 3);
_window->addWidget(new ColorLabel("InCircMotion"), 4, 3);
_window->addWidget(new ColorLabel("InOutCircMotion"), 5, 3);
_window->addWidget(new ColorLabel("OutExpoMotion"), 0, 4);
_window->addWidget(new ColorLabel("InExpoMotion"), 1, 4);
_window->addWidget(new ColorLabel("InOutExpoMotion"), 2, 4);

View File

@ -1,14 +1,14 @@
/* -*-c++-*-
/* -*-c++-*-
* Copyright (C) 2008 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.
*/
@ -34,7 +34,7 @@
osg::Geode* createAxis()
{
osg::Geode* geode (new osg::Geode());
osg::Geode* geode (new osg::Geode());
osg::Geometry* geometry (new osg::Geometry());
osg::Vec3Array* vertices (new osg::Vec3Array());
@ -53,9 +53,7 @@ osg::Geode* createAxis()
colors->push_back (osg::Vec4 (0.0f, 1.0f, 0.0f, 1.0f));
colors->push_back (osg::Vec4 (0.0f, 0.0f, 1.0f, 1.0f));
colors->push_back (osg::Vec4 (0.0f, 0.0f, 1.0f, 1.0f));
geometry->setColorArray (colors);
geometry->setColorBinding (osg::Geometry::BIND_PER_VERTEX);
geometry->setColorArray (colors, osg::Array::BIND_PER_VERTEX);
geometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES,0,6));
geode->addDrawable( geometry );
@ -70,12 +68,11 @@ osgAnimation::RigGeometry* createTesselatedBox(int nsplit, float size)
osg::ref_ptr<osg::Vec3Array> vertices (new osg::Vec3Array());
osg::ref_ptr<osg::Vec3Array> colors (new osg::Vec3Array());
geometry->setVertexArray (vertices.get());
geometry->setColorArray (colors.get());
geometry->setColorBinding (osg::Geometry::BIND_PER_VERTEX);
geometry->setColorArray (colors.get(), osg::Array::BIND_PER_VERTEX);
float step = size / static_cast<float>(nsplit);
float s = 0.5f/4.0f;
for (int i = 0; i < nsplit; i++)
for (int i = 0; i < nsplit; i++)
{
float x = -1.0f + static_cast<float>(i) * step;
std::cout << x << std::endl;
@ -92,7 +89,7 @@ osgAnimation::RigGeometry* createTesselatedBox(int nsplit, float size)
}
osg::ref_ptr<osg::UIntArray> array = new osg::UIntArray;
for (int i = 0; i < nsplit - 1; i++)
for (int i = 0; i < nsplit - 1; i++)
{
int base = i * 4;
array->push_back(base);
@ -123,7 +120,7 @@ osgAnimation::RigGeometry* createTesselatedBox(int nsplit, float size)
array->push_back(base+2);
array->push_back(base+7);
}
geometry->addPrimitiveSet(new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, array->size(), &array->front()));
geometry->setUseDisplayList( false );
riggeometry->setSourceGeometry(geometry);
@ -144,7 +141,7 @@ void initVertexMap(osgAnimation::Bone* b0,
(*vim)[b1->getName()].setName(b1->getName());
(*vim)[b2->getName()].setName(b2->getName());
for (int i = 0; i < (int)array->size(); i++)
for (int i = 0; i < (int)array->size(); i++)
{
float val = (*array)[i][0];
std::cout << val << std::endl;
@ -229,7 +226,7 @@ int main (int argc, char* argv[])
}
manager->registerAnimation(anim);
manager->buildTargetReference();
// let's start !
manager->playAnimation(anim);
@ -247,7 +244,7 @@ int main (int argc, char* argv[])
trueroot->setDataVariance(osg::Object::DYNAMIC);
rootTransform->addChild(trueroot);
scene->addChild(rootTransform);
osgAnimation::RigGeometry* geom = createTesselatedBox(4, 4.0f);
osg::Geode* geode = new osg::Geode;
geode->addDrawable(geom);

View File

@ -1,14 +1,14 @@
/* -*-c++-*-
/* -*-c++-*-
* Copyright (C) 2008 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.
*/
@ -30,7 +30,7 @@ using namespace osgAnimation;
osg::ref_ptr<osg::Geode> createAxis()
{
osg::ref_ptr<osg::Geode> geode (new osg::Geode());
osg::ref_ptr<osg::Geode> geode (new osg::Geode());
osg::ref_ptr<osg::Geometry> geometry (new osg::Geometry());
osg::ref_ptr<osg::Vec3Array> vertices (new osg::Vec3Array());
@ -49,9 +49,7 @@ osg::ref_ptr<osg::Geode> createAxis()
colors->push_back (osg::Vec4 (0.0f, 1.0f, 0.0f, 1.0f));
colors->push_back (osg::Vec4 (0.0f, 0.0f, 1.0f, 1.0f));
colors->push_back (osg::Vec4 (0.0f, 0.0f, 1.0f, 1.0f));
geometry->setColorArray (colors.get());
geometry->setColorBinding (osg::Geometry::BIND_PER_VERTEX);
geometry->setColorArray (colors.get(), osg::Array::BIND_PER_VERTEX);
geometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES,0,6));
geode->addDrawable( geometry.get() );
@ -114,7 +112,7 @@ int main (int argc, char* argv[])
channelAnimation1->getOrCreateSampler()->getOrCreateKeyframeContainer()->push_back(osgAnimation::Vec3Keyframe(0, osg::Vec3(0,0,0)));
channelAnimation1->getOrCreateSampler()->getOrCreateKeyframeContainer()->push_back(osgAnimation::Vec3Keyframe(2, osg::Vec3(1,1,0)));
osgAnimation::Animation* anim1 = new osgAnimation::Animation;
anim1->addChannel(channelAnimation1);
anim1->addChannel(channelAnimation1);
anim1->setPlayMode(osgAnimation::Animation::PPONG);
@ -130,12 +128,12 @@ int main (int argc, char* argv[])
osgAnimation::Animation* anim2 = new osgAnimation::Animation;
anim2->addChannel(channelAnimation2);
anim2->setPlayMode(osgAnimation::Animation::LOOP);
// We register all animation inside the scheduler
mng->registerAnimation(anim1);
mng->registerAnimation(anim2);
//start the animation
mng->playAnimation(anim1);
mng->playAnimation(anim2);

View File

@ -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.
*
* Authors:
@ -37,13 +37,13 @@ const int WIDTH = 1440;
const int HEIGHT = 900;
osg::Geode* createAxis()
osg::Geode* createAxis()
{
osg::Geode* geode = new osg::Geode();
osg::Geode* geode = new osg::Geode();
osg::Geometry* geometry = new osg::Geometry();
osg::Vec3Array* vertices = new osg::Vec3Array();
osg::Vec4Array* colors = new osg::Vec4Array();
vertices->push_back(osg::Vec3(0.0f, 0.0f, 0.0f));
vertices->push_back(osg::Vec3(1.0f, 0.0f, 0.0f));
vertices->push_back(osg::Vec3(0.0f, 0.0f, 0.0f));
@ -57,10 +57,9 @@ osg::Geode* createAxis()
colors->push_back(osg::Vec4(0.0f, 1.0f, 0.0f, 1.0f));
colors->push_back(osg::Vec4(0.0f, 0.0f, 1.0f, 1.0f));
colors->push_back(osg::Vec4(0.0f, 0.0f, 1.0f, 1.0f));
geometry->setVertexArray(vertices);
geometry->setColorArray(colors);
geometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
geometry->setColorArray(colors, osg::Array::BIND_PER_VERTEX);
geometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, 0, 6));
geometry->getOrCreateStateSet()->setMode(GL_LIGHTING, false);
@ -100,7 +99,7 @@ struct AddHelperBone : public osg::NodeVisitor
}
};
int main(int argc, char** argv)
int main(int argc, char** argv)
{
osg::ArgumentParser arguments(&argc, argv);
arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName());
@ -153,7 +152,7 @@ int main(int argc, char** argv)
AnimtkViewerGUI* gui = new AnimtkViewerGUI(&viewer, WIDTH, HEIGHT, 0x1234);
osg::Camera* camera = gui->createParentOrthoCamera();
node->setNodeMask(0x0001);
group->addChild(node);

View File

@ -33,7 +33,7 @@ ImageReaderWriter::DataReference::DataReference():
_center(0.625f,0.0f,0.0f),
_maximumWidth(1.25f,0.0f,0.0f),
_maximumHeight(0.0f,0.0f,1.0f),
_numPointsAcross(10),
_numPointsAcross(10),
_numPointsUp(10),
_backPage(false) {}
@ -44,7 +44,7 @@ ImageReaderWriter::DataReference::DataReference(const std::string& fileName, uns
_center(width*0.5f,0.0f,height*0.5f),
_maximumWidth(width,0.0f,0.0f),
_maximumHeight(0.0f,0.0f,height),
_numPointsAcross(10),
_numPointsAcross(10),
_numPointsUp(10),
_backPage(backPage) {}
@ -55,7 +55,7 @@ ImageReaderWriter::DataReference::DataReference(const DataReference& rhs):
_center(rhs._center),
_maximumWidth(rhs._maximumWidth),
_maximumHeight(rhs._maximumHeight),
_numPointsAcross(rhs._numPointsAcross),
_numPointsAcross(rhs._numPointsAcross),
_numPointsUp(rhs._numPointsUp),
_backPage(rhs._backPage) {}
@ -121,11 +121,11 @@ osgDB::ReaderWriter::ReadResult ImageReaderWriter::local_readNode(const std::str
osg::Image* image = 0;
float s=1.0f,t=1.0f;
// try to load photo from any loaded PhotoArchives
if (!_photoArchiveList.empty())
image = readImage_Archive(dr,s,t);
// not loaded yet, so try to load it directly.
if (!image)
image = readImage_DynamicSampling(dr,s,t);
@ -210,8 +210,7 @@ osgDB::ReaderWriter::ReadResult ImageReaderWriter::local_readNode(const std::str
osg::Vec4Array* colours = new osg::Vec4Array(1);
(*colours)[0].set(1.0f,1.0f,1.0,1.0f);
geom->setColorArray(colours);
geom->setColorBinding(osg::Geometry::BIND_OVERALL);
geom->setColorArray(colours, osg::Array::BIND_OVERALL);
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4));

View File

@ -38,7 +38,7 @@ using namespace osg;
// now register with Registry to instantiate the above reader/writer,
// declaring in main so that the code to set up PagedLOD can get a handle
// to the ImageReaderWriter's
// to the ImageReaderWriter's
osgDB::RegisterReaderWriterProxy<ImageReaderWriter> g_ImageReaderWriter;
class Album;
@ -54,13 +54,13 @@ public:
if (page.valid()) return page.release();
else return 0;
}
virtual void traverse(osg::NodeVisitor& nv);
void setRotation(float angle)
{
_rotation = angle;
_targetRotation = angle;
_rotation = angle;
_targetRotation = angle;
dirtyBound();
}
@ -68,10 +68,10 @@ public:
void rotateTo(float angle, float timeToRotateBy)
{
_targetRotation = angle;
_targetRotation = angle;
_targetTime = timeToRotateBy;
}
bool rotating() const { return _targetRotation!=_rotation; }
void setPageVisible(bool frontVisible,bool backVisible)
@ -86,7 +86,7 @@ public:
public:
virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix,osg::NodeVisitor*) const
virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix,osg::NodeVisitor*) const
{
if (_referenceFrame==RELATIVE_RF)
{
@ -119,7 +119,7 @@ public:
osg::Matrix getInverseMatrix() const { return osg::Matrix::inverse(getMatrix()); }
protected:
Page(Album* album, unsigned int pageNo, const std::string& frontFileName, const std::string& backFileName, float width, float height);
float _rotation;
@ -141,19 +141,19 @@ public:
Album(osg::ArgumentParser& ap, float width, float height);
osg::Group* getScene() { return _group.get(); }
const osg::Group* getScene() const { return _group.get(); }
osg::Matrix getPageOffset(unsigned int pageNo) const;
bool nextPage(float timeToRotateBy) { return gotoPage(_currentPageNo+1,timeToRotateBy); }
bool previousPage(float timeToRotateBy) { return _currentPageNo>=1?gotoPage(_currentPageNo-1,timeToRotateBy):false; }
bool gotoPage(unsigned int pageNo, float timeToRotateBy);
osg::StateSet* getBackgroundStateSet() { return _backgroundStateSet.get(); }
void setVisibility();
protected:
@ -162,13 +162,13 @@ protected:
osg::ref_ptr<osg::Group> _group;
PageList _pages;
osg::ref_ptr<osg::StateSet> _backgroundStateSet;
unsigned int _currentPageNo;
float _radiusOfRings;
float _startAngleOfPages;
float _deltaAngleBetweenPages;
float _deltaAngleBetweenPages;
};
@ -183,12 +183,12 @@ Page::Page(Album* album, unsigned int pageNo, const std::string& frontFileName,
_targetRotation = 0;
_targetTime = 0;
_lastTimeTraverse = 0;
_pageOffset = album->getPageOffset(pageNo);
setNumChildrenRequiringUpdateTraversal(1);
// set up subgraph
osgDB::ReaderWriter* readerWriter = osgDB::Registry::instance()->getReaderWriterForExtension("gdal");
if (!readerWriter)
@ -200,7 +200,7 @@ Page::Page(Album* album, unsigned int pageNo, const std::string& frontFileName,
ImageReaderWriter* rw = g_ImageReaderWriter.get();
// set up non visible page.
osg::Group* non_visible_page = new osg::Group;
_switch->addChild(non_visible_page);
@ -218,7 +218,7 @@ Page::Page(Album* album, unsigned int pageNo, const std::string& frontFileName,
(*coords)[6].set(width,0.0f,0.0f);
(*coords)[7].set(0.0f,0.0f,0.0f);
geom->setVertexArray(coords);
osg::Vec3Array* normals = new osg::Vec3Array(8);
(*normals)[0].set(-1.0f,0.0f,0.0f);
@ -229,8 +229,7 @@ Page::Page(Album* album, unsigned int pageNo, const std::string& frontFileName,
(*normals)[5].set(1.0f,0.0f,0.0f);
(*normals)[6].set(0.0f,0.0f,1.0f);
(*normals)[7].set(0.0f,0.0f,1.0f);
geom->setNormalArray(normals);
geom->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);
geom->setNormalArray(normals, osg::Array::BIND_PER_VERTEX);
osg::Vec2Array* tcoords = new osg::Vec2Array(8);
(*tcoords)[0].set(0.0f,0.0f);
@ -245,16 +244,15 @@ Page::Page(Album* album, unsigned int pageNo, const std::string& frontFileName,
osg::Vec4Array* colours = new osg::Vec4Array(1);
(*colours)[0].set(1.0f,1.0f,1.0,1.0f);
geom->setColorArray(colours);
geom->setColorBinding(osg::Geometry::BIND_OVERALL);
geom->setColorArray(colours, osg::Array::BIND_OVERALL);
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES,0,8));
// set up the geode.
osg::Geode* geode = new osg::Geode;
geode->addDrawable(geom);
non_visible_page->addChild(geode);
}
@ -277,8 +275,7 @@ Page::Page(Album* album, unsigned int pageNo, const std::string& frontFileName,
osg::Vec3Array* normals = new osg::Vec3Array(1);
(*normals)[0].set(0.0f,-1.0f,0.0f);
geom->setNormalArray(normals);
geom->setNormalBinding(osg::Geometry::BIND_OVERALL);
geom->setNormalArray(normals, osg::Array::BIND_OVERALL);
osg::Vec2Array* tcoords = new osg::Vec2Array(4);
(*tcoords)[0].set(0.0f,1.0f);
@ -289,16 +286,15 @@ Page::Page(Album* album, unsigned int pageNo, const std::string& frontFileName,
osg::Vec4Array* colours = new osg::Vec4Array(1);
(*colours)[0].set(1.0f,1.0f,1.0,1.0f);
geom->setColorArray(colours);
geom->setColorBinding(osg::Geometry::BIND_OVERALL);
geom->setColorArray(colours, osg::Array::BIND_OVERALL);
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4));
// set up the geode.
osg::Geode* geode = new osg::Geode;
geode->addDrawable(geom);
front_page->addChild(geode);
}
@ -306,7 +302,7 @@ Page::Page(Album* album, unsigned int pageNo, const std::string& frontFileName,
{
float cut_off_distance = 8.0f;
float max_visible_distance = 300.0f;
osg::Vec3 center(width*0.5f,0.0f,height*0.5f);
osgText::Text* text = new osgText::Text;
@ -320,15 +316,15 @@ Page::Page(Album* album, unsigned int pageNo, const std::string& frontFileName,
osg::Geode* geode = new osg::Geode;
geode->addDrawable(text);
osg::PagedLOD* pagedlod = new osg::PagedLOD;
pagedlod->setCenter(center);
pagedlod->setRadius(1.6f);
pagedlod->setNumChildrenThatCannotBeExpired(2);
pagedlod->setRange(0,max_visible_distance,1e7);
pagedlod->addChild(geode);
pagedlod->setRange(1,cut_off_distance,max_visible_distance);
pagedlod->setFileName(1,rw->insertReference(frontFileName,256,width,height,false));
@ -337,8 +333,8 @@ Page::Page(Album* album, unsigned int pageNo, const std::string& frontFileName,
front_page->addChild(pagedlod);
}
// set up back of page.
osg::Group* back_page = new osg::Group;
_switch->addChild(back_page);
@ -357,8 +353,7 @@ Page::Page(Album* album, unsigned int pageNo, const std::string& frontFileName,
osg::Vec3Array* normals = new osg::Vec3Array(1);
(*normals)[0].set(0.0f,1.0f,0.0f);
geom->setNormalArray(normals);
geom->setNormalBinding(osg::Geometry::BIND_OVERALL);
geom->setNormalArray(normals, osg::Array::BIND_OVERALL);
osg::Vec2Array* tcoords = new osg::Vec2Array(4);
(*tcoords)[0].set(1.0f,1.0f);
@ -369,16 +364,15 @@ Page::Page(Album* album, unsigned int pageNo, const std::string& frontFileName,
osg::Vec4Array* colours = new osg::Vec4Array(1);
(*colours)[0].set(1.0f,1.0f,1.0,1.0f);
geom->setColorArray(colours);
geom->setColorBinding(osg::Geometry::BIND_OVERALL);
geom->setColorArray(colours, osg::Array::BIND_OVERALL);
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4));
// set up the geode.
osg::Geode* geode = new osg::Geode;
geode->addDrawable(geom);
back_page->addChild(geode);
}
@ -386,7 +380,7 @@ Page::Page(Album* album, unsigned int pageNo, const std::string& frontFileName,
{
float cut_off_distance = 8.0f;
float max_visible_distance = 300.0f;
osg::Vec3 center(width*0.5f,0.0f,height*0.5f);
osgText::Text* text = new osgText::Text;
@ -400,15 +394,15 @@ Page::Page(Album* album, unsigned int pageNo, const std::string& frontFileName,
osg::Geode* geode = new osg::Geode;
geode->addDrawable(text);
osg::PagedLOD* pagedlod = new osg::PagedLOD;
pagedlod->setCenter(center);
pagedlod->setRadius(1.6f);
pagedlod->setNumChildrenThatCannotBeExpired(2);
pagedlod->setRange(0,max_visible_distance,1e7);
pagedlod->addChild(geode);
pagedlod->setRange(1,cut_off_distance,max_visible_distance);
pagedlod->setFileName(1,rw->insertReference(backFileName,256,width,height,true));
@ -430,15 +424,15 @@ void Page::traverse(osg::NodeVisitor& nv)
if (framestamp)
{
double t = framestamp->getSimulationTime();
if (_rotation!=_targetRotation)
{
if (t>=_targetTime) _rotation = _targetRotation;
else _rotation += (_targetRotation-_rotation)*(t-_lastTimeTraverse)/(_targetTime-_lastTimeTraverse);
dirtyBound();
}
_lastTimeTraverse = t;
}
@ -458,7 +452,7 @@ Album::Album(osg::ArgumentParser& arguments, float width, float height)
for(int pos=1;pos<arguments.argc();++pos)
{
if (arguments.isString(pos))
if (arguments.isString(pos))
{
std::string filename(arguments[pos]);
if (osgDB::getLowerCaseFileExtension(filename)=="album")
@ -469,7 +463,7 @@ Album::Album(osg::ArgumentParser& arguments, float width, float height)
g_ImageReaderWriter.get()->addPhotoArchive(photoArchive);
photoArchive->getImageFileNameList(fileList);
}
}
else
{
@ -477,17 +471,17 @@ Album::Album(osg::ArgumentParser& arguments, float width, float height)
}
}
}
_radiusOfRings = 0.02;
_startAngleOfPages = 0.0f;
_deltaAngleBetweenPages = osg::PI/(float)fileList.size();
_group = new osg::Group;
_group->getOrCreateStateSet()->setAttributeAndModes(new osg::CullFace,osg::StateAttribute::ON);
_backgroundStateSet = new osg::StateSet;
_backgroundStateSet->setAttributeAndModes(new osg::PolygonOffset(1.0f,1.0f),osg::StateAttribute::ON);
// load the images.
unsigned int i;
for(i=0;i<fileList.size();i+=2)
@ -501,7 +495,7 @@ Album::Album(osg::ArgumentParser& arguments, float width, float height)
_group->addChild(page);
}
}
setVisibility();
}
@ -524,7 +518,7 @@ bool Album::gotoPage(unsigned int pageNo, float timeToRotateBy)
_pages[i]->rotateTo(osg::PI,timeToRotateBy);
}
_currentPageNo = pageNo;
return true;
}
else if (pageNo<_currentPageNo)
@ -534,10 +528,10 @@ bool Album::gotoPage(unsigned int pageNo, float timeToRotateBy)
_pages[i]->rotateTo(0,timeToRotateBy);
}
_currentPageNo = pageNo;
return true;
}
return false;
}
@ -554,10 +548,10 @@ void Album::setVisibility()
((i+1)<_pages.size()?_pages[i+1]->rotating():false) ||
i==_currentPageNo-1 ||
i==_pages.size()-1;
_pages[i]->setPageVisible(front_visible,back_visible);
}
}
@ -569,13 +563,13 @@ class SlideEventHandler : public osgGA::GUIEventHandler
public:
SlideEventHandler();
META_Object(osgStereImageApp,SlideEventHandler);
void set(Album* album, float timePerSlide, bool autoSteppingActive);
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&);
virtual void getUsage(osg::ApplicationUsage& usage) const;
protected:
@ -604,8 +598,8 @@ void SlideEventHandler::set(Album* album, float timePerSlide, bool autoSteppingA
_album = album;
_timePerSlide = timePerSlide;
_autoSteppingActive = autoSteppingActive;
_autoSteppingActive = autoSteppingActive;
}
bool SlideEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&)
@ -648,7 +642,7 @@ bool SlideEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIAction
_album->nextPage(ea.getTime()+1.0f);
}
}
_album->setVisibility();
}
@ -671,7 +665,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 [image_file]");
@ -679,11 +673,11 @@ int main( int argc, char **argv )
arguments.getApplicationUsage()->addCommandLineOption("-a","Enter auto advance of image pairs on start up.");
arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");
arguments.getApplicationUsage()->addCommandLineOption("--create <filename>","Create an photo archive of specified files");
// construct the viewer.
osgViewer::Viewer viewer(arguments);
viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded);
// register the handler to add keyboard and mouse handling.
@ -706,7 +700,7 @@ int main( int argc, char **argv )
std::string archiveName;
while (arguments.read("--create",archiveName)) {}
// any option left unread are converted into errors to write out later.
arguments.reportRemainingOptionsAsUnrecognized();
@ -716,7 +710,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);
@ -732,9 +726,9 @@ int main( int argc, char **argv )
{
if (arguments.isString(i)) fileNameList.push_back(std::string(arguments[i]));
}
PhotoArchive::buildArchive(archiveName,fileNameList);
return 0;
}
@ -746,7 +740,7 @@ int main( int argc, char **argv )
fovy = osg::DegreesToRadians(fovy);
double fovx = atan(tan(fovy*0.5)*aspectRatio)*2.0;
float radius = 1.0f;
float width = 2*radius*tan(fovx*0.5f);
float height = 2*radius*tan(fovy*0.5f);
@ -755,7 +749,7 @@ int main( int argc, char **argv )
// creat the scene from the file list.
osg::ref_ptr<osg::Group> rootNode = album->getScene();
if (!rootNode) return 0;
@ -766,9 +760,9 @@ int main( int argc, char **argv )
// set up the SlideEventHandler.
seh->set(album.get(),timeDelayBetweenSlides,autoSteppingActive);
viewer.realize();
// switch off the cursor
osgViewer::Viewer::Windows windows;
viewer.getWindows(windows);