Outils pour utilisateurs

Outils du site


playground:tuberadiusfunction

Différences

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

Lien vers cette vue comparative

Prochaine révision
Révision précédente
playground:tuberadiusfunction [2017/05/17 18:05]
falsam créée
playground:tuberadiusfunction [2018/01/11 02:04]
falsam
Ligne 1: Ligne 1:
 +**01-Tube Radius Function.sb**
 +
 +<file purebasic ​ 01-Tube Radius Function.sb>​
 +;​Babylon.sbi - Tube
 +
 +EnableExplicit
 +
 +IncludeFile "​babylon/​babylon.sbi"​
 +UseModule BJS
 +
 +Enumeration
 +  #mf
 +  #mfRender
 +EndEnumeration
 +
 +Global Scene, Camera, Tube, TubeMat, Light, ​
 +
 +;A tube consists of an array of 3D vectors. Example with 5 vectors
 +Dim TubeVectors.NewVector(4)
 +
 +Declare ​  ​LoadGame()
 +Declare.f Radius(Position,​ Distance.f)
 +Declare ​  ​RenderGame()
 +
 +;Window & Render
 +OpenWindow(#​mf,​ 0, 0, 900, 600, "​CreateTube()",​ #​PB_Window_ScreenCentered)
 +CanvasGadget(#​mfRender,​ 0, 0, 900, 600, #​PB_Canvas_Transparent)
 +
 +;Init Babylon with a render on a canvas and load game
 +InitEngine(@LoadGame(),​ #mfRender)
 +
 +Procedure LoadGame() ​   ​
 +  Scene = CreateScene()
 +  ​
 +  If Scene
 +    ​
 +    ;Camera & Light
 +    Camera = CreateCamera("​camera",​ 0, 10, 20, #​BJS_ArcRotate)  ​
 +    Light = CreateLight("​light",​ 0, 10, 0, 1)
 +    ​
 +    ;Create Tube 
 +    TubeVectors(0)\x = 0    ​
 +    TubeVectors(0)\y = 0
 +    TubeVectors(0)\z = 0
 +
 +    TubeVectors(1)\x = 0    ​
 +    TubeVectors(1)\y = 1
 +    TubeVectors(1)\z = 0
 +    ​
 +    TubeVectors(2)\x = 0    ​
 +    TubeVectors(2)\y = 2
 +    TubeVectors(2)\z = 0
 +    ​
 +    TubeVectors(3)\x = 0    ​
 +    TubeVectors(3)\y = 3
 +    TubeVectors(3)\z = 0
 +    ​
 +    TubeVectors(4)\x = 0    ​
 +    TubeVectors(4)\y = 4
 +    TubeVectors(4)\z = 0
 +    ​
 +    ;The creation of this tube uses a procedure to calculate the rasius of each vector ​
 +    Tube = CreateTube("​My tube", TubeVectors(),​ 0, 32, @Radius())
 +    ​
 +    ;Material
 +    TubeMat = CreateMaterial("​tube material",​ "​data/​textures/​misc.jpg"​)
 +    SetMaterial(Tube,​ TubeMat)
 +    ​
 +    RenderLoop(@RenderGame())
 +  EndIf
 +EndProcedure
 +
 +;This procedure will be called at each point of the path while constructing the tube.
 +;It will then be passed two arguments : 
 +;   -The position of the current point (1, 2, 3, 4, etc ...)
 +;   -The distance of this point from the beginnig of the tube.
 +;   -Your procedure must just return a radius value.
 +Procedure.f Radius(Position,​ Distance.f)
 +  Protected Radius.f
 +  Radius = 3 * Cos(Distance / 5);
 +  ​
 +  Debug "​Position " + Str(Position) ​ + " Radius " + StrF(Radius)
 +  ProcedureReturn Radius
 +EndProcedure
 +
 +
 +Procedure RenderGame()
 +  RotateMesh(Tube,​ 0, 0.01, 0, #​PB_Relative)
 +  RenderWorld() ​
 +EndProcedure
 +</​file>​
 +
  
playground/tuberadiusfunction.txt · Dernière modification: 2018/01/11 02:04 par falsam