From 311cc19134ec6633631971fd52bbaf278cd9b178 Mon Sep 17 00:00:00 2001 From: Gustl22 Date: Tue, 5 Mar 2019 14:23:18 +0100 Subject: [PATCH] Sun: set progress with custom time (#689) --- vtm/src/org/oscim/renderer/light/Sun.java | 42 +++++++++++++---------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/vtm/src/org/oscim/renderer/light/Sun.java b/vtm/src/org/oscim/renderer/light/Sun.java index d41eb4f1..800dd6bf 100644 --- a/vtm/src/org/oscim/renderer/light/Sun.java +++ b/vtm/src/org/oscim/renderer/light/Sun.java @@ -151,7 +151,7 @@ public class Sun { } /** - * Customize day of the year + * Customize day of the year. */ public void setDayOfYear(int day) { mDayOfYear = day; @@ -171,6 +171,28 @@ public class Sun { mProgress = progress; } + /** + * Customize progress with specified time. + * + * @param hour the hour [0..23] + * @param minute the minute [0..59] + * @param second the second [0..59] + * @return the progress in range 0 to 2 + */ + public float setProgress(int hour, int minute, int second) { + float time = hour; + time += minute / 60f; + time += second / 3600f; + + float progress = (time - mSunrise) / (mSunset - mSunrise); + if (progress > 1f || progress < 0f) { + progress = ((time + 24 - mSunset) % 24) / (mSunrise + 24 - mSunset); + progress += 1; + } + mProgress = MathUtils.clamp(progress, 0f, 2f); + return mProgress; + } + /** * @param h the offset of horizon (in radians) e.g. bend of earth / atmosphere etc. * @return the difference of sunrise or sunset to noon @@ -238,23 +260,7 @@ public class Sun { * @return the progress in range 0 to 2 */ public float updateProgress() { - // TODO Java8 replace with LocalDateTime - // LocalDateTime date = new LocalDateTime(); - // float time = date.getHour(); - // time += date.getMinute() / 60f; - // time += date.getSecond() / 3600f; - - float time = date.getHour(); - time += date.getMinute() / 60f; - time += date.getSecond() / 3600f; - - float progress = (time - mSunrise) / (mSunset - mSunrise); - if (progress > 1f || progress < 0f) { - progress = ((time + 24 - mSunset) % 24) / (mSunrise + 24 - mSunset); - progress += 1; - } - mProgress = MathUtils.clamp(progress, 0f, 2f); - return mProgress; + return setProgress(date.getHour(), date.getMinute(), date.getSecond()); } /**