' ------------------------------------------------------------
'   n3xt-D
'
'    sample 023  as       Pivot And Parent
'   Historique   as 
'     07/04/09  19 as 16    by Comtois For Dreamotion3D adaptation TMyke
'     07/03/11  19 as 16    adaptation For N3xtD v2.0 by 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


'-Constantes
#define NBPivot  4
#Define NbBranche 7 


'-Variable And tab
' Dimes
Dim  i as Integer, j as Integer
Dim font as IGUIFont
Dim cam as CameraNode

Dim mesh(NbBranche+1, NBPivot+1) as EntityNode
Dim pivot(NbBranche+1, NBPivot+1) as EntityNode





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


 
 Dim cubemesh As Mesh = _CreateCubeMesh(1.0)
 _ScaleMesh(cubemesh, 8,8,32)
'-----------------------------------------
'-build general mesh
For j = 0 To NbBranche
  'center Pivot
  pivot(j, 0) = _CreatePivot()
  ' fisrt bones on pivot 0
  mesh(j, 0) = _CreateEntityNode(cubemesh, 0,0,0,pivot(j, 0))
  _LoadTextureNode(mesh(j, 0), "media/glass.bmp") 
  _TranslateNode( mesh(j, 0), 0, 0, 25)
 
  'other bones
  For i = 0 To NBPivot - 1
    pivot(j, i + 1) = _CreatePivot(mesh(j, i))
    _TranslateNode(pivot(j, i + 1), 0, 0, 25)
    mesh(j, i + 1) = _CreateEntityNode(cubemesh , 0,0,0,pivot(j, i + 1)) 
    _LoadTextureNode(mesh(j, i + 1), "media/glass.bmp")  
    _TranslateNode(mesh(j, i + 1), 0, 0, 25)
  Next 
Next 


'----------------------------------------
' Create a camera
cam = _CreateCamera( )
_PositionNode(cam, 0,0,-400)

While Quit=0
 

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



  For j = 0 To NbBranche
    _RotateNode( pivot(j, 0), (45-(_GetMouseY()/8)), 360.0/(NbBranche+1) * j + (_GetMouseX()/2), 0)
    For i = 1 To NBPivot
      _RotateNode(pivot(j, i), 45-(_GetMouseY()/8), 0, 0)
    Next 
  Next 




  	' ---------------
  	'      Render
  	' ---------------
  _BeginScene()
     _DrawScene()
     _DrawText(font, "mouve mouse",  10,10,0,0)
  _EndScene()


Wend 
' end
_FreeEngine()
