ImpostorSprite
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_ImpostorSprite
#define OSG_ImpostorSprite 1
#include <osg/Vec2>
#include <osg/Geometry>
#include <osg/AlphaFunc>
#include <osg/TexEnv>
#include <osg/Texture2D>
#include <osg/Camera>
#include <osgSim/Export>
namespace osgSim {
class Impostor;
class ImpostorSpriteManager;
class OSGSIM_EXPORT ImpostorSprite : public osg::Geometry
{
public:
ImpostorSprite();
virtual osg::Object* cloneType() const { return new ImpostorSprite(); }
virtual osg::Object* clone(const osg::CopyOp&) const { return new ImpostorSprite(); }
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const ImpostorSprite*>(obj)!=NULL; }
virtual const char* libraryName() const { return "osgSim"; }
virtual const char* className() const { return "ImpostorSprite"; }
void setParent(Impostor* parent) { _parent = parent; }
Impostor* getParent() { return _parent; }
const Impostor* getParent() const { return _parent; }
inline void setStoredLocalEyePoint(const osg::Vec3& v) { _storedLocalEyePoint=v; }
inline const osg::Vec3& getStoredLocalEyePoint() const { return _storedLocalEyePoint; }
inline void setLastFrameUsed(unsigned int frameNumber) { _lastFrameUsed = frameNumber; }
inline unsigned int getLastFrameUsed() const { return _lastFrameUsed; }
void dirty();
inline osg::Vec3* getCoords() { return &(_coords->front()); }
inline const osg::Vec3* getCoords() const { return &(_coords->front()); }
inline osg::Vec2* getTexCoords() { return &(_texcoords->front()); }
inline const osg::Vec2* getTexCoords() const { return &(_texcoords->front()); }
inline osg::Vec3* getControlCoords() { return _controlcoords; }
inline const osg::Vec3* getControlCoords() const { return _controlcoords; }
float calcPixelError(const osg::Matrix& MVPW) const;
void setTexture(osg::Texture2D* tex,int s,int t);
osg::Texture2D* getTexture() { return _texture; }
const osg::Texture2D* getTexture() const { return _texture; }
int s() const { return _s; }
int t() const { return _t; }
void setCamera(osg::Camera* camera) { _camera = camera; }
osg::Camera* getCamera() { return _camera.get(); }
const osg::Camera* getCamera() const { return _camera.get(); }
protected:
ImpostorSprite(const ImpostorSprite&);
ImpostorSprite& operator = (const ImpostorSprite&) { return *this;}
virtual ~ImpostorSprite();
void init();
Impostor* _parent;
friend class osgSim::ImpostorSpriteManager;
// camera node for doing the pre rendering.
osg::ref_ptr<osg::Camera> _camera;
// support for a double linked list managed by the
// ImposotorSpriteManager.
ImpostorSpriteManager* _ism;
ImpostorSprite* _previous;
ImpostorSprite* _next;
unsigned int _lastFrameUsed;
osg::Vec3 _storedLocalEyePoint;
osg::ref_ptr<osg::Vec3Array> _coords;
osg::ref_ptr<osg::Vec2Array> _texcoords;
osg::Vec3 _controlcoords[4];
osg::Texture2D* _texture;
int _s;
int _t;
};
class OSGSIM_EXPORT ImpostorSpriteManager : public osg::Referenced
{
public:
ImpostorSpriteManager();
bool empty() const { return _first==0; }
ImpostorSprite* first() { return _first; }
ImpostorSprite* last() { return _last; }
void push_back(ImpostorSprite* is);
void remove(ImpostorSprite* is);
ImpostorSprite* createOrReuseImpostorSprite(int s,int t,unsigned int frameNumber);
osg::StateSet* createOrReuseStateSet();
void reset();
protected:
~ImpostorSpriteManager();
osg::ref_ptr<osg::TexEnv> _texenv;
osg::ref_ptr<osg::AlphaFunc> _alphafunc;
ImpostorSprite* _first;
ImpostorSprite* _last;
typedef std::vector< osg::ref_ptr<osg::StateSet> > StateSetList;
StateSetList _stateSetList;
unsigned int _reuseStateSetIndex;
};
}
#endif
AlphaFunc
Camera
Geometry
TexEnv
Texture2D
Vec2
osgSim::ImpostorSpriteManager
Definition ImpostorSprite:178
osgSim::ImpostorSpriteManager::first
ImpostorSprite * first()
Definition ImpostorSprite:185
osgSim::ImpostorSpriteManager::empty
bool empty() const
Definition ImpostorSprite:183
osgSim::ImpostorSpriteManager::StateSetList
std::vector< osg::ref_ptr< osg::StateSet > > StateSetList
Definition ImpostorSprite:210
osgSim::ImpostorSpriteManager::_last
ImpostorSprite * _last
Definition ImpostorSprite:208
osgSim::ImpostorSpriteManager::reset
void reset()
osgSim::ImpostorSpriteManager::createOrReuseStateSet
osg::StateSet * createOrReuseStateSet()
osgSim::ImpostorSpriteManager::push_back
void push_back(ImpostorSprite *is)
osgSim::ImpostorSpriteManager::remove
void remove(ImpostorSprite *is)
osgSim::ImpostorSpriteManager::_first
ImpostorSprite * _first
Definition ImpostorSprite:207
osgSim::ImpostorSpriteManager::_reuseStateSetIndex
unsigned int _reuseStateSetIndex
Definition ImpostorSprite:212
osgSim::ImpostorSpriteManager::last
ImpostorSprite * last()
Definition ImpostorSprite:187
osgSim::ImpostorSpriteManager::_stateSetList
StateSetList _stateSetList
Definition ImpostorSprite:211
osgSim::ImpostorSpriteManager::~ImpostorSpriteManager
~ImpostorSpriteManager()
osgSim::ImpostorSpriteManager::_texenv
osg::ref_ptr< osg::TexEnv > _texenv
Definition ImpostorSprite:204
osgSim::ImpostorSpriteManager::_alphafunc
osg::ref_ptr< osg::AlphaFunc > _alphafunc
Definition ImpostorSprite:205
osgSim::ImpostorSpriteManager::ImpostorSpriteManager
ImpostorSpriteManager()
osgSim::ImpostorSpriteManager::createOrReuseImpostorSprite
ImpostorSprite * createOrReuseImpostorSprite(int s, int t, unsigned int frameNumber)
osgSim::ImpostorSprite
Definition ImpostorSprite:38
osgSim::ImpostorSprite::_ism
ImpostorSpriteManager * _ism
Definition ImpostorSprite:157
osgSim::ImpostorSprite::getCamera
osg::Camera * getCamera()
Definition ImpostorSprite:134
osgSim::ImpostorSprite::dirty
void dirty()
osgSim::ImpostorSprite::getCoords
const osg::Vec3 * getCoords() const
Definition ImpostorSprite:88
osgSim::ImpostorSprite::_t
int _t
Definition ImpostorSprite:171
osgSim::ImpostorSprite::_next
ImpostorSprite * _next
Definition ImpostorSprite:159
osgSim::ImpostorSprite::getCoords
osg::Vec3 * getCoords()
Definition ImpostorSprite:85
osgSim::ImpostorSprite::_lastFrameUsed
unsigned int _lastFrameUsed
Definition ImpostorSprite:161
osgSim::ImpostorSprite::getParent
Impostor * getParent()
Definition ImpostorSprite:61
osgSim::ImpostorSprite::getCamera
const osg::Camera * getCamera() const
Definition ImpostorSprite:137
osgSim::ImpostorSprite::setStoredLocalEyePoint
void setStoredLocalEyePoint(const osg::Vec3 &v)
Definition ImpostorSprite:67
osgSim::ImpostorSprite::isSameKindAs
virtual bool isSameKindAs(const osg::Object *obj) const
Definition ImpostorSprite:50
osgSim::ImpostorSprite::_parent
Impostor * _parent
Definition ImpostorSprite:148
osgSim::ImpostorSprite::_camera
osg::ref_ptr< osg::Camera > _camera
Definition ImpostorSprite:153
osgSim::ImpostorSprite::getControlCoords
osg::Vec3 * getControlCoords()
Definition ImpostorSprite:112
osgSim::ImpostorSprite::_texcoords
osg::ref_ptr< osg::Vec2Array > _texcoords
Definition ImpostorSprite:166
osgSim::ImpostorSprite::setLastFrameUsed
void setLastFrameUsed(unsigned int frameNumber)
Definition ImpostorSprite:73
osgSim::ImpostorSprite::_s
int _s
Definition ImpostorSprite:170
osgSim::ImpostorSprite::getControlCoords
const osg::Vec3 * getControlCoords() const
Definition ImpostorSprite:115
osgSim::ImpostorSprite::ImpostorSprite
ImpostorSprite(const ImpostorSprite &)
osgSim::ImpostorSprite::~ImpostorSprite
virtual ~ImpostorSprite()
osgSim::ImpostorSprite::getParent
const Impostor * getParent() const
Definition ImpostorSprite:64
osgSim::ImpostorSprite::getTexCoords
osg::Vec2 * getTexCoords()
Definition ImpostorSprite:95
osgSim::ImpostorSprite::setParent
void setParent(Impostor *parent)
Definition ImpostorSprite:58
osgSim::ImpostorSprite::setTexture
void setTexture(osg::Texture2D *tex, int s, int t)
osgSim::ImpostorSprite::libraryName
virtual const char * libraryName() const
Definition ImpostorSprite:51
osgSim::ImpostorSprite::getStoredLocalEyePoint
const osg::Vec3 & getStoredLocalEyePoint() const
Definition ImpostorSprite:70
osgSim::ImpostorSprite::getLastFrameUsed
unsigned int getLastFrameUsed() const
Definition ImpostorSprite:76
osgSim::ImpostorSprite::ImpostorSpriteManager
friend class osgSim::ImpostorSpriteManager
Definition ImpostorSprite:150
osgSim::ImpostorSprite::cloneType
virtual osg::Object * cloneType() const
Definition ImpostorSprite:44
osgSim::ImpostorSprite::_previous
ImpostorSprite * _previous
Definition ImpostorSprite:158
osgSim::ImpostorSprite::getTexture
const osg::Texture2D * getTexture() const
Definition ImpostorSprite:125
osgSim::ImpostorSprite::ImpostorSprite
ImpostorSprite()
osgSim::ImpostorSprite::getTexture
osg::Texture2D * getTexture()
Definition ImpostorSprite:124
osgSim::ImpostorSprite::_coords
osg::ref_ptr< osg::Vec3Array > _coords
Definition ImpostorSprite:165
osgSim::ImpostorSprite::t
int t() const
Definition ImpostorSprite:128
osgSim::ImpostorSprite::_storedLocalEyePoint
osg::Vec3 _storedLocalEyePoint
Definition ImpostorSprite:163
osgSim::ImpostorSprite::getTexCoords
const osg::Vec2 * getTexCoords() const
Definition ImpostorSprite:98
osgSim::ImpostorSprite::setCamera
void setCamera(osg::Camera *camera)
Definition ImpostorSprite:131
osgSim::ImpostorSprite::className
virtual const char * className() const
Definition ImpostorSprite:52
osgSim::ImpostorSprite::_controlcoords
osg::Vec3 _controlcoords[4]
Definition ImpostorSprite:167
osgSim::ImpostorSprite::s
int s() const
Definition ImpostorSprite:127
osgSim::ImpostorSprite::init
void init()
osgSim::ImpostorSprite::clone
virtual osg::Object * clone(const osg::CopyOp &) const
Definition ImpostorSprite:49
osgSim::ImpostorSprite::_texture
osg::Texture2D * _texture
Definition ImpostorSprite:169
osgSim::ImpostorSprite::calcPixelError
float calcPixelError(const osg::Matrix &MVPW) const
osgSim::Impostor
Definition Impostor:65
osg::Camera
Definition Camera:45
osg::CopyOp
Definition CopyOp:41
osg::Geometry
Definition Geometry:31
osg::Object
Definition Object:61
osg::Referenced
Definition Referenced:44
osg::StateSet
Definition StateSet:46
osg::Texture2D
Definition Texture2D:25
osg::ref_ptr
Definition ref_ptr:32
osgSim
Definition BlinkSequence:27
osg::Vec2
Vec2f Vec2
Definition Vec2:21
osg::Vec3
Vec3f Vec3
Definition Vec3:21
osg::Matrix
Matrixd Matrix
Definition Matrix:27
Export
OSGSIM_EXPORT
#define OSGSIM_EXPORT
Definition osgSim/Export:38
NULL
#define NULL
Definition osg/Export:55