openscenegraph
ImpostorSprite
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/Geometry>
19#include <osg/AlphaFunc>
20#include <osg/TexEnv>
21#include <osg/Texture2D>
22#include <osg/Camera>
23
24#include <osgSim/Export>
25
26namespace osgSim {
27
28class Impostor;
29class ImpostorSpriteManager;
30
38{
39 public:
40
42
44 virtual osg::Object* cloneType() const { return new ImpostorSprite(); }
45
49 virtual osg::Object* clone(const osg::CopyOp&) const { return new ImpostorSprite(); }
50 virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const ImpostorSprite*>(obj)!=NULL; }
51 virtual const char* libraryName() const { return "osgSim"; }
52 virtual const char* className() const { return "ImpostorSprite"; }
53
58 void setParent(Impostor* parent) { _parent = parent; }
59
61 Impostor* getParent() { return _parent; }
62
64 const Impostor* getParent() const { return _parent; }
65
67 inline void setStoredLocalEyePoint(const osg::Vec3& v) { _storedLocalEyePoint=v; }
68
70 inline const osg::Vec3& getStoredLocalEyePoint() const { return _storedLocalEyePoint; }
71
73 inline void setLastFrameUsed(unsigned int frameNumber) { _lastFrameUsed = frameNumber; }
74
76 inline unsigned int getLastFrameUsed() const { return _lastFrameUsed; }
77
78
79 void dirty();
80
81
85 inline osg::Vec3* getCoords() { return &(_coords->front()); }
86
88 inline const osg::Vec3* getCoords() const { return &(_coords->front()); }
89
90
91
95 inline osg::Vec2* getTexCoords() { return &(_texcoords->front()); }
96
98 inline const osg::Vec2* getTexCoords() const { return &(_texcoords->front()); }
99
112 inline osg::Vec3* getControlCoords() { return _controlcoords; }
113
115 inline const osg::Vec3* getControlCoords() const { return _controlcoords; }
116
117
121 float calcPixelError(const osg::Matrix& MVPW) const;
122
123 void setTexture(osg::Texture2D* tex,int s,int t);
124 osg::Texture2D* getTexture() { return _texture; }
125 const osg::Texture2D* getTexture() const { return _texture; }
126
127 int s() const { return _s; }
128 int t() const { return _t; }
129
131 void setCamera(osg::Camera* camera) { _camera = camera; }
132
134 osg::Camera* getCamera() { return _camera.get(); }
135
137 const osg::Camera* getCamera() const { return _camera.get(); }
138
139 protected:
140
142 ImpostorSprite& operator = (const ImpostorSprite&) { return *this;}
143
145
146 void init();
147
149
151
152 // camera node for doing the pre rendering.
154
155 // support for a double linked list managed by the
156 // ImposotorSpriteManager.
160
161 unsigned int _lastFrameUsed;
162
164
167 osg::Vec3 _controlcoords[4];
168
170 int _s;
171 int _t;
172
173
174};
175
178{
179 public:
180
182
183 bool empty() const { return _first==0; }
184
185 ImpostorSprite* first() { return _first; }
186
187 ImpostorSprite* last() { return _last; }
188
190
192
193 ImpostorSprite* createOrReuseImpostorSprite(int s,int t,unsigned int frameNumber);
194
196
197 void reset();
198
199 protected:
200
201
203
206
209
210 typedef std::vector< osg::ref_ptr<osg::StateSet> > StateSetList;
213
214
215};
216
217}
218
219#endif
Definition ImpostorSprite:178
ImpostorSprite * first()
Definition ImpostorSprite:185
bool empty() const
Definition ImpostorSprite:183
std::vector< osg::ref_ptr< osg::StateSet > > StateSetList
Definition ImpostorSprite:210
ImpostorSprite * _last
Definition ImpostorSprite:208
osg::StateSet * createOrReuseStateSet()
void push_back(ImpostorSprite *is)
void remove(ImpostorSprite *is)
ImpostorSprite * _first
Definition ImpostorSprite:207
unsigned int _reuseStateSetIndex
Definition ImpostorSprite:212
ImpostorSprite * last()
Definition ImpostorSprite:187
StateSetList _stateSetList
Definition ImpostorSprite:211
osg::ref_ptr< osg::TexEnv > _texenv
Definition ImpostorSprite:204
osg::ref_ptr< osg::AlphaFunc > _alphafunc
Definition ImpostorSprite:205
ImpostorSprite * createOrReuseImpostorSprite(int s, int t, unsigned int frameNumber)
Definition ImpostorSprite:38
ImpostorSpriteManager * _ism
Definition ImpostorSprite:157
osg::Camera * getCamera()
Definition ImpostorSprite:134
const osg::Vec3 * getCoords() const
Definition ImpostorSprite:88
int _t
Definition ImpostorSprite:171
ImpostorSprite * _next
Definition ImpostorSprite:159
osg::Vec3 * getCoords()
Definition ImpostorSprite:85
unsigned int _lastFrameUsed
Definition ImpostorSprite:161
Impostor * getParent()
Definition ImpostorSprite:61
const osg::Camera * getCamera() const
Definition ImpostorSprite:137
void setStoredLocalEyePoint(const osg::Vec3 &v)
Definition ImpostorSprite:67
virtual bool isSameKindAs(const osg::Object *obj) const
Definition ImpostorSprite:50
Impostor * _parent
Definition ImpostorSprite:148
osg::ref_ptr< osg::Camera > _camera
Definition ImpostorSprite:153
osg::Vec3 * getControlCoords()
Definition ImpostorSprite:112
osg::ref_ptr< osg::Vec2Array > _texcoords
Definition ImpostorSprite:166
void setLastFrameUsed(unsigned int frameNumber)
Definition ImpostorSprite:73
int _s
Definition ImpostorSprite:170
const osg::Vec3 * getControlCoords() const
Definition ImpostorSprite:115
ImpostorSprite(const ImpostorSprite &)
const Impostor * getParent() const
Definition ImpostorSprite:64
osg::Vec2 * getTexCoords()
Definition ImpostorSprite:95
void setParent(Impostor *parent)
Definition ImpostorSprite:58
void setTexture(osg::Texture2D *tex, int s, int t)
virtual const char * libraryName() const
Definition ImpostorSprite:51
const osg::Vec3 & getStoredLocalEyePoint() const
Definition ImpostorSprite:70
unsigned int getLastFrameUsed() const
Definition ImpostorSprite:76
virtual osg::Object * cloneType() const
Definition ImpostorSprite:44
ImpostorSprite * _previous
Definition ImpostorSprite:158
const osg::Texture2D * getTexture() const
Definition ImpostorSprite:125
osg::Texture2D * getTexture()
Definition ImpostorSprite:124
osg::ref_ptr< osg::Vec3Array > _coords
Definition ImpostorSprite:165
int t() const
Definition ImpostorSprite:128
osg::Vec3 _storedLocalEyePoint
Definition ImpostorSprite:163
const osg::Vec2 * getTexCoords() const
Definition ImpostorSprite:98
void setCamera(osg::Camera *camera)
Definition ImpostorSprite:131
virtual const char * className() const
Definition ImpostorSprite:52
int s() const
Definition ImpostorSprite:127
virtual osg::Object * clone(const osg::CopyOp &) const
Definition ImpostorSprite:49
osg::Texture2D * _texture
Definition ImpostorSprite:169
float calcPixelError(const osg::Matrix &MVPW) const
Definition Impostor:65
Definition Camera:45
Definition CopyOp:41
Definition Geometry:31
Definition Matrixd:27
Definition Object:61
Definition Referenced:44
Definition StateSet:46
Definition Texture2D:25
Definition Vec2f:29
Definition Vec3f:29
Definition ref_ptr:32
Definition BlinkSequence:27
#define OSGSIM_EXPORT
Definition osgSim/Export:38
#define NULL
Definition osg/Export:55