This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
GopherAtl's profile picture

Wolf3d-style 3d engine (proof of concept)

Started by GopherAtl, 28 February 2013 - 08:35 PM
GopherAtl #1
Posted 28 February 2013 - 09:35 PM
new update: added optional support for my redirect api, which creates buffered redirect objects that can, among other things, be used to implement a back buffer. If the redirect api is found, it does all the messy drawing to a buffer, then copies that to the screen all at once. For me, this eliminated all flicker even on a max-size monitor at text scale .5. ymmv.


on a whim, decided to throw together a simple Wolfenstein 3D-style rendering system in cc. Two hours later, here are the results





screenshots look pretty crappy, what with the 51x19 resolution and 16-color palette, but to properly appreciate it you need to see it in action.
Demo download: pastebin get qpV90qbM wolf3d

I strongly recommended you also grab the redirect API, which will be used if you have it to reduce or eliminate any flickering when drawing. It'll still run fine without it, though. (for more info on the redirect api, see my api thread)

redirect api (optional): pastebin get fU9Kj9zr redirect

pastebin version will keep updating as I work on it. Feel free to take the code and turn it into anything you want.
oeed #2
Posted 28 February 2013 - 10:10 PM
Wow.
Can't believe how small it is too, only 176 lines!
BigSHinyToys #3
Posted 28 February 2013 - 10:23 PM
Now make COD lolz

Great work this is really well done + 1
theoriginalbit #4
Posted 28 February 2013 - 10:45 PM
Very nice! :D/> I wish we had a way to render more pixel detail. would make it look so much better. only real way i can think of is using ascii. but very nice none the less.
GopherAtl #5
Posted 28 February 2013 - 10:46 PM
oeed: thanks. Additions, mainly collision handling with walls, have pushed it to around 250 lines now, but yeah, this kind of engine is surprisingly simple to implement, heh.

BigSHinyToys: no COD, lol. Adding enemies would be … problematic. 16-color sprites at this resolution really don't scale well!

TheOriginalBit: I've toyed with making it run on monitors, but it would have to have on-screen touch controls, ipad-style, which seems like it'll be awkward. Unless there's actually a working version of ccinput around somewhere, seems every time I've tried to use ccinput, it has not wanted to work properly…
remiX #6
Posted 01 March 2013 - 04:47 AM
WOw, this is amazing xD

Try add multiplayer support :o/>
nutcase84 #7
Posted 01 March 2013 - 05:26 AM
OMG! GopherAlt, you are amazing! Make it a shooter and I will bow down to you!
remiX #8
Posted 01 March 2013 - 05:34 AM
Lol got trapped at the dead end :P/>
Rsstn #9
Posted 01 March 2013 - 07:54 AM
Awesome, trying it out!
Zaggy1024 #10
Posted 01 March 2013 - 08:02 AM
I just threw together a few little changes to this because I felt like it needed them. I made the frames be on a timer, which made it flash less (or maybe never), added mouse support for looking left and right (it isn't perfect, because of the way ComputerCraft does mouse_drag events, but it works pretty well), I made it scale properly (possibly not completely properly, but it seems to work), and I put a crosshair in the middle of the screen just for good measure.

http://pastebin.com/V5MRGVZv
Exerro #11
Posted 01 March 2013 - 11:10 AM
wow, i can't even make a 3d game with collision with lwjgl and you do it in cc! so jealous :P/> great job :D/>
Derp_Herpsworth #12
Posted 01 March 2013 - 11:34 AM
You, my friend, deserve a trophy. I'll be happy to try to discover how good it is. :D/>
GopherAtl #13
Posted 01 March 2013 - 12:00 PM
I just threw together a few little changes to this because I felt like it needed them. I made the frames be on a timer, which made it flash less (or maybe never), added mouse support for looking left and right (it isn't perfect, because of the way ComputerCraft does mouse_drag events, but it works pretty well), I made it scale properly (possibly not completely properly, but it seems to work), and I put a crosshair in the middle of the screen just for good measure.

http://pastebin.com/V5MRGVZv

I don't see how making it redraw every frame would help the flicker; I will be making it use my redirect buffer api later (not really sure why I didn't in the first place), which should significantly reduce, if not completely eliminate, the flickering. I'd also implemented automatic scaling to term.getSize() last night, but forgot to update pastebin. Regardless, tho, mod away, make what you want with it!


To everyone else, thanks for the praise, been a fun little diversion from my usual more complex and practical projects :)/>
oeed #14
Posted 01 March 2013 - 12:04 PM
–snip snip–

To everyone else, thanks for the praise, been a fun little diversion from my usual more complex and practical projects :)/>

