' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  009   as   modifiy mesh loaded geometry 

'   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
 


 ' Load an 3D Object 
  Dim obj As Mesh = _LoadMesh("media/earth.x", 0)
 ' dim obj as Mesh = _CreateSphereMesh(1)


' Create several mesh
Dim sphere as EntityNode
dim i as Integer
For  i  = 0 To 3
  ' Create a mesh with one of the 3D Object loaded
    sphere = _CreateEntityNode(obj)
    ' set position
    _PositionNode(sphere, 3*i,0,0)
Next



' send inside the console some mesh buffer information
_SendLog("Number of MeshBuffer as  "+ str( _MeshBufferCount(obj)))
_SendLog("Type of Vertex Buffer as  "+ str( _MeshTypeVertex(obj,  0)))
'_SendLog("adr of mesh buffer 0 as  "+ str(_MeshBuffer(obj, 0)))
_SendLog("number of vertices inside the meshbuffer as  "+ str(_MeshVertexCount(obj,0) ))



'apply the scale transformation For all the vertices
Dim vec(4) as Single
For i = 0 To _MeshVertexCount(obj)-1
  ' get vertex
  _MeshVertex(obj, 0, i, varptr (vec(0)))
  ' multiply vertices position values 
  vec(0)=vec(0)*3
  vec(1)=vec(1)*3
  vec(2)=vec(2)*3
  ' set vertex
  _VertexPositionMesh(obj,0, i, vec(0), vec(1), vec(2))
Next
' because all spheres mesh is based on the same Object geometrie, 
' If you transform this mesh geometrie, all the mesh will be 
' affected by this transformation




' Create a camera
dim cam as CameraNode = _CreateCamera( )
_PositionNode(cam, 6,0,-10)


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

' If Escape Key, Exit	
  If _GetKeyDown(KEY_ESCAPE) then
    Quit=1
  EndIf
  
  
   _TurnNode(sphere, 0,0.5,0) 
   
   
  	' ---------------
 	'      Render
  	' ---------------
  _BeginScene(128,128,128)
     _DrawScene()
  _EndScene()


Wend 
' end
_FreeEngine()
