Grid meshes
Blitz3D Forums/Blitz3D Programming/Grid meshes
| ||
| Any ideas on how to make a grid mesh that I can "deform" in game. Speed is hardly important. It's just, I want to level a terrain in a certain area when something is built on it. IE: A house gets built, so make the land its on flat. |
| ||
| You could use this method: http://www.blitzbasic.com/Community/posts.php?topic=52387 Or alternatively you can construct a terrain manually using vertices by laying them out in a grid and stitching polygons inbetween the vertices - you could use the above example as a meens to learn how to do that. |
| ||
| You could create the mesh in a 3D package or internally using Blitz's own mesh/vertex commands. You can dynamically deform it by calling a function to count the surfaces in the mesh to then 'GetSurface' the mesh to a new surface, count the vertices then loop the vertices and deform as and where you like. Knowing which vertices to flatten will be the only thing you really need to work out. |
| ||
The actual mesh:; Top bit added by puki (for demonstration purposes) - 1/11/04
Graphics3D 640,480,16,2
cam=CreateCamera()
PositionEntity cam,0,0,2
; set the size of Ziltch's square, now use it as a normal entity
; so, as Ziltch said, it is scaleable.
ground=createsquare(25)
PointEntity cam,ground
While KeyHit(1)=0
TurnEntity ground,1,0,0
RenderWorld
Flip
Wend
End
;===================================================================
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 |