MLRInfiniteLightWithFallOff.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. //===========================================================================//
  2. // Copyright (C) Microsoft Corporation. All rights reserved. //
  3. //===========================================================================//
  4. #pragma once
  5. #define MLR_MLRINFINITELIGHTWITHFALLOFF_HPP
  6. #include "MLR.hpp"
  7. namespace MidLevelRenderer {
  8. //##########################################################################
  9. //############## MLRInfiniteLightWithFalloff #########################
  10. //##########################################################################
  11. class MLRInfiniteLightWithFalloff:
  12. public MLRLight
  13. {
  14. public:
  15. static void
  16. InitializeClass();
  17. static void
  18. TerminateClass();
  19. MLRInfiniteLightWithFalloff(ClassData *class_data=MLRInfiniteLightWithFalloff::DefaultData);
  20. MLRInfiniteLightWithFalloff(
  21. ClassData *class_data,
  22. Stuff::MemoryStream *stream,
  23. int version
  24. );
  25. MLRInfiniteLightWithFalloff(
  26. ClassData *class_data,
  27. Stuff::Page *page
  28. );
  29. ~MLRInfiniteLightWithFalloff();
  30. void
  31. Save(Stuff::MemoryStream *stream);
  32. void
  33. Write(Stuff::Page *page);
  34. virtual void
  35. LightVertex(const MLRVertexData&);
  36. virtual LightType
  37. GetLightType()
  38. { Check_Object(this); return InfiniteLightWithFallOff; }
  39. //
  40. // light falloff. The light is infinite if the GetFalloffDistance
  41. // function return false. Lights default to infinite unless
  42. // SetFalloffDistance is called
  43. //
  44. void
  45. SetFalloffDistance(
  46. Stuff::Scalar n,
  47. Stuff::Scalar f
  48. );
  49. bool
  50. GetFalloffDistance(
  51. Stuff::Scalar& n,
  52. Stuff::Scalar& f
  53. );
  54. inline Stuff::Scalar
  55. GetFalloffNear()
  56. { Check_Object(this); return innerRadius; }
  57. inline Stuff::Scalar
  58. GetFalloffFar()
  59. { Check_Object(this); return outerRadius; }
  60. bool
  61. GetFalloff(const Stuff::Scalar& length, Stuff::Scalar& falloff)
  62. {
  63. Check_Object(this);
  64. Verify(length>0.0f);
  65. if(length <= innerRadius)
  66. {
  67. falloff = 1.0f;
  68. return true;
  69. }
  70. if (length >= outerRadius)
  71. {
  72. return false;
  73. }
  74. Verify(outerRadius - innerRadius > Stuff::SMALL);
  75. falloff = (outerRadius - length) * oneOverDistance;
  76. return true;
  77. }
  78. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  79. // Class Data Support
  80. //
  81. public:
  82. static ClassData
  83. *DefaultData;
  84. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  85. // Testing
  86. //
  87. public:
  88. void
  89. TestInstance();
  90. protected:
  91. Stuff::Scalar
  92. innerRadius, outerRadius, oneOverDistance;
  93. };
  94. }