globals = {
	camera = { x = 0.5, y=0.20, z=0.0 },
	fov = 20, 
	target = { x = 0.00, y=.00, z=0 },
	up = { x=0, y=1, z=0 },
	light0 = {   	direction = {x=-2, y=0, z=2 }, 
				color = {x=1, y=1, z=1}, 
			},
	light1 = {   	direction = {x=1, y=.2, z=1 }, 
				color = {x=1, y=1, z=1}, 
			},
	ambient = { x = 0.1, y = 0.1, z = 0.1 },
  	ambient = { x = 0.4, y = 0.4, z = 0.4 },
     raymarch_steps = 80,
	raymarch_shadow_steps = 40,

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



output = {
--	resolution = { width = 160, height=160},
--	resolution = { width = 320, height=160},
	resolution = { width = 32, height=32},
	output_type = 8,
--	palette_file = "images/pals.pal",
	c64_imageType = 0,
	aspect = 0.6,
	dither = 2,
	ditherStrength= {x=6, y=2, z=2 },
--	index_colors = { 0,1,2,3 }
	index_colors = { 0,1,2,3 }
--	index_colors = { 0,2,3,1 }
--	index_colors = { 0,2,3,1 }
--	c64_colors = { 0,1}
}


Material0 = {
   color = { x=1.0, y=0, z=1 },
	reflection = 0.0,
	shininess = 100,
	shininess_intensity = 0.0
}


Material2 = {
	color = { x=0.85, y=8.0, z=0.0 },
	reflection = 0.0,
	shininess = 10,
	shininess_intensity = 0.0

}


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

}


-- Init is called on start  

text = "BEP"

 
function Init()


--  AddObject("cylinder","cyl1", "", "Material0", 0,0,0,    0.2,0.2, 3 )
--  AddObject("box","cyl1", "", "Material0", 0,0,0,    2.4,12,0.5 )

	font = "rom"
	--font = "charsets/gamecharset.flf"

	z = 1
	w = 0.25

	z = -0
	w = 0.9
	r = 0.2
	rs = 2.6
	dx=2.8
	AddObject("box","box1","","Material0", 0,0,0,rs,rs,rs*3);

	ss = 0.04
	AddObject("box","box2","","Material2", -rs,-rs,rs,rs*ss,rs*ss,rs*3);
	AddObject("box","box3","","Material2", -rs,rs,rs,rs*ss,rs*ss,rs*3);
	AddObject("box","box4","","Material2", rs,rs,rs,rs*ss,rs*ss,rs*3);
	


--	AddObject("perlin","box1","","Material0",  "box1", 0.2,1.45,0);
	
	c = string.sub(text,char+1,char+2)
	Message(c)
	c1 = string.byte(c)-64



	a = 0.55
	b = 0.6
	c = 0.0	
	
	wb = 0.31111
	wc = 0.31111	

	if char~=5 then

	AddObject("char","char1", "", "Material2",  font, c1,   
dx,0.3,-z,            -- position
a,b,c,      -- width xyz 
w,wb,wc  -- stretch xyz
);          
	AddObject("char","char2", "", "Material2",  font, c1,   
0.3,dx,-z,            -- position
a,b,c,      -- width xyz 
w,wb,wc  -- stretch xyz
);          
	AddObject("char","char3", "", "Material2",  font, c1,   
-dx,0.3,0,            -- position
a,b,c,      -- width xyz 
w,wb,wc  -- stretch xyz
);          
	AddObject("char","char4", "", "Material2",  font, c1,   
0.3,-dx,-z,            -- position
a,b,c,      -- width xyz 
w,wb,wc  -- stretch xyz
);          
--[[

	p1 = 0.05
	p2 = 1
	p3 = 1

	AddObject("perlin","pox1","","Material2",  "char3", p1, p2, p3);
	SetPosition("pox1",0,0,0);
	
	AddObject("perlin","pox2","","Material2",  "char2",  p1, p2, p3);
	SetPosition("pox2",0,0,0);
	
	AddObject("perlin","pox4","","Material2",  "char4",  p1, p2, p3);
	SetPosition("pox4",0,0,0);

	AddObject("perlin","pox3","","Material2",  "char1",  p1, p2, p3);
	SetPosition("pox3",0,0,0);

--[[

	AddObject("perlin","pox3","","Material2",  "char1", 0.05,2,1);
	SetPosition("char1",0,0,0);

]]--

--[[
	AddObject("char","char2", "", "Material2",  font, char+1,   
0,0,z,            -- position
0.6,0.5,0.5,      -- width xyz 
0.250,0.26,0.31  -- stretch xyz
);          
]]--
--	jj = sin(char+1)*10
	jj = 0
--	deg = 5
	deg = 0
	SetRotation("char2",0,deg,45);
	SetRotation("char4",0,-deg,45);

	SetRotation("char1",0,-deg,0);
	SetRotation("char3",0,deg,0);

--	SetRotation("box1",0,0,0);

--	SetRotation("char2",0,45+90,jj);

	end

	UpdateGraphics()
	isInit = 1
end


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

function UpdateGraphics()

  	t = ((frame)/(noFrames))*3.14159/2.0+3.14159/2.0;--*2 
	r = 10
	r = 20
	t1 = t
	
	globals.camera.x = sin(t1)*r
	globals.camera.y = cos(t1)*r
	

--	globals.up.z = 0
	globals.up.x =0
	globals.up.y =1

    d = frame/noFrames*180-90

--	SetRotation("char1",0,0,d/2+180);
--	SetRotation("box1",90,90,d);


--	t=t+3.14159/4
	t=t
    dt = -0.0
	globals.light0.direction.x = sin(t+dt)
	globals.light0.direction.y = cos(t+dt)
	globals.light0.direction.z = -0.0



--[[	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 then 
		char=char+1
		frame = 0
--		if char == 25 then 
		if char == 4 then 
--			globals.isPaused = 1
			CompressAndSaveHorizontalData(8,3, "data/e1_data.bin","data/e1_tab.bin",0);
			--SaveRawData("data/pal.bin");
			--CompressAndSaveHorizontalData(4,1, "data/screen_sprite.bin","data/table_sprite.bin");



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


--	if (frame ~= noFrames) then 
--		AddC64LineToData(0,0,3,21)
	if (isInit==1) then
--	SetLight(1,0,5,2,1,1,1);
--    AddAmigaBitplaneToData(0,0,4,64, 2);
	
	for y=0, output.resolution.height-1 do
	    AddBBCMode5LineToData(0,y,output.resolution.width,1);
--		for x=0, output.resolution.width/4 do
--	    AddBBCMode5LineToData(x*4,y*8,4,5);
 --   		end
    end
	UpdateGraphics()
	frame=frame+1
	end
--	end
	


end
