Added new BoxPlacer files.

This commit is contained in:
Robert Osfield 2006-01-17 15:18:44 +00:00
parent c9b25a5b50
commit eaf6c5ac35
2 changed files with 233 additions and 0 deletions

View File

@ -0,0 +1,164 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2005 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
//Build by Zach Deedler
#ifndef OSGPARTICLE_BOX_PLACER
#define OSGPARTICLE_BOX_PLACER 1
#include <osgParticle/CenteredPlacer>
#include <osgParticle/Particle>
#include <osgParticle/range>
#include <osg/CopyOp>
#include <osg/Object>
#include <osg/Vec3>
#include <osg/Math>
namespace osgParticle
{
/** A sector-shaped particle placer.
This placer sets the initial position of incoming particle by choosing a random position
within a circular sector; this sector is defined by three parameters: a <I>center point</I>,
which is inherited directly from <CODE>osgParticle::CenteredPlacer</CODE>, a range of values
for <I>radius</I>, and a range of values for the <I>central angle</I> (sometimes called <B>phi</B>).
*/
class BoxPlacer: public CenteredPlacer {
public:
inline BoxPlacer();
inline BoxPlacer(const BoxPlacer& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
/// Get the range of possible values for radius.
inline const rangef& getXRange() const;
/// Set the range of possible values for radius.
inline void setXRange(const rangef& r);
/// Set the range of possible values for radius.
inline void setXRange(float r1, float r2);
/// Get the range of possible values for the central angle.
inline const rangef& getYRange() const;
/// Set the range of possible values for the central angle.
inline void setYRange(const rangef& r);
/// Set the range of possible values for the central angle.
inline void setYRange(float r1, float r2);
/// Get the range of possible values for the height.
inline const rangef& getZRange() const;
/// Set the range of possible values for the height.
inline void setZRange(const rangef& r);
/// Set the range of possible values for the height.
inline void setZRange(float r1, float r2);
META_Object(osgParticle, BoxPlacer);
/// Place a particle. Do not call it manually.
inline void place(Particle* P) const;
/// return the control position
inline osg::Vec3 getControlPosition() const;
protected:
virtual ~BoxPlacer() {}
BoxPlacer& operator=(const BoxPlacer&) { return *this; }
private:
rangef _x_range;
rangef _y_range;
rangef _z_range;
};
// INLINE FUNCTIONS
inline BoxPlacer::BoxPlacer()
: CenteredPlacer(), _x_range(-1, 1), _y_range(-1, 1), _z_range(-1, 1)
{
}
inline BoxPlacer::BoxPlacer(const BoxPlacer& copy, const osg::CopyOp& copyop)
: CenteredPlacer(copy, copyop),
_x_range(copy._x_range), _y_range(copy._y_range), _z_range(copy._z_range)
{
}
inline const rangef& BoxPlacer::getXRange() const
{
return _x_range;
}
inline void BoxPlacer::setXRange(const rangef& r)
{
_x_range = r;
}
inline void BoxPlacer::setXRange(float r1, float r2)
{
_x_range.minimum = r1;
_x_range.maximum = r2;
}
inline const rangef& BoxPlacer::getYRange() const
{
return _y_range;
}
inline void BoxPlacer::setYRange(const rangef& r)
{
_y_range = r;
}
inline void BoxPlacer::setYRange(float r1, float r2)
{
_y_range.minimum = r1;
_y_range.maximum = r2;
}
inline const rangef& BoxPlacer::getZRange() const
{
return _z_range;
}
inline void BoxPlacer::setZRange(const rangef& r)
{
_z_range = r;
}
inline void BoxPlacer::setZRange(float r1, float r2)
{
_z_range.minimum = r1;
_z_range.maximum = r2;
}
inline void BoxPlacer::place(Particle* P) const
{
osg::Vec3 pos(
getCenter().x() + _x_range.get_random(),
getCenter().y() + _y_range.get_random(),
getCenter().z() + _z_range.get_random());
P->setPosition(pos);
}
inline osg::Vec3 BoxPlacer::getControlPosition() const
{
return getCenter();
}
}
#endif

View File

@ -0,0 +1,69 @@
#include <osgParticle/BoxPlacer>
#include <iostream>
#include <osgDB/Registry>
#include <osgDB/Input>
#include <osgDB/Output>
bool BoxPlacer_readLocalData(osg::Object &obj, osgDB::Input &fr);
bool BoxPlacer_writeLocalData(const osg::Object &obj, osgDB::Output &fw);
osgDB::RegisterDotOsgWrapperProxy BoxPlacer_Proxy
(
new osgParticle::BoxPlacer,
"BoxPlacer",
"Object Placer CenteredPlacer BoxPlacer",
BoxPlacer_readLocalData,
BoxPlacer_writeLocalData
);
bool BoxPlacer_readLocalData(osg::Object &obj, osgDB::Input &fr)
{
osgParticle::BoxPlacer &myobj = static_cast<osgParticle::BoxPlacer &>(obj);
bool itAdvanced = false;
osgParticle::rangef r;
if (fr[0].matchWord("xRange")) {
if (fr[1].getFloat(r.minimum) && fr[2].getFloat(r.maximum)) {
myobj.setXRange(r);
fr += 3;
itAdvanced = true;
}
}
if (fr[0].matchWord("yRange")) {
if (fr[1].getFloat(r.minimum) && fr[2].getFloat(r.maximum)) {
myobj.setYRange(r);
fr += 3;
itAdvanced = true;
}
}
if (fr[0].matchWord("zRange")) {
if (fr[1].getFloat(r.minimum) && fr[2].getFloat(r.maximum)) {
myobj.setZRange(r);
fr += 3;
itAdvanced = true;
}
}
return itAdvanced;
}
bool BoxPlacer_writeLocalData(const osg::Object &obj, osgDB::Output &fw)
{
const osgParticle::BoxPlacer &myobj = static_cast<const osgParticle::BoxPlacer &>(obj);
osgParticle::rangef r;
r = myobj.getXRange();
fw.indent() << "xRange " << r.minimum << " " << r.maximum << std::endl;
r = myobj.getYRange();
fw.indent() << "yRange " << r.minimum << " " << r.maximum << std::endl;
r = myobj.getZRange();
fw.indent() << "zRange " << r.minimum << " " << r.maximum << std::endl;
return true;
}