hello, after about 2 years i still don't get raycasting. i know im slow. anyway, i want to implement a raycasting engine in visual basic then later port it to masm and i was wondering if anyone could help me understand it. i really do not get it. i kinda get it but here are a few questions i have to ask about it that i need help with also i would like to know anything anyone will tell me about it. anyway, i want to only use the gdi to implement it because well i want to learn how do do it without directx,etc before i move on to that stuff if it it may be easier for some and im wondering.

what api's would i need?
do i draw it using lines or just pixel by pixel?
or maybe do i draw just squares on the screen?
what about round objects?
how do i load the map and turn that into 3d?
how do i determine my place in the map and how do i update the map to represent my position on it?
how do i render walls and ceilings and floors?
how do i texture walls and ceilings and floors?
how does the game loop work?
how do i remove flickering?
how do i interact with objects in this 3d world?
how do i make it fast but still look nice?
how do i create a resource archive similar to a wad?
can someone explain to me how a bsp tree works in idiot terms?
is there a video tutorial on how to implement this and explain the concept?
what can i do with raycasting?
what can't i do with raycasting?
is it possible to mix different kinds of rendering so i can do what the raycaster can't do?
how do i deal with walking up stairs and down stairs,going up and down elevators etc?
how are stairs,elevators and other objects represented on the map?
how do i do rooms above rooms?
how do i do basements sub level floors etc?
how do i create and use my own file formats?
how do i use assorted texture formats?
how do i use different sound formats?
what about jumping,crouching?
how do i know how far away the wall is? and how do i draw it so it looks correct?
what about that stupid hall of mirrors effect? how do i get rid of it?
what about lines that dont fully intersect? how do i fix them so they are correct?
how do i apply bump mapping, etc. to textures?

if you have any answers to these questions or have information on something ive got id love to hear what you have to say. im motivated to make one. i just don't know how. thanks, hexen.
Posted on 2005-03-13 20:18:30 by HeXeN
I think you should read (again?) about the BeamTree method, but nothing is ever as pure as a pixel projection raycaster.

For a perpixel raycaster, we're really interested in the View Frustum's vertices, because we want to cast rays from (the screen) the near plane of the view frustum to the far plane of the view frustum. We wish to cast a ray from "each screen pixel x,y on the near plane" to corresponding (scaled) points on the far plane. We eant to find the closest intersection between each ray origin and any world geometry, then determine the texel (texture coordinate) for that pixel, ie, the color for each screen pixel comes from the texture of the first surface its projected ray intersects with.

Scronty wrote a "PickRay" demo which provides a a procedure to cast a single ray with respect to the current camera, plus determine the nearest intersection of that ray with geometry. Worth a look at the code involved, you could just feed it pixel coordinates in a loop, instead of driving it with the mouse...


Posted on 2005-03-13 21:34:41 by Homer
thanks for telling me about beamtrees i had never even heard of them until today ive looked up a few things on them and found this http://www.bluesnews.com/abrash/chap64.shtml article the most usefull but im still not exactly sure how they work i "kinda" get it. ill look up more stuff on them.

you mentioned Scronty wrote a "PickRay" demo. would you happen to know where i could get it? also would you happen to know any more usefull resources i could look at theres alot of stuff i need to learn. also thank you for replying Homer
Posted on 2005-03-13 23:04:27 by HeXeN
Take a look through the DirectX demos at http://scrontsoft.com, look out for "MousePicking".
Posted on 2005-03-14 01:34:18 by Homer
I'm in the middle of doing exactly this right now (I think best/fastest in VB unfortunately - but with ThunderVB or VBInLineAsm it's not quite so bad anymore).? I really don't get it yet either, I'm inept at anything graphical, I don't speak 'math' very well, and I'm still learning ASM . . . slowly :)? All in all, I'm pretty much an idiot when it comes to this stuff.? That said, here's some information I've found useful:

some screenshots and c-style pseudocode (heavily commented - man I wish c coders would write like this rather than trying to out obfuscate each other):
http://www.wildfred.dsl.pipex.com/raycast/

here's a pretty good 2d wolfenstein-style tutorial with java source (it's not 6 degree of freedom but it's a start)
http://www.permadi.com/tutorial/raycast/

FlipCode's "Realtime Voxel Landscape Engines" article:
http://www.flipcode.com/articles/voxelland_part01.shtml

FlipCode's "Raytracing Topics & Techniques" article:
http://www.flipcode.com/articles/article_raytrace01.shtml

You'll need a line drawing algorithm (from what I've gathered).? Google will return at least a kajillion hits if you search for "bresenham".? It may not be the best, but it's extremely simple and will point you in the direction of others (DDA for example).

SetPixel in gdi32 is the only api I'm currently using (aside from the DC handling ones anyway).

My map currently takes up 128 megs and I get about 5 seconds per frame in the IDE.? No I didn't say that backwards, 5 seconds per frame.? I'm trying to figure out how to make it work first.? I'll make it work well later.? If you want to see what can be done check out Ken Silverman's Voxlap demos here: http://advsys.net/ken/voxlap.htm

If I ever get my code to the point it's not embarrasing to share, I'll hapilly post it for public consumption.

