import com.cult3d.*;
import com.cult3d.world.*;

import java.util.Date;

// Jonatan Andersson, 15/April/2000
public class Clock implements Cult3DScript, Runnable
{
	private static final double TORADIANS = (Math.PI/180.0);

	// The Hands, Names from object....
	private CultObject sv = new CultObject("SecViser");    // Seconds
	private CultObject mv = new CultObject("BigViser");    // minutes
	private CultObject hv = new CultObject("SmallViser"); // hours
	private boolean clockLoaded = false;

	public Clock()
	{
		Thread thread = new Thread(this);
		thread.start();
	}

	public void run()
	{
		clockLoaded = true;
	}

	// Called to set the time from the system clock
	// Assumes all visers points att 12 o'clock
	public void setTime(String str)
	{
		if (clockLoaded)
		{
			// Get System.time
			Date d = new Date();
			int s = d.getSeconds();
			int m = d.getMinutes();
			int h = d.getHours();

			// Rotate the hands, assumes Z-axle
			sv.rotate(sv.Z, (float)(TORADIANS * -s*6));
			mv.rotate(mv.Z, (float)(TORADIANS * -m*6));
			hv.rotate(hv.Z, (float)(TORADIANS * -(h*30 + m*0.5)));
		}
	}

	public void cult3dDestroy()
	{
	}
}
