|
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
|
| Rev | Line | |
|---|
| [732] | 1 | #include <osgParticle/FluidFrictionOperator> |
|---|
| 2 | #include <osgParticle/ModularProgram> |
|---|
| 3 | #include <osgParticle/Operator> |
|---|
| 4 | #include <osgParticle/Particle> |
|---|
| 5 | #include <osg/Notify> |
|---|
| 6 | |
|---|
| [954] | 7 | osgParticle::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] | 19 | osgParticle::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] | 30 | void 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()); |
|---|
| 39 | |
|---|
| [4121] | 40 | if (_current_program->getReferenceFrame() == ModularProgram::RELATIVE_RF) { |
|---|
| 41 | Fr = _current_program->rotateLocalToWorld(Fr); |
|---|
| [732] | 42 | } |
|---|
| 43 | |
|---|
| [2228] | 44 | |
|---|
| 45 | osg::Vec3 dv = Fr * P->getMassInv() * dt; |
|---|
| 46 | float dvl = dv.length(); |
|---|
| 47 | if (dvl > vm) { |
|---|
| 48 | dv *= vm / dvl; |
|---|
| 49 | } |
|---|
| [2004] | 50 | |
|---|
| 51 | P->addVelocity(dv); |
|---|
| [732] | 52 | } |
|---|