globals = {
 	camera = { x = 23, y=0, z=0 },
     fov = 40,
	target = { x = 0, y=0.0, z=0 },
	light0 = {   	direction = {x=1, y=0.0, z=-0.2 }, 
				color = {x=1, y=1, z=1}, 
			},
	ambient = { x = 0.4, y = 0.4, z = 0.4 },
    raymarch_steps = 30,
	raymarch_shadow_steps = 4,
	up = {x=0.3, y=1, z=0 },
	sky = 0,
	shadow_scale = 0.5,
	isPaused = 0
	
}

output = {
	-- resolution of 2x2 multicolor sprites (12x21 each)
	resolution = { width = 16, height=16},
--	resolution = { width = 320, height=320},
--	resolution = { width = 320, height=200},
	aspect = 1.0,
	output_type = 3,
--	palette_file = "images/pals.pal",
	palette = {0,0,0,  64,64,64,128,128,128,255,255,255},
	aspect = 1,
	ditherStrength= {x=10, y=1, z=1 },
	dither = 2,
	index_colors = { 0,1,2,3 }
}


MaterialBlue = {
   color = { x=1, y=0.5, z=0.5 },
	reflection = 0.0,
	shininess = 50,
	shininess_intensity = 1 
}

MaterialWhite = {
   color = { x=2, y=2, z=2 },
	reflection = 0.5,
	shininess = 50,
	shininess_intensity = 0 
}




MaterialBlack = {
   color = { x=0.5, y=0.0, z=0 },
	reflection = 0.0,
	shininess = 50,
	shininess_intensity = 0 
}




-- Init is called on start  
 

frame = 0
--noFrames = 24
noFrames = 64

hasSaved = 0


function Init()

	w = 0
	xx = 0
	AddObject("box","d2","","MaterialBlue",w,0,xx, 1,3,3);

	dx = -0.2
	z = 0
	font = "rom"
	char = 11
	AddObject("char","char1", "", "MaterialBlack",  font, char+1,   
dx,0,-z,            -- position
0.8,0.6,0,      -- width xyz 
1.2,0.31111,0.6111  -- stretch xyz
);          

	jj = 0
	SetRotation("char1",0,0,jj);



end



function UpdateScene()

  	t = ((frame)/(noFrames-1)) 

	tt = t*3.14159*2
	dt = 0
	globals.light0.direction.x = cos(tt+dt)
	globals.light0.direction.z = sin(tt+dt)
	r=10
	globals.target.z = 0
	globals.camera.x = cos(tt)
	
	globals.camera.z = sin(tt)
	globals.camera.y = sin(tt+3.14/1.2+3.14)

--  normaliz all
	l = globals.camera.x*globals.camera.x + globals.camera.y*globals.camera.y + globals.camera.z*globals.camera.z;
	l = math.sqrt(l)
	-- Normalize		
	globals.camera.x = r*globals.camera.x/l
	globals.camera.y = r*globals.camera.y/l
	globals.camera.z = r*globals.camera.z/l  

end


function Update()
	
	if (frame  <=noFrames and frame>=1) then
	-- save 4 sprites! 
	if (hasSaved == 0) then 
--	    AddAmigaBitplaneToData(0,0,4,32, 2);
--	    AddAmigaBitplaneToData(0,0,2,32, 2);
--		Add4PixelToData(0,0,output.resolution.width,output.resolution.height)
	for x=0, output.resolution.width/4-1 do
	for y=0, output.resolution.height -1 do
			Add4PixelToData(x*4,y,1,1)
--			Message( " x,y : " ..tostring(x).. ", " ..tostring(y));
		end
	end

	end
	end
	frame=frame+1


	if (frame==noFrames+1) then 
		hasSaved = 1
		SaveRawData("data/sprites_data.bin");
		Message("SAVED")
		Message("You can exit now");
	end	

	UpdateScene()


end
