Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » 2.5D game questions

This thread is locked; no one can reply to it. rss feed Print
 1   2   3 
2.5D game questions
Kanzure
Member #3,669
July 2003
avatar

I'm interested in creating a 2.5D game. 2.5D, as in "voxels". Not 'pixels', or 3D objects - but inbetween (or something). I would like to know the following:

(1) Is Allegro a good library for creating 2.5D games?

(2) Are there any open source projects or tutorials that describe how to go about making 2.5D graphics?

(3) Know the equation for displaying a voxel?

Any help would be hot. :)

Kitty Cat
Member #2,815
October 2002
avatar

1) Yes, as long as you're willing to write your own renderer. There were tons of threads about raycasting (or raytracing, I can never get them straight) a while ago, which are in essence 2.5D engines.

2) Try and search for said raycasting/tracing threads. They had full fledge engines w/ code in them practically.

3) For each voxel, draw voxel? Dunno.. check out the Build source.

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Oscar Giner
Member #2,207
April 2002
avatar

A Voxel is just a square. The size of the square is inverse proportional to the distance. You can use allegro 3d math routines to implement translation, rotation and the 2d projection.

Kanzure
Member #3,669
July 2003
avatar

I'll look at raycasting/raytracing. I was looking for an actual formula for displaying a single 'voxel'. For most programming languages, blit would blit a group of pixels..but what about blitting a voxel?

Kitty Cat
Member #2,815
October 2002
avatar

Just blit each voxel as a filled rectangle, and come up with a simple algorithm to cull unseeable voxels.

BTW, "voxel" is a single 3D pixel. A voxel model is made up of voxels.

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Kanzure
Member #3,669
July 2003
avatar

Quote:

Just blit each voxel as a filled rectangle

Such as, get the voxel 'texture' (much like how 2D RPGs have tiles), and then rotate that image, to create the '3D' look??

Obviously, I'm in need of much help.

Kitty Cat
Member #2,815
October 2002
avatar

A voxel doesn't have a texture, much like a pixel doesn't have a texture. First, you loop through each voxel in a model, determining which ones can be seen. Then for each one that can be seen, you use rectfill (or quad3d w/ POLYTYPE_FLAT if you want tilt) to color the area of the screen that voxel takes up (the closer the voxel, the bigger it is, ect).

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Maverick
Member #2,337
May 2002

Kanzure said:

I'm interested in creating a 2.5D game. 2.5D, as in "voxels". Not 'pixels', or 3D objects

Traditionally (to my knowledge, anyways), "2.5D" is generally used to describe the rendering in Doom (and similiar) engines, where it appears to be 3D, but every wall is restricted to being perpendicular to the ground plane.

Kanzure said:

(3) Know the equation for displaying a voxel?

It's the same as displaying any other 3d object: rotate, translate, and scale it from world space to camera space, project it into 2d, and draw it. As Kitty Cat said, drawing is a simple matter of blitting a quad to the screen of the appropriate size (generally, size = 1/z * original_size)

For rendering an entire scene of voxels, you'll want to sort them for back-to-front draw ordering, use z-buffering, or use deferred rendering techniques (like the horizontal span method Allegro's 3d routines used to use, but apparently don't anymore). Essentially, the same things you worry about when rendering polygons; just every polygon is square, and always faces the camera.

-Maverick

-----
"the polls here don't change as much because I believe so much in free speakin' that I want everyone a chance to vote at least once, and possibly a few dozen times, that way they are really heard." -Matthew Leverton

Tobias Dammers
Member #2,604
August 2002
avatar

