globals = {
	camera = { x = 0.5, y=0.5, z=6 },
	fov = 20, 
	target = { x = 0.5, y=0.20, z=0 },
	up = { x=0, y=1, z=0 },
	light0 = {   	direction = {x=0, y=0, z=-20 }, 
				color = {x=1, y=1, z=1}, 
			},
	light1 = {   	direction = {x=1, y=0, z=2 }, 
				color = {x=1, y=1, z=1}, 
			},
	ambient = { x = 0.3, y = 0.3, z = 0.3 },
     raymarch_steps = 80,
	raymarch_shadow_steps = 40,

	sky = 0,
	shadow_scale = 1,
	isPaused = 0
	
}



output = {
--	resolution = { width = 160, height=160},
--	resolution = { width = 320, height=160},
	resolution = { width = 32, height=16},
	output_type = 3,
--	palette = { 0,0,0, 48,48,48, 140,140,140, 255,255,255 },
	palette = { 0,0,0,    255,255,255,  140,140,140,  70,70,70,    255,0,0 },

	c64_imageType = 0,
	c64_multicolor=0,
	aspect = 1,
	dither = 2,
	ditherStrength= {x=15, y=1, z=1 },
	index_colors = { 0,1,2,3 }
--	index_colors = { 0,1,2,3,4,5,6,9,10,11 }
--	index_colors = { 0,2,3,1 }
--	index_colors = { 0,2,3,1 }
--	c64_colors = { 0,1}
}


Material0 = {
   color = { x=0.2, y=0.2, z=0.2 },
	reflection = 0.0,
	shininess = 100,
	shininess_intensity = 0.0
}


Material2 = {
	color = { x=1, y=1, z=1 },
	reflection = 0.2,
	shininess = 60,
	shininess_intensity = 0.3

}


GroundMaterial = {
	color = { x=0.2, y=0.4, z=0.1 },
	reflection = 0.0,
	shininess = 40,
	shininess_intensity = 0 

}


-- Init is called on start  


distance = 10
frame = 0
noFrames = 16
char = 0
pos = 0


 
function Init()


	rs = 1
	dx=-0.5
	s = 2
	h = 1.2
	AddObject("box","box1","","Material2", dx,0,0,rs*s,rs*h,rs*s);
	AddObject("box","box2","","Material2", dx,0,0,rs*s,rs*h,rs*s);

	AddObject("box","box3","","Material2", dx,0,0,rs*s/2,rs*h*2.2,rs*s/2);
	AddObject("box","box4","","Material2", dx,0,0,rs*s/2,rs*h*2.2,rs*s/2);
	

--	AddObject("perlin","box1","","Material0",  "box1", 0.2,1.45,0);

		
	SetRotation("box2",0,45,0);
	SetRotation("box4",0,45,0);
	UpdateGraphics()

end




function UpdateGraphics()

  	t = ((frame)/noFrames)*3.14159/4 
	r = 14
	globals.camera.x = sin(t)*r
	globals.camera.z = cos(t)*r
	globals.camera.y = 10
	globals.target.y = 0
--	t=t+3.14159/4
	t=t
    dt = 0.5
	globals.light0.direction.x = sin(t+dt)
	globals.light0.direction.z = cos(t+dt)



--[[	SetRotation("char1",0,(t*180+90),0);
	SetRotation("char2",0,(t*180+90),0);
	SetRotation("cyl1",0,(t*180+45)*2,0);
	t=t*3.14159*2;
	r=1
	SetPosition("char1",cos(t)*r,0,sin(t)*r);
	t=t+3.14159
	SetPosition("char2",cos(t)*r,0,sin(t)*r);
--	SetPosition("char1",0,0,0);
]]--

end


function Update()
	
	if frame == noFrames+1 then 
		frame = 0
			--globals.isPaused = 1
			SaveRawData("data/cubes.bin");

			Message("Files written")
			
--		ClearAllObjects()
--		Init()
	end


--	if (frame ~= noFrames) then 
--		AddC64LineToData(0,0,3,21)
--	SetLight(1, 0 ,-0,-1,  1,0,1);
	if (frame<noFrames+1 and frame>=1) then
    	AddGameboyData(0,0, 4, 16);
    end
	UpdateGraphics()
	frame=frame+1
--	end
	


end
