• Create Account

## wolfenstein 3D (How To)

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

8 replies to this topic

### #1!Null  Members

380
Like
0Likes
Like

Posted 01 October 2012 - 11:46 AM

So I'm trying to explore more methods of making games for experience.

And a friend of mine can make raycasting games quite well (Like Wolfenstein).

However He tried to explain how the code works and he just failed. Also I've checked a few places Online but theory doesn't work with me unless I see the code explained.

Can any of you wonderful GameDev people Help me out.

Maybe with some pointers (not 0x00000000) or some pseudo code examples to explain to me how to get at least a floor and ceiling done.

I hope someone can help.

/********************************************************************************\
/**********************He Who Dares, Wins**********************************\
/********************************************************************************\

### #2caldiar  Members

715
Like
10Likes
Like

Posted 01 October 2012 - 12:23 PM

POPULAR

With old raycasting engines used in games like Wolfenstein, Doom, etc... the world is actually two-dimensional. This is the origin for the "Z = Up/Down" standard that iD Software uses as the world was originally plotted on X/Y coordinates before they expanded upon it for their 3D engines.

You would have a map consisting of lines drawn out that describe a top-down view of the level and from the player's position, you would cast rays forward. Each ray will describe a vertical strip of pixels which will be a section of what's drawn to the screen. The number of rays you cast will affect the resolution of the sections.

The distance each ray travels until it hits a wall also determines how tall the section that ray creates will be. Typically you would set a threshold for the maximum height of a wall (64 units or w/e feels right). Parts of a wall that are closer will create a shorter ray which will result in a taller strip of pixels.

In the older raycasting engines the view was generally locked on an axis so you couldn't look up or down. The ceiling and floor was created by flooding the pixels that weren't defining a wall section with a solid color. You could do this by filling half the screen with 'floor color' and the other half with 'ceiling color' then draw the walls over that.

Take a look at this series of articles on raycasting for some sample code and excellent descriptions on how ray-casting works. You'll get your own ray-caster up and running in no time ;)

Edited by caldiar, 01 October 2012 - 12:26 PM.

### #3carangil  Members

518
Like
1Likes
Like

Posted 01 October 2012 - 03:50 PM

What rendering API are you targeting? If you are rendering in software (pixel by pixel), then you will want to proper raycasting like the old games did. There's many tutorials on how raycasting was done for wolf-3d style engines.

However, I would recommend you put a modern spin on it and draw with a hardware accelerated API. There are many advantages:
• When you are raycasting, you aren't drawing, you are just building a list of walls or floors that are visible to the player. You can then sort these by texture/material or whatever and just draw it.
• You can rotate on other axes for 'free'; just mess with the modelview matrix.
• Texturing walls and floors are easy; you don't have to deal with constant-z texture mapping
• You can use 3d models for characters instead of sprites
• If you're clever, a bump or displacement-mapped wolf3d level might look pretty good. You will be stuck in a 2.5D maze, but that doesn't mean the brick wall can't look bumpy and metal surfaces can't be environment mapped.
• When the engine gets advanced enough that you want to move on from raycasting to something else (like portals & sectors), you will have a bunch of code you can reuse.

### #4mholmes  Members

190
Like
0Likes
Like

Posted 01 October 2012 - 04:28 PM

You will need a basic understanding of tile maps or you can use a tile map engine to build the maps which in this case would be the hardest part in my eyes. You also need to research the games layout, NPC stats, monsters etc. Its very important in remakes you try to replicate them best you can but add your own flavor in as well. Hope that helps.

Edited by mholmes, 01 October 2012 - 04:28 PM.

### #5!Null  Members

380
Like
2Likes
Like

Posted 02 October 2012 - 02:24 AM

caldiar I just wanted to say thanks for the quick detailed reply.

/********************************************************************************\
/**********************He Who Dares, Wins**********************************\
/********************************************************************************\

### #6DpakoH  Members

1198
Like
2Likes
Like

Posted 02 October 2012 - 03:31 AM

you can check my post with some references and a sample for raycasting written in C# using XNA.

### #7MarkS  Members

2984
Like
0Likes
Like

Posted 02 October 2012 - 11:44 AM

However, I would recommend you put a modern spin on it and draw with a hardware accelerated API. There are many advantages:

• When you are raycasting, you aren't drawing, you are just building a list of walls or floors that are visible to the player. You can then sort these by texture/material or whatever and just draw it.
• You can rotate on other axes for 'free'; just mess with the modelview matrix.
• Texturing walls and floors are easy; you don't have to deal with constant-z texture mapping
• You can use 3d models for characters instead of sprites
• If you're clever, a bump or displacement-mapped wolf3d level might look pretty good. You will be stuck in a 2.5D maze, but that doesn't mean the brick wall can't look bumpy and metal surfaces can't be environment mapped.
• When the engine gets advanced enough that you want to move on from raycasting to something else (like portals & sectors), you will have a bunch of code you can reuse.

I don't need to start a new project... I don't need to start a new project... I don't need to start a new project... Gaah!

### #8caldiar  Members

715
Like
0Likes
Like

Posted 02 October 2012 - 03:18 PM

caldiar I just wanted to say thanks for the quick detailed reply.

Not a problem Ray-casters are always fun projects to work on. They're a very interesting piece of history. It's amazing to me, even today, the results you can get with the relatively simple code and basic trigonometry.

I'm really itching to put together a ray-caster now...

### #9!Null  Members

380
Like
0Likes
Like

Posted 03 October 2012 - 10:42 AM

Not a problem Ray-casters are always fun projects to work on. They're a very interesting piece of history. It's amazing to me, even today, the results you can get with the relatively simple code and basic trigonometry.
I'm really itching to put together a ray-caster now...

you totally should man, I like trying old things because it's good to get a sense of how things evolved.

If you wanna see the code then let me know

Edited by !Null, 03 October 2012 - 01:04 PM.

/********************************************************************************\
/**********************He Who Dares, Wins**********************************\
/********************************************************************************\

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.