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//Build by Zach Deedler
15#ifndef OSGPARTICLE_BOX_PLACER
16#define OSGPARTICLE_BOX_PLACER 1
18#include <osgParticle/CenteredPlacer>
19#include <osgParticle/Particle>
20#include <osgParticle/range>
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.
36 class BoxPlacer: public CenteredPlacer {
39 inline BoxPlacer(const BoxPlacer& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
41 /// Get the range of possible values along the X axis.
42 inline const rangef& getXRange() const;
44 /// Set the range of possible values along the X axis.
45 inline void setXRange(const rangef& r);
47 /// Set the range of possible values along the X axis.
48 inline void setXRange(float r1, float r2);
50 /// Get the range of possible values along the Y axis.
51 inline const rangef& getYRange() const;
53 /// Set the range of possible values along the Y axis.
54 inline void setYRange(const rangef& r);
56 /// Set the range of possible values along the Y axis.
57 inline void setYRange(float r1, float r2);
59 /// Get the range of possible values along the Z axis.
60 inline const rangef& getZRange() const;
62 /// Set the range of possible values along the Z axis.
63 inline void setZRange(const rangef& r);
65 /// Set the range of possible values along the Z axis.
66 inline void setZRange(float r1, float r2);
68 META_Object(osgParticle, BoxPlacer);
70 /// Place a particle. Do not call it manually.
71 inline void place(Particle* P) const;
73 /// return the volume of the box
74 inline float volume() const;
76 /// return the control position
77 inline osg::Vec3 getControlPosition() const;
80 virtual ~BoxPlacer() {}
81 BoxPlacer& operator=(const BoxPlacer&) { return *this; }
91 inline BoxPlacer::BoxPlacer()
92 : CenteredPlacer(), _x_range(-1, 1), _y_range(-1, 1), _z_range(-1, 1)
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)
102 inline const rangef& BoxPlacer::getXRange() const
107 inline void BoxPlacer::setXRange(const rangef& r)
112 inline void BoxPlacer::setXRange(float r1, float r2)
114 _x_range.minimum = r1;
115 _x_range.maximum = r2;
118 inline const rangef& BoxPlacer::getYRange() const
123 inline void BoxPlacer::setYRange(const rangef& r)
128 inline void BoxPlacer::setYRange(float r1, float r2)
130 _y_range.minimum = r1;
131 _y_range.maximum = r2;
134 inline const rangef& BoxPlacer::getZRange() const
139 inline void BoxPlacer::setZRange(const rangef& r)
144 inline void BoxPlacer::setZRange(float r1, float r2)
146 _z_range.minimum = r1;
147 _z_range.maximum = r2;
150 inline void BoxPlacer::place(Particle* P) const
153 getCenter().x() + _x_range.get_random(),
154 getCenter().y() + _y_range.get_random(),
155 getCenter().z() + _z_range.get_random());
160 inline float BoxPlacer::volume() const
162 return (_x_range.maximum - _x_range.minimum) *
163 (_y_range.maximum - _y_range.minimum) *
164 (_z_range.maximum - _z_range.minimum);
167 inline osg::Vec3 BoxPlacer::getControlPosition() const