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//osgParticle - Copyright (C) 2002 Marco Jez
15#ifndef OSGPARTICLE_FLUIDFRICTIONOPERATOR
16#define OSGPARTICLE_FLUIDFRICTIONOPERATOR 1
18#include <osgParticle/Export>
19#include <osgParticle/Operator>
30 /** An operator that simulates the friction of a fluid.
31 By using this operator you can let the particles move in a fluid of a given <I>density</I>
32 and <I>viscosity</I>. There are two functions to quickly setup the parameters for pure water
33 and air. You can decide whether to compute the forces using the particle's physical
34 radius or another value, by calling the <CODE>setOverrideRadius()</CODE> method.
36 class OSGPARTICLE_EXPORT FluidFrictionOperator: public Operator {
39 FluidFrictionOperator();
40 FluidFrictionOperator(const FluidFrictionOperator& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
42 META_Object(osgParticle, FluidFrictionOperator);
44 /// Set the density of the fluid.
45 inline void setFluidDensity(float d);
47 /// Get the density of the fluid.
48 inline float getFluidDensity() const;
50 /// Set the viscosity of the fluid.
51 inline void setFluidViscosity(float v);
53 /// Get the viscosity of the fluid.
54 inline float getFluidViscosity() const;
56 /// Set the wind vector.
57 inline void setWind(const osg::Vec3& wind) { _wind = wind; }
59 /// Get the wind vector.
60 inline const osg::Vec3& getWind() const { return _wind; }
62 /// Set the overriden radius value (pass 0 if you want to use particle's radius).
63 inline void setOverrideRadius(float r);
65 /// Get the overriden radius value.
66 inline float getOverrideRadius() const;
68 /// Set the fluid parameters as for air (20°C temperature).
69 inline void setFluidToAir();
71 /// Set the fluid parameters as for pure water (20°C temperature).
72 inline void setFluidToWater();
74 /// Apply the friction forces to a particle. Do not call this method manually.
75 void operate(Particle* P, double dt);
77 /// Perform some initializations. Do not call this method manually.
78 inline void beginOperate(Program* prg);
81 virtual ~FluidFrictionOperator() {}
82 FluidFrictionOperator &operator=(const FluidFrictionOperator &) { return *this; }
91 Program* _current_program;
96 inline float FluidFrictionOperator::getFluidDensity() const
101 inline float FluidFrictionOperator::getFluidViscosity() const
106 inline void FluidFrictionOperator::setFluidDensity(float d)
109 _coeff_B = 0.2f * osg::PI * _density;
112 inline void FluidFrictionOperator::setFluidViscosity(float v)
115 _coeff_A = 6 * osg::PI * _viscosity;
118 inline void FluidFrictionOperator::setFluidToAir()
120 setFluidViscosity(1.8e-5f);
121 setFluidDensity(1.2929f);
124 inline void FluidFrictionOperator::setFluidToWater()
126 setFluidViscosity(1.002e-3f);
127 setFluidDensity(1.0f);
130 inline float FluidFrictionOperator::getOverrideRadius() const
135 inline void FluidFrictionOperator::setOverrideRadius(float r)
140 inline void FluidFrictionOperator::beginOperate(Program* prg)
142 _current_program = prg;