2007-06-12 22:20:16 +08:00
|
|
|
/* OpenSceneGraph example, osgtexture2D.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2003-03-15 04:35:45 +08:00
|
|
|
#include <osg/Node>
|
|
|
|
#include <osg/Geometry>
|
|
|
|
#include <osg/Notify>
|
|
|
|
#include <osg/MatrixTransform>
|
|
|
|
#include <osg/Texture2D>
|
|
|
|
#include <osg/DrawPixels>
|
2003-04-02 00:00:33 +08:00
|
|
|
#include <osg/PolygonOffset>
|
2003-03-15 04:35:45 +08:00
|
|
|
#include <osg/Geode>
|
|
|
|
|
|
|
|
#include <osgDB/Registry>
|
|
|
|
#include <osgDB/ReadFile>
|
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
#include <osgText/Text>
|
2003-03-15 04:35:45 +08:00
|
|
|
|
2007-01-11 23:19:59 +08:00
|
|
|
#include <osgViewer/Viewer>
|
2003-03-15 04:35:45 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
2003-03-15 04:35:45 +08:00
|
|
|
//
|
2003-04-02 00:00:33 +08:00
|
|
|
// filter wall and animation callback.
|
2003-03-15 04:35:45 +08:00
|
|
|
//
|
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
class FilterCallback : public osg::NodeCallback
|
2003-03-15 04:35:45 +08:00
|
|
|
{
|
2003-04-02 00:00:33 +08:00
|
|
|
public:
|
|
|
|
|
|
|
|
FilterCallback(osg::Texture2D* texture,osgText::Text* text,double delay=1.0):
|
|
|
|
_texture(texture),
|
|
|
|
_text(text),
|
|
|
|
_delay(delay),
|
|
|
|
_currPos(0),
|
|
|
|
_prevTime(0.0)
|
|
|
|
{
|
2003-04-02 04:32:57 +08:00
|
|
|
// start with a mip mapped mode to ensure that
|
|
|
|
_minFilterList.push_back(osg::Texture2D::LINEAR_MIPMAP_LINEAR);
|
|
|
|
_magFilterList.push_back(osg::Texture2D::LINEAR);
|
|
|
|
_textList.push_back("Tri-linear mip mapping (default filtering)\nsetFilter(MIN_FILTER,LINEAR_MIP_LINEAR)\nsetFilter(MAG_FILTER,LINEAR)");
|
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
_minFilterList.push_back(osg::Texture2D::NEAREST);
|
|
|
|
_magFilterList.push_back(osg::Texture2D::NEAREST);
|
|
|
|
_textList.push_back("Nearest filtering\nsetFilter(MIN_FILTER,NEAREST)\nsetFilter(MAG_FILTER,NEAREST)");
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
_minFilterList.push_back(osg::Texture2D::LINEAR);
|
|
|
|
_magFilterList.push_back(osg::Texture2D::LINEAR);
|
|
|
|
_textList.push_back("Linear filtering\nsetFilter(MIN_FILTER,LINEAR)\nsetFilter(MAG_FILTER,LINEAR)");
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
_minFilterList.push_back(osg::Texture2D::NEAREST_MIPMAP_NEAREST);
|
|
|
|
_magFilterList.push_back(osg::Texture2D::LINEAR);
|
|
|
|
_textList.push_back("nearest mip mapping (default filtering)\nsetFilter(MIN_FILTER,)\nsetFilter(MAG_FILTER,LINEAR)");
|
2003-03-15 04:35:45 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
_minFilterList.push_back(osg::Texture2D::LINEAR_MIPMAP_NEAREST);
|
|
|
|
_magFilterList.push_back(osg::Texture2D::LINEAR);
|
|
|
|
_textList.push_back("bi-linear mip mapping\nsetFilter(MIN_FILTER,LINEAR_MIPMAP_NEAREST)\nsetFilter(MAG_FILTER,LINEAR)");
|
2003-03-15 04:35:45 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
_minFilterList.push_back(osg::Texture2D::NEAREST_MIPMAP_LINEAR);
|
|
|
|
_magFilterList.push_back(osg::Texture2D::LINEAR);
|
|
|
|
_textList.push_back("bi-linear mip mapping\nsetFilter(MIN_FILTER,NEAREST_MIPMAP_LINEAR)\nsetFilter(MAG_FILTER,LINEAR)");
|
2003-03-15 04:35:45 +08:00
|
|
|
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
setValues();
|
|
|
|
}
|
2003-03-15 04:35:45 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
virtual void operator()(osg::Node*, osg::NodeVisitor* nv)
|
2003-03-15 04:35:45 +08:00
|
|
|
{
|
2003-04-02 00:00:33 +08:00
|
|
|
if (nv->getFrameStamp())
|
2003-03-15 04:35:45 +08:00
|
|
|
{
|
2007-01-25 20:02:51 +08:00
|
|
|
double currTime = nv->getFrameStamp()->getSimulationTime();
|
2013-06-27 17:54:12 +08:00
|
|
|
if (currTime-_prevTime>_delay)
|
2003-03-15 04:35:45 +08:00
|
|
|
{
|
2003-04-02 00:00:33 +08:00
|
|
|
// update filter modes and text.
|
|
|
|
setValues();
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2015-04-08 02:01:12 +08:00
|
|
|
// advance the current position, wrap round if required.
|
2003-04-02 00:00:33 +08:00
|
|
|
_currPos++;
|
2013-06-27 17:54:12 +08:00
|
|
|
if (_currPos>=_minFilterList.size()) _currPos=0;
|
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
// record time
|
|
|
|
_prevTime = currTime;
|
2003-03-15 04:35:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
void setValues()
|
2003-03-15 04:35:45 +08:00
|
|
|
{
|
2003-04-02 00:00:33 +08:00
|
|
|
_texture->setFilter(osg::Texture2D::MIN_FILTER,_minFilterList[_currPos]);
|
|
|
|
_texture->setFilter(osg::Texture2D::MAG_FILTER,_magFilterList[_currPos]);
|
2003-03-15 04:35:45 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
_text->setText(_textList[_currPos]);
|
|
|
|
}
|
2003-03-15 04:35:45 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
protected:
|
2003-03-15 04:35:45 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
typedef std::vector<osg::Texture2D::FilterMode> FilterList;
|
|
|
|
typedef std::vector<std::string> TextList;
|
2003-03-15 04:35:45 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
osg::ref_ptr<osg::Texture2D> _texture;
|
|
|
|
osg::ref_ptr<osgText::Text> _text;
|
|
|
|
double _delay;
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
FilterList _minFilterList;
|
|
|
|
FilterList _magFilterList;
|
|
|
|
TextList _textList;
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
unsigned int _currPos;
|
|
|
|
double _prevTime;
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
};
|
2003-03-15 04:35:45 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
osg::Node* createFilterWall(osg::BoundingBox& bb,const std::string& filename)
|
2003-03-15 04:35:45 +08:00
|
|
|
{
|
2003-04-02 00:00:33 +08:00
|
|
|
osg::Group* group = new osg::Group;
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
// left hand side of bounding box.
|
|
|
|
osg::Vec3 top_left(bb.xMin(),bb.yMin(),bb.zMax());
|
|
|
|
osg::Vec3 bottom_left(bb.xMin(),bb.yMin(),bb.zMin());
|
|
|
|
osg::Vec3 bottom_right(bb.xMin(),bb.yMax(),bb.zMin());
|
|
|
|
osg::Vec3 top_right(bb.xMin(),bb.yMax(),bb.zMax());
|
2013-06-27 17:54:12 +08:00
|
|
|
osg::Vec3 center(bb.xMin(),(bb.yMin()+bb.yMax())*0.5f,(bb.zMin()+bb.zMax())*0.5f);
|
2003-04-02 00:00:33 +08:00
|
|
|
float height = bb.zMax()-bb.zMin();
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
// create the geometry for the wall.
|
|
|
|
osg::Geometry* geom = new osg::Geometry;
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
osg::Vec3Array* vertices = new osg::Vec3Array(4);
|
|
|
|
(*vertices)[0] = top_left;
|
|
|
|
(*vertices)[1] = bottom_left;
|
|
|
|
(*vertices)[2] = bottom_right;
|
|
|
|
(*vertices)[3] = top_right;
|
|
|
|
geom->setVertexArray(vertices);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
osg::Vec2Array* texcoords = new osg::Vec2Array(4);
|
|
|
|
(*texcoords)[0].set(0.0f,1.0f);
|
|
|
|
(*texcoords)[1].set(0.0f,0.0f);
|
|
|
|
(*texcoords)[2].set(1.0f,0.0f);
|
|
|
|
(*texcoords)[3].set(1.0f,1.0f);
|
|
|
|
geom->setTexCoordArray(0,texcoords);
|
|
|
|
|
|
|
|
osg::Vec3Array* normals = new osg::Vec3Array(1);
|
|
|
|
(*normals)[0].set(1.0f,0.0f,0.0f);
|
2013-06-27 17:54:12 +08:00
|
|
|
geom->setNormalArray(normals, osg::Array::BIND_OVERALL);
|
|
|
|
|
2003-04-04 16:39:58 +08:00
|
|
|
osg::Vec4Array* colors = new osg::Vec4Array(1);
|
|
|
|
(*colors)[0].set(1.0f,1.0f,1.0f,1.0f);
|
2013-06-27 17:54:12 +08:00
|
|
|
geom->setColorArray(colors, osg::Array::BIND_OVERALL);
|
2003-04-04 16:39:58 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4));
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
osg::Geode* geom_geode = new osg::Geode;
|
|
|
|
geom_geode->addDrawable(geom);
|
|
|
|
group->addChild(geom_geode);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
// set up the texture state.
|
2003-04-02 00:00:33 +08:00
|
|
|
osg::Texture2D* texture = new osg::Texture2D;
|
2003-04-02 04:32:57 +08:00
|
|
|
texture->setDataVariance(osg::Object::DYNAMIC); // protect from being optimized away as static state.
|
2003-04-02 00:00:33 +08:00
|
|
|
texture->setImage(osgDB::readImageFile(filename));
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
osg::StateSet* stateset = geom->getOrCreateStateSet();
|
2003-03-15 04:35:45 +08:00
|
|
|
stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
// create the text label.
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
osgText::Text* text = new osgText::Text;
|
2012-04-18 17:51:39 +08:00
|
|
|
text->setDataVariance(osg::Object::DYNAMIC);
|
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
text->setFont("fonts/arial.ttf");
|
|
|
|
text->setPosition(center);
|
|
|
|
text->setCharacterSize(height*0.03f);
|
|
|
|
text->setAlignment(osgText::Text::CENTER_CENTER);
|
|
|
|
text->setAxisAlignment(osgText::Text::YZ_PLANE);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
osg::Geode* text_geode = new osg::Geode;
|
|
|
|
text_geode->addDrawable(text);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
osg::StateSet* text_stateset = text_geode->getOrCreateStateSet();
|
|
|
|
text_stateset->setAttributeAndModes(new osg::PolygonOffset(-1.0f,-1.0f),osg::StateAttribute::ON);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
group->addChild(text_geode);
|
2003-03-15 04:35:45 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
// set the update callback to cycle through the various min and mag filter modes.
|
|
|
|
group->setUpdateCallback(new FilterCallback(texture,text));
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
return group;
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-03-15 04:35:45 +08:00
|
|
|
}
|
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// anisotropic wall and animation callback.
|
|
|
|
//
|
|
|
|
|
|
|
|
class AnisotropicCallback : public osg::NodeCallback
|
2003-03-15 04:35:45 +08:00
|
|
|
{
|
2003-04-02 00:00:33 +08:00
|
|
|
public:
|
|
|
|
|
|
|
|
AnisotropicCallback(osg::Texture2D* texture,osgText::Text* text,double delay=1.0):
|
|
|
|
_texture(texture),
|
|
|
|
_text(text),
|
|
|
|
_delay(delay),
|
|
|
|
_currPos(0),
|
|
|
|
_prevTime(0.0)
|
2003-03-15 04:35:45 +08:00
|
|
|
{
|
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
_maxAnisotropyList.push_back(1.0f);
|
|
|
|
_textList.push_back("No anisotropic filtering (default)\nsetMaxAnisotropy(1.0f)");
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
_maxAnisotropyList.push_back(2.0f);
|
|
|
|
_textList.push_back("Anisotropic filtering\nsetMaxAnisotropy(2.0f)");
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
_maxAnisotropyList.push_back(4.0f);
|
|
|
|
_textList.push_back("Anisotropic filtering\nsetMaxAnisotropy(4.0f)");
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
_maxAnisotropyList.push_back(8.0f);
|
|
|
|
_textList.push_back("Anisotropic filtering\nsetMaxAnisotropy(8.0f)");
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
_maxAnisotropyList.push_back(16.0f);
|
|
|
|
_textList.push_back("Higest quality anisotropic filtering\nsetMaxAnisotropy(16.0f)");
|
2003-03-15 04:35:45 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
setValues();
|
2003-03-15 04:35:45 +08:00
|
|
|
}
|
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
virtual void operator()(osg::Node*, osg::NodeVisitor* nv)
|
2003-03-15 04:35:45 +08:00
|
|
|
{
|
2003-04-02 00:00:33 +08:00
|
|
|
if (nv->getFrameStamp())
|
|
|
|
{
|
2007-01-25 20:02:51 +08:00
|
|
|
double currTime = nv->getFrameStamp()->getSimulationTime();
|
2013-06-27 17:54:12 +08:00
|
|
|
if (currTime-_prevTime>_delay)
|
2003-04-02 00:00:33 +08:00
|
|
|
{
|
|
|
|
// update filter modes and text.
|
|
|
|
setValues();
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2015-04-08 02:01:12 +08:00
|
|
|
// advance the current position, wrap round if required.
|
2003-04-02 00:00:33 +08:00
|
|
|
_currPos++;
|
2013-06-27 17:54:12 +08:00
|
|
|
if (_currPos>=_maxAnisotropyList.size()) _currPos=0;
|
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
// record time
|
|
|
|
_prevTime = currTime;
|
|
|
|
}
|
|
|
|
}
|
2003-03-15 04:35:45 +08:00
|
|
|
}
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
void setValues()
|
2003-03-15 04:35:45 +08:00
|
|
|
{
|
2003-04-02 00:00:33 +08:00
|
|
|
_texture->setMaxAnisotropy(_maxAnisotropyList[_currPos]);
|
2003-03-15 04:35:45 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
_text->setText(_textList[_currPos]);
|
2003-03-15 04:35:45 +08:00
|
|
|
}
|
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
protected:
|
2003-03-15 04:35:45 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
typedef std::vector<float> AnisotropyList;
|
|
|
|
typedef std::vector<std::string> TextList;
|
2003-03-15 04:35:45 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
osg::ref_ptr<osg::Texture2D> _texture;
|
|
|
|
osg::ref_ptr<osgText::Text> _text;
|
|
|
|
double _delay;
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
AnisotropyList _maxAnisotropyList;
|
|
|
|
TextList _textList;
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
unsigned int _currPos;
|
|
|
|
double _prevTime;
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
};
|
2003-03-15 04:35:45 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
osg::Node* createAnisotripicWall(osg::BoundingBox& bb,const std::string& filename)
|
|
|
|
{
|
|
|
|
osg::Group* group = new osg::Group;
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
// left hand side of bounding box.
|
|
|
|
osg::Vec3 top_left(bb.xMin(),bb.yMax(),bb.zMin());
|
|
|
|
osg::Vec3 bottom_left(bb.xMin(),bb.yMin(),bb.zMin());
|
|
|
|
osg::Vec3 bottom_right(bb.xMax(),bb.yMin(),bb.zMin());
|
|
|
|
osg::Vec3 top_right(bb.xMax(),bb.yMax(),bb.zMin());
|
2013-06-27 17:54:12 +08:00
|
|
|
osg::Vec3 center((bb.xMin()+bb.xMax())*0.5f,(bb.yMin()+bb.yMax())*0.5f,bb.zMin());
|
2003-04-02 00:00:33 +08:00
|
|
|
float height = bb.yMax()-bb.yMin();
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
// create the geometry for the wall.
|
|
|
|
osg::Geometry* geom = new osg::Geometry;
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
osg::Vec3Array* vertices = new osg::Vec3Array(4);
|
|
|
|
(*vertices)[0] = top_left;
|
|
|
|
(*vertices)[1] = bottom_left;
|
|
|
|
(*vertices)[2] = bottom_right;
|
|
|
|
(*vertices)[3] = top_right;
|
|
|
|
geom->setVertexArray(vertices);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
osg::Vec2Array* texcoords = new osg::Vec2Array(4);
|
|
|
|
(*texcoords)[0].set(0.0f,1.0f);
|
|
|
|
(*texcoords)[1].set(0.0f,0.0f);
|
|
|
|
(*texcoords)[2].set(1.0f,0.0f);
|
|
|
|
(*texcoords)[3].set(1.0f,1.0f);
|
|
|
|
geom->setTexCoordArray(0,texcoords);
|
|
|
|
|
|
|
|
osg::Vec3Array* normals = new osg::Vec3Array(1);
|
|
|
|
(*normals)[0].set(0.0f,0.0f,1.0f);
|
2013-06-27 17:54:12 +08:00
|
|
|
geom->setNormalArray(normals, osg::Array::BIND_OVERALL);
|
|
|
|
|
2003-04-04 16:39:58 +08:00
|
|
|
osg::Vec4Array* colors = new osg::Vec4Array(1);
|
|
|
|
(*colors)[0].set(1.0f,1.0f,1.0f,1.0f);
|
2013-06-27 17:54:12 +08:00
|
|
|
geom->setColorArray(colors, osg::Array::BIND_OVERALL);
|
2003-04-04 16:39:58 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4));
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
osg::Geode* geom_geode = new osg::Geode;
|
|
|
|
geom_geode->addDrawable(geom);
|
|
|
|
group->addChild(geom_geode);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
// set up the texture state.
|
2003-04-02 00:00:33 +08:00
|
|
|
osg::Texture2D* texture = new osg::Texture2D;
|
2003-04-02 04:32:57 +08:00
|
|
|
texture->setDataVariance(osg::Object::DYNAMIC); // protect from being optimized away as static state.
|
2003-04-02 00:00:33 +08:00
|
|
|
texture->setImage(osgDB::readImageFile(filename));
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
osg::StateSet* stateset = geom->getOrCreateStateSet();
|
|
|
|
stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
// create the text label.
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
osgText::Text* text = new osgText::Text;
|
2012-04-18 17:51:39 +08:00
|
|
|
text->setDataVariance(osg::Object::DYNAMIC);
|
2003-04-02 00:00:33 +08:00
|
|
|
text->setFont("fonts/arial.ttf");
|
|
|
|
text->setPosition(center);
|
|
|
|
text->setCharacterSize(height*0.03f);
|
2003-04-02 19:57:23 +08:00
|
|
|
text->setColor(osg::Vec4(1.0f,0.0f,1.0f,1.0f));
|
2003-04-02 00:00:33 +08:00
|
|
|
text->setAlignment(osgText::Text::CENTER_CENTER);
|
|
|
|
text->setAxisAlignment(osgText::Text::XY_PLANE);
|
2012-04-18 17:51:39 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
osg::Geode* text_geode = new osg::Geode;
|
|
|
|
text_geode->addDrawable(text);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
osg::StateSet* text_stateset = text_geode->getOrCreateStateSet();
|
|
|
|
text_stateset->setAttributeAndModes(new osg::PolygonOffset(-1.0f,-1.0f),osg::StateAttribute::ON);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
group->addChild(text_geode);
|
2003-03-15 04:35:45 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
// set the update callback to cycle through the various min and mag filter modes.
|
|
|
|
group->setUpdateCallback(new AnisotropicCallback(texture,text));
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
return group;
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
}
|
2003-03-15 04:35:45 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2003-04-02 04:32:57 +08:00
|
|
|
// wrap wall and animation callback.
|
2003-04-02 00:00:33 +08:00
|
|
|
//
|
|
|
|
class WrapCallback : public osg::NodeCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
WrapCallback(osg::Texture2D* texture,osgText::Text* text,double delay=1.0):
|
|
|
|
_texture(texture),
|
|
|
|
_text(text),
|
|
|
|
_delay(delay),
|
|
|
|
_currPos(0),
|
|
|
|
_prevTime(0.0)
|
|
|
|
{
|
2003-03-15 04:35:45 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
_wrapList.push_back(osg::Texture2D::CLAMP);
|
|
|
|
_textList.push_back("Default tex coord clamp\nsetWrap(WRAP_S,CLAMP)");
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
_wrapList.push_back(osg::Texture2D::CLAMP_TO_EDGE);
|
|
|
|
_textList.push_back("Clamp to edge extension\nsetWrap(WRAP_S,CLAMP_TO_EDGE)");
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
_wrapList.push_back(osg::Texture2D::CLAMP_TO_BORDER);
|
|
|
|
_textList.push_back("Clamp to border color extension\nsetWrap(WRAP_S,CLAMP_TO_BORDER)");
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
_wrapList.push_back(osg::Texture2D::REPEAT);
|
2003-04-02 04:32:57 +08:00
|
|
|
_textList.push_back("Repeat wrap\nsetWrap(WRAP_S,REPEAT)");
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
_wrapList.push_back(osg::Texture2D::MIRROR);
|
|
|
|
_textList.push_back("Mirror wrap extension\nsetWrap(WRAP_S,MIRROR)");
|
2003-03-15 04:35:45 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
setValues();
|
2003-03-15 04:35:45 +08:00
|
|
|
}
|
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
virtual void operator()(osg::Node*, osg::NodeVisitor* nv)
|
2003-03-15 04:35:45 +08:00
|
|
|
{
|
2003-04-02 00:00:33 +08:00
|
|
|
if (nv->getFrameStamp())
|
|
|
|
{
|
2007-01-25 20:02:51 +08:00
|
|
|
double currTime = nv->getFrameStamp()->getSimulationTime();
|
2013-06-27 17:54:12 +08:00
|
|
|
if (currTime-_prevTime>_delay)
|
2003-04-02 00:00:33 +08:00
|
|
|
{
|
|
|
|
// update filter modes and text.
|
|
|
|
setValues();
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2015-04-08 02:01:12 +08:00
|
|
|
// advance the current position, wrap round if required.
|
2003-04-02 00:00:33 +08:00
|
|
|
_currPos++;
|
2013-06-27 17:54:12 +08:00
|
|
|
if (_currPos>=_wrapList.size()) _currPos=0;
|
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
// record time
|
|
|
|
_prevTime = currTime;
|
|
|
|
}
|
|
|
|
}
|
2003-03-15 04:35:45 +08:00
|
|
|
}
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
void setValues()
|
2003-03-15 04:35:45 +08:00
|
|
|
{
|
2003-04-02 00:00:33 +08:00
|
|
|
_texture->setWrap(osg::Texture2D::WRAP_S,_wrapList[_currPos]);
|
|
|
|
_texture->setWrap(osg::Texture2D::WRAP_T,_wrapList[_currPos]);
|
2003-03-15 04:35:45 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
_text->setText(_textList[_currPos]);
|
2003-03-15 04:35:45 +08:00
|
|
|
}
|
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
protected:
|
|
|
|
|
|
|
|
typedef std::vector<osg::Texture2D::WrapMode> WrapList;
|
|
|
|
typedef std::vector<std::string> TextList;
|
2003-03-15 04:35:45 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
osg::ref_ptr<osg::Texture2D> _texture;
|
|
|
|
osg::ref_ptr<osgText::Text> _text;
|
|
|
|
double _delay;
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
WrapList _wrapList;
|
|
|
|
TextList _textList;
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
unsigned int _currPos;
|
|
|
|
double _prevTime;
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
};
|
2003-03-15 04:35:45 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
osg::Node* createWrapWall(osg::BoundingBox& bb,const std::string& filename)
|
|
|
|
{
|
|
|
|
osg::Group* group = new osg::Group;
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
// left hand side of bounding box.
|
|
|
|
osg::Vec3 top_left(bb.xMax(),bb.yMax(),bb.zMax());
|
|
|
|
osg::Vec3 bottom_left(bb.xMax(),bb.yMax(),bb.zMin());
|
|
|
|
osg::Vec3 bottom_right(bb.xMax(),bb.yMin(),bb.zMin());
|
|
|
|
osg::Vec3 top_right(bb.xMax(),bb.yMin(),bb.zMax());
|
2013-06-27 17:54:12 +08:00
|
|
|
osg::Vec3 center(bb.xMax(),(bb.yMin()+bb.yMax())*0.5f,(bb.zMin()+bb.zMax())*0.5f);
|
2003-04-02 00:00:33 +08:00
|
|
|
float height = bb.zMax()-bb.zMin();
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
// create the geometry for the wall.
|
|
|
|
osg::Geometry* geom = new osg::Geometry;
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
osg::Vec3Array* vertices = new osg::Vec3Array(4);
|
|
|
|
(*vertices)[0] = top_left;
|
|
|
|
(*vertices)[1] = bottom_left;
|
|
|
|
(*vertices)[2] = bottom_right;
|
|
|
|
(*vertices)[3] = top_right;
|
|
|
|
geom->setVertexArray(vertices);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
osg::Vec2Array* texcoords = new osg::Vec2Array(4);
|
|
|
|
(*texcoords)[0].set(-1.0f,2.0f);
|
|
|
|
(*texcoords)[1].set(-1.0f,-1.0f);
|
|
|
|
(*texcoords)[2].set(2.0f,-1.0f);
|
|
|
|
(*texcoords)[3].set(2.0f,2.0f);
|
|
|
|
geom->setTexCoordArray(0,texcoords);
|
|
|
|
|
|
|
|
osg::Vec3Array* normals = new osg::Vec3Array(1);
|
2003-04-02 04:32:57 +08:00
|
|
|
(*normals)[0].set(-1.0f,0.0f,0.0f);
|
2013-06-27 17:54:12 +08:00
|
|
|
geom->setNormalArray(normals, osg::Array::BIND_OVERALL);
|
|
|
|
|
2003-04-04 16:39:58 +08:00
|
|
|
osg::Vec4Array* colors = new osg::Vec4Array(1);
|
|
|
|
(*colors)[0].set(1.0f,1.0f,1.0f,1.0f);
|
2013-06-27 17:54:12 +08:00
|
|
|
geom->setColorArray(colors, osg::Array::BIND_OVERALL);
|
2003-04-04 16:39:58 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4));
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
osg::Geode* geom_geode = new osg::Geode;
|
|
|
|
geom_geode->addDrawable(geom);
|
|
|
|
group->addChild(geom_geode);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
// set up the texture state.
|
2003-04-02 00:00:33 +08:00
|
|
|
osg::Texture2D* texture = new osg::Texture2D;
|
2003-04-02 04:32:57 +08:00
|
|
|
texture->setDataVariance(osg::Object::DYNAMIC); // protect from being optimized away as static state.
|
2003-04-02 00:00:33 +08:00
|
|
|
texture->setBorderColor(osg::Vec4(1.0f,1.0f,1.0f,0.5f)); // only used when wrap is set to CLAMP_TO_BORDER
|
|
|
|
texture->setImage(osgDB::readImageFile(filename));
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
osg::StateSet* stateset = geom->getOrCreateStateSet();
|
|
|
|
stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON);
|
|
|
|
stateset->setMode(GL_BLEND,osg::StateAttribute::ON);
|
|
|
|
stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
// create the text label.
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
osgText::Text* text = new osgText::Text;
|
2012-04-18 17:51:39 +08:00
|
|
|
text->setDataVariance(osg::Object::DYNAMIC);
|
2003-04-02 00:00:33 +08:00
|
|
|
text->setFont("fonts/arial.ttf");
|
|
|
|
text->setPosition(center);
|
|
|
|
text->setCharacterSize(height*0.03f);
|
|
|
|
text->setAlignment(osgText::Text::CENTER_CENTER);
|
|
|
|
text->setAxisAlignment(osgText::Text::YZ_PLANE);
|
2012-04-18 17:51:39 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
osg::Geode* text_geode = new osg::Geode;
|
|
|
|
text_geode->addDrawable(text);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
osg::StateSet* text_stateset = text_geode->getOrCreateStateSet();
|
|
|
|
text_stateset->setAttributeAndModes(new osg::PolygonOffset(-1.0f,-1.0f),osg::StateAttribute::ON);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
group->addChild(text_geode);
|
2003-03-15 04:35:45 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
// set the update callback to cycle through the various min and mag filter modes.
|
|
|
|
group->setUpdateCallback(new WrapCallback(texture,text));
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
return group;
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
}
|
2003-03-15 04:35:45 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2003-04-02 04:32:57 +08:00
|
|
|
// sublooad wall and animation callback.
|
2003-04-02 00:00:33 +08:00
|
|
|
//
|
2003-03-15 04:35:45 +08:00
|
|
|
|
2003-04-02 04:32:57 +08:00
|
|
|
class ImageUpdateCallback : public osg::NodeCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
ImageUpdateCallback(osg::Texture2D* texture,osgText::Text* text,double delay=1.0):
|
|
|
|
_texture(texture),
|
|
|
|
_text(text),
|
|
|
|
_delay(delay),
|
|
|
|
_currPos(0),
|
|
|
|
_prevTime(0.0)
|
|
|
|
{
|
|
|
|
|
2013-06-27 17:54:12 +08:00
|
|
|
#if 1
|
2012-01-24 22:34:02 +08:00
|
|
|
osg::ref_ptr<osg::Image> originalImage = osgDB::readImageFile("Images/dog_left_eye.jpg");
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Image> subImage = new osg::Image;
|
|
|
|
subImage->setUserData(originalImage.get()); // attach the originalImage as user data to prevent it being deleted.
|
|
|
|
|
|
|
|
// now assign the appropriate portion data from the originalImage
|
|
|
|
subImage->setImage(originalImage->s()/2, originalImage->t()/2, originalImage->r(), // half the width and height
|
|
|
|
originalImage->getInternalTextureFormat(), // same internal texture format
|
|
|
|
originalImage->getPixelFormat(),originalImage->getDataType(), // same pixel foramt and data type
|
|
|
|
originalImage->data(originalImage->s()/4,originalImage->t()/4), // offset teh start point to 1/4 into the image
|
|
|
|
osg::Image::NO_DELETE, // don't attempt to delete the image data, leave this to the originalImage
|
|
|
|
originalImage->getPacking(), // use the the same packing
|
|
|
|
originalImage->s()); // use the width of the original image as the row width
|
|
|
|
|
|
|
|
|
|
|
|
subImage->setPixelBufferObject(new osg::PixelBufferObject(subImage.get()));
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
OSG_NOTICE<<"orignalImage iterator"<<std::endl;
|
|
|
|
for(osg::Image::DataIterator itr(originalImage.get()); itr.valid(); ++itr)
|
|
|
|
{
|
|
|
|
OSG_NOTICE<<" "<<(void*)itr.data()<<", "<<itr.size()<<std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
OSG_NOTICE<<"subImage iterator, size "<<subImage->s()<<", "<<subImage->t()<<std::endl;
|
|
|
|
unsigned int i=0;
|
|
|
|
for(osg::Image::DataIterator itr(subImage.get()); itr.valid(); ++itr, ++i)
|
|
|
|
{
|
|
|
|
OSG_NOTICE<<" "<<i<<", "<<(void*)itr.data()<<", "<<itr.size()<<std::endl;
|
|
|
|
|
|
|
|
for(unsigned char* d=const_cast<unsigned char*>(itr.data()); d<(itr.data()+itr.size()); ++d)
|
|
|
|
{
|
|
|
|
*d = 255-*d;
|
|
|
|
}
|
|
|
|
}
|
2013-06-27 17:54:12 +08:00
|
|
|
#endif
|
|
|
|
|
2012-01-24 22:34:02 +08:00
|
|
|
|
|
|
|
_imageList.push_back(subImage.get());
|
|
|
|
|
|
|
|
#else
|
2003-04-06 03:54:51 +08:00
|
|
|
_imageList.push_back(osgDB::readImageFile("Images/dog_left_eye.jpg"));
|
2012-01-24 22:34:02 +08:00
|
|
|
#endif
|
2003-04-02 04:32:57 +08:00
|
|
|
_textList.push_back("Subloaded Image 1 - dog_left_eye.jpg");
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-06 03:54:51 +08:00
|
|
|
_imageList.push_back(osgDB::readImageFile("Images/dog_right_eye.jpg"));
|
2003-04-02 04:32:57 +08:00
|
|
|
_textList.push_back("Subloaded Image 2 - dog_right_eye.jpg");
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 04:32:57 +08:00
|
|
|
setValues();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void operator()(osg::Node*, osg::NodeVisitor* nv)
|
|
|
|
{
|
|
|
|
if (nv->getFrameStamp())
|
|
|
|
{
|
2007-01-25 20:02:51 +08:00
|
|
|
double currTime = nv->getFrameStamp()->getSimulationTime();
|
2013-06-27 17:54:12 +08:00
|
|
|
if (currTime-_prevTime>_delay)
|
2003-04-02 04:32:57 +08:00
|
|
|
{
|
|
|
|
// update filter modes and text.
|
|
|
|
setValues();
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2015-04-08 02:01:12 +08:00
|
|
|
// advance the current position, wrap round if required.
|
2003-04-02 04:32:57 +08:00
|
|
|
_currPos++;
|
2013-06-27 17:54:12 +08:00
|
|
|
if (_currPos>=_imageList.size()) _currPos=0;
|
|
|
|
|
2003-04-02 04:32:57 +08:00
|
|
|
// record time
|
|
|
|
_prevTime = currTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 04:32:57 +08:00
|
|
|
void setValues()
|
|
|
|
{
|
|
|
|
// Note, as long as the images are the same dimensions subloading will be used
|
|
|
|
// to update the textures. If dimensions change then the texture objects have
|
|
|
|
// to be deleted and re-recreated.
|
|
|
|
//
|
|
|
|
// The load/subload happens during the draw traversal so doesn't happen on
|
|
|
|
// the setImage which just updates internal pointers and modifed flags.
|
|
|
|
|
|
|
|
_texture->setImage(_imageList[_currPos].get());
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 04:32:57 +08:00
|
|
|
//_texture->dirtyTextureObject();
|
|
|
|
|
|
|
|
_text->setText(_textList[_currPos]);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 04:32:57 +08:00
|
|
|
typedef std::vector< osg::ref_ptr<osg::Image> > ImageList;
|
|
|
|
typedef std::vector<std::string> TextList;
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Texture2D> _texture;
|
|
|
|
osg::ref_ptr<osgText::Text> _text;
|
|
|
|
double _delay;
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 04:32:57 +08:00
|
|
|
ImageList _imageList;
|
|
|
|
TextList _textList;
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 04:32:57 +08:00
|
|
|
unsigned int _currPos;
|
|
|
|
double _prevTime;
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 04:32:57 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
osg::Node* createSubloadWall(osg::BoundingBox& bb)
|
2003-04-02 00:00:33 +08:00
|
|
|
{
|
2003-04-02 04:32:57 +08:00
|
|
|
osg::Group* group = new osg::Group;
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 04:32:57 +08:00
|
|
|
// left hand side of bounding box.
|
|
|
|
osg::Vec3 top_left(bb.xMin(),bb.yMax(),bb.zMax());
|
|
|
|
osg::Vec3 bottom_left(bb.xMin(),bb.yMax(),bb.zMin());
|
|
|
|
osg::Vec3 bottom_right(bb.xMax(),bb.yMax(),bb.zMin());
|
|
|
|
osg::Vec3 top_right(bb.xMax(),bb.yMax(),bb.zMax());
|
2013-06-27 17:54:12 +08:00
|
|
|
osg::Vec3 center((bb.xMax()+bb.xMin())*0.5f,bb.yMax(),(bb.zMin()+bb.zMax())*0.5f);
|
2003-04-02 04:32:57 +08:00
|
|
|
float height = bb.zMax()-bb.zMin();
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 04:32:57 +08:00
|
|
|
// create the geometry for the wall.
|
|
|
|
osg::Geometry* geom = new osg::Geometry;
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 04:32:57 +08:00
|
|
|
osg::Vec3Array* vertices = new osg::Vec3Array(4);
|
|
|
|
(*vertices)[0] = top_left;
|
|
|
|
(*vertices)[1] = bottom_left;
|
|
|
|
(*vertices)[2] = bottom_right;
|
|
|
|
(*vertices)[3] = top_right;
|
|
|
|
geom->setVertexArray(vertices);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 04:32:57 +08:00
|
|
|
osg::Vec2Array* texcoords = new osg::Vec2Array(4);
|
|
|
|
(*texcoords)[0].set(0.0f,1.0f);
|
|
|
|
(*texcoords)[1].set(0.0f,0.0f);
|
|
|
|
(*texcoords)[2].set(1.0f,0.0f);
|
|
|
|
(*texcoords)[3].set(1.0f,1.0f);
|
|
|
|
geom->setTexCoordArray(0,texcoords);
|
|
|
|
|
|
|
|
osg::Vec3Array* normals = new osg::Vec3Array(1);
|
|
|
|
(*normals)[0].set(0.0f,-1.0f,0.0f);
|
2013-06-27 17:54:12 +08:00
|
|
|
geom->setNormalArray(normals, osg::Array::BIND_OVERALL);
|
|
|
|
|
2003-04-04 16:39:58 +08:00
|
|
|
osg::Vec4Array* colors = new osg::Vec4Array(1);
|
|
|
|
(*colors)[0].set(1.0f,1.0f,1.0f,1.0f);
|
2013-06-27 17:54:12 +08:00
|
|
|
geom->setColorArray(colors, osg::Array::BIND_OVERALL);
|
2003-04-04 16:39:58 +08:00
|
|
|
|
2003-04-02 04:32:57 +08:00
|
|
|
geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4));
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 04:32:57 +08:00
|
|
|
osg::Geode* geom_geode = new osg::Geode;
|
|
|
|
geom_geode->addDrawable(geom);
|
|
|
|
group->addChild(geom_geode);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
// set up the texture state.
|
2003-04-02 04:32:57 +08:00
|
|
|
osg::Texture2D* texture = new osg::Texture2D;
|
|
|
|
texture->setDataVariance(osg::Object::DYNAMIC); // protect from being optimized away as static state.
|
|
|
|
texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR);
|
|
|
|
texture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 04:32:57 +08:00
|
|
|
osg::StateSet* stateset = geom->getOrCreateStateSet();
|
|
|
|
stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 04:32:57 +08:00
|
|
|
// create the text label.
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 04:32:57 +08:00
|
|
|
osgText::Text* text = new osgText::Text;
|
2009-02-03 20:47:41 +08:00
|
|
|
text->setDataVariance(osg::Object::DYNAMIC);
|
2003-04-02 04:32:57 +08:00
|
|
|
text->setFont("fonts/arial.ttf");
|
|
|
|
text->setPosition(center);
|
|
|
|
text->setCharacterSize(height*0.03f);
|
|
|
|
text->setAlignment(osgText::Text::CENTER_CENTER);
|
|
|
|
text->setAxisAlignment(osgText::Text::XZ_PLANE);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 04:32:57 +08:00
|
|
|
osg::Geode* text_geode = new osg::Geode;
|
|
|
|
text_geode->addDrawable(text);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 04:32:57 +08:00
|
|
|
osg::StateSet* text_stateset = text_geode->getOrCreateStateSet();
|
|
|
|
text_stateset->setAttributeAndModes(new osg::PolygonOffset(-1.0f,-1.0f),osg::StateAttribute::ON);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 04:32:57 +08:00
|
|
|
group->addChild(text_geode);
|
|
|
|
|
|
|
|
// set the update callback to cycle through the various min and mag filter modes.
|
|
|
|
group->setUpdateCallback(new ImageUpdateCallback(texture,text));
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-02 04:32:57 +08:00
|
|
|
return group;
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-03-15 04:35:45 +08:00
|
|
|
}
|
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
|
|
|
|
osg::Node* createModel()
|
2003-03-15 04:35:45 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
// create the root node which will hold the model.
|
|
|
|
osg::Group* root = new osg::Group();
|
2013-06-27 17:54:12 +08:00
|
|
|
|
|
|
|
// turn off lighting
|
2003-04-02 04:32:57 +08:00
|
|
|
root->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
|
2003-03-15 04:35:45 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
osg::BoundingBox bb(0.0f,0.0f,0.0f,1.0f,1.0f,1.0f);
|
2003-03-15 04:35:45 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
root->addChild(createFilterWall(bb,"Images/lz.rgb"));
|
2003-04-02 04:32:57 +08:00
|
|
|
root->addChild(createAnisotripicWall(bb,"Images/primitives.gif"));
|
2003-04-02 00:00:33 +08:00
|
|
|
root->addChild(createWrapWall(bb,"Images/tree0.rgba"));
|
2003-04-02 04:32:57 +08:00
|
|
|
root->addChild(createSubloadWall(bb));
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-03-15 04:35:45 +08:00
|
|
|
return root;
|
|
|
|
}
|
|
|
|
|
2007-01-11 23:19:59 +08:00
|
|
|
int main(int , char **)
|
2003-03-15 04:35:45 +08:00
|
|
|
{
|
|
|
|
// construct the viewer.
|
2007-01-11 23:19:59 +08:00
|
|
|
osgViewer::Viewer viewer;
|
2003-03-15 04:35:45 +08:00
|
|
|
|
2003-04-02 00:00:33 +08:00
|
|
|
// add model to viewer.
|
2007-01-11 23:19:59 +08:00
|
|
|
viewer.setSceneData( createModel() );
|
2003-03-15 04:35:45 +08:00
|
|
|
|
2007-01-11 23:19:59 +08:00
|
|
|
return viewer.run();
|
2003-03-15 04:35:45 +08:00
|
|
|
}
|