|
Revision 13041, 1.4 kB
(checked in by robert, 14 months ago)
|
|
Ran script to remove trailing spaces and tabs
|
-
Property svn:eol-style set to
native
-
Property svn:keywords set to
Author Date Id Revision
|
| Line | |
|---|
| 1 | #include <osgParticle/MultiSegmentPlacer> |
|---|
| 2 | #include <osgParticle/Placer> |
|---|
| 3 | |
|---|
| 4 | #include <osg/CopyOp> |
|---|
| 5 | #include <osg/Vec3> |
|---|
| 6 | |
|---|
| 7 | osgParticle::MultiSegmentPlacer::MultiSegmentPlacer() |
|---|
| 8 | : Placer(), _total_length(0) |
|---|
| 9 | { |
|---|
| 10 | } |
|---|
| 11 | |
|---|
| 12 | osgParticle::MultiSegmentPlacer::MultiSegmentPlacer(const MultiSegmentPlacer& copy, const osg::CopyOp& copyop) |
|---|
| 13 | : Placer(copy, copyop), _vx(copy._vx), _total_length(copy._total_length) |
|---|
| 14 | { |
|---|
| 15 | } |
|---|
| 16 | |
|---|
| 17 | void osgParticle::MultiSegmentPlacer::recompute_length() |
|---|
| 18 | { |
|---|
| 19 | Vertex_vector::iterator i; |
|---|
| 20 | Vertex_vector::iterator i0 = _vx.begin(); |
|---|
| 21 | |
|---|
| 22 | _total_length = 0; |
|---|
| 23 | for (i=_vx.begin(); i!=_vx.end(); ++i) |
|---|
| 24 | { |
|---|
| 25 | _total_length += (i->first - i0->first).length(); |
|---|
| 26 | i->second = _total_length; |
|---|
| 27 | i0 = i; |
|---|
| 28 | } |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | void osgParticle::MultiSegmentPlacer::place(Particle* P) const |
|---|
| 32 | { |
|---|
| 33 | if (_vx.size() >= 2) { |
|---|
| 34 | float x = rangef(0, _total_length).get_random(); |
|---|
| 35 | |
|---|
| 36 | Vertex_vector::const_iterator i; |
|---|
| 37 | Vertex_vector::const_iterator i0 = _vx.begin(); |
|---|
| 38 | const Vertex_vector::const_iterator vend = _vx.end(); |
|---|
| 39 | |
|---|
| 40 | for (i=_vx.begin(); i!=vend; ++i) |
|---|
| 41 | { |
|---|
| 42 | if (x <= i->second) |
|---|
| 43 | { |
|---|
| 44 | float t = (x - i0->second) / (i->second - i0->second); |
|---|
| 45 | P->setPosition(i0->first + (i->first - i0->first) * t); |
|---|
| 46 | return; |
|---|
| 47 | } |
|---|
| 48 | i0 = i; |
|---|
| 49 | } |
|---|
| 50 | } |
|---|
| 51 | else |
|---|
| 52 | { |
|---|
| 53 | OSG_WARN << "this MultiSegmentPlacer has less than 2 vertices\n"; |
|---|
| 54 | } |
|---|
| 55 | } |
|---|