2005-04-15 05:41:28 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2005 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.
|
|
|
|
*/
|
2002-06-05 20:44:55 +08:00
|
|
|
//osgParticle - Copyright (C) 2002 Marco Jez
|
|
|
|
|
2005-04-29 17:47:57 +08:00
|
|
|
#ifndef OSGPARTICLE_SEGMENT_PLACER
|
|
|
|
#define OSGPARTICLE_SEGMENT_PLACER 1
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
#include <osgParticle/Placer>
|
|
|
|
#include <osgParticle/Particle>
|
|
|
|
|
|
|
|
#include <osg/CopyOp>
|
|
|
|
#include <osg/Object>
|
|
|
|
#include <osg/Vec3>
|
|
|
|
|
|
|
|
namespace osgParticle {
|
|
|
|
|
|
|
|
/** A segment-shaped particle placer.
|
|
|
|
To use this placer you have to define a segment, by setting its two vertices (<B>A</B> and <B>B</B>);
|
|
|
|
when an emitter requests a <CODE>SegmentPlacer</CODE> to place a particle, the position is chosen randomly
|
|
|
|
within that segment.
|
|
|
|
*/
|
|
|
|
class SegmentPlacer: public Placer {
|
|
|
|
public:
|
|
|
|
inline SegmentPlacer();
|
2005-04-29 17:47:57 +08:00
|
|
|
inline SegmentPlacer(const SegmentPlacer& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
|
2002-06-05 20:44:55 +08:00
|
|
|
|
2002-06-06 21:25:36 +08:00
|
|
|
META_Object(osgParticle, SegmentPlacer);
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
/// get vertex <B>A</B>.
|
2005-04-29 17:47:57 +08:00
|
|
|
inline const osg::Vec3& getVertexA() const;
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
/// Set vertex <B>A</B> of the segment as a vector.
|
2005-04-29 17:47:57 +08:00
|
|
|
inline void setVertexA(const osg::Vec3& v);
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
/// Set vertex <B>A</B> of the segment as three floats.
|
|
|
|
inline void setVertexA(float x, float y, float z);
|
|
|
|
|
|
|
|
/// get vertex <B>B</B>.
|
2005-04-29 17:47:57 +08:00
|
|
|
inline const osg::Vec3& getVertexB() const;
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
/// Set vertex <B>B</B> of the segment as a vector.
|
2005-04-29 17:47:57 +08:00
|
|
|
inline void setVertexB(const osg::Vec3& v);
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
/// Set vertex <B>B</B> of the segment as three floats.
|
|
|
|
inline void setVertexB(float x, float y, float z);
|
|
|
|
|
|
|
|
/// Set both vertices.
|
2005-04-29 17:47:57 +08:00
|
|
|
inline void setSegment(const osg::Vec3& A, const osg::Vec3& B);
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
/// Place a particle. This method is called by <CODE>ModularEmitter</CODE>, do not call it manually.
|
2005-04-29 17:47:57 +08:00
|
|
|
inline void place(Particle* P) const;
|
2002-06-05 20:44:55 +08:00
|
|
|
|
2005-08-25 22:12:08 +08:00
|
|
|
/// return the control position
|
|
|
|
inline osg::Vec3 getControlPosition() const;
|
|
|
|
|
2002-06-05 20:44:55 +08:00
|
|
|
protected:
|
|
|
|
virtual ~SegmentPlacer() {}
|
2005-04-29 17:47:57 +08:00
|
|
|
SegmentPlacer& operator=(const SegmentPlacer&) { return *this; }
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
private:
|
2005-04-29 17:47:57 +08:00
|
|
|
osg::Vec3 _vertexA;
|
|
|
|
osg::Vec3 _vertexB;
|
2002-06-05 20:44:55 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// INLINE FUNCTIONS
|
|
|
|
|
|
|
|
inline SegmentPlacer::SegmentPlacer()
|
2005-04-29 17:47:57 +08:00
|
|
|
: Placer(), _vertexA(-1, 0, 0), _vertexB(1, 0, 0)
|
2002-06-05 20:44:55 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-04-29 17:47:57 +08:00
|
|
|
inline SegmentPlacer::SegmentPlacer(const SegmentPlacer& copy, const osg::CopyOp& copyop)
|
|
|
|
: Placer(copy, copyop), _vertexA(copy._vertexA), _vertexB(copy._vertexB)
|
2002-06-05 20:44:55 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-04-29 17:47:57 +08:00
|
|
|
inline const osg::Vec3& SegmentPlacer::getVertexA() const
|
2002-06-05 20:44:55 +08:00
|
|
|
{
|
2005-04-29 17:47:57 +08:00
|
|
|
return _vertexA;
|
2002-06-05 20:44:55 +08:00
|
|
|
}
|
|
|
|
|
2005-04-29 17:47:57 +08:00
|
|
|
inline const osg::Vec3& SegmentPlacer::getVertexB() const
|
2002-06-05 20:44:55 +08:00
|
|
|
{
|
2005-04-29 17:47:57 +08:00
|
|
|
return _vertexB;
|
2002-06-05 20:44:55 +08:00
|
|
|
}
|
|
|
|
|
2005-04-29 17:47:57 +08:00
|
|
|
inline void SegmentPlacer::setSegment(const osg::Vec3& A, const osg::Vec3& B)
|
2002-06-05 20:44:55 +08:00
|
|
|
{
|
2005-04-29 17:47:57 +08:00
|
|
|
_vertexA = A;
|
|
|
|
_vertexB = B;
|
2002-06-05 20:44:55 +08:00
|
|
|
}
|
|
|
|
|
2005-04-29 17:47:57 +08:00
|
|
|
inline void SegmentPlacer::place(Particle* P) const
|
2002-06-05 20:44:55 +08:00
|
|
|
{
|
2005-04-29 17:47:57 +08:00
|
|
|
P->setPosition(rangev3(_vertexA, _vertexB).get_random());
|
2002-06-05 20:44:55 +08:00
|
|
|
}
|
|
|
|
|
2005-04-29 17:47:57 +08:00
|
|
|
inline void SegmentPlacer::setVertexA(const osg::Vec3& v)
|
2002-06-05 20:44:55 +08:00
|
|
|
{
|
2005-04-29 17:47:57 +08:00
|
|
|
_vertexA = v;
|
2002-06-05 20:44:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void SegmentPlacer::setVertexA(float x, float y, float z)
|
|
|
|
{
|
2005-04-29 17:47:57 +08:00
|
|
|
_vertexA.set(x, y, z);
|
2002-06-05 20:44:55 +08:00
|
|
|
}
|
|
|
|
|
2005-04-29 17:47:57 +08:00
|
|
|
inline void SegmentPlacer::setVertexB(const osg::Vec3& v)
|
2002-06-05 20:44:55 +08:00
|
|
|
{
|
2005-04-29 17:47:57 +08:00
|
|
|
_vertexB = v;
|
2002-06-05 20:44:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void SegmentPlacer::setVertexB(float x, float y, float z)
|
|
|
|
{
|
2005-04-29 17:47:57 +08:00
|
|
|
_vertexB.set(x, y, z);
|
2002-06-05 20:44:55 +08:00
|
|
|
}
|
2005-08-25 22:12:08 +08:00
|
|
|
|
|
|
|
inline osg::Vec3 SegmentPlacer::getControlPosition() const
|
|
|
|
{
|
|
|
|
return (_vertexA+_vertexB)*0.5f;
|
|
|
|
}
|
|
|
|
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|