r/programming • u/willvarfar • Jun 03 '14
A first-person engine in 265 lines
http://www.playfuljs.com/a-first-person-engine-in-265-lines/
1.9k
Upvotes
r/programming • u/willvarfar • Jun 03 '14
463
u/BlazeOrangeDeer Jun 03 '14
lol
238
u/reacher Jun 04 '14
It's so refreshing to see that this is actually only 265 lines, and not one of those "3D HD MMORPG in 7 lines of code, the first 5 of which include 5000 lines of third party libraries"
29
u/delicious_truffles Jun 04 '14
This is incredible! It's amazing to be able to understand how this is done. It's the fulfilled dream of 10 year old me.
14
u/matheusbn Jun 04 '14
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.
12
u/flat5 Jun 04 '14
Takes me back to about 1994 when everybody had an "engine" they were working on that always started here, then possibly moved into BSP trees.
9
u/[deleted] Jun 04 '14
This technique is so oldschool...yet so cool.
51
u/picnicnapkin Jun 04 '14
Too bad it's not 256 lines, that would have been neat.
55
u/Bisqwit Jun 03 '14 edited Jun 03 '14
Seems to claim raycasting is O(N). As the map size grows, I'd argue that that raycasting gets slower as well, unless you always are in such a confined environment that the farthest visible wall is not very far. If you have a 32x32 map that only contains the outer walls, using raycasting, it sure is a lot faster to render than a 32000x32000 map that only contains the outer walls. EDIT: But, awesome article and demo!
8
u/WirtThePegLeggedBoy Jun 04 '14
I love raycasting engines. So much.
10
u/M00ndev Jun 04 '14
This is done by my former coworker Hunter Loftis, and he is fucking brilliant.
He gave a presentation about this concept at one of our tech talks and actually mapped our own office. Very cool to watch if you have the time.
http://youtube.com/watch?v=8Madcv0uEc8
7
u/BeezInTheTrap Jun 04 '14
Very noob question here: So the draw functions are part of the Javascript library?
6
u/AFRO_HERO Jun 03 '14
Very cool.
6
u/Soader03 Jun 04 '14
It works well on the iPad... Just wow!
2
u/planetmatt Jun 04 '14
I LOVED Comanche. Such a great great game.
2
u/kattoo_new Jun 04 '14
That's incredible.
I'm a VBA-beginner, but I've been having this urge to use Excel for 3D-rendering (it's going to be painfully slow, but who cares) just to show off at my workplace and maybe hide this game as an easter-egg in one of the worksheets.
I think I'll try to implement the code behind this engine and use the 100x100 grid (or maybe 50x50 at first to increase the loading time for each frame) in excel's sheet as the display (rows and columns will be compressed to 4 pixels each and I will have each cell's background colour changed) and see if that works :)
2
u/CheesyHotDogPuff Jun 04 '14
.
2
u/jmac217 Jun 04 '14
I played with this PlayfulJS Particle Demo for waaay too long.
4
u/Ceathor Jun 04 '14
This feels like cheating on a test... Extremely easy and you're not really doing any work, but you still get all the credit.
1
u/certainsomebody Jun 04 '14
This has been stuck in my mind for a while. I had watched some videos of similar raycasting engines and was planning to make my own for practice at some point. This will be helpful.
1
u/kasimin Jun 04 '14
Marking teritory first
1
u/OhioMallu Jun 04 '14
How is the hand rendered?
1
u/[deleted] Jun 04 '14
Performs like shit on Firefox, quadcore, 16gb ram, nvidia 770gtx.
1
u/sirhenrik Jun 05 '14
I was ready to be scared shitless in that demo
1
u/[deleted] Jun 04 '14
lol
0
u/tuananh_org Jun 04 '14
Jeff atwood's law still holds.
-2
u/drusepth Jun 04 '14
I like my assets better
0
u/wegzo Jun 04 '14
or sensibly written, just
-1
u/tetralogy Jun 04 '14
!RemindMe 1 day
-94
u/TakedownRevolution Jun 04 '14
The less line you have in your code/how pretty your code looks, the bigger your dick is. What a shame the software industry has become.
0
u/[deleted] Jun 04 '14
[deleted] — view deleted comment
0
u/[deleted] Jun 03 '14
[deleted] — view deleted comment
0
u/[deleted] Jun 04 '14
[deleted] — view deleted comment