' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  020   as  VolumeLight test
'   Historique   as 
'     29/03/09  19 as 16    TMyke
'
' ------------------------------------------------------------

' Includes libraries
#include "N3xtD.bi"

' Dimes
Dim app As any Ptr
Dim Quit As Integer


'----------------------------------------------------------
' open n3xt-D screen
app = _CreateGraphics3D(800,600)
If app=NULL Then
  End
End If

 
'----------------------------------------
' Create volume light And set position
  Dim vlight as VolumeLightNode = _CreateVolumeLight(0, &h00ffffff, 32,32 )
  _ScaleNode(vlight, 100.0, 100.0, 100.0)
  _PositionNode(vlight, -85,50,40)

 ' Import all the bmp file For animation  
  Dim texturelist as NArray = _CreateArray() 
  Dim portal as NTexture
  For  i as Integer = 1 To 7
    Dim nname as string = "media/portal"+str(i)+".bmp"
    portal = _LoadTexture( nname)
    _PushbackArray( texturelist,  portal) 
  Next
  ' define And Create Texture animator
  Dim anim As NNodeAnimator = _CreateTextureAnimator( texturelist,  100)
  ' add inside the node (here vlight) the animator (Texture animator)
  _AddAnimatorTexture(vlight, anim)
  
  
  
  
  
'----------------------------------------
'----------------------------------------
 ' Load 3D objects 
 Dim obj as Mesh = _LoadMesh("media/room.3ds")
 ' change planar texture mapping on the mesh
_MakePlanarTextureMappingMesh(obj, 0.004)
'----------------------------------------
' Create ROOM
Dim room as EntityNode =  _CreateEntityNode(obj)
' Load two textures
Dim colormap as NTexture = _LoadTexture( "media/wall0.jpg") 
' set texture in the New room (room2)
_MaterialTextureNode(room, colormap , 0)
' set material For room parallax mapping 
Dim material as NMaterial = _NodeMaterial(room, 0)
_SpecularColorMaterial(material, 0)
'----------------------------------------



'----------------------------------------
'----------------------------------------
'----------------------------------------
' Create PARTICLE SYSTEM
Dim part as ParticleSystemNode = _CreateParticleSystem()
' Create a box particle emitter
 Dim cyl_emitter as ParticleEmitter =_CreateParticleCylinderEmitter(part, 0,0.3,0, 100, 0,1,0, 300, False, 0,0.03,0, 15, 30) 

' change SizeOf each particle inside the particle emitter
  _MinStartSizeParticle(cyl_emitter,  10.0, 10.0  )
  _MaxStartSizeParticle(cyl_emitter,  10.0, 10.0  )
' add New emitter inside the particlesystem
  _AddEmitterParticleSystem(part, cyl_emitter ) 
' fadeout element
 _FadeOutParticleSystem(part )
  _LoadTextureNode(part, "media/fireball.bmp") 
  _PositionNode(part, -50,100,0) 
  
  Dim mat As NMaterial = _NodeMaterial(part, 0)
  _TypeMaterial(mat,  EMT_TRANSPARENT_ADD_COLOR)   
'----------------------------------------
' Create traditional light And set position
  Dim light as LightNode = _CreateLight(&hffffffff, 300)
  _PositionNode(light, -80,130,40)





'----------------------------------------
' Create a camera
Dim cam as CameraNode = _CreateCameraFPS( )
_PositionNode(cam, -95,155,-263)





' simple text inside the scene area 
_LoadFont("media/courriernew.png")
dim font As IGUIFont = _GetFont()


' ---------------------------------------
'           Main loop
' ---------------------------------------
While Quit=0
 

' If Escape Key, Exit	
  If _GetKeyDown(KEY_ESCAPE) then
    Quit=1
  EndIf
   

  ' ---------------
  '      Render
  ' ---------------
  _BeginScene(128,128,128)
     _DrawScene()
  _EndScene()


Wend 
' end
_FreeEngine()
