2001-01-11 00:32:10 +08:00
|
|
|
#ifndef OSG_BILLBOARD
|
|
|
|
#define OSG_BILLBOARD 1
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
#include <osg/Matrix>
|
2001-01-11 00:32:10 +08:00
|
|
|
#include <osg/Geode>
|
|
|
|
|
|
|
|
namespace osg {
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
/** Billboard - a Geode which orientates its child osg::Drawable's to face
|
2001-01-11 00:32:10 +08:00
|
|
|
the eye point.
|
|
|
|
Typical uses are for trees, or particle explosions.
|
|
|
|
*/
|
|
|
|
class SG_EXPORT Billboard : public Geode
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
enum Mode {
|
|
|
|
AXIAL_ROT,
|
|
|
|
POINT_ROT_EYE,
|
|
|
|
POINT_ROT_WORLD
|
|
|
|
};
|
|
|
|
|
|
|
|
Billboard();
|
|
|
|
|
2001-09-22 10:42:08 +08:00
|
|
|
META_Node(Billboard);
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
/** Set the axis about which all the billboard's drawable rotate. */
|
|
|
|
inline void setAxis(const Vec3& axis) { _axis = axis; }
|
|
|
|
/** Get the axis about which all the billboard's drawable rotate. */
|
|
|
|
inline const Vec3& getAxis() const { return _axis; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
/** Set the billboard rotation mode. */
|
|
|
|
inline void setMode(const Mode mode) { _mode = mode; }
|
|
|
|
/** Get the billboard rotation mode. */
|
|
|
|
inline const Mode getMode() const { return _mode; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
/** Set the position of specified drawable. */
|
|
|
|
inline void setPos(int i,const Vec3& pos) { _positionList[i] = pos; }
|
|
|
|
/** Get the position of specified drawable. */
|
|
|
|
inline const Vec3& getPos(int i) const { return _positionList[i]; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
/** PositionList represents a list of pivot points for each drawable.*/
|
|
|
|
typedef std::vector<Vec3> PositionList;
|
|
|
|
|
|
|
|
/** Get the PostionList from the billboard.*/
|
|
|
|
inline PositionList& getPositionList() { return _positionList; }
|
|
|
|
/** Get a const PostionList from the billboard.*/
|
|
|
|
inline const PositionList& getPositionList() const { return _positionList; }
|
|
|
|
|
|
|
|
/** Add Drawable to Billboard with default position(0,0,0);
|
2001-01-11 00:32:10 +08:00
|
|
|
* If gset not NULL and is not contained in Billboard then increment its
|
|
|
|
* reference count, and dirty the bounding box to cause it to recompute on
|
|
|
|
* next getBound() and return true for success. Otherwise return false.
|
|
|
|
*/
|
2001-09-20 05:08:56 +08:00
|
|
|
virtual const bool addDrawable( Drawable *gset );
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
/** Add Drawable to Geode at position pos.
|
2001-01-11 00:32:10 +08:00
|
|
|
* If gset not NULL and is not contained in Billboard then increment its
|
|
|
|
* reference count, and dirty the bounding box to cause it to recompute on
|
|
|
|
* next getBound() and return true for success. Otherwise return false.
|
|
|
|
*/
|
2001-09-20 05:08:56 +08:00
|
|
|
virtual const bool addDrawable(Drawable *gset,const Vec3& pos);
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
/** Remove Drawable and associated position from Billboard.
|
2001-01-11 00:32:10 +08:00
|
|
|
* If gset is contained in Billboard then remove it from the geoset
|
|
|
|
* list and decrement its reference count, and dirty the
|
|
|
|
* bounding box to cause it to recompute on next getBound() and
|
|
|
|
* return true for success. If gset is not found then return false
|
|
|
|
* and do not the reference count of gset is left unchanged.
|
|
|
|
*/
|
2001-09-20 05:08:56 +08:00
|
|
|
virtual const bool removeDrawable( Drawable *gset );
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
void calcRotation(const Vec3& eye_local, const Vec3& pos_local,Matrix& mat) const;
|
|
|
|
void calcTransform(const Vec3& eye_local, const Vec3& pos_local,Matrix& mat) const;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual ~Billboard();
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
virtual const bool computeBound() const;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
Mode _mode;
|
|
|
|
Vec3 _axis;
|
|
|
|
PositionList _positionList;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|