Generally, voxels are just the same as pixels, except they're 3D, not 2D (and they're not 2.5D, either). Which means that where a pixel is a little square on a plane (a.k.a. 2-space), a voxel is a little cube in a 3-space. Pixels are parts of bitmaps (which are usually 2-dimensional arrays of pixels), voxels are parts of voxel maps (which are then 3-dimensional arrays of voxels). The usual approaches to this are:
a) For each voxel, draw a complete cube (correctly projected to a 2D screen)
b) Use a ray tracing algorithm to find the correct voxel for each screen pixel.
Obviously, a) is better when the voxels are much larger (something around 10 times the size) than screen pixels, which is usually not the case, so b) is the way to go.
The problem with this is that to get an acceptable resolution, the voxel map must be quite large and will eat lots of memory (just give it a shot: figure out the size of a 256x256x256 voxel map with 8 bit color depth - have fun!).
This is where 2.5D kicks in: A 2.5D terrain has all voxels on each position (x|y) filled with the same value up to a certain z-height. All voxels above that are "clear". With this knowledge, we can reduce the storage to a 2D array of heights (the height map) plus a 2D array of colors (the color map or texture), which is absolutely acceptable. Please note that this representation is not a voxel one anymore, but just a heightmap. It is not capable of handling all the scenarios of a voxel map.
Now that we have a heightmap, a variant of rendering approach a) becomes more useful - we can now divide the surface into triangles instead of rendering each voxel independently, which is exactly what most 3D terrain engines do. This way, it is relatively easy to benefit from 3D hardware acceleration and such, as well as "simplify" the terrain for performance boost. Approach b) is still good, though, especially if there is no 3D hardware, or if you can profit from some more assumptions (for example you could use a fixed camera height and pitch, allowing for a lot of pre-calculation to save precious cpu time).

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

Oscar Giner
Member #2,207
April 2002
avatar

Quote:

Which means that where a pixel is a little square on a plane (a.k.a. 2-space), a voxel is a little cube in a 3-space.

No. A voxel is represented by a filled square, not by a cube. Haven't you play any game that uses voxels? It's clear they use filled squares.

I wouldn't use Tobias method of saving a voxel space in memory. Just have a Voxel type, which have x, y, z and color properties. Then have a list of these objects. Draw each voxel as Maverick said.

gnolam
Member #2,030
March 2002
avatar

Quote:

No. A voxel is represented by a filled square, not by a cube.

No, a voxel is indeed a cube in 3d space :) (the word even stands for "volume pixel").

Quote:

Haven't you play any game that uses voxels? It's clear they use filled squares.

Have you ever seen an MRI scan? ;)

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

Oscar Giner
Member #2,207
April 2002
avatar

But we're talking about implementing it for a game. I'm talking about what people understand by voxel in game development. If you're going to do it drawing cubes, then better give up and use polygons: will look better and run much faster.

Tobias Dammers
Member #2,604
August 2002
avatar

Quote:

No. A voxel is represented by a filled square, not by a cube. Haven't you play any game that uses voxels? It's clear they use filled squares.

I was pointing out the difference between voxels and pixels here, not the actual techniques used to render voxels. If you read my post a bit more closely, you will see that I don't really recommend rendering voxels as cubes, but rather to use ray-tracing or a terrain tesselation algo, or to render them as verticals lines or rectangles.
Voxels represent cube-shaped regions in a 3-space, pixels represent square-shaped regions in a 2-space (assuming equally sized dimensions). That does not mean you must render a voxel as a cube. Neither does it mean that you have to render a pixel (or texel) as a square (just consider trilinear filtered textures - or a traditional monitor, which makes three more or less elliptic blobs).
It is important to understand what voxels represent in order to employ techniques to render them.

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

Korval
Member #1,538
September 2001
avatar

Quote:

Traditionally (to my knowledge, anyways), "2.5D" is generally used to describe the rendering in Doom (and similiar) engines, where it appears to be 3D, but every wall is restricted to being perpendicular to the ground plane.

Actually, the traditional concept of 2.5D is a game that is 2D in nature but 3D in graphics. Viewtiful Joe would fall into this category.

Kanzure
Member #3,669
July 2003
avatar

Quote:

will look better

Quote:

Actually, the traditional concept of 2.5D is a game that is 2D in nature but 3D in graphics.

Exactly.

So..a heightmap? But somebody said here that it won't be true 'voxels'. (?) What about displaying voxels via a linked list, for speed issues - that way it won't be just a 256x256x256 map x8 bit color. It would be a 'theoritcal' 256^2 map, or something...right? Would that be faster?

