2006-07-18 23:21:48 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2001-10-04 23:12:57 +08:00
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
#ifndef OSG_ImpostorSprite
|
|
|
|
#define OSG_ImpostorSprite 1
|
|
|
|
|
|
|
|
#include <osg/Vec2>
|
|
|
|
#include <osg/BoundingSphere>
|
|
|
|
#include <osg/Drawable>
|
2001-09-22 10:42:08 +08:00
|
|
|
#include <osg/AlphaFunc>
|
|
|
|
#include <osg/TexEnv>
|
2005-05-02 03:48:49 +08:00
|
|
|
#include <osg/Texture2D>
|
2006-11-27 22:52:07 +08:00
|
|
|
#include <osg/Camera>
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2005-05-02 03:48:49 +08:00
|
|
|
#include <osgSim/Export>
|
|
|
|
|
|
|
|
namespace osgSim {
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
class Impostor;
|
|
|
|
class ImpostorSpriteManager;
|
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** An ImposterSprite is a textured quad which is rendered in place of
|
|
|
|
* 3D geometry. The ImposterSprite is generated by rendering the original
|
2001-09-20 05:19:47 +08:00
|
|
|
* 3D geometry to a texture as an image cache. The ImpostorSprite is
|
2001-10-01 19:15:55 +08:00
|
|
|
* automatically generated by the osgUtil::CullVisitor so it not
|
2001-09-20 05:19:47 +08:00
|
|
|
* necessary to deal with it directly.
|
2004-09-13 23:14:11 +08:00
|
|
|
*/
|
2005-05-02 03:48:49 +08:00
|
|
|
class OSGSIM_EXPORT ImpostorSprite : public osg::Drawable
|
2001-09-20 05:19:47 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
ImpostorSprite();
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Clone an object of the same type as an ImpostorSprite. */
|
2005-05-02 03:48:49 +08:00
|
|
|
virtual osg::Object* cloneType() const { return new ImpostorSprite(); }
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
|
|
|
|
/** Clone on ImpostorSprite just returns a clone of type,
|
2004-09-13 23:14:11 +08:00
|
|
|
* since it is not appropriate to share data of an ImpostorSprite.
|
|
|
|
*/
|
2005-05-02 03:48:49 +08:00
|
|
|
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"; }
|
2001-09-20 05:19:47 +08:00
|
|
|
virtual const char* className() const { return "ImpostorSprite"; }
|
|
|
|
|
|
|
|
/** Set the parent, which must be an Impostor.
|
2004-09-13 23:14:11 +08:00
|
|
|
* Unlike conventional Drawables, ImpostorSprites can only ever have
|
2001-09-20 05:19:47 +08:00
|
|
|
* one parent.
|
2004-09-13 23:14:11 +08:00
|
|
|
*/
|
2001-09-20 05:19:47 +08:00
|
|
|
void setParent(Impostor* parent) { _parent = parent; }
|
|
|
|
|
|
|
|
/** Get the parent, which is an Impostor. */
|
|
|
|
Impostor* getParent() { return _parent; }
|
|
|
|
|
|
|
|
/** Get the const parent, which is an Impostor. */
|
|
|
|
const Impostor* getParent() const { return _parent; }
|
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Set the eye point for when the ImpostorSprite was snapped. */
|
2005-05-02 03:48:49 +08:00
|
|
|
inline void setStoredLocalEyePoint(const osg::Vec3& v) { _storedLocalEyePoint=v; }
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Get the eye point for when the ImpostorSprite was snapped. */
|
2005-05-02 03:48:49 +08:00
|
|
|
inline const osg::Vec3& getStoredLocalEyePoint() const { return _storedLocalEyePoint; }
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Set the frame number for when the ImpostorSprite was last used in rendering. */
|
2002-09-02 20:31:35 +08:00
|
|
|
inline void setLastFrameUsed(int frameNumber) { _lastFrameUsed = frameNumber; }
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Get the frame number for when the ImpostorSprite was last used in rendering. */
|
2001-09-20 05:19:47 +08:00
|
|
|
inline int getLastFrameUsed() const { return _lastFrameUsed; }
|
|
|
|
|
|
|
|
|
|
|
|
/** Get the coordinates of the corners of the quad.
|
|
|
|
* Stored in the order, [0] - top_left, [1] - bottom_left, [2] - bottom_right, [3] - top_left.
|
2004-09-13 23:14:11 +08:00
|
|
|
*/
|
2005-05-02 03:48:49 +08:00
|
|
|
inline osg::Vec3* getCoords() { return _coords; }
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Get the const coordinates of the corners of the quad. */
|
2005-05-02 03:48:49 +08:00
|
|
|
inline const osg::Vec3* getCoords() const { return _coords; }
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Get the texture coordinates of the corners of the quad.
|
|
|
|
* Stored in the order, [0] - top_left, [1] - bottom_left, [2] - bottom_right, [3] - top_left.
|
2004-09-13 23:14:11 +08:00
|
|
|
*/
|
2005-05-02 03:48:49 +08:00
|
|
|
inline osg::Vec2* getTexCoords() { return _texcoords; }
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Get the const texture coordinates of the corners of the quad. */
|
2005-05-02 03:48:49 +08:00
|
|
|
inline const osg::Vec2* getTexCoords() const { return _texcoords; }
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
/** Get the control coordinates of the corners of the quad.
|
2001-10-01 19:15:55 +08:00
|
|
|
* The control coordinates are the corners of the quad projected
|
2001-09-20 05:19:47 +08:00
|
|
|
* out onto the front face of bounding box which enclosed the impostor
|
|
|
|
* geometry when it was pre-rendered into the impostor sprite's texture.
|
|
|
|
* At the point of creation/or update of the impostor sprite the control
|
2001-10-01 19:15:55 +08:00
|
|
|
* coords will lie on top of the corners of the quad in screen space - with a pixel error
|
2004-09-13 23:14:11 +08:00
|
|
|
* of zero. Once the camera moves relative to the impostor sprite the
|
2001-10-01 19:15:55 +08:00
|
|
|
* control coords will no longer lie on top of the corners of the quad in
|
2001-09-20 05:19:47 +08:00
|
|
|
* screen space - a pixel error will have accumulated. This pixel error
|
2001-10-01 19:15:55 +08:00
|
|
|
* can then be used to determine whether the impostor needs to be updated.
|
2001-09-20 05:19:47 +08:00
|
|
|
* Stored in the order, [0] - top_left, [1] - bottom_left, [2] - bottom_right, [3] - top_left.
|
2004-09-13 23:14:11 +08:00
|
|
|
*/
|
2005-05-02 03:48:49 +08:00
|
|
|
inline osg::Vec3* getControlCoords() { return _controlcoords; }
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Get the const control coordinates of the corners of the quad. */
|
2005-05-02 03:48:49 +08:00
|
|
|
inline const osg::Vec3* getControlCoords() const { return _controlcoords; }
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Calculate the pixel error value for passing in the ModelViewProjectionWindow transform,
|
|
|
|
* which transform local coords into screen space.
|
|
|
|
*/
|
2005-05-02 03:48:49 +08:00
|
|
|
float calcPixelError(const osg::Matrix& MVPW) const;
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2005-05-02 03:48:49 +08:00
|
|
|
void setTexture(osg::Texture2D* tex,int s,int t);
|
|
|
|
osg::Texture2D* getTexture() { return _texture; }
|
|
|
|
const osg::Texture2D* getTexture() const { return _texture; }
|
2005-11-18 01:44:48 +08:00
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
int s() const { return _s; }
|
|
|
|
int t() const { return _t; }
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Draw ImpostorSprite directly. */
|
2007-03-28 19:30:38 +08:00
|
|
|
virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2007-03-06 01:34:36 +08:00
|
|
|
/** Return true, osg::ImpostorSprite does support accept(Drawable::AttributeFunctor&). */
|
|
|
|
virtual bool supports(const Drawable::AttributeFunctor&) const { return true; }
|
2002-11-06 18:24:33 +08:00
|
|
|
|
2007-12-11 01:30:18 +08:00
|
|
|
/** Accept an Drawable::AttributeFunctor and call its methods to tell it about the internal attributes that this Drawable has. */
|
2007-03-06 01:34:36 +08:00
|
|
|
virtual void accept(Drawable::AttributeFunctor& af);
|
2002-11-06 18:24:33 +08:00
|
|
|
|
2007-03-06 01:34:36 +08:00
|
|
|
/** Return true, osg::ImpostorSprite does support accept(Drawable::ConstAttributeFunctor&). */
|
|
|
|
virtual bool supports(const Drawable::ConstAttributeFunctor&) const { return true; }
|
2002-11-06 18:24:33 +08:00
|
|
|
|
2007-12-11 01:30:18 +08:00
|
|
|
/** Accept a Drawable::ConstAttributeFunctor and call its methods to tell it about the internal attributes that this Drawable has. */
|
2007-03-06 01:34:36 +08:00
|
|
|
virtual void accept(Drawable::ConstAttributeFunctor& af) const;
|
2002-11-06 18:24:33 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Return true, osg::ImpostorSprite does support accept(PrimitiveFunctor&). */
|
2005-05-02 03:48:49 +08:00
|
|
|
virtual bool supports(const osg::PrimitiveFunctor&) const { return true; }
|
2002-11-06 18:24:33 +08:00
|
|
|
|
2007-12-11 01:30:18 +08:00
|
|
|
/** Accept a PrimtiveFunctor and call its methods to tell it about the internal primitives that this Drawable has. */
|
2005-05-02 03:48:49 +08:00
|
|
|
virtual void accept(osg::PrimitiveFunctor& pf) const;
|
2002-11-06 18:24:33 +08:00
|
|
|
|
2003-01-24 17:11:05 +08:00
|
|
|
// for debugging purposes.
|
2005-05-02 03:48:49 +08:00
|
|
|
osg::Vec4 _color;
|
2002-07-18 23:36:14 +08:00
|
|
|
|
2005-05-12 22:03:22 +08:00
|
|
|
virtual osg::BoundingBox computeBound() const;
|
2005-07-24 03:05:42 +08:00
|
|
|
|
|
|
|
/** Set the camera node to use for pre rendering the impostor sprite's texture.*/
|
2006-11-27 22:52:07 +08:00
|
|
|
void setCamera(osg::Camera* camera) { _camera = camera; }
|
2005-07-24 03:05:42 +08:00
|
|
|
|
|
|
|
/** Get the camera node to use for pre rendering the impostor sprite's texture.*/
|
2006-11-27 22:52:07 +08:00
|
|
|
osg::Camera* getCamera() { return _camera.get(); }
|
2005-07-24 03:05:42 +08:00
|
|
|
|
|
|
|
/** Get the const camera node to use for pre rendering the impostor sprite's texture.*/
|
2006-11-27 22:52:07 +08:00
|
|
|
const osg::Camera* getCamera() const { return _camera.get(); }
|
2005-05-12 22:03:22 +08:00
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
protected:
|
|
|
|
|
2005-05-13 19:11:52 +08:00
|
|
|
ImpostorSprite(const ImpostorSprite&);
|
2001-09-20 05:19:47 +08:00
|
|
|
ImpostorSprite& operator = (const ImpostorSprite&) { return *this;}
|
|
|
|
|
|
|
|
virtual ~ImpostorSprite();
|
|
|
|
|
|
|
|
Impostor* _parent;
|
|
|
|
|
2005-05-02 03:48:49 +08:00
|
|
|
friend class osgSim::ImpostorSpriteManager;
|
2005-07-24 03:05:42 +08:00
|
|
|
|
|
|
|
// camera node for doing the pre rendering.
|
2006-11-27 22:52:07 +08:00
|
|
|
osg::ref_ptr<osg::Camera> _camera;
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
// support for a double linked list managed by the
|
|
|
|
// ImposotorSpriteManager.
|
|
|
|
ImpostorSpriteManager* _ism;
|
|
|
|
ImpostorSprite* _previous;
|
|
|
|
ImpostorSprite* _next;
|
|
|
|
|
|
|
|
int _lastFrameUsed;
|
|
|
|
|
2005-05-02 03:48:49 +08:00
|
|
|
osg::Vec3 _storedLocalEyePoint;
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2005-05-02 03:48:49 +08:00
|
|
|
osg::Vec3 _coords[4];
|
|
|
|
osg::Vec2 _texcoords[4];
|
|
|
|
osg::Vec3 _controlcoords[4];
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2005-05-02 03:48:49 +08:00
|
|
|
osg::Texture2D* _texture;
|
2001-09-20 05:19:47 +08:00
|
|
|
int _s;
|
|
|
|
int _t;
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Helper class for managing the reuse of ImpostorSprite resources. */
|
2005-05-02 03:48:49 +08:00
|
|
|
class OSGSIM_EXPORT ImpostorSpriteManager : public osg::Referenced
|
2001-09-20 05:19:47 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
ImpostorSpriteManager();
|
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
bool empty() const { return _first==0; }
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
ImpostorSprite* first() { return _first; }
|
|
|
|
|
|
|
|
ImpostorSprite* last() { return _last; }
|
|
|
|
|
|
|
|
void push_back(ImpostorSprite* is);
|
|
|
|
|
|
|
|
void remove(ImpostorSprite* is);
|
|
|
|
|
|
|
|
ImpostorSprite* createOrReuseImpostorSprite(int s,int t,int frameNumber);
|
2003-04-10 05:53:09 +08:00
|
|
|
|
2005-05-02 03:48:49 +08:00
|
|
|
osg::StateSet* createOrReuseStateSet();
|
2003-04-10 05:53:09 +08:00
|
|
|
|
|
|
|
void reset();
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
|
|
~ImpostorSpriteManager();
|
|
|
|
|
2005-05-02 03:48:49 +08:00
|
|
|
osg::ref_ptr<osg::TexEnv> _texenv;
|
|
|
|
osg::ref_ptr<osg::AlphaFunc> _alphafunc;
|
2001-09-22 10:42:08 +08:00
|
|
|
|
2005-05-02 03:48:49 +08:00
|
|
|
ImpostorSprite* _first;
|
|
|
|
ImpostorSprite* _last;
|
2003-04-10 05:53:09 +08:00
|
|
|
|
2005-05-02 03:48:49 +08:00
|
|
|
typedef std::vector< osg::ref_ptr<osg::StateSet> > StateSetList;
|
|
|
|
StateSetList _stateSetList;
|
|
|
|
unsigned int _reuseStateSetIndex;
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2002-02-03 20:33:41 +08:00
|
|
|
}
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
#endif
|