MLRInfiniteLight.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //===========================================================================//
  2. // Copyright (C) Microsoft Corporation. All rights reserved. //
  3. //===========================================================================//
  4. #include "MLRHeaders.hpp"
  5. //#############################################################################
  6. //############################### MLRInfiniteLight ##################################
  7. //#############################################################################
  8. MLRInfiniteLight::ClassData*
  9. MLRInfiniteLight::DefaultData = NULL;
  10. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  11. //
  12. void
  13. MLRInfiniteLight::InitializeClass()
  14. {
  15. Verify(!DefaultData);
  16. Verify(gos_GetCurrentHeap() == StaticHeap);
  17. DefaultData =
  18. new ClassData(
  19. MLRInfiniteLightClassID,
  20. "MidLevelRenderer::MLRInfiniteLight",
  21. MLRLight::DefaultData
  22. );
  23. Register_Object(DefaultData);
  24. }
  25. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  26. //
  27. void
  28. MLRInfiniteLight::TerminateClass()
  29. {
  30. Unregister_Object(DefaultData);
  31. delete DefaultData;
  32. DefaultData = NULL;
  33. }
  34. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  35. //
  36. MLRInfiniteLight::MLRInfiniteLight(ClassData *class_data) :
  37. MLRLight(class_data)
  38. {
  39. Verify(gos_GetCurrentHeap() == Heap);
  40. lightMask = MLRState::FaceLightingMode|MLRState::VertexLightingMode;
  41. }
  42. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  43. //
  44. MLRInfiniteLight::MLRInfiniteLight(
  45. ClassData *class_data,
  46. Stuff::MemoryStream *stream,
  47. int version
  48. ) :
  49. MLRLight(class_data, stream, version)
  50. {
  51. Check_Object(stream);
  52. Verify(gos_GetCurrentHeap() == Heap);
  53. lightMask = MLRState::FaceLightingMode|MLRState::VertexLightingMode;
  54. }
  55. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  56. //
  57. MLRInfiniteLight::MLRInfiniteLight(
  58. ClassData *class_data,
  59. Stuff::Page *page
  60. ) :
  61. MLRLight(class_data, page)
  62. {
  63. Check_Object(page);
  64. Verify(gos_GetCurrentHeap() == Heap);
  65. lightMask = MLRState::FaceLightingMode|MLRState::VertexLightingMode;
  66. }
  67. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  68. //
  69. MLRInfiniteLight::~MLRInfiniteLight()
  70. {
  71. }
  72. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  73. //
  74. void
  75. MLRInfiniteLight::TestInstance()
  76. {
  77. Verify(IsDerivedFrom(DefaultData));
  78. }
  79. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  80. //
  81. void
  82. MLRInfiniteLight::LightVertex(const MLRVertexData& vertexData)
  83. {
  84. UnitVector3D light_z;
  85. GetInShapeDirection(light_z);
  86. //
  87. //-------------------------------------------------------------------
  88. // Now we reduce the light level falling on the vertex based upon the
  89. // cosine of the angle between light and normal
  90. //-------------------------------------------------------------------
  91. //
  92. Scalar cosine = -(light_z * (*vertexData.normal)) * intensity;
  93. #if COLOR_AS_DWORD
  94. TO_DO;
  95. #else
  96. RGBColor light_color(color);
  97. if (cosine > SMALL)
  98. {
  99. light_color.red *= cosine;
  100. light_color.green *= cosine;
  101. light_color.blue *= cosine;
  102. vertexData.color->red += light_color.red;
  103. vertexData.color->green += light_color.green;
  104. vertexData.color->blue += light_color.blue;
  105. }
  106. #endif
  107. }