Ooops
May 26, 2020, 06:33:50 PM

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

Offline 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. ;
  5. ;CreateTorus(radius#,width#,segments,sides[,parent])
  6. ;
  7. ;radius# = torus radius
  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.  
  13. Function CreateTorus(torrad#,torwidth#,segments,sides,parent=0)
  14.  
  15.         torusmesh=CreateMesh(parent)
  16.         surf=CreateSurface(torusmesh)
  17.        
  18.         FATSTEP#=360.0/sides
  19.         DEGSTEP#=360.0/segments
  20.  
  21.         radius#=0
  22.         x#=0
  23.         y#=0
  24.         z#=0
  25.        
  26.         fat#=0
  27.         Repeat
  28.                 radius = torrad + (torwidth)*Sin(fat)
  29.                 deg#=0
  30.                 z=torwidth*Cos(fat)
  31.                 Repeat
  32.                         x=radius*Cos(deg)
  33.                         y=radius*Sin(deg)
  34.                         AddVertex surf,x,y,z,x,y,z                     
  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.                
  50.                 AddTriangle surf,v0,v1,v2
  51.                 AddTriangle surf,v1,v3,v2      
  52.         Next
  53.        
  54.         UpdateNormals torusmesh
  55.  
  56.         Return torusmesh
  57. End Function


Comments :


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+...


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal