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

Revision 9568, 1.5 kB (checked in by robert, 6 years ago)

From Lionel Lagarde, removed accounting of local to world transform on the force vector as the particle velocity should already been in world coords. Fixing this addresses a bug where particles accelerated out of the scene rather than slowing down.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
RevLine 
[732]1#include <osgParticle/FluidFrictionOperator>
2#include <osgParticle/ModularProgram>
3#include <osgParticle/Operator>
4#include <osgParticle/Particle>
5#include <osg/Notify>
6
[954]7osgParticle::FluidFrictionOperator::FluidFrictionOperator():
8     Operator(),
[4121]9     _coeff_A(0),
10     _coeff_B(0),
11     _density(0),
12     _viscosity(0),
13     _ovr_rad(0),
14     _current_program(0)
[732]15{
16    setFluidToAir();
17}
18
[4121]19osgParticle::FluidFrictionOperator::FluidFrictionOperator(const FluidFrictionOperator& copy, const osg::CopyOp& copyop)
[732]20:    Operator(copy, copyop),
[4121]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)
[732]27{
28}
29
[4121]30void osgParticle::FluidFrictionOperator::operate(Particle* P, double dt)
[732]31{
[4121]32    float r = (_ovr_rad > 0)? _ovr_rad : P->getRadius();
[3954]33    osg::Vec3 v = P->getVelocity()-_wind;
[732]34
35    float vm = v.normalize();
[4121]36    float R = _coeff_A * r * vm + _coeff_B * r * r * vm * vm;
[732]37   
38    osg::Vec3 Fr(-R * v.x(), -R * v.y(), -R * v.z());
[9568]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.
[4121]43    if (_current_program->getReferenceFrame() == ModularProgram::RELATIVE_RF) {
44        Fr = _current_program->rotateLocalToWorld(Fr);
[732]45    }
[9568]46#endif
[732]47
[2228]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    }
[2004]54
55    P->addVelocity(dv);
[732]56}
Note: See TracBrowser for help on using the browser.