Not logged in, Join Here! or Log In Below:  
News Articles Search    

 Home / General Programming / writing a raycaster Account Manager
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.

March 13, 2005, 01:18 PM

Hi everyone. I am interested in writing a raycaster in C++, but im not really sure where to get started. I would like something simple that I could build my game off of. After searchgin the net, all of the tutorials or source code is either very complex or out dated. If any of you have written a simple ray caster in C++ with MSVC C++ 6.0 or bloodshed dev C++ or know where I can find one, please tell me. Thanks in advance


March 13, 2005, 03:33 PM

If you really mean 'raycasting' and not 'raytracing', I'am your man. I have a little (around 2500 lines) raycasting engine in 100% pure Java (640x480 30 fps on a modern computer).
Here it is some features, maybe are been never see on a raycasting engine :
- Clean OOP design
- Efficient raycasting algorithm (only additions)
- Orthogonal walls
- Multiple view perspective available : classical, fish-eye
- Wall and floor texturing (but no perspective correction for the floor :( )
- Mip-mapping
- Sky-Box
- Room over room (like in Duke Nukem 3D)

I have sources for each evolution, it could be cool to understand my engine...
Now, I have no time... But the next holydays, I plan to convert it to C++ (Using SDL), adding physics (with ODE), nearly-perspective-correct-floor-texturing, adding some lookup tables.

The next evolutions planned :
- Non orthogonal walls
- real time ligthnening
- breakable walls

My goal is a playable pseudo-raytracing engine.


March 13, 2005, 03:56 PM

I might be interested in the C++ version wehn you have it done. However, I was hoping for something a little bit simpeler.


March 13, 2005, 05:03 PM

If you can wait 2 weeks (Exams...), I can give you what you want. You want only simple square walls with unique color ? Or with texture ? Tell me about the features you want.


March 13, 2005, 10:20 PM

Duke Nukem 3D didn't use raycasting.. :)


March 14, 2005, 01:15 AM

Really ? When you move you're head up or down, there is a typical visual artifact from raycasting engines.
A raycasting engine divide the screen into columns, shooting a ray for each columns to have distance information. The walls and the floor are displayed by using distance info, by stretching a slice of texture. The way to cast a ray could be different, many data structures for this.
- Wolfenstein 3D : Raycasting on a regular square grid world
- Doom 1 & 2 : Raycasting on a 2D BSP tree world
- Duke Nukem 3D : Raycasting on a portal world
- Blood : Raycasting on a portal world + voxel sprites
- My engine : Raycasting quadtrees, with splited squares !!!
- Add here your ideas...

To have more info, go to this site
It's the author of the Build Engine, used by Duke Nukem 3D, Blood, Shadow Warrior.


March 14, 2005, 05:51 PM

Nah, DOOM definitely didn't use raycasting. It was a basic 3D polygonal renderer, but walls could only be vertical. This means that walls can be drawn in vertical slices, and each slice has a constant Z, so perspective correction only needs to be done once per slice. This is documented in many places on the net; this question of "is DOOM rasycasting?" comes up often and there is much misinformation around.

If you have a look at the DN3D source code you'll see also that it uses a sector/portal system with texture mapping, similar to DOOM (except it doesn't use BSP trees). The look up/down hack results in a similar shearing artefact to raycasting, but DN3D is most definitely not raycasting. They do some ray intersection tests for collision detection and such (as does DOOM) but for rendering it essentially draws textured polys (with hacks and special cases to take care of things like vertical walls, horizontal walls, and sloped walls).



March 14, 2005, 06:19 PM

hey Marmakoide, I would be interested in your raycaster. I dont mind waiting till its done. what compiler did you write it in? I would prefer it have the ability to load textures, but it doesnt really matter, because I just want to learn how to write my own raycaster from this.


March 14, 2005, 09:44 PM

Im not a big raycaster guy, but im curious how it looks. Could u please post a couple of screenshots, perhaps?

Thanks a lot!

Also, since i dont know much, does raycasting use some sort of API, or is it like your "own" api sort of thing? Just some newbe questions =)



March 14, 2005, 11:14 PM

"This means that walls can be drawn in vertical slices, and each slice has a constant Z"

and this is different from raycasting how...?


March 14, 2005, 11:45 PM

Okay, fair enough on that point, but it still doesn't use ray casting :) They don't send out rays for each pixel on the screen. They use the painter's algorithm to draw walls. It's detailed in quite a few places (not least of all the sources).


March 15, 2005, 01:27 AM

- Thanks for the replies about Doom and Dukem 3D, it's the proof that we learn every day !
- The C++ version (Only a direct port from the Java source) will be done under a VC++ 7, with SDL for graphical low-level. In two weeks, I will have one week of holydays.


March 15, 2005, 02:29 AM

Fair enough =D It's the difference between front-to-back raycasting and back-to-front raycasting =D


March 15, 2005, 05:25 AM

Cool, maybe you could submit an IOTD? I am interested to see what you have done too! People have done some pretty cool stuff with low tech.. There's a pretty cool 2.5D DOOM-style renderer floating around that someone wrote with some really fancy features (fancy lighting, shadows etc). There's that Cube engine too which is pretty cool and just uses quad-trees IIRC.



March 15, 2005, 05:55 AM

I can't submit IOTD, it's no so impressive. Now, think about Duke Nukem screens with mipmapping, skyboxes, and 'cubic-style' maps, that's all... I will submit when the C++ port (One week), the lightning (An other week) and my map editor will work (Must be made from scratch !).

This thread contains 15 messages.
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.