Am I confused, mucking up this entire thing? Does anybody have any suggested sites I can visit? Are voxlap/terraVox good examples?

gnolam
Member #2,030
March 2002
avatar

"True voxels" will require either projection/drawing of all visible voxels or raytracing of some kind.

I don't know about voxlap, but terraVox is a simple 4DOF (no looking up or down) wave surfing heightmapper, as described here (and that's a great tutorial BTW :)).

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

Korval
Member #1,538
September 2001
avatar

Quote:

Exactly.

I'm not quite sure what you're trying to say.

A Voxel is merely a method of storing (and, with a voxel renderer, rendering) 3D data. This doesn't say anything about having 2D gameplay. Hence, this has nothing to do with making 2.5D games.

That aside, voxels are generally considered a pretty bad idea, in terms of a method for representing 3D data. Especially if you want to render it.

Voxels are hard to model with, since no modelling package actually supports them. They're notoriously difficult to render with, and the results usually don't look any better than regular polygonal surfaces, and that's if they don't look far worse. And, certainly, no 3D accelerator supports them. As such, there is really little point in working with them.

Kitty Cat
Member #2,815
October 2002
avatar

Well, they are useful if you need to represent 3d objects in a software environment. As for their look, they're definately worse than polygonal models, but I think they're kind of a mix between polygonal models and 2d sprites. They get pixelated like sprites, but are fully 3D. And at best, you can just use a series of rectfill's to render them, instead of textured 3d polygons (Ken Silverman's voxel editor makes them look like legos, though.. :o though the editor draws them as full-on lit cubes, not flat rectangles).

That said, however.. if you're going to be using 3d hardware acceleration, or if you can get your hands on a good (fast) software 3d renderer, you might do better to use polygonal models. Through the software route, it may bog the cpu a bit more, but as I said, polygonal models can look a lot better than voxels, and voxels end up taking more disk space.

The way I see it: voxels are a good replacement for 2d sprites in 2.5d worlds (Doom, Build, ect). Polygonal models are better in 3d worlds (Quake, Unreal, ect). But they are by no means restricted to those types. It depends on what's needed and how they're applied (polygonal models for objects, voxels for translucent fog, for example).

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Korval
Member #1,538
September 2001
avatar

Quote:

Well, they are useful if you need to represent 3d objects in a software environment.

In what way? A decently well-optimized software engine on modern machines, or even relatively recent ones, can render quite a few polygons. Think back to the 3D games right before the Voodoo 1 came out. You had games like Earthsiege, MechWarrior 2, and X-Wing vs Tie Fighter, all of which were quite capabile of pumping out a decent number of textured triangles. And those had to run on Pentium 75 systems with really crappy RAM access, not the multi-GHz monsters of today.

I wonder what a modern optimized 3D rasterizer would look like.

Kitty Cat
Member #2,815
October 2002
avatar

Quote:

A decently well-optimized software engine on modern machines, or even relatively recent ones, can render quite a few polygons.

Of course. But as I said, it depends on application. And also, rectfill'd voxels won't bog the CPU down as the resolution increases (or the models get closer) as much as polygons will, especially since even Allegro can tap into some hw accel for the rectfills, if writing direct to vram.

But I'll say again. Yes, models look better, and with a good software renderer can keep pace with voxels. But, I also don't think you should have comparitively good quality models in a rather barren/Wolf3d-like world. It would stand out way too much, imo. Even Doom would be pushing it if you had good models, although that could probably work.

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Chris Katko
Member #1,881
January 2002
avatar

Well, if you want to get technical. Voxels are better than polygons, right? You just need a high resolution model. It's the 3D equivalent of a bitmap. So resolution applies. Just like a low resolution bitmap won't look nice, nor will a voxel map/model.

AFAIK, medical scanners normally use voxels to build 3-D images. It wouldn't really make sense to represent a point as a polygon.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Kitty Cat
Member #2,815
October 2002
avatar

Thing is though, is that voxel's would take up a lot of memory/diskspace (especially if animated). I'm not sure who "owns" the voxel format, but Ken's docs on it have it severely size-restrained (I think it was about 256x256x64 max.. but I don't remember), and it can only use 8-bit color.

