Light.h 1.6 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 setInnerAngle(float value);
  39. void setOuterAngle(float value);
  40. void setFalloffExponent(float value);
  41. enum LightType
  42. {
  43. DirectionalLight = 1,
  44. PointLight = 2,
  45. SpotLight = 3,
  46. AmbientLight = 255
  47. };
  48. private:
  49. static float computeRange(float constantAttenuation, float linearAttenuation, float quadraticAttenuation);
  50. static float computeInnerAngle(float outerAngle);
  51. unsigned char _lightType;
  52. float _color[COLOR_SIZE];
  53. float _constantAttenuation;
  54. float _linearAttenuation;
  55. float _quadraticAttenuation;
  56. float _falloffExponent;
  57. float _range;
  58. float _innerAngle;
  59. float _outerAngle;
  60. };
  61. }
  62. #endif