Drawing a grid for an editor...

Blitz3D Forums/Blitz3D Programming/Drawing a grid for an editor...

Have a look at this example...(Warning, Messy code!)
Graphics3D 640,480,0,2
SetBuffer BackBuffer()

AmbientLight 255,255,255 

WireFrame True

CamScale#=0.1

Global Camera = CreateCamera()
PositionEntity Camera,0,0,-50
CameraProjMode Camera,2 
CameraZoom Camera,CamScale# 
CameraClsMode Camera,False,True 

ClsColor 150,150,150

Global GRIDSTEP#=1.0	; Size of each GridBlock
Global GRIDCOLR=90
Global GRIDCOLG=90
Global GRIDCOLB=90

SeedRnd MilliSecs()

mesh1 = CreateCylinder()
PositionEntity mesh1,Int(Rnd(-5,5)),Int(Rnd(-5,5)),0  
EntityColor mesh1,255,0,0 

mesh2 = CreateSphere()
PositionEntity mesh2,Int(Rnd(-5,5)),Int(Rnd(-5,5)),0  
EntityColor mesh2,0,0,255

While Not KeyDown(1)


Select MouseZSpeed ()
 Case -1
  CamScale#=CamScale#*0.9
  If CamScale#<0.001 Then camScale#=0.001
  CameraZoom Camera,CamScale#
 Case 1
  CamScale#=CamScale#*1.1
  If CamScale#<0.001 Then camScale#=0.001
  CameraZoom Camera,CamScale#
End Select

; MousePanning
XDiff=-MouseXSpeed()
YDiff=MouseYSpeed()
If MouseDown(1) Then
MoveEntity Camera,XDiff/(400.0*CamScale#),YDiff/(300.0*CamScale#),0
EndIf


DrawGrid()
Color 0,0,0

RenderWorld

Flip False

Wend
End

Function DrawGrid()

Cls 
CenterX#=EntityX#(Camera)
CenterY#=EntityY#(Camera)
StartDrawX#=Int(CenterX#/GRIDSTEP#)*GRIDSTEP#
StartDrawY#=Int(CenterY#/GRIDSTEP#)*GRIDSTEP#

; Vertical lines
;Draw lines center to left
CurrPosX#=StartDrawX#
Repeat
 CameraProject(Camera,CurrPosX#,CenterY#,0)
 Xpos=ProjectedX()

 If CurrPosX#=0 Then
  Color 0,0,0
 Else
  Color GRIDCOLR,GRIDCOLG,GRIDCOLB 
 EndIf
 Line Xpos,0,Xpos,480 

 CurrPosX#=CurrPosX#-GRIDSTEP#
Until Xpos<0

;Draw lines center to right
CurrPosX#=StartDrawX#+GRIDSTEP#
Repeat
 CameraProject(Camera,CurrPosX#,CenterY#,0)
 Xpos=ProjectedX()
 If CurrPosX#=0 Then
  Color 0,0,0
 Else
  Color GRIDCOLR,GRIDCOLG,GRIDCOLB 
 EndIf
 Line Xpos,0,Xpos,480 
 CurrPosX#=CurrPosX#+GRIDSTEP#
Until Xpos>640

; Horizontal lines
;Draw lines center to up
CurrPosY#=StartDrawY#
Repeat
 CameraProject(Camera,CenterX#,CurrPosY#,0)
 Ypos=ProjectedY()
 If CurrPosY#=0 Then
  Color 0,0,0
 Else
  Color GRIDCOLR,GRIDCOLG,GRIDCOLB 
 EndIf
 Line 0,Ypos,640,Ypos 
 CurrPosY#=CurrPosY#+GRIDSTEP#
Until Ypos<0

;Draw lines center to down
CurrPosY#=StartDrawY#-GRIDSTEP#
Repeat
 CameraProject(Camera,CenterX#,CurrPosY#,0)
 Ypos=ProjectedY()
 If CurrPosY#=0 Then
  Color 0,0,0
 Else
  Color GRIDCOLR,GRIDCOLG,GRIDCOLB 
 EndIf
 Line 0,Ypos,640,Ypos 
 CurrPosY#=CurrPosY#-GRIDSTEP#
Until Ypos>480

End Function