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.

96 lines
2.1 KiB

5 years ago
  1. #include "light.h"
  2. Light::Light()
  3. {
  4. }
  5. void Light::SetAmbientColor(float r, float g, float b, float a)
  6. {
  7. float ambientColor[] = { r,g,b,a };
  8. glLightfv(mLightIdentifier, GL_AMBIENT, ambientColor);
  9. }
  10. void Light::SetDiffuseColor(float r, float g, float b, float a)
  11. {
  12. float diffuseColor[] = { r,g,b,a };
  13. glLightfv(mLightIdentifier, GL_DIFFUSE, diffuseColor);
  14. }
  15. void Light::SetSpecularColor(float r, float g, float b, float a)
  16. {
  17. float specularColor[] = { r,g,b,a };
  18. glLightfv(mLightIdentifier, GL_SPECULAR, specularColor);
  19. }
  20. void Light::Enable()
  21. {
  22. glEnable(GL_LIGHTING);
  23. glEnable(mLightIdentifier);
  24. }
  25. DirectionLight::DirectionLight(GLenum light)
  26. {
  27. mLightIdentifier = light;
  28. }
  29. void DirectionLight::SetPosition(float x, float y, float z)
  30. {
  31. float pos[] = { x,y,z, 0.0f }; //������������д��0.0f��������������Զ��
  32. glLightfv(mLightIdentifier, GL_POSITION, pos);
  33. }
  34. PointLight::PointLight(GLenum light)
  35. {
  36. mLightIdentifier = light;
  37. memset(mPosition, 0, sizeof(mPosition));
  38. }
  39. void PointLight::SetPosition(float x, float y, float z)
  40. {
  41. //float pos[] = {x,y,z, 1.0f};//��������������Ϊ1.0�����ڽ���
  42. //glLightfv(mLightIdentifier, GL_POSITION, pos);
  43. mPosition[0] = x;
  44. mPosition[1] = y;
  45. mPosition[2] = z;
  46. }
  47. void PointLight::SetConstAttenuation(float v)
  48. {
  49. glLightf(mLightIdentifier, GL_CONSTANT_ATTENUATION, v);
  50. }
  51. void PointLight::SetLinearAttenuation(float v)
  52. {
  53. glLightf(mLightIdentifier, GL_LINEAR_ATTENUATION, v);
  54. }
  55. void PointLight::SetQuadricAttenuation(float v)
  56. {
  57. glLightf(mLightIdentifier, GL_QUADRATIC_ATTENUATION, v);
  58. }
  59. void PointLight::Update(float x, float y, float z)
  60. {
  61. float pos[] = {mPosition[0] - x, mPosition[1] - y, mPosition[2] - z, 1.0f};
  62. glLightfv(mLightIdentifier, GL_POSITION, pos);
  63. }
  64. SpotLight::SpotLight(GLenum light):PointLight(light)
  65. {
  66. }
  67. void SpotLight::SetDirection(float x, float y, float z)
  68. {
  69. float dir[] = { x,y,z };
  70. glLightfv(mLightIdentifier, GL_SPOT_DIRECTION, dir);//���þ۹��Ƶij���
  71. }
  72. void SpotLight::SetExpone(float v)
  73. {
  74. glLightf(mLightIdentifier, GL_SPOT_EXPONENT, v);//���þ۹��ȣ���ʵ������һ���Ƕȣ��������Ƕ��ڹ��Dz�˥����
  75. }
  76. void SpotLight::SetCutoff(float v)
  77. {
  78. glLightf(mLightIdentifier, GL_SPOT_CUTOFF, v);//���þ۹ⷶΧ
  79. }