root/OpenSceneGraph/trunk/src/osgParticle/FluidFrictionOperator.cpp @ 4121

Revision 4121, 1.4 kB (checked in by robert, 8 years ago)

Moved osgParticle across to standard OSG coding style.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1#include <osgParticle/FluidFrictionOperator>
2#include <osgParticle/ModularProgram>
3#include <osgParticle/Operator>
4#include <osgParticle/Particle>
5#include <osg/Notify>
6
7osgParticle::FluidFrictionOperator::FluidFrictionOperator():
8     Operator(),
9     _coeff_A(0),
10     _coeff_B(0),
11     _density(0),
12     _viscosity(0),
13     _ovr_rad(0),
14     _current_program(0)
15{
16    setFluidToAir();
17}
18
19osgParticle::FluidFrictionOperator::FluidFrictionOperator(const FluidFrictionOperator& copy, const osg::CopyOp& copyop)
20:    Operator(copy, copyop),
21    _coeff_A(copy._coeff_A),
22    _coeff_B(copy._coeff_B),
23    _density(copy._density),
24    _viscosity(copy._viscosity),
25    _ovr_rad(copy._ovr_rad),
26    _current_program(0)
27{
28}
29
30void osgParticle::FluidFrictionOperator::operate(Particle* P, double dt)
31{
32    float r = (_ovr_rad > 0)? _ovr_rad : P->getRadius();
33    osg::Vec3 v = P->getVelocity()-_wind;
34
35    float vm = v.normalize();
36    float R = _coeff_A * r * vm + _coeff_B * r * r * vm * vm;
37   
38    osg::Vec3 Fr(-R * v.x(), -R * v.y(), -R * v.z());
39
40    if (_current_program->getReferenceFrame() == ModularProgram::RELATIVE_RF) {
41        Fr = _current_program->rotateLocalToWorld(Fr);
42    }
43
44    // correct unwanted velocity increments
45    osg::Vec3 dv = Fr * P->getMassInv() * dt;
46    float dvl = dv.length();
47    if (dvl > vm) {
48        dv *= vm / dvl;
49    }
50
51    P->addVelocity(dv);
52}
Note: See TracBrowser for help on using the browser.