BASIC

Author Topic: Making a grid for a 3d surface?  (Read 2137 times)

Offline FutureCow

  • HelpEditor
  • Prof. Inline
  • ******
  • Posts: 680
    • View Profile
Making a grid for a 3d surface?
« on: 2009-Nov-24 »
I posted some code today (
Code: GLBasic [Select]
http://www.glbasic.com/forum/index.php?topic=3867.msg28244
) that renders a 3D animated ocean (i.e. 3D sine wave) Now I want to put a grid over the top of it for use with positioning things with the mouse. Any takers on how you'd do it? I don't want to texture the grid onto the surface, I'd rather have a discrete flat object above the surface.
 I was hoping to be able to make a polyvector and put a grid texture with transparent "holes" on it, but it doesn't appear that I can move the polyvector in the third dimension to get it where I'd need it.
All I can come up with is making a grid out of 3D objects (boxes) and locating that object above the existing landscape. It'll work, but it will take a lot more coding than the few lines a simple polyvector would have done.
Anyone?

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1635
  • Particle Hawk
    • View Profile
Re: Making a grid for a 3d surface?
« Reply #1 on: 2009-Nov-24 »
Pretty cool, i havent compiled it yet.

Theres a few things you could do, depending on your needs.

Is it for collision detection?
X_OBJ is almost exactly like polyvector, only in 3d, obviously you know this.


Here is a function(below) which will make a grid.
Make sure you include this library, it uses this:
http://www.glbasic.com/forum/index.php?topic=3839.msg28247#new



Code: GLBasic [Select]
FUNCTION Bezier3dGrid: X,Y,Z , WidthX,DepthZ ,  Divisions , Color, LineSize
// plot a 3d grid on Y plane.
//
// XYZ is the start point, and Y here will designate the height.
// WidthX , DepthZ are the size dimensions.
// The grid will build into the + directions starting at point XYZ
//
// Divisions splits the grid into # of sections per direction.
// Color=RGB(255,255,255) //any color
//
// Sample:
// Bezier3dGrid(-50,0,-50 , 100,100 ,  10, 1, RGB(255,255,255) )
// This is a 100x100 size grid at 0 height, it will plot
//  from -50,0,-50, to 50,0,50, with a 10x10 grid.

                LinearBezier2d( 0 , 0 , WidthX , 0 , Divisions )
                FOR i = 0 TO Divisions - 1
                        L = LinearBezierArray2d[i][0] + X
                        X_LINE L , Y , Z , L , Y , Z + DepthZ, LineSize , Color
                        X_LINE X , Y , L , X + WidthX , Y , L , LineSize , Color
                NEXT

ENDFUNCTION

[attachment deleted by admin]
« Last Edit: 2009-Nov-24 by Hemlos »
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline FutureCow

  • HelpEditor
  • Prof. Inline
  • ******
  • Posts: 680
    • View Profile
Re: Making a grid for a 3d surface?
« Reply #2 on: 2009-Nov-24 »
I knew X_OBJ was pretty much the same, but couldn't work out how to do a transparent texture with it.

I'm starting on "Battleship" as another entry for the board game compo (I'm taking a break from "Guess Who" - hopefully I'll get one of them finished!   :S)
I'm thinking at the moment of putting real 3D ships on a moving ocean, with a grid over the top to see where they are. That's the current plan, it may change though! I'll worry about getting things drawing first, then work out how I'm going to do the collision checks / line picks with the mouse etc.

Thanks for the code, I'll give it a try.

Offline FutureCow

  • HelpEditor
  • Prof. Inline
  • ******
  • Posts: 680
    • View Profile
Re: Making a grid for a 3d surface?
« Reply #3 on: 2009-Nov-24 »
 :'(
ARRRRGGGHHH!!! I just realised there's an X_LINE command (who feels like an idiot now hmmm?!)
Any reason you use bezier lines rather than X_LINE for that grid Hemlos?

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1635
  • Particle Hawk
    • View Profile
Re: Making a grid for a 3d surface?
« Reply #4 on: 2009-Nov-24 »
It uses X_LINEs
I only used the linear bezier to output a proportional aray of start points, regulated by the input of divisions, i was lazy building an algorithm for point coords.

You could just make your own regulator.

Linesize=100
Divsions=10
SegmentDistance=Linesize/Divsions

With the lineaer bezier.....you can do this at a diagonal, which will let you rotate the grid...but i didnt build the grid with the rotations....so here you could just the above example.


I love your game idea of battleship.

The ocean and the grid will certainly make it possible.....very impressive what you have so far.
« Last Edit: 2009-Nov-24 by Hemlos »
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline matchy

  • Prof. Inline
  • *****
  • Posts: 1543
    • View Profile
Re: Making a grid for a 3d surface?
« Reply #5 on: 2009-Nov-24 »
Is this the type of effect you are looking for?



[attachment deleted by admin]

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1635
  • Particle Hawk
    • View Profile
Re: Making a grid for a 3d surface?
« Reply #6 on: 2009-Nov-24 »
@Matchy:
That looks really cool man.
What he needed was a grid, he already made the ocean.
However, you can share your water code with us?
 :-[

Yours is a different water effect (standard in most games i think), moving texture coords i assume?
« Last Edit: 2009-Nov-24 by Hemlos »
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline matchy

  • Prof. Inline
  • *****
  • Posts: 1543
    • View Profile
Re: Making a grid for a 3d surface?
« Reply #7 on: 2009-Nov-24 »
Okay Hemos! I've attached a sample project where there are 2 objects demonstrating the basis of some sort of water effect.
One is a grided mesh (100 vert) that waves the other is just a flat (4 vert) both using the same texture and bump mapping and alphamode for see thru.

Really, a flat rectangle with out bump map is frame rate affordable (on the iPhone). ;)

[attachment deleted by admin]

Offline FutureCow

  • HelpEditor
  • Prof. Inline
  • ******
  • Posts: 680
    • View Profile
Re: Making a grid for a 3d surface?
« Reply #8 on: 2009-Nov-24 »
Matchy,
As Hemlos said, I already have the water done as a 3D moving surface, though yours may end up being the better solution. At least I wouldn't have to worry about either trying to make ships move up and down on the waves (I have a sketchy idea of how to do that but no idea if I'm right or if it will work!) or worry that a non-moving ship superimposed on a moving ocean will   be culled incorrectly. I'm working out 3D as I go here *grin*

I was looking for just a technique to draw a grid, but I'm downloading your code now and I'm looking forward to seeing how you've done it.
Thanks for the reply!

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1635
  • Particle Hawk
    • View Profile
Re: Making a grid for a 3d surface?
« Reply #9 on: 2009-Nov-24 »
FC,

I recommend the one you made...you dont require a huge server, so you can supply your left over frame rate to quality.

Some things to consider:
1. you already have a height map.
2. ever see a battleship? They dont bob up and down....the waves just go through(or around it)
3. the water effect he provided is typically used in MMORP type games, for high speed performance.
4. a competition to win

hehe  =D  goodluck buddy!
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline FutureCow

  • HelpEditor
  • Prof. Inline
  • ******
  • Posts: 680
    • View Profile
Re: Making a grid for a 3d surface?
« Reply #10 on: 2009-Nov-25 »
Hemlos
1) True, but the ships will have to change angles to match the water they're sitting on
2) True, but I think it would look better if they moved with the water (regardless of how unrealistic it is!) I will probably forego the movement though due to changing the angles as noted above - at least until I have the rest done anyway
4) Good point :D
It's still early days for this project (actually, it's only day 3 for this project *laugh*) - I'll see what I can do.
« Last Edit: 2009-Nov-25 by FutureCow »