forestWindAccumulator.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _FORESTWINDACCUMULATOR_H_
  23. #define _FORESTWINDACCUMULATOR_H_
  24. #ifndef _MPOINT3_H_
  25. #include "math/mPoint3.h"
  26. #endif
  27. struct TreePlacementInfo;
  28. class ForestItemData;
  29. /// This simple class holds the state of the accumulated
  30. /// wind effect for a single tree.
  31. class ForestWindAccumulator
  32. {
  33. protected:
  34. struct VerletParticle
  35. {
  36. Point2F position;
  37. Point2F lastPosition;
  38. };
  39. F32 mCurrentStrength;
  40. Point2F mCurrentDir;
  41. Point3F mPosition;
  42. F32 mScale;
  43. ForestItemData *mDataBlock;
  44. VerletParticle mParticles[2];
  45. void _updateParticle( VerletParticle *particle, const Point2F &force, F32 timeDelta );
  46. public:
  47. ForestWindAccumulator( const TreePlacementInfo &info );
  48. ~ForestWindAccumulator();
  49. void presimulate( const VectorF &windVector, U32 ticks );
  50. void updateWind( const VectorF &windVector, F32 timeDelta );
  51. void setDirection( const VectorF &dir ) { mCurrentDir.set( dir.x, dir.y ); }
  52. VectorF getDirection() const { return VectorF( mCurrentDir.x, mCurrentDir.y, 0 ); }
  53. void setStrength( F32 strength ) { mCurrentStrength = strength; }
  54. F32 getStrength() const { return mCurrentStrength; }
  55. void setPosition( const Point3F &pos ) { mPosition = pos; }
  56. Point3F getPosition() const { return mPosition; }
  57. void applyImpulse( const VectorF &impulse );
  58. };
  59. #endif // _FORESTWINDACCUMULATOR_H_