Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

11991 Posts in 1587 Topics- by 3508 Members - Latest Member: NevilleKemp

26. May 2012, 04:53:59 pm
Xith3D CommunityGeneral CategorySupport (Moderator: Marvin Fröhlich)Xtih newbie, needs help
Pages: [1]
Print
Author Topic: Xtih newbie, needs help  (Read 483 times)
Ashbad
Just dropped in

Offline Offline

Posts: 5


I would know -- I'm a 2 bit gray Witchdoctor


View Profile WWW Email
« on: 27. February 2011, 11:05:28 pm »

Hello, I am new here to the Xith3D community and the library itself, though after reading some comparisons between this and Java3D, and going O.o over LWJGL (with raw OpenGL, which is fast but I prefer not to code 20 lines to draw a rectangle Wink) I decided to use Xith as my preferred Java 3D library.

Now that I've told my life story, I would like to ask a few questions.  I am making a game that uses Primitive 3D shapes (cubes with textures) as tiles, in a 1000x1000x200 tiles map (though however not all of the cells on the map of filled, of course Wink) in a similar fashion to... I guess I can use Minecraft as my comparison, since it will use a similar 'cell-based' environment, though Minecraft uses raw OpenGL from LWJGL instead.  Here is my question:  what would be the best way to implement this map?

I already have a few possible ways I thought out, the most practical of which are:

- Initiate a Cube[1000][1000][200] array of cube objects to be added to the main scenegraph, and then using StaticTransform on each cube, move them to their right place (and then maybe put like a huge 'fog' thing that hides all tiles more than 50 tiles away to add performance speed)

- Initiate a 100x100x100 scenegraph with blocks that has blocks whose textures change every frame comparatively to the part of the int[1000][1000][200] buffer to be shown to player, based on his coordinates

... and all the other ideas suck Smiley (and these probably do as well).  So, I was wondering, does anybody have an idea of how I can implement this with a respectable framerate?  and possibly without consuming much RAM or processing power?

And question 2: how do you make blocks translucent?  Grin

Logged

ChrisE
Becoming dependent
**
Offline Offline

Posts: 104


View Profile
« Reply #1 on: 28. February 2011, 05:06:18 pm »

Hello, I am new here to the Xith3D community and the library itself, though after reading some comparisons between this and Java3D, and going O.o over LWJGL (with raw OpenGL, which is fast but I prefer not to code 20 lines to draw a rectangle Wink) I decided to use Xith as my preferred Java 3D library.

Hello there!


Quote
Now that I've told my life story, I would like to ask a few questions.  I am making a game that uses Primitive 3D shapes (cubes with textures) as tiles, in a 1000x1000x200 tiles map (though however not all of the cells on the map of filled, of course Wink) in a similar fashion to... I guess I can use Minecraft as my comparison, since it will use a similar 'cell-based' environment, though Minecraft uses raw OpenGL from LWJGL instead.  Here is my question:  what would be the best way to implement this map?

We'll address that in a second.

Quote
I already have a few possible ways I thought out, the most practical of which are:

- Initiate a Cube[1000][1000][200] array of cube objects to be added to the main scenegraph, and then using StaticTransform on each cube, move them to their right place (and then maybe put like a huge 'fog' thing that hides all tiles more than 50 tiles away to add performance speed)

This is almost certainly going to exhaust all of your memory, and might bring the scenegraph of Xith to its knees.

Quote
- Initiate a 100x100x100 scenegraph with blocks that has blocks whose textures change every frame comparatively to the part of the int[1000][1000][200] buffer to be shown to player, based on his coordinates

This has potential. More in a bit.

Quote
... and all the other ideas suck Smiley (and these probably do as well).  So, I was wondering, does anybody have an idea of how I can implement this with a respectable framerate?  and possibly without consuming much RAM or processing power?

It's a hard problem.

Quote
And question 2: how do you make blocks translucent?  Grin

Code:
TransparencyAttributes ta = new TransparencyAttributes(TransparencyAttributes.NICEST, trans);
ta.setMode(BlendMode.NICEST);
    ta.setEnabled(true);
    shape.getAppearance(true).setTransparencyAttributes(ta);

So, let's look at your problem. You've got a world full of blocks, and want to use Xith to render a subset of that. The naive approach is to fill the scenegraph with blocks for each cube. This will choke the scenegraph, most likely.

A better way of looking at this is to consider the data in the problem: a large 3D array of blocks of different types. So, if you allow yourself to group similar blocks into larger and larger cubes (my colleague suggests the term "chunks" while reading over my shoulder), you only have to worry about rendering the larger chunks. For a chunk made of 3x3x3 blocks, you only render 1 Cube, saving 8! A chunk of size 5x5x5 saves 124 Cubes. The saving increases as you make the chunks larger in volume.

To do this, we see a suggested form of the solution: one data structure for the world, and one for the visual representation.

The world data structure contains an array of blocks of known size and shape, so you can quickly find the blocks you need by a quick calculation (think on how you calculate a pixel's address in a frame buffer; this is similar). I imagine that you want blocks of various types. Assuming that you want 255 types of blocks, and an "air" block, you can get away with using a Java byte primitive (signed 8-bit integer type). If you want to add hitpoints, then you look at adding another byte. By this point, you've got 16 bits per blocks, so you could just have a big array of shorts.

The visual representation would be a collection of chunks for similar types of blocks, drawn as Cubes. As you move around, you calculate the chunks needed from the world data structure and generate the Cubes needed to represent them. This might be a somewhat heavy option.

Those're just my first thoughts on the matter.
Logged
Ashbad
Just dropped in

Offline Offline

Posts: 5


I would know -- I'm a 2 bit gray Witchdoctor


View Profile WWW Email
« Reply #2 on: 28. February 2011, 05:14:50 pm »

that's a good idea.  But then won't it be a pain to split the big chunks into smaller chunks after one of the 9 cubes turns to air?
Logged

ChrisE
Becoming dependent
**
Offline Offline

Posts: 104


View Profile
« Reply #3 on: 28. February 2011, 05:22:44 pm »

Yep.

(also, this might be interesting for you: http://notch.tumblr.com/post/434902871/per-request-this-is-how-the-new-lighting-will-work)
Logged
Ashbad
Just dropped in

Offline Offline

Posts: 5


I would know -- I'm a 2 bit gray Witchdoctor


View Profile WWW Email
« Reply #4 on: 28. February 2011, 05:26:22 pm »

I think that was an awesome idea you had, but hard to implement.  I have another idea, a little bit less memory based:

I might make the map 1000x1000x100 and then split the map into 100 different 100x100x100 chunks.  This would be 1,000,000 per scenegraph, is this possible and somewhat fast, or still quite large?
Logged

ChrisE
Becoming dependent
**
Offline Offline

Posts: 104


View Profile
« Reply #5 on: 28. February 2011, 06:25:06 pm »

That could work. I'd suggest writing it up to try it with different chunk sizes, and see what size works best. I would like to hear how this turns out for you!
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic