I have a 3D matrix filled with "empty space" where I put some objects (objects are represented as bunch of occupied space).
The bullet is fired from coordinates (x1,y1,z1) at angles (verticalAngle,horizontalAngle).
How do I find the first coordinates in the bullet's trajectory line which is not market as "empty space"?
I suppose I'd have to loop through all the coordinates in that line till I find the not empty one (or the end of the matrix). But how do I calculate what are those coordinates that I have to go through?
When firing a bullet in 2D space I suppose this would be calculated as
y = cos(angle) * x + startPosition where I'd increment x (in a for loop) to get y and check (x,y) cell for objects or "empty". Actually I'd have to increment y in the for loop to get x instead in case the trajectory line is closer to y-axis than x-axis.
But can someone help me with doing this in 3D space?
Well I found this formula:
(x,y,z)=(x0,y0,z0)+t(a,b,c) where (x0,y0,z0) are starting points and (a,b,c) direction factors, so I think I could increment t in a loop to get the coordinates.