Grid?

Blitz3D Forums/Blitz3D Beginners Area/Grid?

Terry B.(Posted 2007) [#1]
How do you make a simple Grid?
And how would you make it so that a point on this grid points to the mouse position in the corner of that grid?


GfK(Posted 2007) [#2]
graphics 800,600
setbuffer backbuffer()

GridSize = 16

while not keydown(1)
  cls
  Plot (mousex()/gridsize) * gridsize, (mousey()/gridsize)*gridsize
  flip
wend
?


Terry B.(Posted 2007) [#3]
Thanks but i meant in 3d.


GfK(Posted 2007) [#4]
Oh sorry. I did try to call Mystic Meg before I posted but she was busy working out my lottery numbers...


smilertoo(Posted 2007) [#5]
Come on, he's told you exactly what he wants...what more details can you need?


big10p(Posted 2007) [#6]
hehe. Terry, you need to be much more explicit as to exactly what you want to do. We're not psychic here. ;)


Terry B.(Posted 2007) [#7]
I just need to know how to say, put a grid onto a terrain (not as a part of it) and make it so that a block goes from corner to corner on the grid depending on where my mouse is.


Zenith(Posted 2007) [#8]
socks


Terry B.(Posted 2007) [#9]
use a texture

But then how would I make the mouse follow it?


caff_(Posted 2007) [#10]
http://www.blitzbasic.com/codearcs/codearcs.php?code=373

This shows how to 'pick' a selected vertex on a mesh. You can simply modify this to work with a landscape 'mesh'.


Zethrax(Posted 2007) [#11]
Here's some code which may be of use to you.


Global G_grid_cell_size# = 1.0

Graphics3D 800, 600, 0, 2

Global G_camera = CreateCamera()
CameraZoom G_camera, 1.6
TurnEntity G_camera, 90.0, 0.0, 0.0
MoveEntity G_camera, 0.0, 0.0, -20.0

Global G_light = CreateLight()

Global G_cube = CreateCube()
ScaleMesh G_cube, 0.5, 0.5, 0.5
PositionMesh G_cube, 0.5, 0.5, 0.5
UpdateNormals G_cube

Global G_grid = CreateGrid()
EntityPickMode G_grid, 2

Global G_picked_entity

SetBuffer BackBuffer()

Repeat

	G_picked_entity = CameraPick( G_camera, MouseX(), MouseY() )
	
	If G_picked_entity
	
		x# = Floor( PickedX() / G_grid_cell_size# ) * G_grid_cell_size#
		z# = Floor( PickedZ() / G_grid_cell_size# ) * G_grid_cell_size#		
		PositionEntity G_cube, x#, PickedY(), z#
	
	EndIf
	
	UpdateWorld
	RenderWorld
	Flip
	Delay( 1 )

Until KeyHit( 1 )

End



Function CreateGrid()
	; -- Create grid texture.
	Local i, x, y
	Local grid_2d_tex = CreateTexture ( 256, 256, 11 )
	SetBuffer TextureBuffer ( grid_2d_tex )
	For i = 0 To 4
		Rect i, i, 256 - i - i, 256 - i - i, False
	Next
	For y = 5 To 250
		For x = 5 To 250
			WritePixel x, y, 0
		Next
	Next
	;^^^^^^
	; -- Create 2D grid.
	Local grid_2D = CreatePlane ()
	EntityTexture grid_2D, grid_2d_tex
	EntityFX grid_2D, 9
	;^^^^^^
	Return grid_2D
End Function