Sun: set progress with custom time (#689)
This commit is contained in:
parent
9809398517
commit
311cc19134
@ -151,7 +151,7 @@ public class Sun {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Customize day of the year
|
* Customize day of the year.
|
||||||
*/
|
*/
|
||||||
public void setDayOfYear(int day) {
|
public void setDayOfYear(int day) {
|
||||||
mDayOfYear = day;
|
mDayOfYear = day;
|
||||||
@ -171,6 +171,28 @@ public class Sun {
|
|||||||
mProgress = progress;
|
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.
|
* @param h the offset of horizon (in radians) e.g. bend of earth / atmosphere etc.
|
||||||
* @return the difference of sunrise or sunset to noon
|
* @return the difference of sunrise or sunset to noon
|
||||||
@ -238,23 +260,7 @@ public class Sun {
|
|||||||
* @return the progress in range 0 to 2
|
* @return the progress in range 0 to 2
|
||||||
*/
|
*/
|
||||||
public float updateProgress() {
|
public float updateProgress() {
|
||||||
// TODO Java8 replace with LocalDateTime
|
return setProgress(date.getHour(), date.getMinute(), date.getSecond());
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user