W3DDynamicLight.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // W3DDynamicLight.cpp
  24. // Class to handle dynamic lights.
  25. // Author: John Ahlquist, April 2001
  26. #include <stdlib.h>
  27. #include "W3DDevice/GameClient/W3DDynamicLight.h"
  28. W3DDynamicLight::W3DDynamicLight(void):
  29. LightClass(LightClass::POINT)
  30. {
  31. m_priorEnable = false;
  32. m_enabled = true;
  33. }
  34. W3DDynamicLight::~W3DDynamicLight(void)
  35. {
  36. }
  37. void W3DDynamicLight::On_Frame_Update(void)
  38. {
  39. if (!m_enabled) {
  40. return;
  41. }
  42. Real factor = 1.0f;
  43. if (m_curIncreaseFrameCount>0 && m_increaseFrameCount>0) {
  44. // increasing
  45. m_curIncreaseFrameCount--;
  46. factor = (m_increaseFrameCount-m_curIncreaseFrameCount)/(Real)m_increaseFrameCount;
  47. } else if (m_decayFrameCount==0) {
  48. factor = 1.0; // never decays,
  49. } else {
  50. m_curDecayFrameCount--;
  51. if (m_curDecayFrameCount == 0) {
  52. m_enabled = false;
  53. return;
  54. }
  55. factor = m_curDecayFrameCount/(Real)m_decayFrameCount;
  56. }
  57. if (m_decayRange) {
  58. this->FarAttenEnd = factor*m_targetRange;
  59. if (FarAttenEnd < FarAttenStart) {
  60. FarAttenEnd = FarAttenStart;
  61. }
  62. }
  63. if (m_decayColor) {
  64. this->Ambient = m_targetAmbient*factor;
  65. this->Diffuse = m_targetDiffuse*factor;
  66. }
  67. }
  68. void W3DDynamicLight::setFrameFade(UnsignedInt frameIncreaseTime, UnsignedInt decayFrameTime)
  69. {
  70. m_decayFrameCount = decayFrameTime;
  71. m_curDecayFrameCount = decayFrameTime;
  72. m_curIncreaseFrameCount = frameIncreaseTime;
  73. m_increaseFrameCount = frameIncreaseTime;
  74. m_targetAmbient = Ambient;
  75. m_targetDiffuse = Diffuse;
  76. m_targetRange = FarAttenEnd;
  77. }