How isn't this practical :P/>
Left4Cake #15
Posted 02 March 2013 - 04:08 AM
This could be use as a 3d map for levels of a dungeon for house.
wilcomega #16
Posted 02 March 2013 - 04:40 AM
this is sooooo amazing. i have been waiting for this. maybe nitrogenfingers will incude it in the gameutils api. i love it. when i implements that i will make a first person shooter! :D/> :D/> :D/> you are truely amaing. i cant tell you enough
martin509 #17
Posted 02 March 2013 - 04:17 PM
I feel like another of the horde of Tekkit users saying this, but.. Can has standard PC version?
Also, maybe add some things like slash+dash lines on the outer edges of polygons, to give it texture.
Oh, and maybe take it a step further with walls of varying height.
GopherAtl #18
Posted 02 March 2013 - 07:05 PM
ehrum. Yeah, it would have to have some sort of characters as texturing to be remotely comprehensible visually in a version for basic computers. The current algorithm doesn't really lend itself to drawing the edges, so adding that would require some fairly significant rewriting. I may attempt something like that in the future, but not at this time I'm afraid.
wilcomega #19
Posted 03 March 2013 - 12:12 AM
i have said this before: AMAZING
but i would like to see a diffrent map format. like map[x][y] = object5
or like map[x][y] = player2. i also would like to see some object oriented programming. like i did above. that you draw objects
on the screen according to their position. instead of a map. if you know what i mean.
so it will be easyer to make fps( first person shooters ). that is my plan atleast

you should make an explanation on how each line of code works and what it does. i really want to make smaller objects in the world. like bullets :P/>
Lyqyd #20
Posted 03 March 2013 - 05:58 AM
This is a proof of concept. Try to be a little less entitled and demanding when other people make cool stuff.
nitrogenfingers #21
Posted 03 March 2013 - 01:27 PM
goTech1? Looking pretty sharp- great job Gopher :)/> I may have a play around with this at some stage.
brett122798 #22
Posted 03 March 2013 - 07:34 PM
You just unlock the possibly of the actual Minecraft in Minecraft? lol…..
oeed #23
Posted 03 March 2013 - 07:49 PM
You just unlock the possibly of the actual Minecraft in Minecraft? lol…..

First thing I thought when I saw this :P/>
theoriginalbit #24
Posted 03 March 2013 - 07:52 PM
You just unlock the possibly of the actual Minecraft in Minecraft? lol…..

First thing I thought when I saw this :P/>
I thought of Wolfenstein and Doom before Minecraft.
TheOddByte #25
Posted 04 March 2013 - 07:27 AM
I thought off the possibility to create Slender.
=3
Left4Cake #26
Posted 04 March 2013 - 08:19 AM
You just unlock the possibly of the actual Minecraft in Minecraft? lol…..

First thing I thought when I saw this :P/>

He would need to rework it to use 3d maps first wouldn't he.
nutcase84 #27
Posted 04 March 2013 - 12:14 PM
He would need to rework it to use 3d maps first wouldn't he.

<sarcasm>No way…</sarcasm>
oeed #28
Posted 05 March 2013 - 11:41 PM
He would need to rework it to use 3d maps first wouldn't he.

<sarcasm>No way…</sarcasm>

U mad?
FuuuAInfiniteLoop(F.A.I.L) #29
Posted 18 March 2013 - 01:57 PM
oeed: thanks. Additions, mainly collision handling with walls, have pushed it to around 250 lines now, but yeah, this kind of engine is surprisingly simple to implement, heh.

BigSHinyToys: no COD, lol. Adding enemies would be … problematic. 16-color sprites at this resolution really don't scale well!

TheOriginalBit: I've toyed with making it run on monitors, but it would have to have on-screen touch controls, ipad-style, which seems like it'll be awkward. Unless there's actually a working version of ccinput around somewhere, seems every time I've tried to use ccinput, it has not wanted to work properly…
you can just use another monitor with keys and send the keys over wireless modems
superaxander #30
Posted 24 March 2013 - 08:20 PM
Mind blown…
ds84182 #31
Posted 25 March 2013 - 04:05 AM
My gawd. Quick port this to CCLights2! Now we can have Minecraft in Minecraft!
GravityScore #32
Posted 25 March 2013 - 04:53 AM
I was looking at the method you used to do this, and I get it! :D/> I'm going to make my own in Python.

Really helpful paper on Raycasting here, if anyone else is interested in how it works.
paus3d #33
Posted 24 April 2013 - 08:52 AM
Sorry for offtopic, but there is a shooter on bash with the same graphics.
ArchAngel075 #34
Posted 14 June 2013 - 04:47 PM
thses are not requests/demands. Instead they are me thinking out loud for the those interested (or not interested :P/>)
If one uses CClights2's mouse_move events isnt it possible to truly track the mouse?
Also CClights (not 2) has a very nice pixeldrawing system, 128x128 but its only external! (damnit ccinput)

