/opengles/src/Light.h

http://ftk.googlecode.com/ · C Header · 182 lines · 94 code · 42 blank · 46 comment · 0 complexity · b8f2258d4332bef2272071b45dc442db MD5 · raw file

  1. #ifndef EGL_LIGHT_H
  2. #define EGL_LIGHT_H 1
  3. // ==========================================================================
  4. //
  5. // Light.h Light Class for 3D Rendering Library
  6. //
  7. // --------------------------------------------------------------------------
  8. //
  9. // 09-14-2003 Hans-Martin Will initial version
  10. //
  11. // --------------------------------------------------------------------------
  12. //
  13. // Copyright (c) 2004, Hans-Martin Will. All rights reserved.
  14. //
  15. // Redistribution and use in source and binary forms, with or without
  16. // modification, are permitted provided that the following conditions are
  17. // met:
  18. //
  19. // * Redistributions of source code must retain the above copyright
  20. // notice, this list of conditions and the following disclaimer.
  21. // * Redistributions in binary form must reproduce the above copyright
  22. // notice, this list of conditions and the following disclaimer in the
  23. // documentation and/or other materials provided with the distribution.
  24. //
  25. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  26. // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  28. // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  29. // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  30. // OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  31. // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  32. // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  33. // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  34. // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  35. // THE POSSIBILITY OF SUCH DAMAGE.
  36. //
  37. // ==========================================================================
  38. #include "OGLES.h"
  39. #include "linalg.h"
  40. #include "FractionalColor.h"
  41. namespace EGL {
  42. class Material;
  43. class Light {
  44. public:
  45. Light();
  46. void SetAmbientColor(const FractionalColor & color);
  47. FractionalColor GetAmbientColor() const;
  48. void SetDiffuseColor(const FractionalColor & color);
  49. FractionalColor GetDiffuseColor() const;
  50. void SetSpecularColor(const FractionalColor & color);
  51. FractionalColor GetSpecularColor() const;
  52. void SetPosition(const Vec4D & position);
  53. Vec4D GetPosition() const;
  54. void SetDirection(const Vec3D & direction);
  55. Vec3D GetNormalizedDirection() const;
  56. Vec3D GetDirection() const;
  57. void SetConstantAttenuation(EGL_Fixed attenuation);
  58. EGL_Fixed GetConstantAttenuation() const;
  59. void SetLinearAttenuation(EGL_Fixed attenuation);
  60. EGL_Fixed GetLinearAttenuation() const;
  61. void SetQuadraticAttenuation(EGL_Fixed attenuation);
  62. EGL_Fixed GetQuadraticAttenuation() const;
  63. void SetSpotExponent(EGL_Fixed exponent);
  64. EGL_Fixed GetSpotExponent() const;
  65. void SetSpotCutoff(EGL_Fixed cutoff);
  66. EGL_Fixed GetSpotCutoff() const;
  67. void InitWithMaterial(const Material& material);
  68. // one-sided lightning
  69. // TO DO:
  70. // create version for: light at infinity or light at location
  71. // spot light vs. point light
  72. // color material vs. material color
  73. void AccumulateLight(const Vec4D& vertexCoords, const Vec3D& vertexNormal,
  74. const Material& currMaterial, FractionalColor& result);
  75. void AccumulateLight(const Vec4D& vertexCoords, const Vec3D& vertexNormal,
  76. const Material& currMaterial, const FractionalColor& currentColor, FractionalColor& result);
  77. // two-sided lightning
  78. // TO DO:
  79. // create version for: light at infinity or light at location
  80. // spot light vs. point light
  81. // color material vs. material color
  82. void AccumulateLight2(const Vec4D& vertexCoords, const Vec3D& vertexNormal,
  83. const Material& currMaterial, FractionalColor& result,
  84. FractionalColor& result2);
  85. void AccumulateLight2(const Vec4D& vertexCoords, const Vec3D& vertexNormal,
  86. const Material& currMaterial, const FractionalColor& currentColor, FractionalColor& result,
  87. FractionalColor& result2);
  88. private:
  89. FractionalColor m_AmbientColor;
  90. FractionalColor m_DiffuseColor;
  91. FractionalColor m_SpecularColor;
  92. Vec4D m_Position;
  93. Vec3D m_NormalizedSpotDirection;
  94. Vec3D m_SpotDirection;
  95. EGL_Fixed m_ConstantAttenuation;
  96. EGL_Fixed m_LinearAttenuation;
  97. EGL_Fixed m_QuadraticAttenuation;
  98. EGL_Fixed m_SpotExponent;
  99. EGL_Fixed m_SpotCutoff;
  100. EGL_Fixed m_CosineSpotCutoff;
  101. // effective color contributions for current material settings
  102. FractionalColor m_EffectiveAmbientColor;
  103. FractionalColor m_EffectiveDiffuseColor;
  104. FractionalColor m_EffectiveSpecularColor;
  105. };
  106. inline FractionalColor Light :: GetAmbientColor() const {
  107. return m_AmbientColor;
  108. }
  109. inline FractionalColor Light :: GetDiffuseColor() const {
  110. return m_DiffuseColor;
  111. }
  112. inline FractionalColor Light :: GetSpecularColor() const {
  113. return m_SpecularColor;
  114. }
  115. inline Vec4D Light :: GetPosition() const {
  116. return m_Position;
  117. }
  118. inline Vec3D Light :: GetNormalizedDirection() const {
  119. return m_NormalizedSpotDirection;
  120. }
  121. inline Vec3D Light :: GetDirection() const {
  122. return m_SpotDirection;
  123. }
  124. inline EGL_Fixed Light :: GetConstantAttenuation() const {
  125. return m_ConstantAttenuation;
  126. }
  127. inline EGL_Fixed Light :: GetLinearAttenuation() const {
  128. return m_LinearAttenuation;
  129. }
  130. inline EGL_Fixed Light :: GetQuadraticAttenuation() const {
  131. return m_QuadraticAttenuation;
  132. }
  133. inline EGL_Fixed Light :: GetSpotExponent() const {
  134. return m_SpotExponent;
  135. }
  136. inline EGL_Fixed Light :: GetSpotCutoff() const {
  137. return m_SpotCutoff;
  138. }
  139. }
  140. #endif //ndef EGL_LIGHT_H