# C++ Ray Traversing in 3D Voxel game

I'm currently working on a Voxel game in 3D and need a tad bit of help to figure out what Voxel the player is looking at. This is the data I currently have:

GRRLIB_Camera3dSettings(Player.x, Player.y, Player.z + 4, 0,0,1, Player.x + Camera.lookx,Player.y + Camera.looky,Player.z + Camera.lookz);


And the two 3d arrays that contains the player cords and block cords:

struct Player{
int X;
int Y;
int Z;
}
int World[X_MAX][Y_MAX][Z_MAX];
//The cords are ALWAYS positive. ( and the array data: 0 Means air, anything higher is solid), The player


(GRRLIB camera is described here: http://grrlib.santo.fr/doc/group___all_func.html#ga7300940a38526ab5aa9be0f4abe4a32a)

So what I basically need to understand is how I would implement ray tracing using this data. The whole project can be found here: https://github.com/filfat/WiiCraft

For clarification I am asking for a simple way in C or C++ to create a Ray tracing algorithm that would be used in a Minecraft like game for selecting the block the player is looking at, all data that is needed is above. So in short I need help to understand the math in a Ray Tracing algorithm and need a simple example so I could implement it myself.

Thanks! :)

• Please describe a bit more what you've tried and exactly what the problem is you're having now. How to implement an entire feature is a bit broad, so I'd suggest narrowing the scope if that's your question. – MichaelHouse Nov 10 '14 at 15:55
• Alright, edited question to be more understandable. – Filiph Sandström Nov 10 '14 at 19:13
• this is called traversing. It is the most important and basic setup step before the actual ray/thing collision routine takes place, to reduce the potential collider's set. Some people uses marching as a specific case of traversal, which incrementally progresses in the partitionning structure, often using crazy SSE tricks for packet marching, when the structure is regular enough (grids..). – v.oddou Nov 11 '14 at 1:44
• @v.oddou Didnt not know that, thanks for the heads up :) – Filiph Sandström Nov 11 '14 at 6:17