//created=08 Feb 08
//description=Parametric sky generation based on the paper by Preetam et. al.
//title=Sky
//titlebar=Parametric sky generation
//publish=true
 
import SGQuickVar.*;
import SGCamera.*;
import SGBackground.*;
import Tuple.*;
 
Sky sky;
SGCamera cam;
 
SGVariable turbidity, labels, time, res;
 
PFont font;
 
 
void setup(){
 
size(550,550,P3D);
frameRate(30);
font = loadFont("writing.vlw");
textFont(font);
 
//GUIControls
labels = new SGVariable(this,font,"Labels",'s','x',0,1,0,1);
turbidity = new SGVariable(this,font,"Turbidity",'a','z',2.75,.05f,1.8f,10);
time = new SGVariable(this,font,"Time",'d','c',6.8,.025f,0,24);
res = new SGVariable(this,font,"Resolution",'f','v',25,1,4,60);
cam = new SGCamera(this,-90,64,-70,0,0,0);
cam.setFOV(2.f);
cam.setMouseMode(LEFT,SGCamera.ORBIT);
cam.setMouseMode(RIGHT,SGCamera.ZOOM);
 
sky = new Sky(this,cam);
}
 
 
void draw(){
 
//sun position set by passing local time
sky.setSunByTime(0,0,0,time.val,0);
sky.setTurbidity(turbidity.val);
 
//sky resolution
//skysamples will be the square of this number
sky.draw((int)res.val);
cam.feed();
if (labels.val == 0){
stroke(255);
line(0,0,0,30*sky.toSun.x,30*sky.toSun.y,30*sky.toSun.z);
fill(255);
text("To Sun",screenX(30*sky.toSun.x,30*sky.toSun.y,30*sky.toSun.z),screenY(30*sky.toSun.x,30*sky.toSun.y,30*sky.toSun.z));
line(0,0,0,0,-30,0);
text("Zenith",screenX(0,-30,0),screenY(0,-30,0));
 
line(0,0,0,30,0,0);
text("North",screenX(30,0,0),screenY(30,0,0));
 
line(0,0,0,0,0,30);
text("East",screenX(0,0,30),screenY(0,0,30));
 
 
}
 
 
}