3d Wire Grid (Help Improvements)

Blitz3D Forums/Blitz3D Programming/3d Wire Grid (Help Improvements)

Function createline(x1#,y1#,z1#, x2#,y2#,z2#, mesh=0)
	
	If mesh = 0 Then 
		mesh=CreateMesh()
		EntityFX(mesh,16)
		surf=CreateSurface(mesh)	
		verts = 0	
	
		AddVertex surf,x1#,y1#,z1#,0,0
	Else
		surf = GetSurface(mesh,1)
		verts = CountVertices(surf)-1
	End If
	
	AddVertex surf,(x1#+x2#)/2,(y1#+y2#)/2,(z1#+z2#)/2,0,0 
	; you could skip creating the above vertex and change the line below to
	;AddTriangle surf,verts,verts+1,verts+0
	; so your line mesh would use less vertices, the drawback is that some videocards (like the matrox g400)
	; aren't able to create a triangle with 2 vertices. so, it's your call :)
	AddVertex surf,x2#,y2#,z2#,1,0
	
	AddTriangle surf,verts,verts+2,verts+1
	
	Return mesh
End Function

; --- set graphics
Graphics3D 640,480,32,0
SetBuffer(BackBuffer())

AntiAlias False

; --- create scene setup
camPiv = CreatePivot()
camera = CreateCamera(camPiv)
CameraClsColor camera,128,128,128
PositionEntity(camera, 0,0,-10)

light=CreateLight(2) 
PositionEntity(light,4,10,0) 
LightRange(light,10)

; --- create lines

lines = createLine(-1+x#,1+x#,1,    1+x#,1+x#,1)
lines = createLine(1+x#,1+x#,1,    1+x#,-1+x#,1, lines)
lines = createLine(1+x#,-1+x#,1,    -1+x#,-1+x#,1, lines)
lines = createLine(-1+x#,-1+x#,1,    -1+x#,1+x#,1, lines)
EntityColor(lines, 0,0,0)
HideEntity lines
gsize=24


x=-gsize
y=-gsize

Repeat 
	l=CopyEntity(lines)
	PositionEntity l,x,0,y
	RotateEntity l,90,0,0
	x=x+2
	If x=>gsize Then x=-gsize : y=y+2
Until y=>gsize

CreateSphere()

;TurnEntity(campiv, 35,35,35)

While Not KeyHit(1)

	; --- camera controls
	scrollwheel = MouseZSpeed()
	If MouseDown(1) Then 
		TurnEntity(camPiv, MouseYSpeed(),-MouseXSpeed(),0)
	Else If scrollwheel <> 0 Then 
		MoveEntity(camera, 0,0,scrollwheel*3)
	Else
		dummy = MouseYSpeed():dummy = MouseXSpeed():dummy = MouseZSpeed() ; prevent mousespeed blips.
	End If

	; --- rendering
	CameraClsMode(camera, 1, 1)
	WireFrame(0)
	RenderWorld()
	
	CameraClsMode(camera, 0, 0)
	WireFrame(1)
	RenderWorld()

	Flip()
Wend

End


Can anyone improve on this?, it seams a little over kill.

While this works, I'd much rather the grid be infinit in x,y & z rather than just an area, anyone have any idea how ?