Making a grid for a 3d surface?

Previous topic - Next topic

FutureCow

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?

Hemlos

#1
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]
Bing ChatGpt is pretty smart :O

FutureCow

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.

FutureCow

 :'(
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?

Hemlos

#4
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.
Bing ChatGpt is pretty smart :O

matchy

Is this the type of effect you are looking for?



[attachment deleted by admin]

Hemlos

#6
@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?
Bing ChatGpt is pretty smart :O

matchy

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]

FutureCow

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!

Hemlos

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!
Bing ChatGpt is pretty smart :O

FutureCow

#10
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.