openscenegraph
BoxPlacer
Go to the documentation of this file.
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//Build by Zach Deedler
14
15#ifndef OSGPARTICLE_BOX_PLACER
16#define OSGPARTICLE_BOX_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
27namespace osgParticle
28{
29
30 /** A box-shaped particle placer.
31 This placer sets the initial position of incoming particle by choosing a random position
32 within the volume of a box; this placer is defined by four parameters: a <I>center point</I>,
33 which is inherited directly from <CODE>osgParticle::CenteredPlacer</CODE>, and three ranges of values
34 for the valid <I>X</I>, <I>Y</I>, and <I>Z</I> coordinates.
35 */
36 class BoxPlacer: public CenteredPlacer {
37 public:
38 inline BoxPlacer();
39 inline BoxPlacer(const BoxPlacer& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
40
41 /// Get the range of possible values along the X axis.
42 inline const rangef& getXRange() const;
43
44 /// Set the range of possible values along the X axis.
45 inline void setXRange(const rangef& r);
46
47 /// Set the range of possible values along the X axis.
48 inline void setXRange(float r1, float r2);
49
50 /// Get the range of possible values along the Y axis.
51 inline const rangef& getYRange() const;
52
53 /// Set the range of possible values along the Y axis.
54 inline void setYRange(const rangef& r);
55
56 /// Set the range of possible values along the Y axis.
57 inline void setYRange(float r1, float r2);
58
59 /// Get the range of possible values along the Z axis.
60 inline const rangef& getZRange() const;
61
62 /// Set the range of possible values along the Z axis.
63 inline void setZRange(const rangef& r);
64
65 /// Set the range of possible values along the Z axis.
66 inline void setZRange(float r1, float r2);
67
68 META_Object(osgParticle, BoxPlacer);
69
70 /// Place a particle. Do not call it manually.
71 inline void place(Particle* P) const;
72
73 /// return the volume of the box
74 inline float volume() const;
75
76 /// return the control position
77 inline osg::Vec3 getControlPosition() const;
78
79 protected:
80 virtual ~BoxPlacer() {}
81 BoxPlacer& operator=(const BoxPlacer&) { return *this; }
82
83 private:
84 rangef _x_range;
85 rangef _y_range;
86 rangef _z_range;
87 };
88
89 // INLINE FUNCTIONS
90
91 inline BoxPlacer::BoxPlacer()
92 : CenteredPlacer(), _x_range(-1, 1), _y_range(-1, 1), _z_range(-1, 1)
93 {
94 }
95
96 inline BoxPlacer::BoxPlacer(const BoxPlacer& copy, const osg::CopyOp& copyop)
97 : CenteredPlacer(copy, copyop),
98 _x_range(copy._x_range), _y_range(copy._y_range), _z_range(copy._z_range)
99 {
100 }
101
102 inline const rangef& BoxPlacer::getXRange() const
103 {
104 return _x_range;
105 }
106
107 inline void BoxPlacer::setXRange(const rangef& r)
108 {
109 _x_range = r;
110 }
111
112 inline void BoxPlacer::setXRange(float r1, float r2)
113 {
114 _x_range.minimum = r1;
115 _x_range.maximum = r2;
116 }
117
118 inline const rangef& BoxPlacer::getYRange() const
119 {
120 return _y_range;
121 }
122
123 inline void BoxPlacer::setYRange(const rangef& r)
124 {
125 _y_range = r;
126 }
127
128 inline void BoxPlacer::setYRange(float r1, float r2)
129 {
130 _y_range.minimum = r1;
131 _y_range.maximum = r2;
132 }
133
134 inline const rangef& BoxPlacer::getZRange() const
135 {
136 return _z_range;
137 }
138
139 inline void BoxPlacer::setZRange(const rangef& r)
140 {
141 _z_range = r;
142 }
143
144 inline void BoxPlacer::setZRange(float r1, float r2)
145 {
146 _z_range.minimum = r1;
147 _z_range.maximum = r2;
148 }
149
150 inline void BoxPlacer::place(Particle* P) const
151 {
152 osg::Vec3 pos(
153 getCenter().x() + _x_range.get_random(),
154 getCenter().y() + _y_range.get_random(),
155 getCenter().z() + _z_range.get_random());
156
157 P->setPosition(pos);
158 }
159
160 inline float BoxPlacer::volume() const
161 {
162 return (_x_range.maximum - _x_range.minimum) *
163 (_y_range.maximum - _y_range.minimum) *
164 (_z_range.maximum - _z_range.minimum);
165 }
166
167 inline osg::Vec3 BoxPlacer::getControlPosition() const
168 {
169 return getCenter();
170 }
171
172}
173
174#endif