Outils pour utilisateurs

Outils du site


playground:terrain

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
Dernière révisionLes deux révisions suivantes
playground:terrain [2017/05/11 18:09] falsamplayground:terrain [2018/01/11 01:58] falsam
Ligne 1: Ligne 1:
 +**10-Terrain.sb**
 +
 +La représentation du relief d'un terrain passe par une carte des altitudes, plus communément appelée par son terme anglo-saxon, **heightmap**. Les zones les plus claires (//blanches//) correspondent aux hautes altitudes, tandis que les zones les plus sombres (//noires//) correspondent aux basses altitudes.
 +
 +{{:wiki:heightmap.png?300|}}
 +
 +Exemple : heightMap.png
 +
 +
 +[[http://falsam.com/sbbjs/terrain.html|Voir]]
 +
 +<file purebasic  10-Terrain.sb>
 +;Babylon.sbi - Create Terrain
 +
 +EnableExplicit
 +
 +IncludeFile "babylon/babylon.sbi"
 +
 +Global Camera, Light, Sky, Ground, GroundTex, GroundMat, Water, Box, Mesh, Texture, Material
 +Global Box0, Box1, Box2
 +
 +Declare LoadGame()
 +Declare RenderGame()
 +
 +UseModule BJS
 +
 +InitEngine(@LoadGame())
 +
 +Procedure LoadGame()  
 +  If CreateScene()
 +    InitKey()
 +    
 +    ;Camera & Light
 +    Camera = CreateCamera("camera", 0, 65, 100, #BJS_Universal)
 +    CameraBodySize(Camera, 1, 15, 1)
 +    CameraLookAt(Camera, 0, 30, 0)
 +    
 +    ;Redefine the camera keys
 +    CameraMapKey(Camera, #PB_Key_Left, #PB_Key_A)
 +    CameraMapKey(Camera, #PB_Key_Right, #PB_Key_Z)   
 +        
 +    Light = CreateLight("Light", 0, 200, -100, 0.8, #BJS_Point)
 +        
 +    ;SkyBox
 +    Sky = SkyBox("Clouds", "data/textures/sky/cloud", 2000)
 +    
 +    ;Terrain
 +    Ground = CreateTerrain("island", "data/textures/heightMap.png", 1000, 1000, 210, 0, 70)
 +    GroundTex = LoadTexture("sand", "data/textures/Ground.jpg")
 +    GroundMat = CreateMaterial("sand")
 +    SetMaterialTexture(GroundMat, #BJS_Diffuse, GroundTex)
 +    ScaleMaterial(GroundMat, 16, 16)
 +    SetMeshMaterial(Ground, GroundMat)
 +    SetMaterialColor(GroundMat, #BJS_Specular, RGB(80, 80, 80))
 +    MoveMesh(Ground, 0, -12, 0)
 +    
 +    ;Box
 +    Box0 = CreateBox("box", 10, 10, 10)
 +    Texture = LoadTexture("box", "data/textures/crate.png")
 +    Material = CreateMaterial("box")
 +    SetMaterialTexture(Material, #BJS_Diffuse, Texture)
 +    SetMaterialColor(Material, #BJS_Emissive, RGB(80, 80, 80))
 +    SetMeshMaterial(Box0, Material)
 +    MoveMesh(Box0, -4, 22, -70)
 +    Box1 = CloneMesh(Box0)
 +    MoveMesh(Box1, 7, 22, -70)
 +    Box2 = CloneMesh(Box0)
 +    MoveMesh(Box2, 0, 32, -70)
 +    RotateMesh(Box2, 0, 45, 0)
 +    
 +    ;Water
 +    Water = CreateWater("water", "data/textures/waterbump.png", 2000, 2000, 128) 
 +    WaterRenderList(Water, Ground)
 +    WaterRenderList(Water, Sky)
 +    
 +    ;Shadow
 +    InitShadow(Light)
 +    ShadowEmitter(Box0)
 +    ShadowEmitter(Box1)
 +    ShadowEmitter(Box2)
 +    RenderShadows(Ground)
 +    
 +    RenderLoop(@RenderGame())
 +  EndIf
 +EndProcedure
 +
 +Procedure RenderGame()   
 +  If KeyPushed(#PB_Key_Left)
 +    RotateCamera(Camera, 0, -0.05, 0, #PB_Relative)
 +  EndIf
 +  
 +  If KeyPushed(#PB_Key_Right)
 +    RotateCamera(Camera, 0, 0.05, 0, #PB_Relative)
 +  EndIf
 +    
 +  RenderWorld() 
 +EndProcedure
 +</file>
 +
  
playground/terrain.txt · Dernière modification : 2023/03/15 15:49 de 127.0.0.1