oliver2s@ your last example is not working, minute_ always stays at zero, same for hour.
Code:
hour_+=integer(minute_/60);

Doesn't do the trick.. I changed your example like this:
Code:
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:
Code:
#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..

Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung