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_MULTISEGMENT_PLACER
|
|
|
|
#define OSGPARTICLE_MULTISEGMENT_PLACER 1
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
#include <osgParticle/Export>
|
|
|
|
#include <osgParticle/Placer>
|
|
|
|
#include <osgParticle/Particle>
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
#include <osg/Notify>
|
|
|
|
#include <osg/CopyOp>
|
|
|
|
#include <osg/Object>
|
|
|
|
#include <osg/Vec3>
|
|
|
|
|
|
|
|
namespace osgParticle {
|
|
|
|
|
|
|
|
/** A polyline-shaped particle placer.
|
|
|
|
This placer class sets the position of incoming particles by choosing a random point on the
|
|
|
|
specified sequence of connected segments.
|
|
|
|
*/
|
|
|
|
class OSGPARTICLE_EXPORT MultiSegmentPlacer: public Placer {
|
|
|
|
public:
|
|
|
|
MultiSegmentPlacer();
|
2005-04-29 17:47:57 +08:00
|
|
|
MultiSegmentPlacer(const MultiSegmentPlacer& 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, MultiSegmentPlacer);
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
/// Get the number of vertices which define the segments.
|
|
|
|
inline int numVertices() const;
|
|
|
|
|
|
|
|
/// Get a vertex.
|
2005-04-29 17:47:57 +08:00
|
|
|
inline const osg::Vec3& getVertex(int i) const;
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
/// Set a vertex.
|
2005-04-29 17:47:57 +08:00
|
|
|
inline void setVertex(int i, const osg::Vec3& v);
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
/// Set a vertex.
|
|
|
|
inline void setVertex(int i, float x, float y, float z);
|
|
|
|
|
|
|
|
/// Add a vertex.
|
2005-04-29 17:47:57 +08:00
|
|
|
inline void addVertex(const osg::Vec3& v);
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
/// Add a vertex.
|
|
|
|
inline void addVertex(float x, float y, float z);
|
|
|
|
|
|
|
|
/// Remove a vertex.
|
|
|
|
inline void removeVertex(int i);
|
|
|
|
|
|
|
|
/// Place a partice. Called automatically by <CODE>ModularEmitter</CODE>, do not call this method manually.
|
2005-04-29 17:47:57 +08:00
|
|
|
void place(Particle* P) const;
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~MultiSegmentPlacer() {}
|
2005-04-29 17:47:57 +08:00
|
|
|
MultiSegmentPlacer& operator=(const MultiSegmentPlacer&) { return *this; }
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
typedef std::pair<osg::Vec3, float> Vertex_data;
|
|
|
|
typedef std::vector<Vertex_data> Vertex_vector;
|
|
|
|
|
2005-04-29 17:47:57 +08:00
|
|
|
Vertex_vector _vx;
|
|
|
|
float _total_length;
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
void recompute_length();
|
|
|
|
};
|
|
|
|
|
|
|
|
// INLINE FUNCTIONS
|
|
|
|
|
|
|
|
|
|
|
|
inline int MultiSegmentPlacer::numVertices() const
|
|
|
|
{
|
2005-04-29 17:47:57 +08:00
|
|
|
return static_cast<int>(_vx.size());
|
2002-06-05 20:44:55 +08:00
|
|
|
}
|
|
|
|
|
2005-04-29 17:47:57 +08:00
|
|
|
inline const osg::Vec3& MultiSegmentPlacer::getVertex(int i) const
|
2002-06-05 20:44:55 +08:00
|
|
|
{
|
2005-04-29 17:47:57 +08:00
|
|
|
return _vx[i].first;
|
2002-06-05 20:44:55 +08:00
|
|
|
}
|
|
|
|
|
2005-04-29 17:47:57 +08:00
|
|
|
inline void MultiSegmentPlacer::setVertex(int i, const osg::Vec3& v)
|
2002-06-05 20:44:55 +08:00
|
|
|
{
|
2005-04-29 17:47:57 +08:00
|
|
|
_vx[i].first = v;
|
2002-06-05 20:44:55 +08:00
|
|
|
recompute_length();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void MultiSegmentPlacer::setVertex(int i, float x, float y, float z)
|
|
|
|
{
|
2005-04-29 17:47:57 +08:00
|
|
|
_vx[i].first.set(x, y, z);
|
2002-06-05 20:44:55 +08:00
|
|
|
recompute_length();
|
|
|
|
}
|
|
|
|
|
2005-04-29 17:47:57 +08:00
|
|
|
inline void MultiSegmentPlacer::addVertex(const osg::Vec3& v)
|
2002-06-05 20:44:55 +08:00
|
|
|
{
|
|
|
|
float l = 0;
|
2005-04-29 17:47:57 +08:00
|
|
|
if (_vx.size() > 0) {
|
|
|
|
l = (v - _vx.back().first).length();
|
2002-06-05 20:44:55 +08:00
|
|
|
}
|
2005-04-29 17:47:57 +08:00
|
|
|
_total_length += l;
|
|
|
|
_vx.push_back(std::make_pair(v, _total_length));
|
2002-06-05 20:44:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void MultiSegmentPlacer::addVertex(float x, float y, float z)
|
|
|
|
{
|
|
|
|
addVertex(osg::Vec3(x, y, z));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void MultiSegmentPlacer::removeVertex(int i)
|
|
|
|
{
|
2005-04-29 17:47:57 +08:00
|
|
|
_vx.erase(_vx.begin()+i);
|
2002-06-05 20:44:55 +08:00
|
|
|
recompute_length();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|