Creating a 3D Grid

Blitz3D Forums/Blitz3D Programming/Creating a 3D Grid

GIB3D(Posted 2008) [#1]
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



Pongo(Posted 2008) [#2]
If you change these two lines to this I think you will get what you are looking for.

If KeyHit(20) GridSize = GridSize + 2
If KeyHit(34) GridSize = GridSize - 2


It's the odd numbers that are messing up your grid. When you only add one point, the whole thing will shift over 1/2 of a unit. By adding 2 at a time you can avoid this.


GIB3D(Posted 2008) [#3]
Well the thing is, I don't want just even numbers.

I'm trying a different way now by making the points come out from the center instead of... somewhere else. So far it works except I can't get it to show it like a grid, it's more like one big X. I'll post code later.


Pongo(Posted 2008) [#4]
The grid scale can be anything, but to expand the grid size you need to add a border all the way around, and that means adding 2 rows or columns at a time. (One on the negative axis, the other on the positive) These can be even or odd, but they need to increment by 2.

If you have odd numbers, then the center will always fall on 0, which is probably what you want. You just have to increment by 2 each time.

For example,...draw a grid on paper,... then try to add a single line. You will see that you need to add one to each side, or you will be making one side bigger than the other. (Unless the grid shifts, which you stated you don't want)


GIB3D(Posted 2008) [#5]
Edit: I made the way the dots are displayed a lot better by adding functions and found out that I needed to do

For pos# = 0 To GridSize*(GridSpace^-1)
instead of
For pos# = 0 To GridSize

to show more dots when the GridSpace goes below 1



The grid spacing shouldn't matter whether its 1002.5125 or 2.9.
The grid size is the border and should limit how many dots are made/displayed.

Here is what it should look like on paper (note, I made this the day BEFORE Pongo posted the idea)


The number above each grid is the grid size, the one to the right is the grid space. The grids on the the right side of the page are all a grid space of 2.




GIB3D(Posted 2008) [#6]
Now I just gotta figure out how I'm gonna draw all the grid lines instead using a whole bunch of dots in the shape of an X

I wish using CameraProject wasn't so friggin slow.


GIB3D(Posted 2008) [#7]
I HAVE FOUND IT!

Edit: Fixed the borders not showing exactly the way they're supposed to ;)


...now if only I could find a way so I don't have to make the grid disappear(if I don't, then the lines will appear in odd places)


boomboom(Posted 2008) [#8]
if this is for an editing tool consider doing it with a surface and verts rather than a texture.

Then it will be a lot easier to do grid snapping etc.


GIB3D(Posted 2008) [#9]
This isn't a texture... it's just putting a bunch of 2D lines on screen depending on the GridSize and GridSpace.

And grid snapping isn't hard to do anyways XD I've known how for awhile.

I'm trying to make a simple 3D Modeling program and don't try to tell me not to make one because I'm going to anyways.

Edit:
Do you think other 3D modeling programs use a surface to make the grid? I don't understand how you could make the grid lines not look distorted if you use a texture, and how you could change the grid size and spacing in real time.


big10p(Posted 2008) [#10]
I started a 3D model viewer years ago and used this basic technique to render the grid:
http://www.blitzbasic.com/codearcs/codearcs.php?code=839

I also developed this technique for vertex 'handles':
http://www.blitzbasic.com/codearcs/codearcs.php?code=1008


GIB3D(Posted 2008) [#11]
Thanks, I'll see what I can get out of it. ;)


Pongo(Posted 2008) [#12]
I thought you might find this useful. It's a bit of code I use for navigating the camera around my objects when I am testing things out.

Left button down orbits around the pivot
middle button pans
mouse wheel zooms





GIB3D(Posted 2008) [#13]
Woo cool, thanks. That was the way I was going to do it except I was going to make it more like Maya where you hold down Alt and then use the mouse to rotate and stuff (You can pan and zoom with the middle button without the Alt button being down in Maya).