Archived

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

robertgamble

Any tutorials on Doom style engines?

Recommended Posts

All of the raycasting tutorials I can find are grid based.. I.e the map is something like this:- 1,1,1,1,1, 1,0,0,0,1, 1,0,0,0,1, 1,1,1,1,1, I would like a tutorial, or maybe a simple well commented code example, showing how to do less limiting raycasting engine. I figure that instead of the ray being extended per grid square it''ll have to be extended per pixel, but I don''t know how to check if the ray has hit a wall.

Share this post


Link to post
Share on other sites
Good question.

The way it''s done without a grid is with 2d polygons.
For this example, I''ll just use lines.

Say you have a two walls (a-b, b-c):

b .
. .
a c
X

and your standing at X. You want to calculate the view by ''casting'' rays.

First create a line of length n (where n is the the furtherst away you want the player to see), and rotate through your field of view. Your left with a ''ray'' (x1,y1 - x2, y2).

Check to see if there is an intersection between your ray and each and every one of your wall line-segments. Remeber the closest intersection. Look for a line intersection algorithm on the web and you''ll find one.

Once you know what the closest intersection is, you can determien how to draw it.

Repeate for each ''ray'' that your going to cast.

Heres some pseudo-code:

increment = 90degrees / screen_width;

x = 0;
for ( angle = view-45; angle < view+45; angle += increment)
{
myRay = CreateNewRay (angle);

closestWall = INFINITY;
for ( i = 0; i < number_of_walls; i++)
{
distance = CheckIntersection ( myRay, wall);
if (distance < closestWall)
{
closestWall = distance;
color = wall[i]->color;
}
}

DrawOurWall ( x, distance, color);
x++;
}

Thats pretty much it. The reason people used to use grids was because they''re faster. The polygon method gives you a lot more options though (like Doom).

It doesnt take much to add textures, etc..

You can optimze your code a lot. Just for starters you dont have to check EVERY wall.

Hope this helps,
Will

Share this post


Link to post
Share on other sites
I''ve got something up and running Right now it''s very simple, and is checking against all walls (this is where a BSP tree comes in, right?), and is surprisingly fast

Right now I''m calculating wall height like this:-

tmp=(Math.abs(ints[0]-pX)*Math.abs(cos[i]))+(Math.abs(ints[1]-pY)*Math.abs(sin[i]));
tmp=(20/tmp*210); if(tmp>Height){Height=tmp;bg=walls[c].bg}


where ints[0] is the intersection x coordinate, and ints[1] is the y coordinate.

This code is just taken from my grid based raycaster (and then with some values adjusted to make it look right), and whilst it works I suspect that it is very wrong!! (for the most part everything looks fine but there''s some fisheye type problems..). What''s the correct way of doing it?

Cheers!

Share this post


Link to post
Share on other sites
Glad to hear that it worked out. :D

If it looks right, then it probably is. The code for the grid based system and the line based system should be identical in the calculation for distance.

I''ve never actually implemented anything to correct fisheye, so I might be full of it at this point, however there is a lot of info. out there on it..

I imagine you would adjust the height of your walls (as they are drawn on screen) with some value that changes as you move along the horizonatal.

ie: height *= fisheye[screen_x];

Another way of speeding it up is to use a method called ''portals''. Generally, rather than having one huge map, you instead have many ''rooms'', with ''portal'' walls that connect one room to another. When your ray intersects a ''portal'' wall, you continue the ray in to the adjoining room. The saves you from having to calculate intersections for EVERY stinking wall.


Once your done with this you should try Voxels. The results can be very impressive, and the idea is generally the same.


Will

Share this post


Link to post
Share on other sites
quote:
Original post by RPGeezus

Once your done with this you should try Voxels. The results can be very impressive, and the idea is generally the same.




Voxels look good, but isn''t that an outdated technique that isn''t used anymore because it cannot be hardware accelerated ?

Rob

Share this post


Link to post
Share on other sites
Outdated? Probably. Can''t be accelerated? I think there is an article here on gamedev (or maybe FlipCode) on doing that very thing.

I think It''s worth doing for no reason other than the fact that it''s rewarding.

Will

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Doom didn''t use raycasting.
It was based upon a 2D BSP with constant-z perspective texture mapped polygons (pretty much as stated above).

Share this post


Link to post
Share on other sites
so you''re outdated if you don''t use the newest gf4 pixelshaders?

well, i prefer to raytracing. am i now outdated, or indated, or predated, or what? i think its the future (and voxels then can come back with ease)

