1 | /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield |
---|
2 | * |
---|
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. |
---|
7 | * |
---|
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. |
---|
12 | */ |
---|
13 | //osgParticle - Copyright (C) 2002 Marco Jez |
---|
14 | |
---|
15 | #ifndef OSGPARTICLE_SECTOR_PLACER |
---|
16 | #define OSGPARTICLE_SECTOR_PLACER 1 |
---|
17 | |
---|
18 | #include <osgParticle/CenteredPlacer> |
---|
19 | #include <osgParticle/Particle> |
---|
20 | #include <osgParticle/range> |
---|
21 | |
---|
22 | #include <osg/CopyOp> |
---|
23 | #include <osg/Object> |
---|
24 | #include <osg/Vec3> |
---|
25 | #include <osg/Math> |
---|
26 | |
---|
27 | namespace osgParticle |
---|
28 | { |
---|
29 | |
---|
30 | /** A sector-shaped particle placer. |
---|
31 | This placer sets the initial position of incoming particle by choosing a random position |
---|
32 | within a circular sector; this sector is defined by three parameters: a <I>center point</I>, |
---|
33 | which is inherited directly from <CODE>osgParticle::CenteredPlacer</CODE>, a range of values |
---|
34 | for <I>radius</I>, and a range of values for the <I>central angle</I> (sometimes called <B>phi</B>). |
---|
35 | */ |
---|
36 | class SectorPlacer: public CenteredPlacer { |
---|
37 | public: |
---|
38 | inline SectorPlacer(); |
---|
39 | inline SectorPlacer(const SectorPlacer& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY); |
---|
40 | |
---|
41 | /// Get the range of possible values for radius. |
---|
42 | inline const rangef& getRadiusRange() const; |
---|
43 | |
---|
44 | /// Set the range of possible values for radius. |
---|
45 | inline void setRadiusRange(const rangef& r); |
---|
46 | |
---|
47 | /// Set the range of possible values for radius. |
---|
48 | inline void setRadiusRange(float r1, float r2); |
---|
49 | |
---|
50 | /// Get the range of possible values for the central angle. |
---|
51 | inline const rangef& getPhiRange() const; |
---|
52 | |
---|
53 | /// Set the range of possible values for the central angle. |
---|
54 | inline void setPhiRange(const rangef& r); |
---|
55 | |
---|
56 | /// Set the range of possible values for the central angle. |
---|
57 | inline void setPhiRange(float r1, float r2); |
---|
58 | |
---|
59 | META_Object(osgParticle, SectorPlacer); |
---|
60 | |
---|
61 | /// Place a particle. Do not call it manually. |
---|
62 | inline void place(Particle* P) const; |
---|
63 | |
---|
64 | /// return the area of the sector |
---|
65 | inline float volume() const; |
---|
66 | |
---|
67 | /// return the control position |
---|
68 | inline osg::Vec3 getControlPosition() const; |
---|
69 | |
---|
70 | protected: |
---|
71 | virtual ~SectorPlacer() {} |
---|
72 | SectorPlacer& operator=(const SectorPlacer&) { return *this; } |
---|
73 | |
---|
74 | private: |
---|
75 | rangef _rad_range; |
---|
76 | rangef _phi_range; |
---|
77 | }; |
---|
78 | |
---|
79 | // INLINE FUNCTIONS |
---|
80 | |
---|
81 | inline SectorPlacer::SectorPlacer() |
---|
82 | : CenteredPlacer(), _rad_range(0, 1), _phi_range(0, osg::PI*2) |
---|
83 | { |
---|
84 | } |
---|
85 | |
---|
86 | inline SectorPlacer::SectorPlacer(const SectorPlacer& copy, const osg::CopyOp& copyop) |
---|
87 | : CenteredPlacer(copy, copyop), _rad_range(copy._rad_range), _phi_range(copy._phi_range) |
---|
88 | { |
---|
89 | } |
---|
90 | |
---|
91 | inline const rangef& SectorPlacer::getRadiusRange() const |
---|
92 | { |
---|
93 | return _rad_range; |
---|
94 | } |
---|
95 | |
---|
96 | inline const rangef& SectorPlacer::getPhiRange() const |
---|
97 | { |
---|
98 | return _phi_range; |
---|
99 | } |
---|
100 | |
---|
101 | inline void SectorPlacer::setRadiusRange(const rangef& r) |
---|
102 | { |
---|
103 | _rad_range = r; |
---|
104 | } |
---|
105 | |
---|
106 | inline void SectorPlacer::setRadiusRange(float r1, float r2) |
---|
107 | { |
---|
108 | _rad_range.minimum = r1; |
---|
109 | _rad_range.maximum = r2; |
---|
110 | } |
---|
111 | |
---|
112 | inline void SectorPlacer::setPhiRange(const rangef& r) |
---|
113 | { |
---|
114 | _phi_range = r; |
---|
115 | } |
---|
116 | |
---|
117 | inline void SectorPlacer::setPhiRange(float r1, float r2) |
---|
118 | { |
---|
119 | _phi_range.minimum = r1; |
---|
120 | _phi_range.maximum = r2; |
---|
121 | } |
---|
122 | |
---|
123 | inline void SectorPlacer::place(Particle* P) const |
---|
124 | { |
---|
125 | float rad = _rad_range.get_random_sqrtf(); |
---|
126 | float phi = _phi_range.get_random(); |
---|
127 | |
---|
128 | osg::Vec3 pos( |
---|
129 | getCenter().x() + rad * cosf(phi), |
---|
130 | getCenter().y() + rad * sinf(phi), |
---|
131 | getCenter().z()); |
---|
132 | |
---|
133 | P->setPosition(pos); |
---|
134 | } |
---|
135 | |
---|
136 | inline float SectorPlacer::volume() const |
---|
137 | { |
---|
138 | return 0.5f * (_phi_range.maximum - _phi_range.minimum) * |
---|
139 | (_rad_range.maximum*_rad_range.maximum - _rad_range.minimum*_rad_range.minimum); |
---|
140 | } |
---|
141 | |
---|
142 | inline osg::Vec3 SectorPlacer::getControlPosition() const |
---|
143 | { |
---|
144 | return getCenter(); |
---|
145 | } |
---|
146 | |
---|
147 | } |
---|
148 | |
---|
149 | #endif |
---|