May 26, 2020, 06:33:50 PM

### Author Topic: [bb] CreateTorus by BODYPRINT [ 1+ years ago ]  (Read 957 times)

#### BlitzBot

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

Description : This is a simple function to create a torus to your liking.
Feel free to use/modify it as you like.

All parameters are described in the code.

Code :
Code: BlitzBasic
1. ;Create Torus Function
2. ;Written by Philip Merwarth
3. ;Friday the 13th August, 2004 (oooooh)
4. ;
6. ;
8. ;width# = radius of tube in the torus
9. ;segments = the number of segments around the torus
10. ;sides = the number of segments, or sides of the tube in the torus
11. ;parent = parent entity handle
12.
14.
15.         torusmesh=CreateMesh(parent)
16.         surf=CreateSurface(torusmesh)
17.
18.         FATSTEP#=360.0/sides
19.         DEGSTEP#=360.0/segments
20.
22.         x#=0
23.         y#=0
24.         z#=0
25.
26.         fat#=0
27.         Repeat
29.                 deg#=0
30.                 z=torwidth*Cos(fat)
31.                 Repeat
35.                         deg=deg+DEGSTEP
36.                 Until deg>=360
37.                 fat=fat+FATSTEP
38.         Until fat>=360
39.
40.         For vert=0 To segments*sides-1
41.                 v0=vert
42.                 v1=vert+segments
43.                 v2=vert+1
44.                 v3=vert+1+segments
45.
46.                 If v1>=(segments*sides) Then v1=v1-(segments*sides)
47.                 If v2>=(segments*sides) Then v2=v2-(segments*sides)
48.                 If v3>=(segments*sides) Then v3=v3-(segments*sides)
49.
52.         Next
53.
54.         UpdateNormals torusmesh
55.
57. End Function

Clyde(Posted 1+ years ago)

Nice one mate!Cheers

rbraz(Posted 1+ years ago)

Really nice !I will try to code a torus function for B+...