Thursday, August 4, 2016

Raycasting woes

What I'm working on now is a raycasting engine, like was used back in the days of Wolfenstein 3D. It's not a complicated technique, really, but it's a little fussy, and I just couldn't get my last attempt to quite work right.

My original attempt was based partly on trying to convert A first-person engine in 265 lines from javascript to haxe, with this actionscript-based raycaster as a second opinion. I never quite got the math to work right, and it was running painfully slowly anyway. I might have been able to work it out if I'd been more diligent about putting debugging tools into my code, but I instead went the simpler route of ripping everything out and starting over!

This time, I'm using a technique from Lode's Computer Graphics Tutorial. Instead of doing a bunch of trigonometry for every column to be rendered like the previous technique I was trying to use, this technique uses vectors, basically just calculating once per frame instead of once per pixel-column. It turned out to get a much better framerate even without doing any optimizations, and as an added bonus:

It actually works!

Next up is to draw the ceiling and the floor, instead of just using solid colors.

 I've tossed the code up on bitbucket, if you want to poke around at it.

1 comment:

  1. Heyho :). I'm trying to learn AS3 + Flex SDK + Flixel to jump a little bit more into the practice of game developing. You're helping me a lot. I never did a project with Flash Develop (or something with Flash in general), so i'm starting totally from scratch as you did time ago. Hope to hear from you somehow at some time. I will now read through this whole blog and try to learn as much from you as possible ^__^.