MultiSegmentPlacer
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* 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.
*/
//osgParticle - Copyright (C) 2002 Marco Jez
#ifndef OSGPARTICLE_MULTISEGMENT_PLACER
#define OSGPARTICLE_MULTISEGMENT_PLACER 1
#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 {
class OSGPARTICLE_EXPORT MultiSegmentPlacer: public Placer {
public:
MultiSegmentPlacer();
MultiSegmentPlacer(const MultiSegmentPlacer& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
META_Object(osgParticle, MultiSegmentPlacer);
inline int numVertices() const;
inline const osg::Vec3& getVertex(int i) const;
inline void setVertex(int i, const osg::Vec3& v);
inline void setVertex(int i, float x, float y, float z);
inline void addVertex(const osg::Vec3& v);
inline void addVertex(float x, float y, float z);
inline void removeVertex(int i);
void place(Particle* P) const;
inline float volume() const;
inline osg::Vec3 getControlPosition() const;
protected:
virtual ~MultiSegmentPlacer() {}
MultiSegmentPlacer& operator=(const MultiSegmentPlacer&) { return *this; }
private:
typedef std::pair<osg::Vec3, float> Vertex_data;
typedef std::vector<Vertex_data> Vertex_vector;
Vertex_vector _vx;
float _total_length;
void recompute_length();
};
// INLINE FUNCTIONS
inline int MultiSegmentPlacer::numVertices() const
{
return static_cast<int>(_vx.size());
}
inline const osg::Vec3& MultiSegmentPlacer::getVertex(int i) const
{
return _vx[i].first;
}
inline void MultiSegmentPlacer::setVertex(int i, const osg::Vec3& v)
{
_vx[i].first = v;
recompute_length();
}
inline void MultiSegmentPlacer::setVertex(int i, float x, float y, float z)
{
_vx[i].first.set(x, y, z);
recompute_length();
}
inline void MultiSegmentPlacer::addVertex(const osg::Vec3& v)
{
float l = 0;
if (_vx.size() > 0) {
l = (v - _vx.back().first).length();
}
_total_length += l;
_vx.push_back(std::make_pair(v, _total_length));
}
inline void MultiSegmentPlacer::addVertex(float x, float y, float z)
{
addVertex(osg::Vec3(x, y, z));
}
inline void MultiSegmentPlacer::removeVertex(int i)
{
_vx.erase(_vx.begin()+i);
recompute_length();
}
inline float MultiSegmentPlacer::volume() const
{
return _total_length;
}
inline osg::Vec3 MultiSegmentPlacer::getControlPosition() const
{
return _vx.empty() ? osg::Vec3(0.0f,0.0f,0.0f) : _vx[0].first;
}
}
#endif
CopyOp
Notify
Object
Particle
Placer
Vec3
osgParticle::MultiSegmentPlacer::getVertex
const osg::Vec3 & getVertex(int i) const
Get a vertex.
Definition MultiSegmentPlacer:95
osgParticle::MultiSegmentPlacer::META_Object
META_Object(osgParticle, MultiSegmentPlacer)
osgParticle::MultiSegmentPlacer::MultiSegmentPlacer
MultiSegmentPlacer()
osgParticle::MultiSegmentPlacer::addVertex
void addVertex(const osg::Vec3 &v)
Add a vertex.
Definition MultiSegmentPlacer:112
osgParticle::MultiSegmentPlacer::~MultiSegmentPlacer
virtual ~MultiSegmentPlacer()
Definition MultiSegmentPlacer:74
osgParticle::MultiSegmentPlacer::volume
float volume() const
return the length of the multi-segment
Definition MultiSegmentPlacer:133
osgParticle::MultiSegmentPlacer::numVertices
int numVertices() const
Get the number of vertices which define the segments.
Definition MultiSegmentPlacer:90
osgParticle::MultiSegmentPlacer::getControlPosition
osg::Vec3 getControlPosition() const
return the control position
Definition MultiSegmentPlacer:138
osgParticle::MultiSegmentPlacer::MultiSegmentPlacer
MultiSegmentPlacer(const MultiSegmentPlacer &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
osgParticle::MultiSegmentPlacer::place
void place(Particle *P) const
Place a partice. Called automatically by ModularEmitter, do not call this method manually.
osgParticle::MultiSegmentPlacer::operator=
MultiSegmentPlacer & operator=(const MultiSegmentPlacer &)
Definition MultiSegmentPlacer:75
osgParticle::MultiSegmentPlacer::removeVertex
void removeVertex(int i)
Remove a vertex.
Definition MultiSegmentPlacer:127
osgParticle::MultiSegmentPlacer::setVertex
void setVertex(int i, const osg::Vec3 &v)
Set a vertex.
Definition MultiSegmentPlacer:100
osgParticle::Particle
Definition Particle:47
osgParticle::Placer::Placer
Placer()
Definition Placer:56
osg::CopyOp
Definition CopyOp:41
osg::CopyOp::SHALLOW_COPY
@ SHALLOW_COPY
Definition CopyOp:47
osgParticle
Definition AccelOperator:27
osg::Vec3
Vec3f Vec3
Definition Vec3:21
Export
OSGPARTICLE_EXPORT
#define OSGPARTICLE_EXPORT
Definition osgParticle/Export:40