7 ms·
This 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 a
by pervycreeper 12y ago
This 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 embarrassing) attempt at doing the same thing is here: https://github.com/pervycreeper/game1/blob/master/main.cpp 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
- sillysaurus3 12y agoWhy is it incorrect? From looking at the demo, it doesn't seem incorrect at all. If it's incorrect, then the incorrectness doesn't affect the end product, which is all that matters. Lines seem to map to lines, so it seems mistaken to call it incorrect. I'd be interested in further explanation about why you feel the underlying math could be improved, though.
- pervycreeper 12y agoHe ought to be using what Wikipedia calls a "perspective projection", or, sufficiently in this case, a restriction thereof. Notice how the edges of walls do not appear straight on the screen, even though he mentioned correcting "a fisheye effect" (tellingly alluding to a popular tutorial on this topic at lodev.org). A correct formula is on line 485 of my implementation linked above, found the old fashioned way using basic geometry.
- sillysaurus3 12y agoIndeed, you're right: http://i.imgur.com/oQ7S3Jo.jpg http://i.imgur.com/oQ7S3Jo.jpg On my old laptop, the demo looked fine. But after switching over to a widescreen (and higher FPS) you can tell that it's slightly wrong up close, and noticeably wrong (jittery) in the distance. I wonder what's causing the jitter...
- hunterloftis 12y agoI'm not sure I'm convinced, as finding the cosine does in fact find the linear distance from the camera plane to the intersection. This is, as far as I have seen, the standard implementation, eg: http://www.permadi.com/tutorial/raycast/rayc8.html#FINDING http://www.permadi.com/tutorial/raycast/rayc8.html#FINDING DISTANCE TO WALLS However, I would love to see your proposed solution demonstrated. Would you care to fork the raycaster and compute the results with an alternative method?
- pervycreeper 12y agoMy implementation above complies, but I can send you binaries if you need them. Be forewarned that I neglected to implement atmosphere. Here's a screenshot http://i.imgur.com/7LJocjS.jpg http://i.imgur.com/7LJocjS.jpg
- hunterloftis 12y agoI'm less interested in seeing binary output and more interested in understanding the principles behind what you're saying. The wikipedia page you mentioned: http://en.wikipedia.org/wiki/3D_projection#Diagram http://en.wikipedia.org/wiki/3D_projection#Diagram ...appears to be describing exactly how this example works, right down to the diagram: http://www.playfuljs.com/images/raycaster-distance.png http://www.playfuljs.com/images/raycaster-distance.png I'd be happy to update this article with an improved method once I understand it.
- Torn 12y agoI'd love to see an updated version and a 'before and after' shot
- userbinator 12y agoAs an aside, the division by a square root being in the main loop of the algorithm is related to why http://en.wikipedia.org/wiki/Fast_inverse_square_root http://en.wikipedia.org/wiki/Fast_inverse_square_root was developed.
- agentultra 12y agoI think what's most interesting about the original article is the write-up and not necessarily the implementation itself. I find reading and following >~ 500 LOC to be burdensome and difficult so keeping it short and small is certainly an advantage for this style of article. I'd really enjoy seeing your write-up on your implementation. If there's going to be an article we're going to link new people to in order to teach them ray-casting I'd hope we could teach them the best techniques that we can.