Maybe we can collaborate.? My goal is to duplicate (although not copy) Ken Silverman's work.? I'm using the GDI and all of my rotations are using Sin/Cos lookup tables.? None of what I'm doing is fast or pretty currently.? My goal is to leave the thing as a complete 6 degree of freedom 30 fps + step by step tutorial and explanation of what why and how in the three languages I don't get to use at work (C/C++, VB, and ASM) using either trig, matrices, or quats for the rotations at the user's choice (to compare speed).? That goal is because that is what I'd like to have.? I can't find it elsewhere, so I'm building it.


what api's would i need?

At a minimum?? None.? You could do it all with PSet.? It'll be extremely, painfully slow.? Speed shouldn't be a goal to start with though.


do i draw it using lines or just pixel by pixel?

From what I understand the answer is "both, and neither."? Or rather, the one covers the other.? A line goes shooting out from your eyeball, through the monitor (near viewing frustrum) and into the world (until it hits something or hits the far viewing frustrum).? If the line hits something, you find out what color that something is at the point of the intersection and make the point on the monitor that color.


or maybe do i draw just squares on the screen?
what about round objects?

I think you're stuck in 2d.? I can't be sure though.  I'm inept when it comes to graphics remember?


how do i load the map and turn that into 3d?
how do i determine my place in the map and how do i update the map to represent my position on it?

For the first question, I'm doing it the other way around.? I'm drawing the map in 3d voxel space and then saving it.? I found it was really quite a pain to build 3d models by hand and building an editor seemed sort of counter productive when I could just as easily build the editor into the "engine."


how do i render walls and ceilings and floors?
how do i texture walls and ceilings and floors?

by casting rays from your eye into the world as I described under your question about lines or pixel by pixel, above.


how does the game loop work?

Infinitely.? Seriously though, it's just a loop that hogs all the computer's resources to do your bidding any way you choose.? For now just do (in VB) Do . . . Loop While True.
Put all the draw to screen stuff in place of the elipses.


how do i remove flickering?
how do i interact with objects in this 3d world?
how do i make it fast but still look nice?
how do i create a resource archive similar to a wad?

I personally feel that this stuff is gravy.? Add it after you've filled your plate.? After all, you can't eat the gravy and then add the mashed potatoes later.? Don't worry about it until after the spuds are mashed.


can someone explain to me how a bsp tree works in idiot terms?

I'm sure someone can.? I'm equally sure that someone isn't me.? I understand the concept basically, but I skipped all the tree stuff and went to hash tables.? They fit how my mind works better.


is there a video tutorial on how to implement this and explain the concept?

I found one but can't seem to find the link to it now . . .? Spoke too soon, here it is:
http://www.siggraph.org/education/materials/HyperGraph/raytrace/rt_java/raytrace.html
Now, keep in mind that the animation here describes shadows and reflections.? I'm not planning on doing that to start (you start looking at extremely realistic renderings that take hours or days per frame when you do that).? Basically, as soon as the animation gets to 'If intersect something' I skip calling 'Shade' and just go straight to 'Put final shade in pixel'


what can i do with raycasting?
what can't i do with raycasting?
is it possible to mix different kinds of rendering so i can do what the raycaster can't do?

Google for "RayTrace".? That'll give you a good idea that will answer the above questions.? I havn't found anything that can't be done yet if you're willing to wait (raycasting/raytracing takes a long, long time for the realistic looking stuff).? See the Voxlap link above for stuff that's more applicable to games.


how do i deal with walking up stairs and down stairs,going up and down elevators etc?
how are stairs,elevators and other objects represented on the map?
how do i do rooms above rooms?
how do i do basements sub level floors etc?
how do i create and use my own file formats?
how do i use assorted texture formats?
how do i use different sound formats?
what about jumping,crouching?
how do i know how far away the wall is? and how do i draw it so it looks correct?
what about that stupid hall of mirrors effect? how do i get rid of it?
what about lines that dont fully intersect? how do i fix them so they are correct?
how do i apply bump mapping, etc. to textures?

All the rest of these are answered in one form or another above.? They're also pretty off topic for "how-to raycasting."? If you really have no idea on some of these, I suggest starting with 2d tilemap/sidescrollers.? If I'm misinterpreting the question and you just don't see how they apply to raycasting, but understand these things otherwise, the answer is that they work just the same as you already know them.

I hope that was some help.? If you or anyone else has any other references or resources, please post them!? I could use all the help I can get.

P.S. if anybody who stumbles across this has any "explained for a 5 year old" or "heavily commented for boneheads" articles or source on syntax parsing or lexical analysis I'd be forever in your debt.
Posted on 2005-03-17 03:36:34 by ChupaThingy
Don't use lookup tables for sin/cos stuff.
We're asm coders.. there's an asm solution to every problem.
Ask.
Posted on 2005-03-17 03:41:37 by Homer
if you're not referring to fsincos, consider this asking.
Posted on 2005-03-17 16:48:33 by ChupaThingy
Yeah I was referring to fsin, fcos, fsincos, and the rest..
The fpu is fast and uses no resources.
Sine lookup tables are something I used on 8 bit machines (no fpu) in the 1980s.


When I was a child, I spoke as a child, and did childish things...
Posted on 2005-03-17 17:54:05 by Homer
The only reason I'm using them at all is that the primary environment is VB.  VB is extremely slow in almost every regard except development time.  When I'm debugging in the IDE I use the tables.  When I'm not using the JIT the precompiler switches kick in and I use the asm.  I pretty much use VB as a compile-able pseudocode now.
Thanks for the response btw.
Posted on 2005-03-17 19:01:39 by ChupaThingy