/*
 * Copyright (C) 2007 askywhale
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License (version 2)
 *  as published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 */
package com.askywhale.rings;

import java.io.*;

import net.sf.j3d.threeD.io.*;
import net.sf.j3d.threeD.raytracer.camera.*;
import net.sf.j3d.threeD.raytracer.engine.*;
import net.sf.j3d.util.graphics.RGB;
import net.sf.j3d.threeD.raytracer.lighting.*;
//import threeD.raytracer.primitives.Sphere;
import net.sf.j3d.util.Vector;

public class Test1Sphere {
  
    
    public static void main(String[] args) {
        int width = 800;
        int height = 600;
        int ssWidth = 2;
        int ssHeight = 2;
        System.out.println("Starting ...");
        try {
            Thread.sleep(100);
        } catch (InterruptedException e1) { }
        int nb = 100;
        /*
        Surface surfaces[] = new Surface[(nb*2+1)*(nb*2+1)*(nb*2+1)];
        int n = 0;        
        for(int x=-nb;x<=nb;x++)
            for(int y=-nb;y<=nb;y++)
                for(int z=-nb;z<=nb;z++) {
                    surfaces[n] = new SphereSurface(new Vector(x*2,y*2,z*2),.1,
                            new RGB(1,1,0));
                    n++;
                }*/
        
        Surface surfaces[] = new Surface[nb];
        for(double n=0;n<nb;n++)
            surfaces[(int)n] = new SphereSurface(
                    new Vector(
                            Math.sqrt(n)*Math.cos(n/2),
                            Math.sqrt(n)*Math.sin(n/2),
                            n/10),
                    1,
                    new RGB(1,1,0));
        
        Light lights[] = {new AmbientLight(.5), 
                new DirectionalAmbientLight(
                        .5,
                        new RGB(1,0,1),
                        new Vector(-1,-1,-1)),
                new DirectionalAmbientLight(
                        .5,
                        new RGB(0,1,1),
                        new Vector(-1,1,-1))
                        };
        PinholeCamera camera = new PinholeCamera();
        camera.setFocalLength(.2);
        //ThinLensCamera camera = new ThinLensCamera(); 
        //OrthographicCamera camera = new OrthographicCamera();        
        //camera.setFocalLength(1);
        //camera.setProjectionWidth(1);
        //camera.setProjectionHeight(1.6);
        camera.setLocation(new Vector(10,10,10));
        camera.setViewDirection(new Vector(-1,-1,-1));
        Scene scene = new Scene(camera, lights, surfaces);
        
        RGB image[][] = RayTracingEngine.render(scene, width, 
        		height, ssWidth, ssHeight, null);
        try {
            FileEncoder.encodeImageFile(image, 
                    new File("test\\test1.jpeg"), 
                    FileEncoder.JPEGEncoding);
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("done !");
    }
}
