/*
 * 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.awt.Dimension;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

import net.sf.j3d.threeD.raytracer.engine.Surface;
import net.sf.j3d.threeD.raytracer.engine.Texture;
import net.sf.j3d.threeD.raytracer.graphics.ColorProducer;
import net.sf.j3d.util.graphics.RGB;
import net.sf.j3d.threeD.raytracer.primitives.Plane;
import net.sf.j3d.threeD.raytracer.shaders.DiffuseShader;
import net.sf.j3d.threeD.raytracer.shaders.HighlightShader;
import net.sf.j3d.threeD.raytracer.shaders.ReflectionShader;
import net.sf.j3d.threeD.raytracer.shaders.RefractionShader;
import net.sf.j3d.threeD.raytracer.shaders.ShaderSet;
import net.sf.j3d.threeD.raytracer.textures.ImageTexture;
//import threeD.raytracer.util.TransformMatrix;
import net.sf.j3d.util.Vector;

public class Test7JHyperTransp extends Test3BaseSphere {

	public static void main(String[] args) {
		new Test7JHyperTransp().doJob();
	}
	@SuppressWarnings("deprecation")
	public Surface[] getSurfaces() {
		
/*		FractalIsoSurface iso = new FractalIsoSurface(
				new Vector(0,-.2,.3),2,new RGB(1,1,.7),0){
			protected double getValue(Vector point) {
				double x = point.x, y = point.y, z = point.z;
	    		double [] c = {1,1,0,0};
	    		double [] z0 = {x,y,z,0};
	    		return getThresold()-getJuliaHypercomplex(c,z0);
			}		
		};
*/
//		SphereSurface iso = new SphereSurface(
//		new Vector(1,1,1),1,new RGB(1,1,.7));

		SimpleSymetricIsoSurface iso = new SimpleSymetricIsoSurface(
				new Vector(1,1,1),1,new RGB(1,1,.7),
				SimpleSymetricIsoSurface.SPHERE);
//		iso.setQPrecision(250);
		iso.setQPrecision(60);
		//iso.setThresold(2.5);
		//iso.setQMaxRelativeSize(3);
		iso.setScaleCoefficients(.5,.5,.5);
		//iso.setRotationCoefficients(0, 3.14/2, 0);

		iso.setIndexOfRefraction(1.8);
		iso.setRefractedPercentage(.6);
		
//		ShaderSet ssWater = new ShaderSet();
//		ssWater.add(new ReflectionShader(0,new ColorProducer(){
//			public RGB evaluate(Object[] args) {
//				return new RGB(1,1,1);
//			}}));		
		
		//Plane p = new Plane(Plane.XY,new RGB(.4,.8,.2));
		Plane p = new Plane(Plane.XY,new RGB(.4,.4,.7));
//		p.setShaders(ssWater);		
		p.setReflectedPercentage(.6);
		
		SphereSurface sky = new SphereSurface(
				new Vector(0,0,0),100,new RGB(1,1,1)); //sky
		sky.setShadeBack(false);
		sky.setShadeFront(false);
		try {
			ImageTexture it = new ImageTexture(
					ImageTexture.SPHERICAL_PROJECTION,
//from http://mpan3.homeip.net/page?earth					
					new File("textures/sky/day-fair.jpg").toURL(),
					1,2,0,0);
			sky.addTexture(it);
			sky.setRotationCoefficients(-Math.PI/2,0,0);

		} catch (MalformedURLException e) {
			e.printStackTrace();
		}
		Surface surfaces[] = {               
				p,sky,
				new SphereSurface(new Vector(-4,0,1),3.5,new RGB(1,.7,.6)),				
				iso,
		};	
		
		return surfaces;
	}
	protected Dimension getDimensions() {
		int width = 200;
		int height = width*3/4;
		return new Dimension(width,height);
	}
	
}