Obviously, you're not required to abide by these restrictions. Just make your own editor and tweak the format a little, and poof. But, considering the OP, and that he probably wants to keep it simple (if I'm wrong, I sincerely apologize), that would require yet more work.

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Korval
Member #1,538
September 2001
avatar

Quote:

And also, rectfill'd voxels won't bog the CPU down as the resolution increases (or the models get closer) as much as polygons will, especially since even Allegro can tap into some hw accel for the rectfills, if writing direct to vram.

But you can't rasterize a voxel image using rectfills. Remember, each voxel element is effectively a 3D cube. You cannot guarentee the angle of the camera (and if you can, why not just blit a 2D sprite and be done with it), so you can easily be looking at the cube at various angles. Most of these angles don't produce a 2D projection that is a rectangle. They produce something more akin to a polygon.

Quote:

But, I also don't think you should have comparitively good quality models in a rather barren/Wolf3d-like world. It would stand out way too much, imo. Even Doom would be pushing it if you had good models, although that could probably work.

Where does this Doom/Wolfenstein 3D stuff keep coming from? Neither of these games used voxels. For non-wall objects, they used what would be called "imposters". These are sprites that are created from various angles so that, when the camera is in a particular direction, an appropriate sprite can be blitted that looks somewhat close to what a real 3D model would have.

And if you're bothering to have voxels at all, then leverage that power and build the world out of them. No need to use that "ray-casting" crap.

Quote:

Well, if you want to get technical. Voxels are better than polygons, right?

No. Voxels are 3D raster images of a model; a 3D sprite, for all intents and purposes. They are digital.

Triangles are 3D vector representations of a model. They are analog, to within floating-point precision.

It is best to postpone analog-to-digital conversion for as long as possible. This allows for filtering and antialiasing techniques to be done specifically for the display in question.

For 2D, raster images are OK usually, because you mostly only look at them in one orientation. The "analog-to-digital" conversion doesn't change if you do it before the final viewing or after.

For 3D, the orientation is never guarenteed. It can be stretched and rotated in 3 dimensions. As such, a raster representation, regarldess of resolution, can never be as correct as a vector represntation. Coupled with the fact that vector graphics take less space and time to render, what more do you need?

Kitty Cat
Member #2,815
October 2002
avatar

Quote:

But you can't rasterize a voxel image using rectfills.

Why not? Just calculate the position of each voxel, it's distance to the camera, and use rectfill to stretch it. Granted it's not the best way to rasterize it, but in software, such shortcuts are usually alright. Especially since 2.5D engines don't typically have any z-tilt so all you'd really lose is the edge shading. and even if there is z-tilt, you could go with POLYTYPE_FLAT quad3d's, which would still be faster than POLYTYPE_?TEX*, and still scale better.

Quote:

Remember, each voxel element is effectively a 3D cube.

Right. But that doesn't mean it has to be rendered as such.

Quote:

Where does this Doom/Wolfenstein 3D stuff keep coming from? Neither of these games used voxels.

No, but the OP mentioned a 2.5D game, which is what Doom/Wolf-3D are, and voxels would be pretty well suited for that type of visual environment, IMO.

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Niunio
Member #1,975
March 2002
avatar

Quote:

Where does this Doom/Wolfenstein 3D stuff keep coming from? Neither of these games used voxels.

But Blood and Shadow Warrior do, and both use Ken Silverman's Build Engine, also used int Duke Nukem 3D, Redneck Rampage and more.

Quote:

A voxel is represented by a filled square, not by a cube. Haven't you play any game that uses voxels? It's clear they use filled squares.

Ken is working in a 'pure' voxel engine, and seeing the screenshots I'm not sure if he's using poligons or cubes...

BTW, I'm now writing a tutorial about how to write a simple landscape voxeled renderer that will be published at Pixelate. I'll try to finish it before the 14th issue.

-----------------
Current projects: Allegro.pas | MinGRo

 1   2   3 


Go to: