Outils pour utilisateurs

Outils du site


playground:skybox

08-SkyBox.sb

Voir

08-SkyBox.sb
;Babylon.sbi - Skybox
 
EnableExplicit
 
IncludeFile "babylon/babylon.sbi"
Enumeration
  #mf
  #mfRender
EndEnumeration
Global Camera, Light0, Light1, Sky, Ground, TexGround, MatGround, Torus0, Torus1, ShadowGenerator
 
Declare LoadGame()
Declare RenderGame()
 
UseModule BJS
OpenWindow(#mf, 0, 0, 0, 0 ,"", #PB_Window_Background)
CanvasGadget(#mfRender, 0, 0, WindowWidth(#mf), WindowHeight(#mf), #PB_Canvas_Transparent)
 
InitEngine(@LoadGame(), #mfRender)
 
Procedure LoadGame()   
  Protected n
  If CreateScene()
 
    Camera = CreateCamera("camera", 0, 20, -80, #BJS_ArcRotate)
 
    Light0 = CreateLight("light0", 0, 30, 0, 0.6, #BJS_Point)
    Light1 = CreateLight("light1", 0, 30, 0, 0.2, #BJS_Hemispheric)
 
    ;SkyBox
    Sky = SkyBox("Night", "data/textures/sky/night", 1000)
 
    ;Ground
    Ground = CreateGround("Ground", 1000, 1000)
    TexGround = LoadTexture("Grass", "data/textures/grass1.jpg")
    MatGround = CreateMaterial("Grass")
    SetMaterialTexture(MatGround, #BJS_Diffuse, TexGround)
    ScaleMaterial(MatGround, 40, 40)
    SetMeshMaterial(Ground, MatGround)
 
    ;Torus
    Torus0 = CreateTorus("torus0", 8, 2, 32)
    MoveMesh(Torus0, 0, 8, 0)
 
    Torus1 = CreateTorus("torus1", 4, 1, 32)
    MoveMesh(Torus1, 0, 8, 0)
 
    ;Shadow
    ShadowGenerator = InitShadow(Light0)
    ShadowEmitter(Torus0)
    ShadowEmitter(Torus1)
    RenderShadows(Ground, #True)
 
    RenderLoop(@RenderGame())
  EndIf
EndProcedure
 
Procedure RenderGame()
  RotateMesh(Torus0, 0.5, 0.00, 0.5, #PB_Relative)
  RotateMesh(Torus1, 1, 1, 0.00, #PB_Relative)
 
  If GetCameraBeta(Camera) > 1.50
    SetCameraBeta(Camera, 1.50)
  EndIf            
 
  If GetCameraRadius(Camera) < 30
    SetCameraRadius(Camera, 30)
  EndIf
 
  RenderWorld() 
EndProcedure
playground/skybox.txt · Dernière modification: 2018/01/11 01:57 de falsam