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.
14#ifndef OSGPARTICLE_FLUIDPROGRAM
15#define OSGPARTICLE_FLUIDPROGRAM 1
17#include <osgParticle/Export>
18#include <osgParticle/Program>
23#include <osg/NodeVisitor>
28 /** A program class for performing operations on particles using a sequence of <I>operators</I>.
29 To use a <CODE>FluidProgram</CODE> you have to create some <CODE>Operator</CODE> objects and
30 add them to the program.
31 All operators will be applied to each particle in the same order they've been added to the program.
33 class OSGPARTICLE_EXPORT FluidProgram: public Program {
36 FluidProgram(const FluidProgram& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
38 META_Node(osgParticle,FluidProgram);
40 /// Set the viscosity of the fluid.
41 inline void setFluidViscosity(float v)
44 _viscosityCoefficient = 6 * osg::PI * _viscosity;
47 /// Get the viscosity of the fluid.
48 inline float getFluidViscosity() const { return _viscosity; }
50 /// Set the density of the fluid.
51 inline void setFluidDensity(float d)
54 _densityCoefficient = 0.2f * osg::PI * _density;
57 /// Get the density of the fluid.
58 inline float getFluidDensity() const { return _density; }
61 /// Set the wind vector.
62 inline void setWind(const osg::Vec3& wind) { _wind = wind; }
64 /// Get the wind vector.
65 inline const osg::Vec3& getWind() const { return _wind; }
67 /// Set the acceleration vector.
68 inline void setAcceleration(const osg::Vec3& v) { _acceleration = v; }
70 /// Get the acceleration vector.
71 inline const osg::Vec3& getAcceleration() const { return _acceleration; }
73 /** Set the acceleration vector to the gravity on earth (0, 0, -9.81).
74 The acceleration will be multiplied by the <CODE>scale</CODE> parameter.
76 inline void setToGravity(float scale = 1.0f) { _acceleration.set(0, 0, -9.81f*scale); }
78 /// Set the fluid parameters as for air (20°C temperature).
79 inline void setFluidToAir()
82 setFluidDensity(1.2929f);
83 setFluidViscosity(1.8e-5f);
86 /// Set the fluid parameters as for pure water (20°C temperature).
87 inline void setFluidToWater()
90 setFluidDensity(1.0f);
91 setFluidViscosity(1.002e-3f);
97 virtual ~FluidProgram() {}
98 FluidProgram& operator=(const FluidProgram&) { return *this; }
100 virtual void execute(double dt);
102 osg::Vec3 _acceleration;
107 float _viscosityCoefficient;
108 float _densityCoefficient;