--object viewer - scroll mouse up/down to change index, press 1/2 to change object block.
--http://www.lua.org/pil/ 	<- lua how2s!
--reddit.com/r/boxengine 	<- for discussion!
--Doc.txt					<- boxEngine documentation!

dofile "data/scripts/lib/objReferences.lua"	--defines names -> geom indices

--globals

mouseX = 0
mouseY = 0

objDraw = 0
objIOffset = 0
texI = 0

math.randomseed( os.time() )
math.random();  math.random();  math.random();	--first few numbers aren't really random :O

--objIOffset = 256 * math.floor( math.random() * 1.99 )

function Init()
	AddGeom( "data/geom/core/common.bxo" )
	AddGeom( "data/geom/core/monkey.bxo" )
	AddGeom( "data/geom/core/funkyboxes.bxo" )
	AddTex( "data/textures/grad1.png" )
	AddTex( "data/textures/grad2.png" )
	AddTex( "data/textures/hueH.png" )
	
end


function KeyHappen( inVal, inDown, inT )	--also registers mouse clicks
	--chVal = string.format( "%c", inVal )
	
	
	
	if ( inDown == true ) then
		print ( inVal, inDown, chVal )
	end
	
	if ( inDown ) then
		if ( inVal == 11 ) then	--scrollup
			objDraw = objDraw + 1
			print ( objDraw + objIOffset )
		end
		if ( inVal == 12 ) then	--scrolldown
			objDraw = objDraw - 1
			print ( objDraw + objIOffset )
		end
		if ( inVal == 13 ) then	--1, 2, 3
			texI = 0
		end
		if ( inVal == 14 ) then
			texI = 1
		end
		if ( inVal == 15 ) then
			texI = 2
		end
		
	end
end



function Draw( t, dt )	--time and deltaTime ( time since last frame )
	mouseX, mouseY = GetMouseTotal()
	LookAt( 0, -3, 0, 0, 0, 0 )	--3d view
	Push()
	
	Rotate( 1, 0, 0, mouseY + .1 )
	Rotate( 0, 0, 1, mouseX )
	Tex( texI )
	
	SetLight( 0, 2 * math.cos( t ), 0, 4 * math.sin( t ) )
	SetLight( 1, 0, -2, 0 )
	Geom( math.abs( objDraw + objIOffset ) )
	SetLighting( 0 )
	Pop()
	
	


end