#Include "Ninfa3d.bi"

dim Shared camera As nCAMERA
dim light01 As nLIGHT
Dim terrain As nTERRAIN
Dim msh2 As nMESH
Dim As nBODY PHSterrain,bdy2
Dim font01 As nFONT
Dim As nTEXTURE tex01,tex02
Dim wire As Integer

'Enable vertical synch.
EnableVsync()

'Starts the Ninfa3D Engine
InitEngine(640,480,32,0)
	BackGroundColor(128,128,128)'Background Color
	AmbientLight(64,64,64)'Ambient color
	PhysicQuality(Q_LINEAR)
	WorldSize(15000,15000,15000)
	WorldGravity(0,-200,0)
	Fog(96,96,96,0.001)' Fog

'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,1)
	CameraRange(camera,1,42000)
	PositionEntity(camera,2400,256,4500)' Position

'Creates the lights
light01 = CreateLight(LGT_DIRECTIONAL)
	PositionEntity(light01,0,512,0)' Position
    

font01 = LoadFont("media\courier.xml")'Load the font, in format XML

'Load textures
tex01 = LoadTexture("media\Mud0029_1_M.jpg")
tex02 = LoadTexture("media\FullskiesOvercast0036_1_S.jpg")

'Create a terrain mesh
terrain = LoadTerrain("media\TOPOMAP1.jpg")
	ScaleMesh(terrain,10,4,10)
	EntityTexture(terrain,tex01,0)
	ScaleTexture(terrain,10,0)'Scale the texture of the terrain
	PositionEntity(terrain,-100,0,0)

PHSterrain = CreateBodyTerrain(terrain,5)
	PositionEntity(PHSterrain,-100,0,0)

Dim i As integer
For i = 0 To 100

	msh2 = CreateMeshCube()'Load a mesh
		ScaleMesh(msh2,50,50,50)
        EntityColor(msh2,Rand(50,200),Rand(50,200),Rand(50,200))
        EntityFlag(msh2,8,1)'Fog

	bdy2 = CreateBodyCube(50,50,50,1)'Create a cube body
		EntityParent(bdy2,msh2)'This makes the mesh assigned, follow both
								  'Position as the rotation of the body.
		PositionEntity(bdy2,2400-Rand(-1000,2000),Rand(900,2048),4500-Rand(0,4000))'Position the body.
Next

CreateSkyDome(tex02,10000)'Creates the sky
Collisions(terrain,camera,3)
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))

	If KeyHit(KEY_E) Then wire = wire + 1
		
	If wire>1 Then wire = 0
	
	If Wire = 1 Then
		EntityFlag(terrain,0,1)
	Else
		EntityFlag(terrain,0,0)
	EndIf

	Font(font01)'assign the font to use
	Text(15,75,"E - Wireframe",0,0)

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

	'End the scene
	EndScene()
	
Wend

'Ends Ninfa3D Engine
EndEngine()