Jump to content
  • Advertisement

Archived

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

robertgamble

Any tutorials on Doom style engines?

This topic is 5761 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

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
Advertisement
Guest Anonymous Poster
just go around and find a SNES mode7 manual. its all about Zoom, Scale, Rotate afterall.

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
quote:

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


Outdated?? Hey, I''m doing raycasting! Being upto date isn''t really a priority

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!