playground:tuberadiusfunction
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Prochaine révision | Révision précédente | ||
| playground:tuberadiusfunction [2017/05/17 18:05] – créée falsam | playground:tuberadiusfunction [2023/03/15 15:49] (Version actuelle) – modification externe 127.0.0.1 | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | **01-Tube Radius Function.sb** | ||
| + | |||
| + | <file purebasic | ||
| + | ; | ||
| + | |||
| + | EnableExplicit | ||
| + | |||
| + | IncludeFile " | ||
| + | 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 | ||
| + | Declare.f Radius(Position, | ||
| + | Declare | ||
| + | |||
| + | ;Window & Render | ||
| + | OpenWindow(# | ||
| + | CanvasGadget(# | ||
| + | |||
| + | ;Init Babylon with a render on a canvas and load game | ||
| + | InitEngine(@LoadGame(), | ||
| + | |||
| + | Procedure LoadGame() | ||
| + | Scene = CreateScene() | ||
| + | | ||
| + | If Scene | ||
| + | | ||
| + | ;Camera & Light | ||
| + | Camera = CreateCamera(" | ||
| + | Light = CreateLight(" | ||
| + | | ||
| + | ;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(" | ||
| + | | ||
| + | ;Material | ||
| + | TubeMat = CreateMaterial(" | ||
| + | SetMaterial(Tube, | ||
| + | | ||
| + | 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, | ||
| + | Protected Radius.f | ||
| + | Radius = 3 * Cos(Distance / 5); | ||
| + | | ||
| + | Debug " | ||
| + | ProcedureReturn Radius | ||
| + | EndProcedure | ||
| + | |||
| + | |||
| + | Procedure RenderGame() | ||
| + | RotateMesh(Tube, | ||
| + | RenderWorld() | ||
| + | EndProcedure | ||
| + | </ | ||
| + | |||
