#Include "Ninfa3d.bi"

dim Shared camera As nCAMERA
dim As nLIGHT light01,light02

'Enable vertical synch.
EnableVsync()

'Starts the Ninfa3D Engine
InitEngine(640,480,32,0)
	BackGroundColor(128,128,128)'Background Color
	AmbientLight(16,16,16)'Ambient color
	WorldGravity(0,-200.0,0)
	PhysicQuality(Q_LINEAR)

'Include the file "SampleFuntions.bi.
'It contains useful features, such as drawing the interface and create the test area.
#Include "SampleFunctions.bi"

'Create a camera
camera = CreateCamera()'FPS(100,1)
	PositionEntity(camera,0,64,-200)'Position

'Creates the lights
light01 = CreateLight(LGT_POINT)
    lightradius(light01,50)
    lightcolor(light01,200,200,0)
	PositionEntity(light01,0,128,-128)' Position
	
    
light02 = CreateLight(LGT_POINT)
    lightradius(light02,50)
    lightcolor(light02,200,0,0)
	PositionEntity(light02,0,128,128)
	

CreateGround()'Creates the test area

'Create cubes in total approximately 490
Dim As nMESH msh(490),mesh
Dim As nBODY bdy(490),body

Dim As I x,y,z,i

For x = -5 To 5 Step 3
	For y = 1 To 38 Step 2
		For z = -5 To 5 Step 3
		
			i = i + 1
			
			msh(i) = CreateMeshSphere(10)'Creates a mesh type sphere
				ScaleMesh(msh(i),5,5,5)'Scale the mesh
				EntityColor(msh(i),Rand(0,255),Rand(0,255),Rand(0,255))'Change the color
				EntityShininess(msh(i),20)
			bdy(i) = CreateBodySphere(5,5,5,5)'Create a cube sphere
				EntityParent(bdy(i),msh(i))'This makes the mesh assigned, follow both
													'Position as the rotation of the body.
				
				PositionEntity(bdy(i),x*6,21+y*6,z*6)'Position the body.

		Next
	Next
Next

'Create cone
mesh = CreateMeshCone(16)
	ScaleMesh(mesh,10,20,10)
	
body = CreateBodyCone(10,20,0)
	PositionEntity(body,0,10,0)
	
While(EngineRun)'Returns 1 if the engine is running.

	'Begins scene
	BeginScene()
	
	'By pressing the "ESCAPE" closes the engine.
	If KeyHit(KEY_ESCAPE) Then CloseEngine()

	'Update the Engine.
	'Changing the value (only affects the physics) that will update the
	'Physical faster or slower.
	UpdateEngine(0.05)
    WorldMousePick(MouseX(),MouseY(),MouseDown(MOUSE_LEFT))
	'Displays the interface (FPS and triangles)
	Interface()

	'End the scene
	EndScene()
	
Wend

'Ends Ninfa3D Engine
EndEngine()