root/OpenSceneGraph/trunk/include/osgParticle/FluidProgram @ 13041

Revision 13041, 3.6 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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
14#ifndef OSGPARTICLE_FLUIDPROGRAM
15#define OSGPARTICLE_FLUIDPROGRAM 1
16
17#include <osgParticle/Export>
18#include <osgParticle/Program>
19
20#include <osg/CopyOp>
21#include <osg/Object>
22#include <osg/Node>
23#include <osg/NodeVisitor>
24
25namespace osgParticle
26{
27
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.
32    */
33    class OSGPARTICLE_EXPORT FluidProgram: public Program {
34    public:
35        FluidProgram();
36        FluidProgram(const FluidProgram& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
37
38        META_Node(osgParticle,FluidProgram);
39
40        /// Set the viscosity of the fluid.
41        inline void setFluidViscosity(float v)
42        {
43            _viscosity = v;
44            _viscosityCoefficient = 6 * osg::PI * _viscosity;
45        }
46
47        /// Get the viscosity of the fluid.
48        inline float getFluidViscosity() const { return _viscosity; }
49
50        /// Set the density of the fluid.
51        inline void setFluidDensity(float d)
52        {
53            _density = d;
54            _densityCoefficient = 0.2f * osg::PI * _density;
55        }
56
57        /// Get the density of the fluid.
58        inline float getFluidDensity() const { return _density; }
59
60
61        /// Set the wind vector.
62        inline void setWind(const osg::Vec3& wind) { _wind = wind; }
63
64        /// Get the wind vector.
65        inline const osg::Vec3& getWind() const { return _wind; }
66
67        /// Set the acceleration vector.
68        inline void setAcceleration(const osg::Vec3& v) { _acceleration = v; }
69
70        /// Get the acceleration vector.
71        inline const osg::Vec3& getAcceleration() const { return _acceleration; }
72
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.
75        */
76        inline void setToGravity(float scale = 1.0f) { _acceleration.set(0, 0, -9.81f*scale); }
77
78        /// Set the fluid parameters as for air (20°C temperature).
79        inline void setFluidToAir()
80        {
81            setToGravity(1.0f);
82            setFluidDensity(1.2929f);
83            setFluidViscosity(1.8e-5f);
84        }
85
86        /// Set the fluid parameters as for pure water (20°C temperature).
87        inline void setFluidToWater()
88        {
89            setToGravity(1.0f);
90            setFluidDensity(1.0f);
91            setFluidViscosity(1.002e-3f);
92        }
93
94
95    protected:
96
97        virtual ~FluidProgram() {}
98        FluidProgram& operator=(const FluidProgram&) { return *this; }
99
100        virtual void execute(double dt);
101
102        osg::Vec3   _acceleration;
103        float       _viscosity;
104        float       _density;
105        osg::Vec3   _wind;
106
107        float       _viscosityCoefficient;
108        float       _densityCoefficient;
109    };
110
111
112}
113
114#endif
Note: See TracBrowser for help on using the browser.