Anyways, amazing :D/>
basdxz #35
Posted 14 June 2013 - 06:33 PM
Well, portal 3 can now be made with computercraft in THREE-DEEE! Yay!
nutcase84 #36
Posted 14 June 2013 - 07:28 PM
Well, portal 3 can now be made with computercraft in THREE-DEEE! Yay!

Portal 3? If you want to make a prototype Portal 3, make it outside CC please. I LOVE PORTAL.
murky white #37
Posted 14 June 2013 - 09:29 PM
this is insane. you are insane. will you marry me?
Nuchaz #38
Posted 16 June 2013 - 03:18 AM
The 3D stuff that is being pulled off is amazing. Really great job on this. I am wondering if someday someone might apply this to a floor/wall/ceiling monitor configuration with lan cables and make a holodeck of sorts. That would be so awesome.
Geforce Fan #39
Posted 17 June 2013 - 12:19 AM
Amazing. I thought it would crash when I edited the map but it didn't! Nice work.
billysback #40
Posted 17 June 2013 - 02:14 PM
I thought this would be the most appropriate place to share this, as it is this.

Earlier Gopher said about entities scaling badly and stuff, so to test this theory I tried it out. So far I have done nothing but prove him correct, however whilst playing around with his code I added a few new features :P/>

Here's a pastebin:
http://pastebin.com/VHrMFTE7

what I added:
"bobbing" - you bobb when you move now… rather simple.
"vision" - adds vision distance to the game, can't see anything but a gray silhouette when out of vision radius
"mouse" - can control the game with the mouse (will explain later)
"sprint" - lets you move faster, toggled by middle mouse button or "e" key
"white_circle" - fits with ceilings_floors and vision kinda, I don't like it tbh
"ceilings_floors" - makes the floors lightGray and the ceilings black

NOTE: all of this can be toggled off at the top of the code with the "settings" table, just make things true/false

mouse controls:
clicking the left quarter of the screen with your left mouse button moves you left,
clicking the right quarter of the screen with your left mouse button moved you right,
clicking the top-middle quarter of the screen with your left mouse button moves you forwards,
clicking the bottom-middle quarter of the screen with your left mouse button moves you backwards,
clicking the right side of the screen with your right mouse button makes you look right,
clicking the left side of the screen with your right mouse button makes you look left,
clicking the middle mouse button will toggle sprint
NOTE: mouse_drag is enabled so move your mouse slightly side to side inside one of these zones to move properly

this isn't trying to steal Gopher's thunder or anything, it's just me sharing the results of what Gopher produced, btw Gopher, this is awesome :D/>

I might still try and work on getting entities to work but I dunno…
maybe adding switched and doors would be cooler, with the use-item key being F or clicking the middle of the screen.
jesusthekiller #41
Posted 17 June 2013 - 04:02 PM
I thought I'll share it, created 3D game using this engine couple days ago, so here it is:

http://www.computercraft.info/forums2/index.php?/topic/13483-3d-game-3d-maze-its-friggin-3d-woo/page__fromsearch__1
GopherAtl #42
Posted 17 June 2013 - 07:35 PM
I thought this would be the most appropriate place to share this, as it is this.

Earlier Gopher said about entities scaling badly and stuff, so to test this theory I tried it out. So far I have done nothing but prove him correct, however whilst playing around with his code I added a few new features :P/>

Here's a pastebin:
http://pastebin.com/VHrMFTE7

what I added:
"bobbing" - you bobb when you move now… rather simple.
"vision" - adds vision distance to the game, can't see anything but a gray silhouette when out of vision radius
"mouse" - can control the game with the mouse (will explain later)
"sprint" - lets you move faster, toggled by middle mouse button or "e" key
"white_circle" - fits with ceilings_floors and vision kinda, I don't like it tbh
"ceilings_floors" - makes the floors lightGray and the ceilings black

NOTE: all of this can be toggled off at the top of the code with the "settings" table, just make things true/false

mouse controls:
clicking the left quarter of the screen with your left mouse button moves you left,
clicking the right quarter of the screen with your left mouse button moved you right,
clicking the top-middle quarter of the screen with your left mouse button moves you forwards,
clicking the bottom-middle quarter of the screen with your left mouse button moves you backwards,
clicking the right side of the screen with your right mouse button makes you look right,
clicking the left side of the screen with your right mouse button makes you look left,
clicking the middle mouse button will toggle sprint
NOTE: mouse_drag is enabled so move your mouse slightly side to side inside one of these zones to move properly

this isn't trying to steal Gopher's thunder or anything, it's just me sharing the results of what Gopher produced, btw Gopher, this is awesome :D/>

I might still try and work on getting entities to work but I dunno…
maybe adding switched and doors would be cooler, with the use-item key being F or clicking the middle of the screen.

