canvas-raycasting | Canvas Raycasting Experiment | Canvas library
kandi X-RAY | canvas-raycasting Summary
kandi X-RAY | canvas-raycasting Summary
Requires HTML5 canvas and requestAnimationFrame support. Tested with Firefox 19 and Chromium 23. Chromium seems to be slightly faster in my tests, but I get around 30 FPS in both browsers. I did this to try the HTML5 canvas element and to play around with Javascript. This demo is the result of a couple of hack sessions, so please keep it in mind when reading the code (as in "there are probably better ways of doing this"). Juan J. Martínez .
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of canvas-raycasting
canvas-raycasting Key Features
canvas-raycasting Examples and Code Snippets
Community Discussions
Trending Discussions on canvas-raycasting
QUESTION
I am trying to build a raycasting-engine. i have successfully rendered a scene column by column using ctx.fillRect()
as follows.
the code i wrote for above render:
...ANSWER
Answered 2019-Jul-03 at 18:57The way that you're mapping (or not, as the case may be) texture coordinates isn't working as intended.
I am looking for the Maths used to produce pseudo 3d effect using 2D raycasting
The Wikipedia Entry for Texture Mapping has a nice section with the specific maths of how Doom performs texture mapping. From the entry:
The Doom engine restricted the world to vertical walls and horizontal floors/ceilings, with a camera that could only rotate about the vertical axis. This meant the walls would be a constant depth coordinate along a vertical line and the floors/ceilings would have a constant depth along a horizontal line. A fast affine mapping could be used along those lines because it would be correct.
A "fast affine mapping" is just a simple 2D interpolation of texture coordinates, and would be an appropriate operation for what you're attempting. A limitation of the Doom engine was also that
Doom renders vertical and horizontal spans with affine texture mapping, and is therefore unable to draw ramped floors or slanted walls.
It doesn't appear that your logic contains any code for transforming coordinates between various coordinate spaces. You'll need to apply transforms between a given raytraced coordinate and texture coordinate spaces in the very least. This typically involves matrix math and is very common and can also be referred to as Projection, as in projecting points from one space/surface to another. With affine transformations you can avoid using matrices in favor of linear interpolation.
The coordinate equation for this adapted to your variables (see above) might look like the following:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install canvas-raycasting
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page