|
Re: real sun position by time, date and location
[Re: oliver2s]
#422008
04/30/13 10:22
04/30/13 10:22
|
Joined: May 2009
Posts: 5,377 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,377
Caucasus
|
oliver2s@ your last example is not working, minute_ always stays at zero, same for hour.
hour_+=integer(minute_/60);
Doesn't do the trick.. I changed your example like this:
while(1){
DEBUG_VAR(second_, 10);
DEBUG_VAR(minute_, 50);
DEBUG_VAR(hour_, 100);
second_ += time_speed_*time_step;
if(second_ >= 60)
{
second_ = fraction(second_ / 60);
minute_ += 1;
if(minute_ >= 60)
{
minute_ = fraction(minute_ / 60);
hour_+= 1;
hour_ %= 24;
}
}
set_sun_position(day_, hour_, minute_, second_, LOCATION_LATITUDE, LOCATION_TIME_SPRING_EQUINOX);
wait(1);
}
It looks like it works now. Thank you for your contribution anyway. Edit: maybe thats cause I've changed your script wrong, I don't know, but the sun position jerks when the time goes from 11 a.m to 1 p.m. Here is a small example, just take a look at it:
#define EARTH_AXIAL_TILT 23.5 //earth axial tilt in degrees
#define EARTH_ORBITAL_PERIOD 365.25 //earth orbital period in days (length of a year)
#define EARTH_ROTATION_PERIOD 24.0 //earth rotation period in hours (length of a day)
#define LOCATION_TIME_SPRING_EQUINOX 81 //day number of the year when day and night cycle is exactly 12/12 hours
#define LOCATION_LATITUDE 48 //latitude of current location
void set_sun_position(var day_,var hour_,var minute_,var second_,var latitude_,var spring_equinox_)
{
var B=(360/EARTH_ORBITAL_PERIOD) * (day_-spring_equinox_);
//Equation of Time (EoT)
var EoT=9.87*sinv(2*B) - 7.53*cosv(B) - 1.5*sinv(B);
//Time Correction Factor (TC)
var TC=EoT;
//Local Time (LT)
var LT=hour_ + (minute_/60.0) + (second_/3600.0);
//Local Solar Time (LST)
var LST=LT + TC/60;
//Hour Angle (HRA)
var HRA=15 * (LST - 12);
//Number of days since the start of the year (d)
var d=day_ + LT/24;
//Declination (D)
var D=EARTH_AXIAL_TILT * sinv((360/EARTH_ORBITAL_PERIOD) * (d - spring_equinox_));
//Sun Elevation (sun_angle.tilt)
sun_angle.tilt=asinv((cosv(HRA) * cosv(D) * cosv(latitude_)) + (sinv(D) * sinv(latitude_)));
//Sun Azimuth (sun_angle.pan)
sun_angle.pan=acosv( (sinv(D) - sinv(sun_angle.tilt) * sinv(latitude_)) / (cosv(sun_angle.tilt) * cosv(latitude_)) );
if(LST>12 && HRA >0){sun_angle.pan=360-sun_angle.pan;}
}
void main(){
shadow_stencil = 2;
level_load("");
ENTITY* ground = ent_create(CUBE_MDL, vector(0, 0, 0), NULL);
vec_set(ground.scale_x, vector(100, 100, 1));
ENTITY* ball = ent_create(SPHERE_MDL, vector(random(20), random(20), 150), NULL);
set(ball, SHADOW);
vec_set(camera.x, vector(-1436, 0, 897));
vec_set(camera.pan, vector(0, -36, 0));
var second_ = 0;
var minute_ = 0;
var hour_ = 10;
var time_speed_ = 150;
var day_ = 120; // april 30th
while(1)
{
DEBUG_VAR(second_, 10);
DEBUG_VAR(minute_, 50);
DEBUG_VAR(hour_, 100);
second_ += time_speed_*time_step;
if(second_ >= 60)
{
second_ = fraction(second_ / 60);
minute_ += 1;
if(minute_ >= 60)
{
minute_ = fraction(minute_ / 60);
hour_+= 1;
hour_ %= 24;
}
}
set_sun_position(day_, hour_, minute_, second_, LOCATION_LATITUDE, LOCATION_TIME_SPRING_EQUINOX);
wait(1);
}
}
Last edited by 3run; 04/30/13 10:28. Reason: problems..
|
|
|
Entire Thread
|
real sun position by time, date and location
|
oliver2s
|
04/29/13 22:02
|
Re: real sun position by time, date and location
|
Hummel
|
04/29/13 22:47
|
Re: real sun position by time, date and location
|
PadMalcom
|
04/30/13 06:14
|
Re: real sun position by time, date and location
|
sivan
|
04/30/13 08:06
|
Re: real sun position by time, date and location
|
oliver2s
|
04/30/13 08:33
|
Re: real sun position by time, date and location
|
3run
|
04/30/13 10:22
|
Re: real sun position by time, date and location
|
oliver2s
|
04/30/13 10:41
|
Re: real sun position by time, date and location
|
oliver2s
|
04/30/13 12:26
|
Re: real sun position by time, date and location
|
3run
|
04/30/13 12:37
|
Re: real sun position by time, date and location
|
djfeeler
|
05/01/13 04:28
|
Re: real sun position by time, date and location
|
lemming
|
05/01/13 07:29
|
Re: real sun position by time, date and location
|
HeelX
|
05/01/13 08:18
|
Re: real sun position by time, date and location
|
oliver2s
|
05/01/13 08:22
|
Re: real sun position by time, date and location
|
PadMalcom
|
05/01/13 15:43
|
Re: real sun position by time, date and location
|
oliver2s
|
05/02/13 09:24
|
Re: real sun position by time, date and location
|
Rei_Ayanami
|
05/02/13 15:18
|
Re: real sun position by time, date and location
|
Hummel
|
05/02/13 18:31
|
Re: real sun position by time, date and location
|
oliver2s
|
12/16/13 12:25
|
Re: real sun position by time, date and location
|
3run
|
12/24/13 08:34
|
Re: real sun position by time, date and location
|
MasterQ32
|
12/24/13 12:47
|
Re: real sun position by time, date and location
|
3run
|
12/24/13 17:40
|
Re: real sun position by time, date and location
|
oliver2s
|
12/24/13 21:15
|
|
|