An open API service indexing awesome lists of open source software.

https://github.com/rafapp/doomcaster

Project created to master C/C++ which renders a map created in the "map builder" using a ray casting algorithm in a style similar to games like Doom, or Wolfenstein. The map can be traversed with the wasd keys.
https://github.com/rafapp/doomcaster

3d doom graphics rendering videogames

Last synced: 4 months ago
JSON representation

Project created to master C/C++ which renders a map created in the "map builder" using a ray casting algorithm in a style similar to games like Doom, or Wolfenstein. The map can be traversed with the wasd keys.

Awesome Lists containing this project

README

          

DoomCaster

An exploration of 3D rendering



### What?
DoomCaster is a project that renders a pseudo-3D map using a raycasting algorithm. It has the following features:
- Map editor.
- Top-down raycast algorithm visualizer.
- 3D map, which can be explored with the WASD keys.

### Why?
I wanted to practice, and strengthen my C/C++ programming skills to become a more competitive programmer in the Game Development industry, as well as learn more about 3D graphics, 3D mathematics, and rendering algorithms as much as possible.

Doom is one of the most disruptive videogames ever created, as it set a new standard for the games industry, and was the stepping stone in the transition to 3D graphics in games. It began development in 1992, and was released in 1993 by John Carmack, John Romero, Adrian Carmack, Kevin Cloud, and Tom Hall selling more than one million copies!

I have nothing but respect for the developers of id software, since they are some of the game changers that moved the industry forward and a huge inspiration to me. It blows me away what they were able to achieve with the limited technologies they had during their time, so I wanted to learn how they did it firsthand!



>*The team at id software in 1993 from left to right: John Carmack, Kevin Cloud, Adrian Carmack, John Romero, Tom Hall, and Jay Wilbur*

### How?

#### C/C++
I started by refreshing my knowledge of C and C++. To do so, I created the programs learning.c and learning.cpp in the /learning folder, where I studied math functions, I/O, bitwise and logical operations etc. After doing so, I wanted to get started with 3D graphics.

#### OpenGL
OpenGL (Open Graphics Library) is a cross-platform API (Application Programming Interface) for rendering 2D and 3D computer graphics. I chose it, since it's standardized among the industry, and although its use is not as frequent nowadays, it can give a solid understanding of computer graphics.

My first step, was to create a simple program, this is the "Hello world!" of 3D graphics, which is drawing a triangle by connecting 3 vertex with different colors.



The original program was rather simple, so I decided to make the triangle spin using circle geometry, and the sin/cos functions ( Script is in /LearningFiles/Triangle ) and it spins given a movement speed, which is fun!

> In progress ...

#### Rays:

The aforementioned games build upon one of the foundations of 3D rendering, which is Ray Casting. To begin, we can define a ray in its parametrized form as a point $(X_0, Y_0, Z_0)$ with a direction vector $(D_x, D_y, D_z)$, where points in the line are accessed with a parameter $t$ which all lead to the following equations:
$$X = X_0 + (t * D_x)$$
$$Y = Y_0 + (t * D_y)$$
$$Z = Z_0 + (t * D_z)$$

These rays can be casted in multiple ways from a "camera," which is a perspective. The most popular ones are:

#### ***Isometric***

The projection lines are completely orthogonal to the screen, meaning completely "Straight." This perspective is used commonly in city building games such as Age of Empires, or StarCraft.




#### Perspective
The projection lines all funnel out from a single point, in a similar way to how light and depth are perceived by the human eye or a pinhole camera. This is the most used form of rendering in modern games, as it is the most realistic (to humans, I wonder how aliens see the world 👽).




>

#### The Ray Casting algorithm
We will be using one of the early forms of ray casting, which casts rays in a 2D map which translates to a 3D environment.

- In order to render the screen at any given point, the following steps are taken:
1. Given geometric definitions of game surfaces (i.e. walls) $n$ rays are projected at regular angle intervals, so that each ray can intersect with a different map element to be rendered on the screen.
2. We store the $t$ parameters from these rays in an array we call t[n], this gives us the distance in $x,y,z$ coordinates to a wall hit or wall exit.
3. We store the $S$ surface which was hit. This surface may have information such as material, transparency, and color and is stored in an array S[n].



Vieira L., Own Work, 2012

### Run it!
> In progress ...

### Resources used:
- OpenGL: https://www.opengl.org
- Learning OpenGL: https://learnopengl.com/Getting-started/OpenGL
- Wikipedia, ray casting: https://en.wikipedia.org/wiki/Ray_casting
- Wikipedia, id software: https://en.wikipedia.org/wiki/Id_Software
- Doom Fan Wiki, Logo: https://doom.fandom.com/wiki/Logo
- w3cschools, c++: https://www.w3schools.com/cpp/default.asp
- Video that helped me a ton: https://www.youtube.com/watch?v=eOCQfxRQ2pY