(quoted billysback's whole post to save it from botp hell)

billysback + jesusthekiller: Excellent, I'm glad to see people working with this code :D/> Keep sharing anything you make!
ElectricOverride #43
Posted 01 July 2013 - 12:47 PM
Wow.
Can't believe how small it is too, only 176 lines!
Does anybody have the origional copy of this when it was only 176 lines? I want to see if I can make it even smaller!
TableCraft0R #44
Posted 24 July 2013 - 09:37 AM
Minecraft on minecraft?
RatcheT2497 #45
Posted 14 September 2013 - 02:53 PM
Wow. In the future, we will have Doom CC! And Wolfenstein CC! And CC-Quake! (I can't think of more names :/)
neptune12100 #46
Posted 08 November 2013 - 10:43 PM
I tried to make a raycaster in python (with pygame). I failed miserably.
Gumball #47
Posted 22 May 2016 - 08:06 AM
I myself and trying to make a raycasting method, I have it able to draw currently, as in an array specifying a color, and distance, and it does simple math to calculate the lines to draw, but for the love of god making it GET a view is hard.
Gumball #48
Posted 24 May 2016 - 08:07 AM
[indent=1]Whilst this is EPIC, this is technically NOT 3D. It is a 2d plane mapped with perspective to give an illusion of 3D. Minecraft would be impossible to implement. Portal, thats iffy. Take example of how you cannot look up and down. Portal COULD work, but it wouldn't be able to work the best.[/indent]
SquidDev #49
Posted 24 May 2016 - 04:43 PM
Whilst this is EPIC, this is technically NOT 3D. It is a 2d plane mapped with perspective to give an illusion of 3D. Minecraft would be impossible to implement. Portal, thats iffy. Take example of how you cannot look up and down. Portal COULD work, but it wouldn't be able to work the best.

Technically all 3D on a computer is just a 2D plane mapped to give the illusion of 3D. It wouldn't be too hard to adapt this to look up and down either: just adding pitch as well as yaw. The real limiting factor with ComputerCraft 3D engines is performance. Lua is not a great number crunching language and so any implementation will be reasonably slow. This combined with the 20fps cap (due to the server tick rate) means you're never going to get a very responsive game.
LDDestroier #50
Posted 24 July 2016 - 04:21 AM
Is there a variable that I can modify to give this an FOV of 360 degrees?
Saldor010 #51
Posted 24 July 2016 - 04:33 AM
You guys do know this is an almost 3 year old thread, right? :mellow:/>
LDDestroier #52
Posted 24 July 2016 - 06:25 AM
You guys do know this is an almost 3 year old thread, right? :mellow:/>

Guy (singular), and yes.
Saldor010 #53
Posted 24 July 2016 - 02:51 PM
You guys do know this is an almost 3 year old thread, right? :mellow:/>

Guy (singular), and yes.

I was referring to BlueBird and SquidDev as well.
LDDestroier #54
Posted 24 July 2016 - 06:34 PM
Oh, sorry. Didn't realize.

The reason I ask being that I'm trying to rig sine sure of VR four monitor thing, and 3D Maze uses stitch to wrap around all four.

Is FOV changing possible with this, and if it is, how?
Bomb Bloke #55
Posted 04 August 2016 - 04:38 AM
The viewing angle of each screen column is tracked by scan[x].angle, set during initialisation at line 151.

Increasing those angles leads to a wider FOV, decreasing them shrinks it.
jakejakey #56
Posted 11 November 2016 - 03:32 PM
WOw, this is amazing xD

Try add multiplayer support :o/>
This isn't a game, its a rendering engine, therefore multiplayer is impossible. Unless you want to have social rendering LOL

This post probably doesn't belong here, but is it possible to have more layers of rendering? I mean instead of a floor, then a layer of blocks, then a ceiling.
Bomb Bloke #57
Posted 12 November 2016 - 01:41 AM
This engine is built to handle 2D maps in a similar manner to Wolfenstein (although it doesn't support texturing) - it works under the concept that in any given column of the screen, you'll only ever be able to see part of one wall. By figuring out the distance between that part of the wall and the camera (by casting a ray from the camera along an angle corresponding to the current screen column), and rendering a vertical line of a proportional length more or less centered within that column on the screen, once you've processed all display columns you've got a 3D representation of the 2D area.

id's next engine (used by Doom) was a little closer to 3D, in that the height of the floor / ceiling could vary at each map location (though it was still only possible to have up to one gap between the two). This made it a good deal more complex, as finding the closest wall to the camera (eg created by a raised floor or lowered ceiling) did not ensure that you'd found the only wall that needed to be drawn within that display column.

Having multiple gaps per section of the map would ramp the workload even higher - each would add another couple of checks to be performed by each ray for each map location. Sure, anything's possible, but performance would definitely be suffering by that point.