[flash width=480 height=320]http://64digits.com/users/DesertFox/alpha_test_v2.swf[/flash]
Minor alpha test of my Flash-SAT port, math-optimized build. 72 raycasts per frame, drawing raycast results and level. The level is generated from a tileset.Runs decently fast, and in standalone tests, I can do 100000+ raycasts per second (360 rays per frame, 300+ fps), if I don't draw the raycast results, even with drawing the level. Not too shabby, all things considered.I really need to opti mize the line-drawing code, because if I do draw the line results, that 300 fps drops to 40. Thank god I'll never actually need to draw 360 raycasts per frame.*Note - all framerates are in the standalone player unless otherwise noted. In-browser performance is usually a bit slower.Obligatory spiel for CNAlso, some of you should join Cybernations - it doesn't take up too much time, and if you join, it will get Hero off my back about getting people to join :DSeriously, its an interesting game if a bit slow paced, and it doesn't take up too much time. Humorous things happen to stupid people, wars are fought and won (or lost), and political turmoil was had for all!
I created something like this in GM using objects as pixels. Needless to say, it was very slow.
Yay! Ray caster!!
Very fast O-oDF <3Now make a voxel raytracer and you'll be my BFF.
Actually making a per-voxel raytrace hit detection would not be that hard, because with voxels it is either filled or not - and you get massive speed increases if you have some sort of BSP tree. 2D to 3D would be easy too :3
*does a bit of CODES*I'll probably post some nice voxel-traversal pseudocode soon.Here's the basic algorithm for pixel traversal. I've edited it for per-pixel tests, with pixels being either FULL or NOT_FULL. I have also neglected bound-checking so if you try to test a pixel that isn't in the array, it *will* error (index out of range, anybody :D). I may have made a mistake somewhere (it is pseudocode) but I've commented with what I'm trying to do and where. Also, read the pdf I supplied in the comments.
This algorithm should be fairly efficient - even more efficient than my flash implementation, as it is doing a simple boolean filled-or-not check instead of doing a ray-polygon intersection test.A final note, when doing actual raycasts, you will probably want to cast from the center of the pixel (Pixel.X + 0.5, etc). If you have a specific pixel target position (and not just an angle) you should also cast towards the center of that pixel.Array voxels is a 3D array of voxels, with a method of determining whether they are filled or not.Point origin is the starting 3-dimensional point origin of the raycast.Point target is point in space that the origin will cast towards.int max_len is the maximum number of pixels to check. It is not the max distance, but is a rough approximation of. You could probably easily modify the for loop for actual distance.OMG *yoink* *run*
Then much editing as pasting it turns into more of a barf then a clean sheet of code….