Live data from Hacker News

A first-person engine in 265 lines of JS

playfuljs.com

91–99 of 99 posts

Re: A first-person engine in 265 lines of JS

#91

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 e…

I 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.

Re: A first-person engine in 265 lines of JS

#92

Earlier quoted context omitted.

I'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 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…

My 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

I'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

...appears to be describing exactly how this example works, right down to the diagram:

http://www.playfuljs.com/images/raycaster-distance.png

I'd be happy to update this article with an improved method once I understand it.

Re: A first-person engine in 265 lines of JS

#93

Nice demo! But one note, I don't know about DaggerFall but Duke Nukem 3D does NOT uses Raycasting to draw walls. DN3D uses sectors (Convex Polygon) to store room's lines (or walls), and draws those lines using player's FOV (Field Of View). When those sectors are connected with others sectors, it's called portal. This is used to sort only the sectors that is inside the player's FOV.

Thanks for letting me know! It's referenced as a raycaster in several places, and of course the output looks very much like a raycaster's, so I checked up on this.

After a little reading, it sounds like DN3D uses a cousin of a raycaster, as it's still rendering independent columns. Instead of casting rays to find them, it's projecting their vertices. Neat!

Re: A first-person engine in 265 lines of JS

#95

Earlier quoted context omitted.

> 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? Your eye doesn't see it as straight, your brain does. Your eye doesn't actually gather a single coherent image, in fact. It's constantly moving[1], bringing the higher-precision fovea at the center of your retina to bear on interesting parts of the scene. Your brain then accumulates all of t…

Wow, the blind-spot test on that Wikipedia page just blew my mind. There were situations in traffic when I was driving a car and simply did not see cyclists or pedestrians coming. At the time I was aware that one of my eyes were obstructed by the rear-view mirror on the windshield, but that did not explain why I did not see them coming with the other eye. I wonder why are people not alerted about this when taking the…

Blind spots are crazy. Your brain will continue some patterns and straight lines right through the blind spot, so it doesn't look blank. http://www.swarthmore.edu/SocSci/fdurgin1/publications/Blind...

Re: A first-person engine in 265 lines of JS

#96

Earlier quoted context omitted.

My 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

I'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 ...appears to be describing exactly how this example works, right down to the diagram: http://www.playfuljs.com/images/raycaster-distance.png I'd be happy to update this article with an improved method once I und…

I'd love to see an updated version and a 'before and after' shot

Re: A first-person engine in 265 lines of JS

#97
post #25

Earlier quoted context omitted.

If you missed it a couple of weeks ago, this article about its creation was really interesting: http://fgiesen.wordpress.com/2012/04/08/metaprogramming-for-... ( Thread: https://news.ycombinator.com/item?id=7739599 )

It's really interesting but would someone mind explaining why they have to keep this code under some size limit?

https://en.wikipedia.org/wiki/Demoscene

Re: A first-person engine in 265 lines of JS

#98

Earlier quoted context omitted.

It's really interesting but would someone mind explaining why they have to keep this code under some size limit?

https://en.wikipedia.org/wiki/Demoscene

Cool, thanks, looks like that's what I was missing.

Re: A first-person engine in 265 lines of JS

#99

Nice demo! But one note, I don't know about DaggerFall but Duke Nukem 3D does NOT uses Raycasting to draw walls. DN3D uses sectors (Convex Polygon) to store room's lines (or walls), and draws those lines using player's FOV (Field Of View). When those sectors are connected with others sectors, it's called portal. This is used to sort only the sectors that is inside the player's FOV.

Didn't games like Duke Nukem 3d, post-Doom, Wolf games use what was called a scanline algorithm? Drawing the lines in the players FOV as you just stated and then using a clipping algorithm to keep unwanted information out. I think raycasting would be a type of scanline algorithm, but the technique is less primitive since your not using a proper 3d engine. It's a long time since I programmed games like this so am now a bit fuzzy on the specifics.
Post reply on HN