Light.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #ifndef LIGHT_H_
  2. #define LIGHT_H_
  3. #include "Object.h"
  4. namespace gameplay
  5. {
  6. class Light : public Object
  7. {
  8. public:
  9. static const int COLOR_SIZE = 3;
  10. /**
  11. * Constructor.
  12. */
  13. Light(void);
  14. /**
  15. * Destructor.
  16. */
  17. virtual ~Light(void);
  18. virtual unsigned int getTypeId(void) const;
  19. virtual const char* getElementName(void) const;
  20. virtual void writeBinary(FILE* file);
  21. virtual void writeText(FILE* file);
  22. float getRed() const;
  23. float getGreen() const;
  24. float getBlue() const;
  25. bool isAmbient() const;
  26. /**
  27. * Sets the light type to ambient.
  28. */
  29. void setAmbientLight();
  30. void setDirectionalLight();
  31. void setPointLight();
  32. void setSpotLight();
  33. void setColor(float r, float g, float b);
  34. void setColor(float r, float g, float b, float a);
  35. void setConstantAttenuation(float value);
  36. void setLinearAttenuation(float value);
  37. void setQuadraticAttenuation(float value);
  38. void setFalloffAngle(float value);
  39. void setFalloffExponent(float value);
  40. enum LightType
  41. {
  42. DirectionalLight = 1,
  43. PointLight = 2,
  44. SpotLight = 3,
  45. AmbientLight = 255
  46. };
  47. private:
  48. static float computeRange(float constantAttenuation, float linearAttenuation, float quadraticAttenuation);
  49. static float computeInnerAngle(float outerAngle);
  50. unsigned char _lightType;
  51. float _color[COLOR_SIZE];
  52. float _constantAttenuation;
  53. float _linearAttenuation;
  54. float _quadraticAttenuation;
  55. float _falloffAngle;
  56. float _falloffExponent;
  57. float _range;
  58. float _innerAngle;
  59. float _outerAngle;
  60. };
  61. }
  62. #endif