CParticleGravityAffector.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright (C) 2002-2012 Nikolaus Gebhardt
  2. // This file is part of the "Irrlicht Engine".
  3. // For conditions of distribution and use, see copyright notice in irrlicht.h
  4. #include "CParticleGravityAffector.h"
  5. #include "os.h"
  6. #include "IAttributes.h"
  7. namespace irr
  8. {
  9. namespace scene
  10. {
  11. //! constructor
  12. CParticleGravityAffector::CParticleGravityAffector(
  13. const core::vector3df& gravity, u32 timeForceLost)
  14. : IParticleGravityAffector(), TimeForceLost(static_cast<f32>(timeForceLost)), Gravity(gravity)
  15. {
  16. #ifdef _DEBUG
  17. setDebugName("CParticleGravityAffector");
  18. #endif
  19. }
  20. //! Affects an array of particles.
  21. void CParticleGravityAffector::affect(u32 now, SParticle* particlearray, u32 count)
  22. {
  23. if (!Enabled)
  24. return;
  25. f32 d;
  26. for (u32 i=0; i<count; ++i)
  27. {
  28. d = (now - particlearray[i].startTime) / TimeForceLost;
  29. if (d > 1.0f)
  30. d = 1.0f;
  31. if (d < 0.0f)
  32. d = 0.0f;
  33. d = 1.0f - d;
  34. particlearray[i].vector = particlearray[i].startVector.getInterpolated(Gravity, d);
  35. }
  36. }
  37. //! Writes attributes of the object.
  38. void CParticleGravityAffector::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
  39. {
  40. out->addVector3d("Gravity", Gravity);
  41. out->addFloat("TimeForceLost", TimeForceLost);
  42. }
  43. //! Reads attributes of the object.
  44. void CParticleGravityAffector::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
  45. {
  46. Gravity = in->getAttributeAsVector3d("Gravity");
  47. TimeForceLost = in->getAttributeAsFloat("TimeForceLost");
  48. }
  49. } // end namespace scene
  50. } // end namespace irr