Code archives/3D Graphics - Mesh/CreateSquare
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
This command creates a flat 2d square to use in a 3d world. CreateSquare(number of segments per side[,parententity]) example; ground = createsquare(20) ScaleEntity ground,1000,1,1000 This creates a large 1000x1000 square to use as ground. | |||||
Function createsquare(segs#=2,parent=0) ; by ADAmor Ziltch. Oct 2002 ; v2 Feb 2003 ;v3 may 2003 fixed rounding bug mesh=CreateMesh( parent ) surf=CreateSurface( mesh ) l# =-.5 b# = -.5 tvc= 0 ;create all the vertices first Repeat u# = l + .5 v# = b + .5 AddVertex surf,l,0,b,u,1-v tvc=tvc + 1 l = l + 1/segs If l > .501 Then l = -.5 b = b + 1/segs End If Until b > .5 ;create polys vc# =0 Repeat AddTriangle (surf,vc,vc+segs+1,vc+segs+2) AddTriangle (surf,vc,vc+segs+2,vc+1) vc = vc + 1 tst# = ((vc+1) /(segs+1)) -floor ((vc+1) /(segs+1)) If (vc > 0) And (tst=0) Then vc = vc + 1 End If Until vc=>tvc-segs-2 UpdateNormals mesh Return mesh End Function |
Comments
None.
Code Archives Forum