#Include "Ninfa3d.bi"

dim Shared camera As nCAMERA
dim As nLIGHT light01
Dim sprite As nSPRITE
Dim tex01 As nTEXTURE
Dim As nMESH mesh,mesh2,mesh03
Dim As nBODY body,body2
Dim As nMATERIAL material1,material2

'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
	WorldGravity(0,-200.0,0)
	
'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)
	PositionEntity(camera,0,128,-128)' Position

'Creates the lights
light01 = CreateLight(LGT_POINT)
    lightcolor(light01,100,100,50)
    lightradius(light01,256)
	PositionEntity(light01,0,128,256)' Position
	LightCastShadow(light01)'It makes the light cast shadows.
	
    
sprite = LoadSprite("media/glow.bmp")
	EntityParent(sprite,light01)
	ScaleSprite(sprite,30,30)

CreateGround()'Creates the test area

material1=CreateMaterial( )
material2=CreateMaterial( )
MaterialElasticity( material1, material2, 0.98 ) 

mesh = CreateMeshCylinder(12)
	EntityColor(mesh,0,0,255)
	ScaleMesh(mesh,100,25,100)
	PositionEntity(mesh,0,25,0)'Move the mesh

body = CreateBodyCylinder(100,25,0)' 0 = Static
	PositionEntity(body,0,25,0)'Move the mesh
    BodyMaterial(body,material1)
    
mesh2 = CreateMeshSphere(12)
	EntityColor(mesh2,255,0,0)
	ScaleMesh(mesh2,10,10,10)
	
body2 = CreateBodySphere(10,10,10,1)
	EntityParent(body2,mesh2)
	PositionEntity(body2,10,100,0)'Move the mesh
	RotateEntity(body2,0,0,0)
    BodyMaterial(body2,material2)

mesh03 = CreateMeshCube()
	ScaleMesh(mesh03,10,1,10)

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 BodiesCollide(body,body2) Then Text(25,125,"Collided!",0,0)

		Text(25,150,"ColX: "+Str$(BodyCollX(body,body2)),0,0)
		Text(25,160,"ColY: "+Str$(BodyCollY(body,body2)),0,0)
		Text(25,170,"ColZ: "+Str$(BodyCollZ(body,body2)),0,0)
		Text(25,190,"ColNX: "+Str$(BodyCollNX(body,body2)),0,0)
		Text(25,200,"ColNY: "+Str$(BodyCollNY(body,body2)),0,0)
		Text(25,210,"ColNZ: "+Str$(BodyCollNZ(body,body2)),0,0)

	PositionEntity(mesh03,BodyCollX(body,body2),BodyCollY(body,body2),BodyCollZ(body,body2))
	RotateEntity(mesh03,BodyCollNX(body,body2),BodyCollNY(body,body2),BodyCollNZ(body,body2))
	
	'Displays the interface (FPS and triangles)
	'Interface()
	
	'End the scene
	EndScene()
	
Wend

'Ends Ninfa3D Engine
EndEngine()