←  Programs

ComputerCraft | Programmable Computers for Minecraft

»

Wolf3d-style 3d engine (proof of concept)

GopherAtl's Photo GopherAtl 28 Feb 2013

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


Posted Image
Posted Image

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

oeed's Photo oeed 28 Feb 2013

Wow.
Can't believe how small it is too, only 176 lines!
Quote

BigSHinyToys's Photo BigSHinyToys 28 Feb 2013

Now make COD lolz

Great work this is really well done + 1
Quote

theoriginalbit's Photo theoriginalbit 28 Feb 2013

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

GopherAtl's Photo GopherAtl 28 Feb 2013

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

remiX's Photo remiX 01 Mar 2013

WOw, this is amazing xD

Try add multiplayer support :o
Quote

nutcase84's Photo nutcase84 01 Mar 2013

OMG! GopherAlt, you are amazing! Make it a shooter and I will bow down to you!
Quote

remiX's Photo remiX 01 Mar 2013

Lol got trapped at the dead end :P
Quote

Rsstn's Photo Rsstn 01 Mar 2013

Awesome, trying it out!
Quote

Zaggy1024's Photo Zaggy1024 01 Mar 2013

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
Quote

Exerro's Photo Exerro 01 Mar 2013

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
Quote

Derp_Herpsworth's Photo Derp_Herpsworth 01 Mar 2013

You, my friend, deserve a trophy. I'll be happy to try to discover how good it is. :D
Quote

GopherAtl's Photo GopherAtl 01 Mar 2013

View PostZaggy1024, on 01 March 2013 - 08:02 AM, said:

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 :)
Quote

oeed's Photo oeed 01 Mar 2013

View PostGopherAtl, on 01 March 2013 - 12:00 PM, said:

--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
Quote

Left4Cake's Photo Left4Cake 02 Mar 2013

This could be use as a 3d map for levels of a dungeon for house.
Quote

wilcomega's Photo wilcomega 02 Mar 2013

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
Quote

martin509's Photo martin509 02 Mar 2013

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

GopherAtl's Photo GopherAtl 02 Mar 2013

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

wilcomega's Photo wilcomega 03 Mar 2013

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
Quote

Lyqyd's Photo Lyqyd 03 Mar 2013

This is a proof of concept. Try to be a little less entitled and demanding when other people make cool stuff.
Quote