2012-03-22 01:36:20 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
2012-03-22 01:36:20 +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
|
2003-01-22 00:45:36 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2003-01-22 00:45:36 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-03-22 01:36:20 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2003-01-22 00:45:36 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2001-10-04 23:12:57 +08:00
|
|
|
|
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 {
|
|
|
|
|
2004-09-01 16:15:36 +08:00
|
|
|
/** Billboard is a derived form of Geode that orients its osg::Drawable
|
2007-12-11 01:30:18 +08:00
|
|
|
* children to face the eye point. Typical uses include trees and
|
2004-09-01 16:15:36 +08:00
|
|
|
* particle explosions,
|
2001-01-11 00:32:10 +08:00
|
|
|
*/
|
2005-04-12 01:14:17 +08:00
|
|
|
class OSG_EXPORT Billboard : public Geode
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
enum Mode {
|
|
|
|
POINT_ROT_EYE,
|
2002-01-19 06:15:59 +08:00
|
|
|
POINT_ROT_WORLD,
|
|
|
|
AXIAL_ROT
|
2001-01-11 00:32:10 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
Billboard();
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2004-09-01 16:15:36 +08:00
|
|
|
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
|
2002-01-29 22:04:06 +08:00
|
|
|
Billboard(const Billboard&,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
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
|
|
|
|
2002-06-06 21:25:36 +08:00
|
|
|
META_Node(osg, Billboard);
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2002-01-19 06:15:59 +08:00
|
|
|
/** Set the billboard rotation mode. */
|
2002-09-02 20:31:35 +08:00
|
|
|
void setMode(Mode mode);
|
2002-01-19 06:15:59 +08:00
|
|
|
/** Get the billboard rotation mode. */
|
2002-09-02 20:31:35 +08:00
|
|
|
inline Mode getMode() const { return _mode; }
|
2002-01-19 06:15:59 +08:00
|
|
|
|
2004-09-01 16:15:36 +08:00
|
|
|
/** Set the rotation axis for the billboard's child Drawables.
|
2007-12-11 01:30:18 +08:00
|
|
|
* Only utilized when mode==AXIAL_ROT. */
|
2002-01-19 06:15:59 +08:00
|
|
|
void setAxis(const Vec3& axis);
|
2004-09-01 16:15:36 +08:00
|
|
|
/** Get the rotation axis. */
|
2002-01-19 06:15:59 +08:00
|
|
|
inline const Vec3& getAxis() const { return _axis; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2004-09-01 16:15:36 +08:00
|
|
|
/** This normal defines child Drawables' front face direction when unrotated. */
|
2002-08-10 00:27:39 +08:00
|
|
|
void setNormal(const Vec3& normal);
|
2004-09-01 16:15:36 +08:00
|
|
|
/** Get the front face direction normal. */
|
2002-08-10 00:27:39 +08:00
|
|
|
inline const Vec3& getNormal() const { return _normal; }
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2004-09-01 16:15:36 +08:00
|
|
|
/** Set the specified child Drawable's position. */
|
2004-06-15 03:34:43 +08:00
|
|
|
inline void setPosition(unsigned int i,const Vec3& pos) { _positionList[i] = pos; }
|
2004-09-01 16:15:36 +08:00
|
|
|
/** Get the specified child Drawable's position. */
|
2004-06-15 03:34:43 +08:00
|
|
|
inline const Vec3& getPosition(unsigned int i) const { return _positionList[i]; }
|
|
|
|
|
2004-09-01 16:15:36 +08:00
|
|
|
/** Type definition for pivot point position list. */
|
2001-09-20 05:08:56 +08:00
|
|
|
typedef std::vector<Vec3> PositionList;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2004-12-13 09:07:24 +08:00
|
|
|
/** Set the list of pivot point positions. */
|
2005-11-18 01:44:48 +08:00
|
|
|
inline void setPositionList(PositionList& pl) { _positionList=pl; }
|
2004-12-13 09:07:24 +08:00
|
|
|
|
2004-09-01 16:15:36 +08:00
|
|
|
/** Get the list of pivot point positions. */
|
2005-11-18 01:44:48 +08:00
|
|
|
inline PositionList& getPositionList() { return _positionList; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2004-09-01 16:15:36 +08:00
|
|
|
/** Get a const list of pivot point positions. */
|
2005-11-18 01:44:48 +08:00
|
|
|
inline const PositionList& getPositionList() const { return _positionList; }
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2004-09-01 16:15:36 +08:00
|
|
|
/** Add a Drawable with a default position of Vec3(0,0,0).
|
|
|
|
* Call the base-class Geode::addDrawble() to add the given Drawable
|
|
|
|
* gset as a child. If Geode::addDrawable() returns true, add the
|
|
|
|
* default position to the pivot point position list and return true.
|
|
|
|
* Otherwise, return false. */
|
2002-09-02 20:31:35 +08:00
|
|
|
virtual bool addDrawable( Drawable *gset );
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2004-09-01 16:15:36 +08:00
|
|
|
/** Add a Drawable with a specified position.
|
|
|
|
* Call the base-class Geode::addDrawble() to add the given Drawable
|
|
|
|
* gset as a child. If Geode::addDrawable() returns true, add the
|
|
|
|
* given position pos to the pivot point position list and return true.
|
|
|
|
* Otherwise, return false. */
|
2002-09-02 20:31:35 +08:00
|
|
|
virtual bool addDrawable(Drawable *gset,const Vec3& pos);
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2004-09-01 16:15:36 +08:00
|
|
|
/** Remove a Drawable and its associated position.
|
|
|
|
* If gset is a child, remove it, decrement its reference count,
|
|
|
|
* remove its pivot point position. and return true.
|
|
|
|
* Otherwise, return false. */
|
2002-09-02 20:31:35 +08:00
|
|
|
virtual bool removeDrawable( Drawable *gset );
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2003-12-09 22:07:44 +08:00
|
|
|
bool computeMatrix(Matrix& modelview, const Vec3& eye_local, const Vec3& pos_local) const;
|
2002-05-29 07:43:22 +08:00
|
|
|
|
2005-05-12 22:03:22 +08:00
|
|
|
virtual BoundingSphere computeBound() const;
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual ~Billboard();
|
|
|
|
|
2002-01-19 06:15:59 +08:00
|
|
|
enum AxisAligned
|
|
|
|
{
|
|
|
|
AXIAL_ROT_X_AXIS=AXIAL_ROT+1,
|
|
|
|
AXIAL_ROT_Y_AXIS,
|
2002-08-10 00:27:39 +08:00
|
|
|
AXIAL_ROT_Z_AXIS,
|
2004-10-28 21:26:06 +08:00
|
|
|
POINT_ROT_WORLD_Z_AXIS,
|
2002-08-10 00:27:39 +08:00
|
|
|
CACHE_DIRTY
|
2002-01-19 06:15:59 +08:00
|
|
|
};
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2002-02-07 09:07:11 +08:00
|
|
|
Mode _mode;
|
|
|
|
Vec3 _axis;
|
2002-08-10 00:27:39 +08:00
|
|
|
Vec3 _normal;
|
2006-10-15 05:47:13 +08:00
|
|
|
Matrix _rotateNormalToZAxis;
|
2002-02-07 09:07:11 +08:00
|
|
|
PositionList _positionList;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2002-01-19 06:15:59 +08:00
|
|
|
// used internally as cache of which what _axis is aligned to help
|
2002-10-21 21:03:02 +08:00
|
|
|
// decide which method of rotation to use.
|
2002-08-10 00:27:39 +08:00
|
|
|
int _cachedMode;
|
|
|
|
Vec3 _side;
|
|
|
|
void updateCache();
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2002-02-03 20:33:41 +08:00
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
#endif
|