   Drawing a 3D grid ..... HOW???
  Suppose you want to draw a 3D grid of thin (transparent?) lines, to give the user a better spatial orientation. There should be a fixed spacing between the lines of the grid (say 1000 meters of simulated space) so that the user has a good sense of the distances between objects.How do you decide how many lines you need? For instance, if I expect the grid to be visible out to a total distance of 100,000 simulated meters then I'd have to draw about 100 lines (from the z-perspective of the camera), right? The thing is, I'm not really sure how far the grid can be seen though, so I don't know the required dimensions of my grid cube. :-(Also, I don't want the grid to move with the camera ... I want its position and attitude in space to remain fixed, so that the motion of all objects within my 3D space can be observed relative to the lines of the grid.Anyway, my main concern at the moment is that I may have to constantly resize the grid depending on the dimensions of current view frustum and the way I see it this would be very hard since I'm using a scene graph (OpenSceneGraph). By that I mean that I create the grid once and then add it to the scene graph and it gets rendered automatically in every pass. I don't see how I could easily (efficiently) remove or add lines to my grid whenever the view frustum changes. Oh, I'm so confused ...Can anyone kinda see where I'm coming from? I'm still quite a noob at graphics programming and I don't really have this quite laid out in my head yet. I'd appreciate it if someone could give my some guidance here. How do the pros go about displaying 3D grids?   
  If the grids positions are in world-space, and the scene graph has the right translations between world-camera co-ordinates there shouldn't be a problem.   ;Quote:Original post by Interesting DaveIf the grids positions are in world-space, and the scene graph has the right translations between world-camera co-ordinates there shouldn't be a problem.But you see, what about the dimensions of the grid? Like I said, I don't think I have a good estimation of how far the grid can be seen, so I don't know how large the grid should be. Sure, I could just go and make it way larger than necessary, to make sure no one would ever see the 'end' of the grid. I really want to create the impression of an infinitely large grid, but I'm not sure how to best achieve this because if I just make it much larger than required, that'd be rather wasteful, no?;  does your camera exist inside a space that you define as your 'level' or 'map' ?   ;  I'm sorry, I don't know what you mean by that. :\   ;  Something like this prehaps?glColor3ub(0, 255, 0);glBegin(GL_LINES);for (int i = -200; i < 200; i++){   glVertex3i(-200, 0, i);   glVertex3i(200, 0, i);}for (int i = -200; i < 200; i++){   glVertex3i(i, 0, -200);   glVertex3i(i, 0, 200);}glEnd();/Lizard   ;  I understand the problem you're describing, although I'm not sure of a great solution (especially in the context of a SG renderer). One option is to experimentally determine how big such a grid needs to be relative to a fixed camera position, and then only make it that big. Then transform it by the inverse camera position (position modulo the grid size) so that it appears to remain fixed in space while you move. You'd want to add one extra line on every dimension to account for the shifting before you 'wrap' and shift the grid again. Does that make sense?   ;  Here's some technical stuff that may (or may not) help. And there are several things to consider.If you have a grid of 1000 meters spacing at 100,000 meters, the angle between lines in the grid is the arctan of 1000/100000 (1/100).The arctan of 1/100 is about .6 degrees. That's the angle between two grid lines. The human eye (according to a google) [edit- has a resolution of] about 20 arcseconds. 0.6 degrees is 0.6 * 3600 = 2160 arcseconds so the spacing of the lines at that distance would be recognizable.However, you have to consider whether the lines can be seen.If you want to fill a screen with grid lines and the angle (fov) from top to bottom of the screen is 45 degrees (a common perspective projection setting), the size of the grid at 100,000 meters would be 82840 meters - or 82 grid lines.Here's the calc:From the middle of the screen to the top is 22.5 degrees (half of 45) and 22.5 degrees from the middle to the bottom.The tangent of 22.5 degrees is 0.4142. For a distance of 100,000, the grid is 100000 * 0.4142 = 41420 meters. Since the grid extends both up and down from the middle, that 41420 * 2 = 82840 meters.That tells you how many grid lines you'll need top to bottom. From side-to-side, you have to multiply by the screen's aspect ratio, say 800/600 = 1.333.82840 * 1.333 = 110453 (approx) or 110 grid lines.For a 800 pixel-wide screen, the grid lines will rendered about 8 pixels apart (800 pixels/110 grid lines). That may be sort of dense.For the grid lines themselves to be visible, they have to be drawn such that they end up being about 1/2 pixel in size so something appears on the screen.1/2 pixel at the center of the screen covers 1/1200 of the distance top to bottom* ( 600 pixels top to bottom / 1/2 pixel ). Since the grid is 82840 meters high, that 1/2 pixel covers 82840/1200 meters on the grid. Each line would have to be about 69 meters wide ( 82840/1200 = 69 ).*that's at the center of the screen. At the top and bottom of the screen, the grid is farther away and the lines would appear a little thinner.Whew. Is that the sort of info you're looking for?[Edited by - Buckeye on March 12, 2008 9:54:36 AM];  Position the grid based on the camera position as follows:Lets say the grid has a line every 1000 units.If the camera is at 500, 400, 100 position the grid at 0, 0, 0If the camera is at 1500, 3250, 5000 position the grid at 1000, 3000, 5000Always position the grid to the nearest multiples of 1000 based on the camera position, so the grid moves with the camera, but the user doesn't perceive it's movements.The distance to draw grid lines is dependant on the maximum distance between corners of your frustum.  If the frustum doesn't change during the program then just make your grid bigger than it to start with.Hope that helps.   ;  osmanb, Buckeye, trippytarka, great input from you guys! Buckeye's post I'll need to re-read a couple more times to make sense of it all ;-) but that was definitely the kind of info I'm looking for! Having read these posts and spent some more thought on the matter myself, this is what I got at the moment.In my application, the view frustum can change radically (I want the user to be able to zoom in & out, although I will probably limit this ability to sensible minimum / maximum values). Since the zoom level can be changed, it would probably make sense to adjust the scale of my grid (i.e. the grid spacing) as well ... after all it would be silly to show the user an incedibly dense cluster of grid lines when he's viewing the world at a large zoom level, so I should probably increase the line spacing in sensible increments as the user zooms out ... but not in such a way that every tiny change of the zoom level will also result in the grid spacing changing. I don't want silly grid scales such as 1 grid sector == 764.245 meters but more like 1 grid sector = 1000 meters and then 5000 meters, 20000 meters, etc. so that the grid scale will remain constant at first when the user only zooms a little and then jump to the next scale when the user exceeds a certain zoom level. That shouldn't be too hard.I definitely like your (osmanb, trippytarka) idea about placing my grid at the nearest multiple of my grid spacing relative to the camera position; that certainly makes things a lot easier. Thanks a bunch, guys, you've put me on the right track. :-)