|
Revision 13041, 1.5 kB
(checked in by robert, 14 months 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 | |
|---|
| 7 | osgParticle::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 | |
|---|
| 19 | osgParticle::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 | |
|---|
| 30 | void 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 | |
|---|
| 42 | |
|---|
| 43 | if (_current_program->getReferenceFrame() == ModularProgram::RELATIVE_RF) { |
|---|
| 44 | Fr = _current_program->rotateLocalToWorld(Fr); |
|---|
| 45 | } |
|---|
| 46 | #endif |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 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 | } |
|---|