Raycasting Math Help

Blitz3D Forums/Blitz3D Programming/Raycasting Math Help

ClayPigeon(Posted 2012) [#1]
I'm working on a raycaster for rendering a voxel dataset. I have already decided on how I'm going to project the rays: I will create a vector out of a pixel on the viewing plane relative to the viewer. Then, I'll normalize the vector and use that vector as the ray's step size. The only thing that I need help with is all the confusing math required to rotate the viewing plane about the viewer. It seems the only way I can find so far involves a projection matrix, which is rather hard for me to grasp at this point. If anyone can show me a way of rotating the viewing plane about the viewer, I would greatly appreciate it. And, I am specifically looking for a way to rotate the viewing plane, as apposed to the dataset because it's faster to transform 640*480 points as opposed to 1024*64*1024 or however many voxels I'll end up with. All help appreciated!!


P.S. I'm not interested in people trying to tell me I shouldn't be writing a software renderer. I'm aware B3D can be a little slow. :)

Last edited 2012

Last edited 2012


Yasha(Posted 2012) [#2]
the only way I can find so far involves a projection matrix


You're not going to like this answer, but you basically need to learn how to manipulate matrices if you want to do anything serious in 3D, such as this task.

Roll/Pitch/Yaw simply don't provide the necessary information, consistency, or speed for this kind of work, which is why nobody uses them (which in turn will be why there are no examples). Take note that internally Blitz3D doesn't use them either.


ClayPigeon(Posted 2012) [#3]
You're not going to like this answer


I kind of expected this answer, and frankly, I'm fine with it. I really shouldn't beat around the bush. I really need to learn this kind of stuff anyway if I want to make any useful progress.

I did read up on matrices all day today, trying to understand them. I know how to add, subtract, and multiply matrices, and it seems that's all I need to know how to do. Also, I (think) I understand the "homogeneous coordinates". (I guess it could be described as a vector, and w is the magnitude?) And that's where it I sort of lose track of what's going on. Can you supply an example of a function that rotates a point around the origin using a transformation matrix? I would like to understand this. (Copy-Pasting code is like scratching nails on a chalkboard to me XD -- I have to re-write it myself and know how every aspect of my code works to be happy)

Last edited 2012


Adam Novagen(Posted 2012) [#4]
I have a particular interest in this thread too. For the moment, my 3D work is comprised almost exclusively of using 3D hardware rendering to display 2D imagery, but that won't hold me forever; I know absolutely NOTHING about matrices. Most of the first half of ClayPigeon's post was gibberish to me, so I think it's time I expanded my horizons.


jfk EO-11110(Posted 2012) [#5]
Not sure if I get this right at all, but as far as I remember there were no matrices involved when I wrote those old Raycasters, for something like a 2.5D Wolfenstein-like maze in QB. With Atan2, Sin and Cos I was able to get the X and Z Stepsize. Sorry if I completely missed the point.

(there may be a sample or two in the archives)

Last edited 2012


Yasha(Posted 2012) [#6]
Sorry my comment about 3D requiring matrices was assuming full 3D... as jfk says, if you want 2.5D you should be fine with "simpler" maths and yes, there are examples of this in action in the archives (and they're awesome).

You could probably make a 2.5D renderer more efficient with matrices, but they're not quite as necessary as they are for full 3D rotation (strictly speaking they're not necessary there either, it's just that the maths for using Euler angles becomes unspeakably complex and filled with edge cases).

Jfk's own examples (man, you're too modest with your own work):

http://www.blitzbasic.com/codearcs/codearcs.php?code=579
http://www.blitzbasic.com/codearcs/codearcs.php?code=418
http://www.blitzbasic.com/codearcs/codearcs.php?code=896 (this one's especially cool)

Last edited 2012


ClayPigeon(Posted 2012) [#7]
I figured that would be assumed. No. I do not want 2.5D, but I don't want to call it raytracing because then everyone will have a seizure and get all "NO RAYTRACINGS ON TEH BLITZ3D!!!!! U CRAZY!?!?!?". I want a fully 3D renderer, and I know how I'm going to optimize it. I'm not having anything insane like multiple bounces and volumetric subsurface scattering. In other words, I'm not going to be simulating the entire universe and everything in it. It'll be pretty fast, just not 2.5D. :)