You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

101 lines
2.0 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://www.wtfpl.net/ for more details.
  9. //
  10. #pragma once
  11. //
  12. // The Light class
  13. // ---------------
  14. //
  15. #include <cfloat> /* for FLT_MAX */
  16. #include "engine/worldentity.h"
  17. namespace lol
  18. {
  19. struct LightType
  20. {
  21. enum Value
  22. {
  23. Directional = 0,
  24. Point,
  25. Max,
  26. }
  27. m_value;
  28. String ToString()
  29. {
  30. switch (m_value)
  31. {
  32. case Directional:
  33. return "<Directional>";
  34. case Point:
  35. return "<Point>";
  36. default:
  37. return "<UNDEFINED>";
  38. }
  39. }
  40. inline LightType(float v)
  41. {
  42. float top = FLT_MAX;
  43. int iv = Directional;
  44. for (int i = 0; i < Max; ++i)
  45. {
  46. LightType lv = LightType(i);
  47. float nv = lv.f();
  48. float ntop = lol::abs(nv - v);
  49. if (ntop < top)
  50. {
  51. top = ntop;
  52. iv = i;
  53. }
  54. }
  55. m_value = LightType(iv);
  56. }
  57. inline LightType(int v) : m_value((Value)v) {}
  58. inline LightType(Value v) : m_value(v) {}
  59. inline LightType() : m_value(Directional) {}
  60. inline operator Value() { return m_value; }
  61. inline float f() { return ((float)m_value / (float)Max); }
  62. };
  63. class Light : public WorldEntity
  64. {
  65. public:
  66. Light();
  67. ~Light();
  68. char const *GetName() { return "<light>"; }
  69. void SetType(LightType const &type);
  70. LightType GetType();
  71. void SetColor(vec4 const &color);
  72. vec4 GetColor();
  73. void SetPosition(vec3 const &pos);
  74. vec3 GetPosition();
  75. protected:
  76. virtual void TickGame(float seconds);
  77. virtual void TickDraw(float seconds, Scene &scene);
  78. private:
  79. vec4 m_color;
  80. LightType m_type;
  81. };
  82. } /* namespace lol */