Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Big Cheez

How do you make the (in?)famous "grid of cubes"?

This topic is 5301 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
Yeah. Basically, lots of cubes lined up horizontally and vertically. I see it all the time.

[edited by - Big Cheez on February 8, 2004 7:44:42 AM]

Share this post


Link to post
Share on other sites
Oh, THAT grid of cubes!

I personally use good old weed, but LSD works as well.

Seriously, once you know how to render a cube, you know how to render more than one. After that, it''s your choice of rendering each cube separately (using transforms) with two for loops or sending the data for all the cubes at once to the card (build that data using for loops, again).

Share this post


Link to post
Share on other sites
ow, like the famous 3d grid of lines, only with cubes?

Display lists is the answer. Just do:

for(double x=-50.0;x<=50.0;x+=1.0){
for(double y=-50.0;y<=50.0;y+=1.0){
for(double z=-50.0;z<=50.0;z+=1.0){
glPushMatrix();
glTranslated(x,y,z);
glCallList(cubelist);
glPopMatrix();
};
};
};


Of course there are plenty of ways to do it but this is i think the easiest one, you might also want to make a display list of these calls (this will speed it up a bit). Also, the -50.0, 50.0 and 1.0 values are just examples, so set it to whatever you want, the reason i use doubles and not floats is that when adding 1.0 to a float a few times, a tiny value will be added so the last test fails (as it is 50.0000342 or something instead of 50.0).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
OR... you could use integers for your loop counters, because there is no such thing as a fraction of a loop (it always checks for TRUE OR FALSE for for(*;counter<=max;*) ), & an integer never messes up like that.

Share this post


Link to post
Share on other sites
Wait, the kind that stretches off towards infinity in every direction?

Well, if you want to use 3d hardware acceleration, you''ll need to iterate through a display list sort of like the other peeps have posted.

If you want to get in depth on the subject, you''d want to think about either creating some sort of culling algorythm or raytracing engine. I''m thinking you''re thinking of closely spaced cubes, with an animated fly-through of?

That''s the only (in)famous one that I can think of. And I don''t consider that famous really... although I have seen it... .

Also, the AP is right for the wrong reasons. The float fors will work just fine ( (12.3 <= 12.0) evaluates to false, so the loop will end just fine... and (1.0+1.0+1.0+1.0+1.0 <= 5.0) could evaluate either true or false - but in order to get a smooth transition you''d need to blur out to fog anyways.

However, integer math is faster than floating point math. Hence switching to ints will create an infentesimly small speed boost.

If you want to change the orientation of the grid, glRotatef, glScalef, and glTransformf should make it possible to change the angle/scale/transformation of the cube grid without needing to change your loops.

For a raytracing engine, you''d probably want to use the floats so you can change scales without imlpementing a matrix stack akin to OGL (although that might be the better idea in the long run).

On the culling note, I dont just mean FOV culling. Assuming you had, say, .9u sized cubes with .1u sized gaps, and you were at the intersection of 3 such gaps (aka, equadistant from 8 cubes) the only cubes you''d be able to see would be the ones directly bordering your x/y/z axis. Aka, looking at the cubes you needed to render from another angle, it''d look like an extruded + symbol with another plane cutting it in half.

For < 50% cube sizes (aka, where the distance between cubes is greater than their edge lengths), you''d need to render along 45 degree angles as well. As you continue to get smaller, you''d need less and less culling. at 10% cube sizes, I would only worry about FOV culling and backface culling. Everything else would be superflous.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!