2005-04-15 05:41:28 +08:00
|
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2005 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2002-06-05 20:44:55 +08:00
|
|
|
|
//osgParticle - Copyright (C) 2002 Marco Jez
|
|
|
|
|
|
2005-04-29 17:47:57 +08:00
|
|
|
|
#ifndef OSGPARTICLE_FLUIDFRICTIONOPERATOR
|
|
|
|
|
#define OSGPARTICLE_FLUIDFRICTIONOPERATOR 1
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
|
|
#include <osgParticle/Export>
|
|
|
|
|
#include <osgParticle/Operator>
|
|
|
|
|
|
|
|
|
|
#include <osg/CopyOp>
|
|
|
|
|
#include <osg/Object>
|
|
|
|
|
#include <osg/Math>
|
|
|
|
|
|
|
|
|
|
namespace osgParticle
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
class Particle;
|
|
|
|
|
|
|
|
|
|
/** An operator that simulates the friction of a fluid.
|
|
|
|
|
By using this operator you can let the particles move in a fluid of a given <I>density</I>
|
|
|
|
|
and <I>viscosity</I>. There are two functions to quickly setup the parameters for pure water
|
|
|
|
|
and air. You can decide whether to compute the forces using the particle's physical
|
|
|
|
|
radius or another value, by calling the <CODE>setOverrideRadius()</CODE> method.
|
|
|
|
|
*/
|
|
|
|
|
class OSGPARTICLE_EXPORT FluidFrictionOperator: public Operator {
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
FluidFrictionOperator();
|
2005-04-29 17:47:57 +08:00
|
|
|
|
FluidFrictionOperator(const FluidFrictionOperator& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
2002-06-06 21:25:36 +08:00
|
|
|
|
META_Object(osgParticle, FluidFrictionOperator);
|
2005-04-04 15:54:52 +08:00
|
|
|
|
|
|
|
|
|
/// Set the density of the fluid.
|
|
|
|
|
inline void setFluidDensity(float d);
|
|
|
|
|
|
2002-06-05 20:44:55 +08:00
|
|
|
|
/// Get the density of the fluid.
|
|
|
|
|
inline float getFluidDensity() const;
|
|
|
|
|
|
2005-04-04 15:54:52 +08:00
|
|
|
|
/// Set the viscosity of the fluid.
|
|
|
|
|
inline void setFluidViscosity(float v);
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
|
|
/// Get the viscosity of the fluid.
|
|
|
|
|
inline float getFluidViscosity() const;
|
|
|
|
|
|
2005-04-04 15:54:52 +08:00
|
|
|
|
/// Set the wind vector.
|
|
|
|
|
inline void setWind(const osg::Vec3& wind) { _wind = wind; }
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
2005-04-04 15:54:52 +08:00
|
|
|
|
/// Get the wind vector.
|
|
|
|
|
inline const osg::Vec3& getWind() const { return _wind; }
|
|
|
|
|
|
2002-06-05 20:44:55 +08:00
|
|
|
|
/// Set the overriden radius value (pass 0 if you want to use particle's radius).
|
|
|
|
|
inline void setOverrideRadius(float r);
|
2005-04-04 15:54:52 +08:00
|
|
|
|
|
|
|
|
|
/// Get the overriden radius value.
|
|
|
|
|
inline float getOverrideRadius() const;
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
|
|
/// Set the fluid parameters as for air (20<32>C temperature).
|
|
|
|
|
inline void setFluidToAir();
|
|
|
|
|
|
|
|
|
|
/// Set the fluid parameters as for pure water (20<32>C temperature).
|
|
|
|
|
inline void setFluidToWater();
|
|
|
|
|
|
|
|
|
|
/// Apply the friction forces to a particle. Do not call this method manually.
|
2005-04-29 17:47:57 +08:00
|
|
|
|
void operate(Particle* P, double dt);
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
|
|
/// Perform some initializations. Do not call this method manually.
|
2005-04-29 17:47:57 +08:00
|
|
|
|
inline void beginOperate(Program* prg);
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
virtual ~FluidFrictionOperator() {}
|
|
|
|
|
FluidFrictionOperator &operator=(const FluidFrictionOperator &) { return *this; }
|
|
|
|
|
|
|
|
|
|
private:
|
2005-04-29 17:47:57 +08:00
|
|
|
|
float _coeff_A;
|
|
|
|
|
float _coeff_B;
|
|
|
|
|
float _density;
|
|
|
|
|
float _viscosity;
|
|
|
|
|
float _ovr_rad;
|
2005-04-04 15:54:52 +08:00
|
|
|
|
osg::Vec3 _wind;
|
2005-04-29 17:47:57 +08:00
|
|
|
|
Program* _current_program;
|
2002-06-05 20:44:55 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// INLINE FUNCTIONS
|
|
|
|
|
|
|
|
|
|
inline float FluidFrictionOperator::getFluidDensity() const
|
|
|
|
|
{
|
2005-04-29 17:47:57 +08:00
|
|
|
|
return _density;
|
2002-06-05 20:44:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline float FluidFrictionOperator::getFluidViscosity() const
|
|
|
|
|
{
|
2005-04-29 17:47:57 +08:00
|
|
|
|
return _viscosity;
|
2002-06-05 20:44:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline void FluidFrictionOperator::setFluidDensity(float d)
|
|
|
|
|
{
|
2005-04-29 17:47:57 +08:00
|
|
|
|
_density = d;
|
|
|
|
|
_coeff_B = 0.2f * osg::PI * _density;
|
2002-06-05 20:44:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline void FluidFrictionOperator::setFluidViscosity(float v)
|
|
|
|
|
{
|
2005-04-29 17:47:57 +08:00
|
|
|
|
_viscosity = v;
|
|
|
|
|
_coeff_A = 6 * osg::PI * _viscosity;
|
2002-06-05 20:44:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline void FluidFrictionOperator::setFluidToAir()
|
|
|
|
|
{
|
|
|
|
|
setFluidViscosity(1.8e-5f);
|
|
|
|
|
setFluidDensity(1.2929f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline void FluidFrictionOperator::setFluidToWater()
|
|
|
|
|
{
|
|
|
|
|
setFluidViscosity(1.002e-3f);
|
|
|
|
|
setFluidDensity(1.0f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline float FluidFrictionOperator::getOverrideRadius() const
|
|
|
|
|
{
|
2005-04-29 17:47:57 +08:00
|
|
|
|
return _ovr_rad;
|
2002-06-05 20:44:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline void FluidFrictionOperator::setOverrideRadius(float r)
|
|
|
|
|
{
|
2005-04-29 17:47:57 +08:00
|
|
|
|
_ovr_rad = r;
|
2002-06-05 20:44:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
2005-04-29 17:47:57 +08:00
|
|
|
|
inline void FluidFrictionOperator::beginOperate(Program* prg)
|
2002-06-05 20:44:55 +08:00
|
|
|
|
{
|
2005-04-29 17:47:57 +08:00
|
|
|
|
_current_program = prg;
|
2002-06-05 20:44:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|