#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(32,32,32)'Ambient color
	WorldGravity(0,-200,0)
	WorldSize(1024,1024,1024)
	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 = CreateCameraFPS(100,0.5)
	CameraTarget(camera,0,256,0)
	PositionEntity(camera,0,256,-512)'Position

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

CreateGround()'Creates the test area

'Create cubes in total approximately 490
Dim As nMESH msh2(50)
Dim As nBODY bdy2(50)

Dim i As UInteger
For i = 0 To 50

	msh2(i) = LoadMesh("media\turtle1.b3d",VT_TCOORS)'Load a mesh

	bdy2(i) = CreateBodyHull(msh2(i),Rand(5,15))'Create a cube body
		EntityParent(bdy2(i),msh2(i))'This makes the mesh assigned, follow both
								           'Position as the rotation of the body.
		PositionEntity(bdy2(i),Rand(-250,250),Rand(510,512),Rand(-250,250))'Position the body.
Next

Dim As nBODY waterBody = CreateBodyWater(512,256,512,0.008,0.8,0.8)
	PositionEntity(waterBody,0,128,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)

	'Displays the interface (FPS and triangles)
	Interface()

	WorldMousePick(MouseX(),MouseY(),MOUSEDOWN(MOUSE_LEFT))

	DrawBody(waterBody)' Draw the physic body

	'End the scene
	EndScene()
	
Wend

'Ends Ninfa3D Engine
EndEngine()