October 28, 2020, 06:13:12 AM

### Author Topic: [bb] Tunnel Effect by Olive [ 1+ years ago ]  (Read 1139 times)

#### BlitzBot

• Jr. Member
• Posts: 1
##### [bb] Tunnel Effect by Olive [ 1+ years ago ]
« on: June 29, 2017, 12:28:43 AM »
Title : Tunnel Effect
Author : Olive
Posted : 1+ years ago

Description : This effect use the function CreateMyCylinder from Todd Riggins.
Everything is hard-coded so you have to look inside to adapt, but you can try to change the TWIST value or MAX_CTRL_POINTS.

This is a "demo" version, in a real tunnel ride you have to place ControlPoints at specific positions with a step (10 for example) and interpolate values between them, here i use simple cos/sin values.

Use as you wish.

Code :
Code: BlitzBasic
1. ; CreateMyCylinder Example
2. ; ----------------------
3. ; By Pigmin (alias Olive) 02-20-2004
4. ;
6. ;
7. ; meet me at http://www.blitz3dfr.com (forum section)
8. ;
9. ;
10. ;
11. ; With wonderfull function :
12. ;
13. ; CreateMyCylinder
14. ; ----------------------
15. ; By: Todd Riggins 12-22-2003
16. ;
17. ; a CreateCylinder blitz-like function. Does the Same thing. Just wanted to do
18. ; this to see how to actaully create a cylinder with the addvertex/addtriangle
19. ; commands. Just thought I would share.
20.
21. ; -----------------
22. ; 2004-2-19 1:10:00
23. ; - Added ring segments. Ring Segment param of zero acts like the
24. ; blitz-like Function. IE: no ring segments.
25. ; - The added ring segments adds vertices to help bend cylinder tunnels or angle
26. ; pipe meshs. Ofcoarse, you will need to add your own code to manipulate the
27. ; cylinder's vertices.
28. ; 2004-2-18 21:00:00
29. ; - Fixed normal vectors problem: Needed to have cylinder ends as seperate surface
30. ;
31. ; Left sphere is created by the CreateMyCylinder function.
32. ; Right sphere is created by blitz's CreateCylinder command.
33. ;
34. ; Controls:
35. ; - Use mouse to rotate the cylinders
36. ; - wireframe toggle
37. ; - Esc key to escape
38.
39. ; rediminsionable arrays
40. Dim tRing(0)
41. Dim bRing(0)
42.
43. Type TCtrlPoint
44.         Field x#
45.         Field y#
46. End Type
47.
48. Const MAX_CTRL_POINTS = 16
49. Const TWIST# = 30
50.
51. Global CtrlPoints.TCtrlPoint[MAX_CTRL_POINTS]
52. Global CtrlPointsPhase% = 0
53. Global CtrlPointsPhase2% = 0
54.
55. Graphics3D 640,480,0,2
56. SetBuffer BackBuffer()
57.
58.
59. AmbientLight 32,0,0
60.
61. camera=CreateCamera()
62. CameraRange camera,.1,2000
63. light=CreateLight()
64. RotateEntity light,90,0,0
65.
66. ; enter how many segments the sphere has
67. Global vsegs=32
68. Global rsegs=MAX_CTRL_POINTS
69.
70. ;Texture
71. tex=CreateTexture(32,32,1+8)
72. SetBuffer(TextureBuffer(tex))
73. colR = 128
74. For j = 0 To 31 Step 8
75.         colR = 64 - colR
76.         For i = 0 To 31 Step 8
77.                 colR = 64 - colR
78.                 Color colR,colR,colR
79.                 Rect(i,j,8,8,1)
80.         Next
81. Next
82. SetBuffer (BackBuffer())
83. ScaleTexture tex,.25,.25
84.
85. ;Texture2
86. tex2=CreateTexture(64,64,1+4+8)
87. SetBuffer(TextureBuffer(tex2))
88. For j = 0 To 16
89.         colR = Rand(10,64)
90.         colG = Rand(0,128)
91.         colB = Rand(0,180)
92.         Color colR,colG,colB
93.         Rect(Rand(0,63),Rand(0,63),Rand(1,2),Rand(1,31))
94.         Rect(Rand(0,63),Rand(0,63),Rand(1,31),Rand(1,2))
95. Next
96. SetBuffer (BackBuffer())
97. ScaleTexture tex2,.1,.25
98. TextureBlend tex,2
99. TextureBlend tex2,3
100.
101. ; Create Cylinder manually
102. mycylinder=CreateMyCylinder(vsegs,rsegs,False,0)
103. ScaleMesh mycylinder,6,40,6
104. RotateMesh mycylinder,90,0,0
105. FlipMesh mycylinder
106. PositionEntity mycylinder,0,0,39
107. EntityTexture mycylinder,tex,0,0
108. EntityTexture mycylinder,tex2,0,1
109.
110. mycylindercopy = CopyMesh(mycylinder)
111. HideEntity mycylindercopy
112.
113. ;allocate control points
114. For i = 0 To MAX_CTRL_POINTS
115.         CtrlPoints[i] = New TCtrlPoint
116.         CtrlPoints[i]x# = (i*260/MAX_CTRL_POINTS)
117.         CtrlPoints[i]y# = (i*460/MAX_CTRL_POINTS)
118. Next
119.
120. ; key helper
121. wkey=0
122.
123. xx#=0
124. cnt#=0
125. freqX = 1
126. freqY = 1
127. While Not KeyDown( 1 )
128.         Tunnel_effect(mycylinder, mycylindercopy,  CtrlPointsPhase,  CtrlPointsPhase2)
129.         CtrlPointsPhase = CtrlPointsPhase + freqX
130.         CtrlPointsPhase2 = CtrlPointsPhase2 + freqY
131.
132.         If (Not Rand(0,200))
133.                 freqY = Rand(0,4)
134.         EndIf
135.
136.         If (Not Rand(0,400))
137.                 freqX = Rand(1,4)
138.         EndIf
139.
140.         PositionTexture Tex,0,cnt#
141.         PositionTexture Tex2,cnt#,cnt#
142.         cnt#=cnt#+.01*(freqX+freqY)*.5
143.
144.         If KeyDown(17) And wkey=0
145.         wkey=1
146.         EndIf
147.
148.         If KeyDown(17)=False And wkey=1
149.         wkey=0
150.         If wframe=0
151.         wframe=1
152.         Else
153.         wframe=0
154.         EndIf
155.         If wframe=0 WireFrame False
156.         If wframe=1 WireFrame True
157.         EndIf
158.
159.
160.         RenderWorld
161.
162.         Flip
163. Wend
164.
165. End
166.
167. ; ---------------------------------------------------------
168. Function CreateMyCylinder(verticalsegments,ringsegments=0,solid=True,parent=0)
169.         Local tr,tl,br,bl; side of cylinder
170.         Local ts0,ts1,newts; top side vertexs
171.         Local bs0,bs1,newbs; bottom side vertexs
172.         If verticalsegments<3 Or verticalsegments>100 Then Return 0
173.         If ringsegments<0 Or ringsegments>100 Then Return 0
174.
175.         thiscylinder=CreateMesh(parent)
176.         thissurf=CreateSurface(thiscylinder)
177.         If solid=True
178.                 thissidesurf=CreateSurface(thiscylinder)
179.         EndIf
180.         div#=Float(360.0/(verticalsegments))
181.
182.         height#=1.0
183.         ringSegmentHeight#=(height#*2.0)/(ringsegments+1)
184.         upos#=1.0
185.         udiv#=Float(1.0/(verticalsegments))
186.         vpos#=1.0
187.         vdiv#=Float(1.0/(ringsegments+1))
188.
189.         SideRotAngle#=90
190.
191.         ; re-diminsion arrays to hold needed memory.
192.         ; this is used just for helping to build the ring segments...
193.         Dim tRing(verticalsegments)
194.         Dim bRing(verticalsegments)
195.
196.         ;render end caps if solid
197.         If solid=True
198.                 XPos#=-Cos(SideRotAngle#)
199.                 ZPos#=Sin(SideRotAngle#)
200.
203.
204.                 SideRotAngle#=SideRotAngle#+div#
205.
206.                 XPos#=-Cos(SideRotAngle#)
207.                 ZPos#=Sin(SideRotAngle#)
208.
211.
212.                 For i=1 To (verticalsegments-2)
213.                         SideRotAngle#=SideRotAngle#+div#
214.
215.                         XPos#=-Cos(SideRotAngle#)
216.                         ZPos#=Sin(SideRotAngle#)
217.
220.
223.
224.                         If i<(verticalsegments-2)
225.                                 ts1=newts
226.                                 bs1=newbs
227.                         EndIf
228.                 Next
229.         EndIf
230.
231.         ; -----------------------
232.         ; middle part of cylinder
233.         thisHeight#=height#
234.
235.         ; top ring first
236.         SideRotAngle#=90
237.         XPos#=-Cos(SideRotAngle#)
238.         ZPos#=Sin(SideRotAngle#)
239.         thisUPos#=upos#
240.         thisVPos#=0
242.         For i=0 To (verticalsegments-1)
243.                 SideRotAngle#=SideRotAngle#+div#
244.                 XPos#=-Cos(SideRotAngle#)
245.                 ZPos#=Sin(SideRotAngle#)
246.                 thisUPos#=thisUPos#-udiv#
248.         Next
249.
250.         For ring=0 To (ringsegments)
251.
252.                 ; decrement vertical segment
253.                 thisHeight=thisHeight-ringSegmentHeight#
254.
255.                 ; now bottom ring
256.                 SideRotAngle#=90
257.                 XPos#=-Cos(SideRotAngle#)
258.                 ZPos#=Sin(SideRotAngle#)
259.                 thisUPos#=upos#
260.                 thisVPos#=thisVPos#+vdiv#
262.                 For i=0 To (verticalsegments-1)
263.                         SideRotAngle#=SideRotAngle#+div#
264.                         XPos#=-Cos(SideRotAngle#)
265.                         ZPos#=Sin(SideRotAngle#)
266.                         thisUPos#=thisUPos#-udiv#
268.                 Next
269.
270.                 ; Fill in ring segment sides with triangles
271.                 For v=1 To (verticalsegments)
272.                         tl=tRing(v)
273.                         tr=tRing(v-1)
274.                         bl=bRing(v)
275.                         br=bRing(v-1)
276.
279.                 Next
280.
281.                 ; make bottom ring segmentthe top ring segment for the next loop.
282.                 For v=0 To (verticalsegments)
283.                         tRing(v)=bRing(v)
284.                 Next
285.         Next
286.
287.         UpdateNormals thiscylinder
288.         Return thiscylinder
289. End Function
290.
291. Function Tunnel_Effect(mesh, mesh_original, phase, phase2)
292.
293.         cntsurf = CountSurfaces(mesh)
294.
295.         surf=GetSurface(mesh,cntsurf)
296.         surf_original=GetSurface(mesh_original,cntsurf)
297.
298.         cnt=CountVertices(surf)
299.         For s=0 To rsegs
300.
301.                 deltax# = Cos(CtrlPoints[s]x# + phase)*(TWIST#/(s+1))
302.                 deltay# = Sin(CtrlPoints[s]y# + phase2)*(TWIST#/(s+1))
303.
304.                 firstVertice = s*(vsegs+1)
305.                 endVertice = firstVertice + vsegs
306.                 For a=firstVertice To endVertice
307.                         x#=VertexX#(surf_original,a)
308.                         y#=VertexY#(surf_original,a)
309.                         z#=VertexZ#(surf_original,a)
310.
311.                         x#=x#+deltax#
312.                         y#=y#+deltay#
313.
314.                         VertexCoords surf,a,x#,y#,z#
315.                 Next
316.         Next
317.         UpdateNormals mesh
318.
319. End Function

Pepsi(Posted 1+ years ago)

Thats cool! That would make for a pretty wild game.

Clyde(Posted 1+ years ago)

Would make an even cooler Gfx Demo.Well Done Pigmin!