Raycasting engine assistance?

BlitzMax Forums/BlitzMax Programming/Raycasting engine assistance?

codermax(Posted 2012) [#1]
Ok, so I decided to start on a raycasting engine, as I love the early FPS games of the 90s and wanted to make my own. Once I did that, I'd be able to port the engine to C# using XNA as this particular type of fake 3D rendering is more beneficial than true 3D to me at the moment. Sadly, it's always the complex math that stops me in my tracks.

The specific cork in my plans for world domination, is the fact that I wanna make the engine RIGHT. In this case I'm following the "tutorial" on this page:
http://www.permadi.com/tutorial/raycast/index.html

I'm stuck on the wall finding part. I would make a workaround, but...
-I wanna make the engine according to the tutorial, to follow along and do all the cool stuff in it. That's what I wanna accomplish, that's the goal. :)
-Coding a workaround might stop me from doing that. I might find a way to track walls and might even get to texture maps, but maybe not drawing ceilings etc. That's wasted time I could've used to just follow along and code an engine proper.

So I go with it and try to follow the "tutorial". However it's not one with a decent codebase, so I can't just copy it/improvise and port to BlitzMax. Which would be the best thing ever. :D

The problem that keeps me up after I try finding walls is that when I go to draw walls, my math equations don't equal a wall, it's more like... this... ghost thing! And since there's nothing resembling a source, I can't just use it as a reference and keep trying to get it right, I'd waste days doing so.

There are other sources out there that do raycasting, but they don't follow this tutorial, and worse so they don't have any comments about their code, it's usually just huge walls of text with not even so much as a sign where the main loop starts! To top it off, they're in different languages(asm!?) and if you don't know them, you're better off reading Chinese. XD I'm not one who likes to use stuff and not know what the heck it is. That's why I don't use premade sources if they're not well commented. I wanna understand what I'm coding, so it'd be easier to use/expand and port.

So, I'd appreciate it if someone who is knowledgable about this and able to at least give a dog a bone, well...give a dog a bone! :D I just need a hand in fully deciphering what's going on, I should be able to take it from there.


matibee(Posted 2012) [#2]
That tutorial looks really good. I don't want to sound harsh but if you really want to learn sit down with a pen, graph paper and a calculator. Run through some example inputs and calculate the outputs. When you're happy with the procedure test your code with the same inputs. Otherwise you won't know if your code or methodology is flawed. It's a great way to cement your knowledge.

I've been doing exactly this for a number of weeks for all kinds of 3d math problems.. cone vs triangle intersection, cylinder vs triangle, sphere vs triangle etc etc (including all the relevant edge, surface and vertex tests), things are becoming more and more clear as I go on and I have great confidence in my resultant (and thoroughly tested) code. Time spent this way is a great investment for the future.

Anyway, if you want a bone, read through this :) ...
http://www.blitzbasic.com/Community/posts.php?topic=89478


AdamStrange(Posted 2012) [#3]
yep, when things get complex (number wise), it is always better to sit down with some paper and do the math there, then check if the routine gives you what you expected.

If it isn't what you expect, then either the math is wrong (very likely as converting paper math to computer math always has a bug or two) or the data is wrong (garbage in = garbage out)?

I could get my head around 3d vertexes, but not how models fitted together, so I ended up writing a 3d editor so I could check everything at the vertex level. It turned out that an x should have been a z and everything suddenly worked...


codermax(Posted 2012) [#4]
YAY! I managed to draw the 3D world somewhat correctly now. However, I still need to correct the fish-eye distortion. I have NO IDEA what the author is talking about on figure 17 on the Finding Distance to Walls page, where they describe a couple of equations. The problem is, I have no idea how to apply them in the code! Apparently I need them to fix the fish-eye, as my simple length variable for rays won't cut it.

EDIT:
Awesome! Texture mapped walls with some strafing and ADS for good measure. However, I just can't seem to wrap my head around drawing textured floors/ceilings! I tried to bring over code from various tutorials, but they don't seem to work in my engine and one piece of code I used was WAY too slow. I can complete every part of the raycasting tutorial on the permadi website, EXCEPT drawing floors and ceilings! If somebody can help me out I'd greatly appreciate it! :D

Here's my source so far:



*sigh* I was planning on drawing the floor by horizontal row, as I was told that would be faster, since there'd be no per-pixel division.

Last edited 2012

Last edited 2012


codermax(Posted 2012) [#5]
Anyone happened to have ported the floors and ceiling render code from http://lodev.org/cgtutor/raycasting2.html ?