Check the Pycasting demonstration short video
If you want to use the web in your computer, you should follow this steps.
- Python (v3.7+) installed.
- Git installed and configured
- pip (v3) instaled
git clone https://github.com/PabloCorbCon/pycasting.git
cd 2d-raycast
pip install -r requirements.txt
python app.py
python3 app.py
For contributing to the project read the CONTRIBUTING.md file
All the configuration of the application has been externalized to the code itself so that you can modify it to your liking in the simplest way possible.
You can see the default configuration in the CONFIG.json
file.
You can modify this configuration to your liking, for example to change the width of the tiles or the color of the walls.
You can also add walls to the game. Just go to the /walls/walls
configuration file section and you will see a list of values with this syntax.
[
[[a1, b1], [c1, d1]],
[[a2, b2], [c2, d2]],
...
[[aN, bN], [cN, dN]]
]
These lists represent Cartesian coordinates, in a plane a segment has a start point and an end point. This two points can be seen as a & b
where a = {x1, y1}
and b = {x2, y2}
. So the wall segments are determined in the form of:
[
[[x1, y1], [x2, y2]]
]
In our game we consider that {a, b} ∈ N
.
The so-called RayCasting is a technique designed to solve multiple problems in ray tracing to an object by simulating natural light rays. In RayCasting a ray is traced from a point a
to a point a + 1
as long as this ray does not collide with any obstacle.
Taking this into account, we can launch rays that advance in a certain direction. These rays will never stop moving unless they hit an obstacle.
Techniques as complex as Envidia RTX can be simplified to the maximum with a two-dimensional demonstration like the one in this repository. After all, Ray tracing is based on bouncing light rays with the most light-like properties possible against solid objects.
When a casting beam detects an obstacle, it can produce a signal, this could be used for countless purposes such as improving the physics of a simulator or even improving the layout of lasers in a game. The possibilities are endless. To check the distance of the ray to an object, you can use any mathematical equation. In this project we use the Euclidean distance formula to calculate the distance.
This project is under the Apache 2.0 License
Copyright 2020 - @pablocorbcon
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.