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_SEGMENT_PLACER
16#define OSGPARTICLE_SEGMENT_PLACER 1
18#include <osgParticle/Placer>
19#include <osgParticle/Particle>
25namespace osgParticle {
27 /** A segment-shaped particle placer.
28 To use this placer you have to define a segment, by setting its two vertices (<B>A</B> and <B>B</B>);
29 when an emitter requests a <CODE>SegmentPlacer</CODE> to place a particle, the position is chosen randomly
32 class SegmentPlacer: public Placer {
34 inline SegmentPlacer();
35 inline SegmentPlacer(const SegmentPlacer& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
37 META_Object(osgParticle, SegmentPlacer);
39 /// get vertex <B>A</B>.
40 inline const osg::Vec3& getVertexA() const;
42 /// Set vertex <B>A</B> of the segment as a vector.
43 inline void setVertexA(const osg::Vec3& v);
45 /// Set vertex <B>A</B> of the segment as three floats.
46 inline void setVertexA(float x, float y, float z);
48 /// get vertex <B>B</B>.
49 inline const osg::Vec3& getVertexB() const;
51 /// Set vertex <B>B</B> of the segment as a vector.
52 inline void setVertexB(const osg::Vec3& v);
54 /// Set vertex <B>B</B> of the segment as three floats.
55 inline void setVertexB(float x, float y, float z);
57 /// Set both vertices.
58 inline void setSegment(const osg::Vec3& A, const osg::Vec3& B);
60 /// Place a particle. This method is called by <CODE>ModularEmitter</CODE>, do not call it manually.
61 inline void place(Particle* P) const;
63 /// return the length of the segment
64 inline float volume() const;
66 /// return the control position
67 inline osg::Vec3 getControlPosition() const;
70 virtual ~SegmentPlacer() {}
71 SegmentPlacer& operator=(const SegmentPlacer&) { return *this; }
80 inline SegmentPlacer::SegmentPlacer()
81 : Placer(), _vertexA(-1, 0, 0), _vertexB(1, 0, 0)
85 inline SegmentPlacer::SegmentPlacer(const SegmentPlacer& copy, const osg::CopyOp& copyop)
86 : Placer(copy, copyop), _vertexA(copy._vertexA), _vertexB(copy._vertexB)
90 inline const osg::Vec3& SegmentPlacer::getVertexA() const
95 inline const osg::Vec3& SegmentPlacer::getVertexB() const
100 inline void SegmentPlacer::setSegment(const osg::Vec3& A, const osg::Vec3& B)
106 inline void SegmentPlacer::place(Particle* P) const
108 P->setPosition(rangev3(_vertexA, _vertexB).get_random());
111 inline float SegmentPlacer::volume() const
113 return (_vertexB - _vertexA).length();
116 inline void SegmentPlacer::setVertexA(const osg::Vec3& v)
121 inline void SegmentPlacer::setVertexA(float x, float y, float z)
123 _vertexA.set(x, y, z);
126 inline void SegmentPlacer::setVertexB(const osg::Vec3& v)
131 inline void SegmentPlacer::setVertexB(float x, float y, float z)
133 _vertexB.set(x, y, z);
136 inline osg::Vec3 SegmentPlacer::getControlPosition() const
138 return (_vertexA+_vertexB)*0.5f;