Clone of Bael'Zharon's Respite @ https://github.com/boardwalk/bzr

SkyModel.h 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Bael'Zharon's Respite
  3. * Copyright (C) 2014 Daniel Skorupski
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. #ifndef BZR_GRAPHICS_SKYMODEL_H
  19. #define BZR_GRAPHICS_SKYMODEL_H
  20. class SkyModel
  21. {
  22. public:
  23. struct Params
  24. {
  25. // dt is the day of the year, between 0 and 365
  26. fp_t dt;
  27. // tm is a normalized value, 0 indicating midnight, 0.5 indicating noon
  28. fp_t tm;
  29. // lng is in radians, -pi to pi
  30. fp_t lng;
  31. // lat is in radians, -pi to pi
  32. fp_t lat;
  33. // tu is the turbidity, or haziness, of the sky
  34. // rough scale of values:
  35. // 1 pure air
  36. // 1.5 very clear
  37. // 2.5 clear
  38. // 8 light haze
  39. // 24 haze
  40. // 48 thin fog
  41. fp_t tu;
  42. };
  43. // prepare for getColor to be called
  44. void prepare(const Params& p);
  45. // theta is the zenith angle (angle from directly above)
  46. // phi is the azimuth angle (ccw angle from directly south)
  47. // returns a normalized sRGB color value
  48. glm::vec3 getColor(fp_t theta, fp_t phi);
  49. fp_t thetaSun() const;
  50. fp_t phiSun() const;
  51. private:
  52. // zenith angle of the sun
  53. fp_t theta_s_;
  54. // azimuth angle of the sun
  55. fp_t phi_s_;
  56. // A, B, C, D and E coefficients for F()
  57. fp_t coeffs_Y_[5];
  58. fp_t coeffs_x_[5];
  59. fp_t coeffs_y_[5];
  60. // color at zenith
  61. fp_t Y_z_;
  62. fp_t x_z_;
  63. fp_t y_z_;
  64. };
  65. #endif