globals = {
	camera = { x = -0, y=-0.0, z=6.0 },
	fov = 30, 
	target = { x = 0, y=0.3, z=0 },
	light0 = {   	direction = {x=1, y=1, z=2 }, 
				color = {x=1, y=1, z=1}, 
			},
	ambient = { x = 0, y = 0, z = 0 },
     up = { x = 0, y=1, z=0 },
	sky = 0,
	shadow_scale = 0.0,
	isPaused = 0,
	
	raymarch_steps = 90,
	raymarch_shadow_steps = 40

}


output = {
	-- 32 pixels in multicolor = 16 bytes of c64 multicolor data
	resolution = { width = 64, height=64},
	output_type = 1, -- c64 image type
	c64_imageType=0,
	aspect=1,
	c64_multicolor=0,
	dither = 1,
	ditherStrength={x=0.5,y=10,z=1},
	index_colors = { 0,1 }
}


Material0 = {
   color = { x=0.3, y=1.0, z=0.4 },
	reflection = 0.5,
	shininess = 100,
	shininess_intensity = 0 
}


Material2 = {
	color = { x=1.0, y=0.6, z=0.6 },
	reflection = 0.1,
	shininess = 1000,
	shininess_intensity = 0

}


MaterialG = {
	color = { x=1, y=1, z=1 },
	reflection = 0.0,
	shininess = 100,
	shininess_intensity = 2

}


-- Init is called on start  
 
function Init()

	Message("Rendering.. please wait")

	AddObject("box","box1","","MaterialG",  -0.0,0,0,1,100,1, 0, 0.01,5);
	-- send box through a Perlin node to create som variation
	AddObject("perlin","box1","","MaterialG",  "box1", 0.1,0.55,0);

	size = 0.2
	dist = 1



--[[	
    z = 0.0
    w = 2.35
    s = 0.5
    	font = "rom"
    char=1

	AddObject("char","char1", "", "Material2",  font, char+1,   
		-0,0.0,-z,            -- position
		0.55*s,0.6*s,0.0,      -- width xyz 
		w*s,0.31*s,0.27*s  -- stretch xyz
);          

]]--

	UpdateGraphics()

end

frame = 0
noFrames = 64
char = 0
curStep = 0
maxSteps = 1

function UpdateGraphics()

  	t = ((frame)/noFrames)*3.14159/2
	r = 6

	globals.camera.x = sin(t)*r 
	globals.camera.z = cos(t)*r
	
	globals.camera.y = 0;
	globals.target.y = 0;

	t=t+(3.14159*2)/maxSteps*curStep + -0.4
	globals.light0.direction.x = sin(t)
	globals.light0.direction.z = cos(t)
end




function Update()


	if (frame == noFrames+1) then 
		frame = 0
		curStep = curStep +1

		if (curStep == maxSteps) then 
			SaveRawData("data/twister.bin");
			Message("Data writen to disk. You can now close this window.");
		end		

	end


	UpdateGraphics()

	if (frame~=0) then 
--		AddScreen(64,1,  0,  1)
		
		 AddC64LineToData(0,frame&63,output.resolution.width/8,1);
--	 AddC64LineToData(0,1, 16,1);
--    AddAmigaBitplaneToData(0,frame&63,16,1, 2);
	end


	frame=frame+1
	time = time +1


end
