|
|
#1 |
|
New-born car whore
Join Date: Aug 2001
Location: Manchester
Posts: 3,984
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
PHP "raycaster" 3D renderer
I mentioned recently that I was looking for an interesting PHP project. This evening I remembered an idea I had a while ago to make a 3D renderer in PHP (and if anyone's tempted to ask - "because I can"
). I did a bit of reading on old 3D engines, as I didn't want something modern and slow, and found out that the "raycaster" rendering used in Wolfenstein 3D is ridiculously easy to implement. A few hours later and it's up and running I've not run any proper speed tests yet, but the images load up pretty much instantaneously. I have a couple of ideas of what this could be used for, so watch this space ![]() Sample render: ![]() Works off axis too of course: ![]() And on the vertical: ![]() The code is currently just over 300 lines long. It could be compressed down a lot (maybe even to half it's current size) just to show how stupidly simple things are with PHP. It will bulk out marginally once I get all of the functions in place for setting up the render size, camera position, angle, FOV etc as they are currently all just variables set in __construct. Even the map is just being randomly generated and thrown in. Next real things to do will be to expand the texture mapping somewhat (at the moment it's just 1 for each of walls, floor and ceiling) and get it showing sprites. Then maybe HDR and anisotropic filtering
__________________
Flickr Last edited by NiHiLiST; 6th Jul 2006 at 22:57. |
|
|
|
|
|
#2 |
|
Eh! Steve
Join Date: Apr 2002
Location: Melbourne - Australia
Posts: 1,386
![]() ![]() |
Wow, that's awesome. That could be used for some great stuff. 3d website, HTML based RPG, stuff like that!
__________________
-= JazzXP =- There are three kinds of lies: Lies, damned lies, and benchmarks. there is no such thing as "Fool-Proof" just "Idiot resistant" - Pflumingo |
|
|
|
|
|
#3 |
|
Super Moderator
Moderator
Join Date: May 2005
Location: London, UK
Posts: 4,877
![]() ![]() ![]() |
Wow - very nice work! Reminds me of the 3D Maze screensaver that you used to get with Win95
__________________
"Nothing is more practical than a good theory" - Kurt Lewin |
|
|
|
|
|
#4 |
|
Your appeal has already been filed.
Join Date: Dec 2003
Location: UK
Posts: 2,410
![]() |
Awesome, can't wait to see what you get up to with this!
__________________
om nom nom nom |
|
|
|
|
|
#5 |
|
New-born car whore
Join Date: Aug 2001
Location: Manchester
Posts: 3,984
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Thanks, Jazz. I did consider it could be used to add some visual depth to those HTML-based RPG games. Would be pretty easy to do, but until I've run some load tests I couldn't say how it would affect the server, it might get pretty intensive if the site's getting a lot of hits.
One of the big overheads at the moment is that the textures have to be loaded from disk each time, and there are a lot of sin/cos/tan calculations. It's currently using lookup tables for those, but again, it's having to either generate or load those each time the script runs so some persistent memory or suchlike may need to be looked at ![]() Of course if you wanted this kind of thing on a large site it would make more sense to just code the renderer in C or something and have your scripts execute the program when necessary. PHP's not bad for things like this, but it's far from being the fastest.
__________________
Flickr |
|
|
|
|
|
#7 |
|
An irresponsible
Moderator
Join Date: Mar 2001
Location: London, SE1
Posts: 13,399
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Surely you're loading .dlls and just calling functions from within the DLL using PHP?
I'm not denying that it's cool - it is - but if i'm right then PHP isn't doing the fun stuff ![]() Please tell me I'm 110% wrong! |
|
|
|
|
|
#8 |
|
New-born car whore
Join Date: Aug 2001
Location: Manchester
Posts: 3,984
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
No I'm not, RTT, that would be silly
The only thing I'm using is mathematical functions, binary operators and the GD library. No extensions, no DLLs, just classic software rendering.
__________________
Flickr |
|
|
|
|
|
#9 |
|
An irresponsible
Moderator
Join Date: Mar 2001
Location: London, SE1
Posts: 13,399
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Cor blimey
Color me impressed!
|
|
|
|
|
|
#10 |
|
New-born car whore
Join Date: Aug 2001
Location: Manchester
Posts: 3,984
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Here are the functions used RTT
:![]() mt_rand sin cos tan pi sqrt pow imagecreatetruecolor imagecreatefrompng imagecopy imagedestroy imagepng imagecolorat imagesetpixel header Plus of course the functions in the class I've written.
__________________
Flickr Last edited by NiHiLiST; 8th Jul 2006 at 17:34. |
|
|
|
|
|
#11 |
|
Lazy Lurker
Join Date: Jan 2004
Location: 'States
Posts: 4,588
![]() |
Add sprites!
__________________
Technology Schmecnology |
|
|
|
|
|
#13 | |
|
An irresponsible
Moderator
Join Date: Mar 2001
Location: London, SE1
Posts: 13,399
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Quote:
![]() Hehe... can't wait for updates on this. Some source wouldn't go amiss either /curious
|
|
|
|
|
|
|
#14 |
|
Supermodder
Join Date: Jan 2004
Location: Kent Uni
Posts: 351
![]() |
some source and a demo would be awesome ;D
|
|
|
|
|
|
#15 |
|
Supermodder
Join Date: Jul 2005
Location: Peadobrough
Posts: 486
![]() |
This is teh funkey, seconded on the intrest ub the source it would be interesting to look through.
__________________
BOO
|
|
|
|
|
|
#16 | |
|
New-born car whore
Join Date: Aug 2001
Location: Manchester
Posts: 3,984
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Quote:
__________________
Flickr |
|
|
|
|
|
|
#17 |
|
New-born car whore
Join Date: Aug 2001
Location: Manchester
Posts: 3,984
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Code for those who were asking:
PHP Code:
__________________
Flickr |
|
|
|
|
|
#18 |
|
Freerider
Join Date: Feb 2002
Location: Whistler, BC
Posts: 4,007
![]() |
Wow, very impressive. I wouldn't even know where to begin with soemthing like this.
Damn I hate sucking at math.
__________________
Clickr my Flickr |
|
|
|
|
|
#19 |
|
durr
Join Date: Oct 2003
Location: Vaasa, Finland
Posts: 160
![]() |
Whoa, VERY Nice!
(Oh yes, and you got dugg.)
__________________
the world is not enough, i gotta have modding too. |
|
|
|
|
|
#20 |
|
Multimodder
Join Date: Nov 2002
Location: Norway
Posts: 198
![]() |
That's pretty awesome. Nice work!
![]() Oh and yeah, you got dugg
__________________
- Rexxie Sanity is a full time job. |
|
|
|
![]() |
| Thread Tools | |
|
|