Code archives/Graphics/3D Circle function
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
| This function creates a mesh based circle. 'segs' sets the number of sides (4 being a square, 100 very round). 'parent' allows you to parent it. 'twosided' is set to true/false (1 or 0). True if you want a circle you can see from both sides. To adjust size use the scaleentity command. To texture use the entitytexture command. example disk=createcircle(20,0,true) This creates a 20 sided circle that can be seen from top and bottom. | |||||
Function createcircle(segs=8,parent=0,twosided=False)
mesh=CreateMesh( parent )
surf=CreateSurface( mesh )
AddVertex surf,0,0,0,.5,.5
vc=0
inc#=360/segs
ii#=0
While ii<= 360
vc = vc+1
ii = ii +inc
xc# = Sin(ii)
zc# = Cos(ii)
u#=xc/2+.5
v#=zc/2+.5
AddVertex surf,xc,0,zc,u,v
AddTriangle (surf,0,vc-1,vc)
If twosided Then AddTriangle (surf,0,vc,vc-1)
Wend
AddTriangle (surf,0,vc,1)
If twosided Then AddTriangle (surf,0,vc-1,vc)
UpdateNormals mesh
Return mesh
End Function |
Comments
None.
Code Archives Forum