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

import net.sf.j3d.threeD.raytracer.engine.*;
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.*;
import net.sf.j3d.threeD.raytracer.textures.ImageTexture;
//import threeD.raytracer.util.TransformMatrix;
import net.sf.j3d.util.Vector;

public class Test8JHyper2 extends Test3BaseSphere {

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

		iso.setQPrecision(250);
//		iso.setQPrecision(60);
		iso.setThresold(6.5);
		iso.setQMaxRelativeSize(250);
//		iso.setQMaxRelativeSize(20);
//		iso.setScaleCoefficients(.5,.5,.5);
		iso.setRotationCoefficients(3.14/8, 3.14/4, 3.14/8);
		//iso.setShaders(ssIso);

		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);		
		
		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,
					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(1,0,0),.3,new RGB(1,.7,.6)),				
				iso,
		};	
		
		return surfaces;
	}
}
