1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
13//osgParticle - Copyright (C) 2002 Marco Jez
15#ifndef OSGPARTICLE_MULTISEGMENT_PLACER
16#define OSGPARTICLE_MULTISEGMENT_PLACER 1
18#include <osgParticle/Export>
19#include <osgParticle/Placer>
20#include <osgParticle/Particle>
30namespace osgParticle {
32 /** A polyline-shaped particle placer.
33 This placer class sets the position of incoming particles by choosing a random point on the
34 specified sequence of connected segments.
36 class OSGPARTICLE_EXPORT MultiSegmentPlacer: public Placer {
39 MultiSegmentPlacer(const MultiSegmentPlacer& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
41 META_Object(osgParticle, MultiSegmentPlacer);
43 /// Get the number of vertices which define the segments.
44 inline int numVertices() const;
47 inline const osg::Vec3& getVertex(int i) const;
50 inline void setVertex(int i, const osg::Vec3& v);
53 inline void setVertex(int i, float x, float y, float z);
56 inline void addVertex(const osg::Vec3& v);
59 inline void addVertex(float x, float y, float z);
62 inline void removeVertex(int i);
64 /// Place a partice. Called automatically by <CODE>ModularEmitter</CODE>, do not call this method manually.
65 void place(Particle* P) const;
67 /// return the length of the multi-segment
68 inline float volume() const;
70 /// return the control position
71 inline osg::Vec3 getControlPosition() const;
74 virtual ~MultiSegmentPlacer() {}
75 MultiSegmentPlacer& operator=(const MultiSegmentPlacer&) { return *this; }
78 typedef std::pair<osg::Vec3, float> Vertex_data;
79 typedef std::vector<Vertex_data> Vertex_vector;
84 void recompute_length();
90 inline int MultiSegmentPlacer::numVertices() const
92 return static_cast<int>(_vx.size());
95 inline const osg::Vec3& MultiSegmentPlacer::getVertex(int i) const
100 inline void MultiSegmentPlacer::setVertex(int i, const osg::Vec3& v)
106 inline void MultiSegmentPlacer::setVertex(int i, float x, float y, float z)
108 _vx[i].first.set(x, y, z);
112 inline void MultiSegmentPlacer::addVertex(const osg::Vec3& v)
115 if (_vx.size() > 0) {
116 l = (v - _vx.back().first).length();
119 _vx.push_back(std::make_pair(v, _total_length));
122 inline void MultiSegmentPlacer::addVertex(float x, float y, float z)
124 addVertex(osg::Vec3(x, y, z));
127 inline void MultiSegmentPlacer::removeVertex(int i)
129 _vx.erase(_vx.begin()+i);
133 inline float MultiSegmentPlacer::volume() const
135 return _total_length;
138 inline osg::Vec3 MultiSegmentPlacer::getControlPosition() const
140 return _vx.empty() ? osg::Vec3(0.0f,0.0f,0.0f) : _vx[0].first;