sun.nas 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # Melchior FRANZ, < mfranz # aon : at >
  2. var sun = {
  3. init: func () {
  4. me.sun = "sim/model/sun-on-panel";
  5. me.sun_angle = "sim/time/sun-angle-rad";
  6. me.timeh = "sim/time/local-day-seconds";
  7. me.head = "orientation/heading-deg";
  8. setprop(me.sun, 0);
  9. me.r = "rendering/scene/ambient/red";
  10. me.g = "rendering/scene/ambient/green";
  11. me.b = "rendering/scene/ambient/blue";
  12. settimer(func me.update(),0.2);
  13. },
  14. update: func () {
  15. var x = getprop(me.sun_angle);
  16. var heading = getprop(me.head);
  17. var pitch = 0; #todo: include pitch in calc.
  18. # very simple sun direction estimation
  19. var time = getprop(me.timeh)/3600;
  20. var sundir = time / 24 * 360;
  21. var sunang = x / math.pi*180;
  22. var relsundir = math.abs(heading - sundir);
  23. var relsunang = math.abs(pitch - sunang);
  24. var illum = ( getprop(me.r)+getprop(me.g)+getprop(me.b) )/3;
  25. var out = ((illum > 0.3) and (relsundir > 90) and (relsunang > 10 and relsunang < 70));
  26. setprop( me.sun, out);
  27. settimer(func me.update(),0.2);
  28. }
  29. };
  30. sun.init();