openscenegraph
FluidFrictionOperator
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//osgParticle - Copyright (C) 2002 Marco Jez
14
15#ifndef OSGPARTICLE_FLUIDFRICTIONOPERATOR
16#define OSGPARTICLE_FLUIDFRICTIONOPERATOR 1
17
18#include <osgParticle/Export>
19#include <osgParticle/Operator>
20
21#include <osg/CopyOp>
22#include <osg/Object>
23#include <osg/Math>
24
25namespace osgParticle
26{
27
28 class Particle;
29
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.
35 */
36 class OSGPARTICLE_EXPORT FluidFrictionOperator: public Operator {
37 public:
38
39 FluidFrictionOperator();
40 FluidFrictionOperator(const FluidFrictionOperator& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
41
42 META_Object(osgParticle, FluidFrictionOperator);
43
44 /// Set the density of the fluid.
45 inline void setFluidDensity(float d);
46
47 /// Get the density of the fluid.
48 inline float getFluidDensity() const;
49
50 /// Set the viscosity of the fluid.
51 inline void setFluidViscosity(float v);
52
53 /// Get the viscosity of the fluid.
54 inline float getFluidViscosity() const;
55
56 /// Set the wind vector.
57 inline void setWind(const osg::Vec3& wind) { _wind = wind; }
58
59 /// Get the wind vector.
60 inline const osg::Vec3& getWind() const { return _wind; }
61
62 /// Set the overriden radius value (pass 0 if you want to use particle's radius).
63 inline void setOverrideRadius(float r);
64
65 /// Get the overriden radius value.
66 inline float getOverrideRadius() const;
67
68 /// Set the fluid parameters as for air (20°C temperature).
69 inline void setFluidToAir();
70
71 /// Set the fluid parameters as for pure water (20°C temperature).
72 inline void setFluidToWater();
73
74 /// Apply the friction forces to a particle. Do not call this method manually.
75 void operate(Particle* P, double dt);
76
77 /// Perform some initializations. Do not call this method manually.
78 inline void beginOperate(Program* prg);
79
80 protected:
81 virtual ~FluidFrictionOperator() {}
82 FluidFrictionOperator &operator=(const FluidFrictionOperator &) { return *this; }
83
84 private:
85 float _coeff_A;
86 float _coeff_B;
87 float _density;
88 float _viscosity;
89 float _ovr_rad;
90 osg::Vec3 _wind;
91 Program* _current_program;
92 };
93
94 // INLINE FUNCTIONS
95
96 inline float FluidFrictionOperator::getFluidDensity() const
97 {
98 return _density;
99 }
100
101 inline float FluidFrictionOperator::getFluidViscosity() const
102 {
103 return _viscosity;
104 }
105
106 inline void FluidFrictionOperator::setFluidDensity(float d)
107 {
108 _density = d;
109 _coeff_B = 0.2f * osg::PI * _density;
110 }
111
112 inline void FluidFrictionOperator::setFluidViscosity(float v)
113 {
114 _viscosity = v;
115 _coeff_A = 6 * osg::PI * _viscosity;
116 }
117
118 inline void FluidFrictionOperator::setFluidToAir()
119 {
120 setFluidViscosity(1.8e-5f);
121 setFluidDensity(1.2929f);
122 }
123
124 inline void FluidFrictionOperator::setFluidToWater()
125 {
126 setFluidViscosity(1.002e-3f);
127 setFluidDensity(1.0f);
128 }
129
130 inline float FluidFrictionOperator::getOverrideRadius() const
131 {
132 return _ovr_rad;
133 }
134
135 inline void FluidFrictionOperator::setOverrideRadius(float r)
136 {
137 _ovr_rad = r;
138 }
139
140 inline void FluidFrictionOperator::beginOperate(Program* prg)
141 {
142 _current_program = prg;
143 }
144
145}
146
147
148#endif