;
; ------------------------------------------------------------
;
;   PureBasic - Mesh (Skeleton Animation)
;
;    (c) 2002 - Fantaisie Software
;
; ------------------------------------------------------------
;

IncludeFile "Screen3DRequester.pb"

Define.f KeyX, KeyY, MouseX, MouseY

#RobotMesh    = 0
#RobotTexture = 0
#Robot        = 0
  
If InitEngine3D()

  Add3DArchive("Data\"          , #PB_3DArchive_FileSystem)
  Add3DArchive("Data\Skybox.zip", #PB_3DArchive_Zip)
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  If Screen3DRequester()
    
    LoadMesh   (#RobotMesh   , "Robot.mesh")
    LoadTexture(#RobotTexture, "clouds.jpg")
    
    CreateMaterial(0, TextureID(#RobotTexture))
    
    CreateEntity(#Robot, MeshID(#RobotMesh), MaterialID(0))
    EntityMaterial(#Robot, MaterialID(0))
    
    AnimateEntity(#Robot, "Walk")
    
    DisableMaterialLighting(0, 1)
    
    MaterialAmbientColor(0, RGB(100, 100, 100))
    MaterialSpecularColor(0, RGB(255, 255, 255))
    ScrollMaterial(0, 0.15, 0, 1)
        
    CreateLight(0, RGB(0,0,255), 100.0, 0, 0)
    LightSpecularColor(0, RGB(255, 0, 0))
    
    ; SkyBox("Stevecube.jpg")
   
    CreateCamera(0, 0, 0, 100, 100)
    CameraLocate(0,0,0,100)
    ; CameraBackColor(0, RGB(0, 0, 255))
      
    Repeat
      Screen3DEvents()
      
      ClearScreen(RGB(0, 0, 0))
            
      If ExamineKeyboard()
      
        If KeyboardPushed(#PB_Key_Left)
          KeyX = -1
        ElseIf KeyboardPushed(#PB_Key_Right)
          KeyX = 1
        Else
          KeyX = 0
        EndIf
        
        If KeyboardPushed(#PB_Key_Up)
          KeyY = -1
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY = 1
        Else
          KeyY = 0
        EndIf
        
        If KeyboardPushed(#PB_Key_PageUp)
          RollZ = 3
        Else
          RollZ = 0
        EndIf
        
        If KeyboardPushed(#PB_Key_Add)
          Frame.f+0.005
        EndIf
        
      EndIf
      
      If ExamineMouse()
        MouseX = -MouseDeltaX()/10 
        MouseY = -MouseDeltaY()/10
      EndIf
      
      RotateEntity(#Robot, 1, 0, 0)
      
      RotateCamera(0, MouseX, MouseY, RollZ)
      MoveCamera  (0, KeyX, 0, KeyY)
      
      RenderWorld()
      Screen3DStats()
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  EndIf
    
Else
  MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf
  
Endç