The 3D grid

Blitz3D Forums/Blitz3D Programming/The 3D grid

Thanks for the code, you must have been doing this for awhile.

Some of the triangles appear backwards and show up black. I messed around for a few hours and managed to get what I was looking for.

Something like this


Graphics3D 400,400,16,2

SetBuffer BackBuffer()

;;;;The size of each square
Global gridindex# = 20.0;;20.0 is the actual size, divided by 2 to represent the + side of the x/y axis and the - side of x/y
Global gridsize = (gridindex#/2.0)
Global gridx = 20,gridy = 10;;;;how many grid squares

;;;Use this to center the entire grid to the screen
Global centerx = (gridx*gridsize)/2
Global centery = (gridy*gridsize)/2

;;;;Grid Type
Type grid
	Field mesh
	Field surface
	Field ispicked
End Type 
;;;;Grid Array//Determines how many squares in the grid
Dim mapgrid(gridx,gridy)


;Environmental variables
Global cam1,light1
;setup camera and light
cam1 = CreateCamera()
CameraViewport cam1,0,0,400,400
light1 = CreateLight()




;;;CreateGrid Function
CreateGrid(gridsize)

While Not KeyHit(1)


PickAndKill()

UpdateWorld 
RenderWorld

FPS()

 
Flip
Cls

Wend

;;;;create grid according to dimensions
Function CreateGrid(size)
For x = 1 To (gridx - 1)
	For y = 1 To (gridy - 1)
		newgrid.grid = New Grid
		newgrid\mesh = CreateMesh()
		newgrid\surface = CreateSurface(newgrid\mesh)
	
		AddVertex newgrid\surface,-size,+size,+100:AddVertex newgrid\surface,+size,+size,+100
		AddVertex newgrid\surface,-size,-size,+100:AddVertex newgrid\surface,+size,-size,+100
		AddTriangle newgrid\surface,0,1,2:AddTriangle newgrid\surface,2,1,3
	
	
		PositionEntity newgrid\mesh,(x*gridsize) - centerx,(y*gridsize) - centery,100
		EntityPickMode newgrid\mesh,2
	Next
	
Next 

End Function 

;;Click and kill each grid square
Function PickAndKill()
CameraPick(cam1,MouseX(),MouseY())
PickedEnt = PickedEntity()
	If MouseDown(1)
		If PickedEnt <> 0 
			For tile.grid = Each grid
				If PickedEnt = tile\mesh
					FreeEntity tile\mesh				
			EndIf
		Next
	EndIf
EndIf
End Function

;;;;;;//FPS
Global fpstime,fpscount,fps
Function FPS()
fpscount=fpscount+1
If MilliSecs()>fpstime Then 
    fpstime=MilliSecs()+1000
    fps=fpscount
    fpscount=0
EndIf 
Text 10,0,"FPS: "+fps
End Function
;;;;;\\FPS


Yours appears to render much faster then this code. I'm wondering if I could some how get the effect and visuals of this code with the speed of yours?