CParticleFadeOutAffector.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 "CParticleFadeOutAffector.h"
  5. #include "IAttributes.h"
  6. #include "os.h"
  7. namespace irr
  8. {
  9. namespace scene
  10. {
  11. //! constructor
  12. CParticleFadeOutAffector::CParticleFadeOutAffector(
  13. const video::SColor& targetColor, u32 fadeOutTime)
  14. : IParticleFadeOutAffector(), TargetColor(targetColor)
  15. {
  16. #ifdef _DEBUG
  17. setDebugName("CParticleFadeOutAffector");
  18. #endif
  19. FadeOutTime = fadeOutTime ? static_cast<f32>(fadeOutTime) : 1.0f;
  20. }
  21. //! Affects an array of particles.
  22. void CParticleFadeOutAffector::affect(u32 now, SParticle* particlearray, u32 count)
  23. {
  24. if (!Enabled)
  25. return;
  26. f32 d;
  27. for (u32 i=0; i<count; ++i)
  28. {
  29. if (particlearray[i].endTime - now < FadeOutTime)
  30. {
  31. d = (particlearray[i].endTime - now) / FadeOutTime; // FadeOutTime probably f32 to save casts here (just guessing)
  32. particlearray[i].color = particlearray[i].startColor.getInterpolated(
  33. TargetColor, d);
  34. }
  35. }
  36. }
  37. //! Writes attributes of the object.
  38. //! Implement this to expose the attributes of your scene node animator for
  39. //! scripting languages, editors, debuggers or xml serialization purposes.
  40. void CParticleFadeOutAffector::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
  41. {
  42. out->addColor("TargetColor", TargetColor);
  43. out->addFloat("FadeOutTime", FadeOutTime);
  44. }
  45. //! Reads attributes of the object.
  46. //! Implement this to set the attributes of your scene node animator for
  47. //! scripting languages, editors, debuggers or xml deserialization purposes.
  48. //! \param startIndex: start index where to start reading attributes.
  49. //! \return: returns last index of an attribute read by this affector
  50. void CParticleFadeOutAffector::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
  51. {
  52. TargetColor = in->getAttributeAsColor("TargetColor");
  53. FadeOutTime = in->getAttributeAsFloat("FadeOutTime");
  54. }
  55. } // end namespace scene
  56. } // end namespace irr