Creating a 3D Grid

Blitz3D Forums/Blitz3D Programming/Creating a 3D Grid

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

How would you create a 3D grid like on Maya or Milkshape3D (maybe 3DSMax too) where you can change the grid size and grid spacing? The math of it and displaying it confuses me.

Edit:
Displaying using CameraProject can get kind of slow
I can't get the grid to center when using certain numbers like 3
Changing the GridSpace shouldn't change the size of the GridSize

One way I think that might help, is if someone (including me) can figure out how to make the points come out from the center instead of point X:1,Z:1 on the grid.

An example program
Global GridTexture
Global GridSize#=16
Global GridSpace#=2

InitGraphics(800,600,"GIA Map Editor")
GridTexture = CreateGridTexture(2+4)

Global DefaultLight = CreateLight()

Global cube = CreateCube()
EntityTexture cube,GridTexture
ScaleEntity cube,GridSpace,GridSpace,GridSpace

Global Camera = CreateCamera()
	PositionEntity Camera,0,GridSize*.5,-GridSize*1.5
	CameraClsColor Camera,100,100,100
	CameraRange Camera,.01,1000
	RotateEntity Camera,20,0,0


While Not KeyDown(1)
	
	If KeyHit(20) GridSize = GridSize + 1
	If KeyHit(34) GridSize = GridSize - 1
	
	If KeyHit(21) GridSpace = GridSpace + 1
	If KeyHit(35) GridSpace = GridSpace - 1
	
	If KeyDown(31) TranslateEntity Camera,0,0,-.25
	If KeyDown(17) TranslateEntity Camera,0,0,.25
	If KeyDown(32) TranslateEntity Camera,.25,0,0
	If KeyDown(30) TranslateEntity Camera,-.25,0,0
	If KeyDown(18) TranslateEntity Camera,0,.25,0
	If KeyDown(16) TranslateEntity Camera,0,-.25,0
	
	If KeyDown(200) TurnEntity Camera,-4,0,0
	If KeyDown(208) TurnEntity Camera,4,0,0
	
	DrawWorld()
	
	TempPoints = 0
	
	For x# = -(GridSize/2) To (GridSize/2)
		For y# = -(GridSize/2) To (GridSize/2)
			CameraProject Camera,x*GridSpace,0,y*GridSpace
			Color 255,0,0
			TempX# = ProjectedX()
			TempY# = ProjectedY()
			Rect TempX,TempY,4,4
			
			Color 0,255,255
			TempPoints = TempPoints + 1
			
			If TempPoints < 32
				Text TempX,TempY-22.5,"Point:"+TempPoints,1,1
				Text TempX,TempY-7.5,"X:"+(x),1,1
				Text TempX,TempY+7.5,"Y:"+(y),1,1
			EndIf
		Next
	Next
	
	Text 0,40,"Points = " + TempPoints
	
	Color 0,0,0
	Text 0,80,"Cube depth " + MeshDepth(cube)
	Text 0,120,"Grid Size " + GridSize
	Text 0,140,"Grid Space " + GridSpace
	Text 0,160,"Press T and G to change the Grid Size"
	Text 0,180,"Press Y and H to change the Grid Space"
	
	
	Flip
Wend
ClearWorld 1,1,1
End

Function CreateGridTexture(flags%)
	Local gtexture = CreateTexture(32,32,flags)
	
	SetBuffer TextureBuffer(gtexture)
	Color 0,0,0
	Rect 0,0,32,32
	
	Color 90,90,90
	Line 16,0,16,32
	Line 0,16,32,16
	
	SetBuffer BackBuffer()
	
	Return gtexture
End Function

Function DrawWorld()
	UpdateWorld
	RenderWorld
End Function

Function InitGraphics(width = 800, height = 600,title$="Blitz3D Program",exit_message$="Are you sure?")
	Graphics3D width, height, 32, 2
	SetBuffer BackBuffer()
	SeedRnd MilliSecs()
	AppTitle title,exit_message
End Function