Yaw(), Pitch() example

Everything related to 3D programming
User avatar
Comtois
Addict
Addict
Posts: 1432
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Yaw(), Pitch() example

Post by Comtois »

Need PB 5.20 beta9

Save this code in 'examples\3D\'

Code: Select all

#CameraSpeed = 2

IncludeFile "Screen3DRequester.pb"

Define.f KeyX, KeyY, MouseX, MouseY

If InitEngine3D()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  If Screen3DRequester()
    
    Add3DArchive("Data/Textures", #PB_3DArchive_FileSystem)
    Add3DArchive("Data/Models", #PB_3DArchive_FileSystem)
    Add3DArchive("Data/Scripts", #PB_3DArchive_FileSystem)
    Add3DArchive("Data/Packs/skybox.zip", #PB_3DArchive_Zip)
    Parse3DScripts()
    
    ; First create materials
    ;
    
    GrassMaterial = CreateMaterial(#PB_Any, TextureID(LoadTexture(#PB_Any,"grass1.png")))
    MaterialBlendingMode(GrassMaterial, #PB_Material_AlphaBlend)
    DirtMaterial = CreateMaterial(#PB_Any, TextureID(LoadTexture(#PB_Any,"Dirt.jpg")))
    
    
    ; Then create the billboard group and use the previous material
    ;
    ;-Billboard
    
    Billboard = CreateBillboardGroup(#PB_Any, MaterialID(GrassMaterial), 96, 96)
    For i = 0 To 600
      AddBillboard(#PB_Any, Billboard, Random(2000)-1000, Random(18) + 30, Random(2000) - 1000)
    Next i
    
    ; create ground
    
    MeshPlane = CreatePlane(#PB_Any, 2000, 2000, 40, 40, 4, 4)
    CreateEntity(#PB_Any, MeshID(MeshPlane), MaterialID(DirtMaterial))
    
    ; Add house
    MeshHouse = LoadMesh(#PB_Any, "tudorhouse.mesh")
    House = CreateEntity(#PB_Any, MeshID(MeshHouse), #PB_Material_None, 0, 280, 0)
    ScaleEntity(House, 0.5, 0.5, 0.5)
    
    ; SkyBox
    SkyBox("stevecube.jpg")
    
    ; create camera
    Camera = CreateCamera(#PB_Any, 0, 0, 100, 100)
    
    NodePitch = CreateNode(#PB_Any)
    NodeYaw = CreateNode(#PB_Any,200, 90, 900)
    AttachNodeObject(NodePitch, CameraID(camera))
    AttachNodeObject(NodeYaw, NodeID(NodePitch))
    
    Repeat
      Screen3DEvents()
      
      If ExamineMouse()
        MouseX = -MouseDeltaX() * #CameraSpeed * 0.05
        MouseY = -MouseDeltaY() * #CameraSpeed * 0.05
      EndIf
      
      If ExamineKeyboard()
        
        If KeyboardPushed(#PB_Key_Left)
          KeyX = -#CameraSpeed 
        ElseIf KeyboardPushed(#PB_Key_Right)
          KeyX = #CameraSpeed 
        Else
          KeyX = 0
        EndIf
        
        If KeyboardPushed(#PB_Key_Up)
          KeyY = -#CameraSpeed 
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY = #CameraSpeed 
        Else
          KeyY = 0
        EndIf
        
      EndIf
      
      Pitch(NodeID(NodePitch),MouseY, #PB_Local)
      Yaw(NodeID(NodeYaw),MouseX, #PB_World)
      MoveNode(NodeYaw, KeyX, 0, KeyY, #PB_Local)
      
      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
Please correct my english
http://purebasic.developpez.com/