-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path01-Tube Radius Function.sb
More file actions
101 lines (78 loc) · 2.65 KB
/
01-Tube Radius Function.sb
File metadata and controls
101 lines (78 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
;Babylon.sbi - Tube
EnableExplicit
IncludeFile "babylon/babylon.sbi"
UseModule BJS
Enumeration
#mf
#mfRender
EndEnumeration
Global Scene, Camera, Tube, TubeMat, TubeTex, 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
TubeTex = LoadTexture("Data/textures/misc.jpg")
TubeMat = CreateMaterial("tube material")
SetMaterialTexture(TubeMat, #BJS_Diffuse, TubeTex)
SetMeshMaterial(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
; IDE Options = SpiderBasic 2.20 (Windows - x86)
; CursorPosition = 62
; FirstLine = 26
; Folding = -
; WebAppName = Tube Radius Function
; HtmlFilename = tuberadiusfunction.html
; JavaScriptFilename = tuberadiusfunction.js
; JavaScriptPath = sb
; iOSAppOrientation = 0
; AndroidAppOrientation = 0
; EnableXP
; CompileSourceDirectory