It is very interesting to me that you need to multiply the distance-to-wall by the cosine of the angle to transform the image from fisheye to normal. It makes me wonder, why is it that our eye in real life sees straight lines as straight, the way this demo renders the image? To illustrate the question, see https://en.wikipedia.org/wiki/File:Panotools5618.jpg – why do we see the world as in the bottom image instead of…
A first-person engine in 265 lines of JS
51–60 of 99 posts
Re: A first-person engine in 265 lines of JS
#52It is very interesting to me that you need to multiply the distance-to-wall by the cosine of the angle to transform the image from fisheye to normal. It makes me wonder, why is it that our eye in real life sees straight lines as straight, the way this demo renders the image? To illustrate the question, see https://en.wikipedia.org/wiki/File:Panotools5618.jpg – why do we see the world as in the bottom image instead of…
Re: A first-person engine in 265 lines of JS
#53I feel very pathetic from this. You could have given me 265K lines and I wouldn't have figured it out.
Besides, we all start somewhere mate.
Re: A first-person engine in 265 lines of JS
#54My raycast engine in Javascript needs a few more lines and works a little bit different, but gives also impressive results I think :) . http://simulationcorner.net/index.php?page=comanche
Re: A first-person engine in 265 lines of JS
#55It is very interesting to me that you need to multiply the distance-to-wall by the cosine of the angle to transform the image from fisheye to normal. It makes me wonder, why is it that our eye in real life sees straight lines as straight, the way this demo renders the image? To illustrate the question, see https://en.wikipedia.org/wiki/File:Panotools5618.jpg – why do we see the world as in the bottom image instead of…
It's not the distance to the points in the scene that determine where they appear in a perspective projection, it's the angle. For any single point on the screen/retina/projective plane, it can actually correspond to any distance from the camera/eye (i.e., a ray of possible points).
Re: A first-person engine in 265 lines of JS
#56Earlier quoted context omitted.
2D canvas should be hw accelerated too on most browsers.
Yes, however the raycasting is drawing pixel by pixel. That part is not hardware accelerated, and that is the expensive part. That is that part that shaders speedup a lot, by delegating a lot of the work to the GPU. Just compare with this pure fragment shader demo: https://www.shadertoy.com/view/MsS3W3
Re: A first-person engine in 265 lines of JS
#57Re: A first-person engine in 265 lines of JS
#58My raycast engine in Javascript needs a few more lines and works a little bit different, but gives also impressive results I think :) . http://simulationcorner.net/index.php?page=comanche
I really like how your code uses much less cpu than that of the article. whats the trick ?
1. No fullscreen
2. I update the screen only if a key is pressed.(No rain, that has to be rendered all the time)
3. I don't use any costly canvas functions. I render everything myself in a pixelbuffer.
4. Typed arrays
Re: A first-person engine in 265 lines of JS
#59My (admittedly n00bish and embarrassing) attempt at doing the same thing is here: https://github.com/pervycreeper/game1/blob/master/main.cpp
[1] in the sense that lines map to lines, as in most photography, Renaissance and later painting, and most computer graphics
Re: A first-person engine in 265 lines of JS
#60This demo unfortunately uses an incorrect perspective transformation. There is no reason to go to trig if you represent the camera plane as a vector, and step along it one pixel at a time, and allowing the wall height to vary linearly in the distance to the camera vector (taking lines to lines). In addition to being correct[1], it has the added benefit of being faster if implemented well. My (admittedly n00bish and e…
I'd be interested in further explanation about why you feel the underlying math could be improved, though.