選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

104 行
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. //
  11. // The Light class
  12. // ---------------
  13. //
  14. #if !defined __LIGHT_H__
  15. #define __LIGHT_H__
  16. #include <cfloat> /* for FLT_MAX */
  17. #include "worldentity.h"
  18. namespace lol
  19. {
  20. struct LightType
  21. {
  22. enum Value
  23. {
  24. Directional = 0,
  25. Point,
  26. Max,
  27. }
  28. m_value;
  29. static char const *GetName(Value v)
  30. {
  31. switch (v)
  32. {
  33. case Directional:
  34. return "<Directional>";
  35. case Point:
  36. return "<Point>";
  37. default:
  38. return "<UNDEFINED>";
  39. }
  40. }
  41. inline LightType(float v)
  42. {
  43. float top = FLT_MAX;
  44. int iv = Directional;
  45. for (int i = 0; i < Max; ++i)
  46. {
  47. LightType lv = LightType(i);
  48. float nv = lv.f();
  49. float ntop = lol::abs(nv - v);
  50. if (ntop < top)
  51. {
  52. top = ntop;
  53. iv = i;
  54. }
  55. }
  56. m_value = LightType(iv);
  57. }
  58. inline LightType(int v) : m_value((Value)v) {}
  59. inline LightType(Value v) : m_value(v) {}
  60. inline LightType() : m_value(Directional) {}
  61. inline operator Value() { return m_value; }
  62. inline float f() { return ((float)m_value / (float)Max); }
  63. };
  64. class Light : public WorldEntity
  65. {
  66. public:
  67. Light();
  68. ~Light();
  69. char const *GetName() { return "<light>"; }
  70. void SetType(LightType const &type);
  71. LightType GetType();
  72. void SetColor(vec4 const &color);
  73. vec4 GetColor();
  74. void SetPosition(vec3 const &pos);
  75. vec3 GetPosition();
  76. protected:
  77. virtual void TickGame(float seconds);
  78. virtual void TickDraw(float seconds);
  79. private:
  80. vec4 m_color;
  81. LightType m_type;
  82. };
  83. } /* namespace lol */
  84. #endif /* __LIGHT_H__ */