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

Revision 13041, 1.5 kB (checked in by robert, 2 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#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 0
41    // Commenting out rotation of force vector rotation from local to world as the particle velocity itself
42    // should already be in world coords so shouldn't need rotating.
43    if (_current_program->getReferenceFrame() == ModularProgram::RELATIVE_RF) {
44        Fr = _current_program->rotateLocalToWorld(Fr);
45    }
46#endif
47
48    // correct unwanted velocity increments
49    osg::Vec3 dv = Fr * P->getMassInv() * dt;
50    float dvl = dv.length();
51    if (dvl > vm) {
52        dv *= vm / dvl;
53    }
54
55    P->addVelocity(dv);
56}
Note: See TracBrowser for help on using the browser.