it doesn''t mather if its hw or not. it does mather if it looks cool. voxel do. and espencially on newest p4 2.5 giga and such, they can look awesome (just imagining how they look as i played the whole outcast on a p3 500:D)

"take a look around" - limp bizkit
www.google.com

Share this post


Link to post
Share on other sites
http://www.elephantsneverforget.co.uk/rg/px/new-3d.asp

It doesn''t seem to be fisheye really.. But kind of the reverse? The walls seem to kind of wrap around you, but they are displayed where they should be and look kind of correct. Any help would be much appreciated.

Share this post


Link to post
Share on other sites
Um - I have to disagree. Everything I find about Doom says raycasting. But I am gonna drop so as not to start an argument.

Check this out. In my wanderings - I have found a list of reviews about Doom. Most were written in... 2001!?!?! What? Just read them...

All the reviews here.

Was this guy even playing the right game?? Arm blowing off? Parts on the screen???



God was my co-pilot but we crashed in the mountains and I had to eat him...
Landsknecht

Share this post


Link to post
Share on other sites
this guy played in on the gameboy, if you check at the bottom, you see platform: gameboy..

:D

and doom used raycasting to draw the bsp. so what? both work perfect together. wolfenstein used raycasting on a grid. quake was the first rastericing game of carmack. the first full 3dgame as well.

"take a look around" - limp bizkit
www.google.com

Share this post


Link to post
Share on other sites
Hi in raycastin gyou draw the walls with 1 pixel thick strips at a time(at least in tricks of the game programming gurus that''s what it says.) what would be the highest resolution be that you could render like this in 16 bit color and still get good performance? also would it be more worthwhile to use the ddraw blitter for resizing and blitting or would it be as fast to do it in software?
thanks in advance.

Share this post


Link to post
Share on other sites
hey DavePermen, not to nitpick,but wasnt Descent released before Quake? I think it was the first 3d Game. (character models were 3d, and you had 6 DOF) Altho it used sprites for ammo packs and such, but even Quake had some sprites in it. (bubbles and gold spheres)

Share this post


Link to post
Share on other sites
I''ll be damned. Descent was released in 1994 while Quake didn''t come out till ''96. Very cool bit ''o history there. I guess Id wasn''t the first. Way to nail it, Waramp!



God was my co-pilot but we crashed in the mountains and I had to eat him...
Landsknecht

Share this post


Link to post
Share on other sites
quote:
Original post by WarAmp
hey DavePermen, not to nitpick,but wasnt Descent released before Quake? I think it was the first 3d Game. (character models were 3d, and you had 6 DOF) Altho it used sprites for ammo packs and such, but even Quake had some sprites in it. (bubbles and gold spheres)


the first carmack game

"take a look around" - limp bizkit
www.google.com

Share this post


Link to post
Share on other sites
Doom did not use raycasting whatsoever. It used a BSP tree. It walked the tree to render the scene with simple polygons.

Back in 1994 I released Wacky Wheels which used raycasting for painting the floor.

Biggest problem with ray casting is that you can suffer a lot of cache misses which hurts on todays processors.

I once thought that if we had a processor per pixel we could do real time raytracing. The theory seemed fine at the time until some bright spark told me that the memory read/writes would really hurt you. Unless of course you could have a small cache of memory for each processor

I hear that the next Playstation is going to have some kind of parallel processing. Interesting.

Share this post


Link to post
Share on other sites
Nope. Doom didn''t use polygons. If it used polys, it would have been able to do true 3D, not the 2.5 stuff that it used. Yes, it used a crude form of BSP tree to help in the process, especially with monsters and such. That dies not mean raycasting was not used. Do a google search for Doom or Doom engine. Everything that comes up says raycasting. No mention of poly rendering at all.

If you can show something that says otherwise, I''ll eat my words. But until then, Doom was a raycasting engine.


God was my co-pilot but we crashed in the mountains and I had to eat him...
Landsknecht

Share this post


Link to post
Share on other sites
yeah, ancientcoder, you''re very very wrong unfortunately. Doom was a raycaster and it used bsp trees for sorting and culling. I wrote a doom style engine except it was a portal engine instead of using bsp''s, and it looked exactly the same, just a different sorting/culling technique.

Share this post


Link to post
Share on other sites
In regards to a previous message the guy reviewing DOOM was actually talking about the DOS version. If you go to more reviews on the game he is listed under the DOS review. Kind of weird, I have to wonder if he actually played the game or if he just made stuff up based on media hype or something.

seed(time(NULL));
int i=srand()%100;
PrintWittyQuote(i);

Share this post


Link to post
Share on other sites