- Timestamp:
- 09/04/06 14:46:49 (7 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osgtexturerectangle/osgtexturerectangle.cpp
r5381 r5522 20 20 #include <osg/Geometry> 21 21 #include <osg/Geode> 22 #include <osg/TexMat> 22 23 23 24 #include <osg/Group> … … 41 42 { 42 43 public: 43 TexturePanCallback(osg:: Geometry* geom, osg::Image* img,44 TexturePanCallback(osg::TexMat* texmat, 44 45 double delay = 0.05) : 45 _geom(geom), 46 _img(img), 46 _texmat(texmat), 47 47 _phaseS(35.0f), 48 48 _phaseT(18.0f), … … 55 55 virtual void operator()(osg::Node*, osg::NodeVisitor* nv) 56 56 { 57 if (!_ geom || !_img)57 if (!_texmat) 58 58 return; 59 59 … … 70 70 // calculate new texture coordinates 71 71 float s, t; 72 s = ((sin(rad * _phaseS) + 1) * 0.5f) * (_img->s() * scaleR); 73 t = ((sin(rad * _phaseT) + 1) * 0.5f) * (_img->t() * scaleR); 74 75 // set new texture coordinate array 76 osg::Vec2Array* texcoords = (osg::Vec2Array*) _geom->getTexCoordArray(0); 77 float w = _img->s() * scale, h = _img->t() * scale; 78 (*texcoords)[0].set(s, t+h); 79 (*texcoords)[1].set(s, t); 80 (*texcoords)[2].set(s+w, t); 81 (*texcoords)[3].set(s+w, t+h); 72 s = ((sin(rad * _phaseS) + 1) * 0.5f) * (scaleR); 73 t = ((sin(rad * _phaseT) + 1) * 0.5f) * (scaleR); 74 75 76 _texmat->setMatrix(osg::Matrix::translate(s,t,1.0)*osg::Matrix::scale(scale,scale,1.0)); 82 77 83 78 // record time … … 88 83 89 84 private: 90 osg::Geometry* _geom; 91 osg::Image* _img; 85 osg::TexMat* _texmat; 92 86 93 87 float _phaseS, _phaseT, _phaseScale; … … 149 143 state->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON); 150 144 145 // setup state 146 osg::TexMat* texmat = new osg::TexMat; 147 texmat->setScaleByTextureRectangleSize(true); 148 state->setTextureAttributeAndModes(0, texmat, osg::StateAttribute::ON); 149 151 150 // turn off lighting 152 151 state->setMode(GL_LIGHTING, osg::StateAttribute::OFF); … … 155 154 osg::Geode* geode = new osg::Geode; 156 155 geode->addDrawable(geom); 157 geode->setUpdateCallback(new TexturePanCallback( geom, img));156 geode->setUpdateCallback(new TexturePanCallback(texmat)); 158 157 159 158 return geode; … … 195 194 "TextureRectangle Mini-HOWTO", 196 195 "- essentially behaves like Texture2D, *except* that:", 197 "- tex coords must be non-normalized (0..pixel) instead of (0..1) ",196 "- tex coords must be non-normalized (0..pixel) instead of (0..1),\nalternatively you can use osg::TexMat to scale normal non dimensional texcoords.", 198 197 "- wrap modes must be CLAMP, CLAMP_TO_EDGE, or CLAMP_TO_BORDER\n repeating wrap modes are not supported", 199 198 "- filter modes must be NEAREST or LINEAR since\n mipmaps are not supported",
