OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ImpostorSprite.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
3  * This library is open source and may be redistributed and/or modified under
4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5  * (at your option) any later version. The full license is in LICENSE file
6  * included with this distribution, and on the openscenegraph.org website.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * OpenSceneGraph Public License for more details.
12 */
13 
14 #ifndef OSG_ImpostorSprite
15 #define OSG_ImpostorSprite 1
16 
17 #include <osg/Vec2>
18 #include <osg/BoundingSphere>
19 #include <osg/Drawable>
20 #include <osg/AlphaFunc>
21 #include <osg/TexEnv>
22 #include <osg/Texture2D>
23 #include <osg/Camera>
24 
25 #include <osgSim/Export>
26 
27 namespace osgSim {
28 
29 class Impostor;
30 class ImpostorSpriteManager;
31 
39 {
40  public:
41 
43 
45  virtual osg::Object* cloneType() const { return new ImpostorSprite(); }
46 
50  virtual osg::Object* clone(const osg::CopyOp&) const { return new ImpostorSprite(); }
51  virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const ImpostorSprite*>(obj)!=NULL; }
52  virtual const char* libraryName() const { return "osgSim"; }
53  virtual const char* className() const { return "ImpostorSprite"; }
54 
59  void setParent(Impostor* parent) { _parent = parent; }
60 
62  Impostor* getParent() { return _parent; }
63 
65  const Impostor* getParent() const { return _parent; }
66 
68  inline void setStoredLocalEyePoint(const osg::Vec3& v) { _storedLocalEyePoint=v; }
69 
71  inline const osg::Vec3& getStoredLocalEyePoint() const { return _storedLocalEyePoint; }
72 
74  inline void setLastFrameUsed(unsigned int frameNumber) { _lastFrameUsed = frameNumber; }
75 
77  inline unsigned int getLastFrameUsed() const { return _lastFrameUsed; }
78 
79 
83  inline osg::Vec3* getCoords() { return _coords; }
84 
86  inline const osg::Vec3* getCoords() const { return _coords; }
87 
88 
89 
93  inline osg::Vec2* getTexCoords() { return _texcoords; }
94 
96  inline const osg::Vec2* getTexCoords() const { return _texcoords; }
97 
110  inline osg::Vec3* getControlCoords() { return _controlcoords; }
111 
113  inline const osg::Vec3* getControlCoords() const { return _controlcoords; }
114 
115 
119  float calcPixelError(const osg::Matrix& MVPW) const;
120 
121  void setTexture(osg::Texture2D* tex,int s,int t);
122  osg::Texture2D* getTexture() { return _texture; }
123  const osg::Texture2D* getTexture() const { return _texture; }
124 
125  int s() const { return _s; }
126  int t() const { return _t; }
127 
129  virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
130 
132  virtual bool supports(const Drawable::AttributeFunctor&) const { return true; }
133 
135  virtual void accept(Drawable::AttributeFunctor& af);
136 
138  virtual bool supports(const Drawable::ConstAttributeFunctor&) const { return true; }
139 
141  virtual void accept(Drawable::ConstAttributeFunctor& af) const;
142 
144  virtual bool supports(const osg::PrimitiveFunctor&) const { return true; }
145 
147  virtual void accept(osg::PrimitiveFunctor& pf) const;
148 
149  // for debugging purposes.
151 
152  virtual osg::BoundingBox computeBoundingBox() const;
153 
155  void setCamera(osg::Camera* camera) { _camera = camera; }
156 
158  osg::Camera* getCamera() { return _camera.get(); }
159 
161  const osg::Camera* getCamera() const { return _camera.get(); }
162 
163  protected:
164 
166  ImpostorSprite& operator = (const ImpostorSprite&) { return *this;}
167 
168  virtual ~ImpostorSprite();
169 
171 
173 
174  // camera node for doing the pre rendering.
176 
177  // support for a double linked list managed by the
178  // ImposotorSpriteManager.
182 
183  unsigned int _lastFrameUsed;
184 
186 
187  osg::Vec3 _coords[4];
188  osg::Vec2 _texcoords[4];
189  osg::Vec3 _controlcoords[4];
190 
192  int _s;
193  int _t;
194 
195 
196 };
197 
200 {
201  public:
202 
204 
205  bool empty() const { return _first==0; }
206 
207  ImpostorSprite* first() { return _first; }
208 
209  ImpostorSprite* last() { return _last; }
210 
211  void push_back(ImpostorSprite* is);
212 
213  void remove(ImpostorSprite* is);
214 
215  ImpostorSprite* createOrReuseImpostorSprite(int s,int t,unsigned int frameNumber);
216 
217  osg::StateSet* createOrReuseStateSet();
218 
219  void reset();
220 
221  protected:
222 
223 
225 
228 
231 
232  typedef std::vector< osg::ref_ptr<osg::StateSet> > StateSetList;
233  StateSetList _stateSetList;
234  unsigned int _reuseStateSetIndex;
235 
236 
237 };
238 
239 }
240 
241 #endif
virtual bool isSameKindAs(const osg::Object *obj) const
const osg::Vec2 * getTexCoords() const
#define OSGSIM_EXPORT
Definition: Export.h:38
void setCamera(osg::Camera *camera)
virtual bool supports(const Drawable::AttributeFunctor &) const
const osg::Vec3 * getControlCoords() const
#define NULL
Definition: Export.h:59
osg::Texture2D * getTexture()
virtual osg::Object * cloneType() const
const osg::Vec3 & getStoredLocalEyePoint() const
osg::Camera * getCamera()
virtual const char * libraryName() const
void setParent(Impostor *parent)
std::vector< osg::ref_ptr< osg::StateSet > > StateSetList
ImpostorSprite * _previous
osg::Texture2D * _texture
const Impostor * getParent() const
const osg::Camera * getCamera() const
osg::ref_ptr< osg::AlphaFunc > _alphafunc
const osg::Texture2D * getTexture() const
virtual bool supports(const Drawable::ConstAttributeFunctor &) const
osg::Vec3 * getCoords()
virtual bool supports(const osg::PrimitiveFunctor &) const
void setStoredLocalEyePoint(const osg::Vec3 &v)
osg::Vec2 * getTexCoords()
ImpostorSpriteManager * _ism
unsigned int _lastFrameUsed
unsigned int getLastFrameUsed() const
osg::ref_ptr< osg::Camera > _camera
void setLastFrameUsed(unsigned int frameNumber)
const osg::Vec3 * getCoords() const
virtual osg::Object * clone(const osg::CopyOp &) const
osg::Vec3 * getControlCoords()
ImpostorSprite * _next
osg::ref_ptr< osg::TexEnv > _texenv
virtual const char * className() const