fast_voxel_traversal icon indicating copy to clipboard operation
fast_voxel_traversal copied to clipboard

last fix neg_ray ...

Open iperov opened this issue 8 years ago • 1 comments

now its cause move through diagonal on start

bool neg_ray=false;
  if (current_voxel[0]!=last_voxel[0] && ray[0]<0) { diff[0]--; neg_ray=true; }
  if (current_voxel[1]!=last_voxel[1] && ray[1]<0) { diff[1]--; neg_ray=true; }
  if (current_voxel[2]!=last_voxel[2] && ray[2]<0) { diff[2]--; neg_ray=true; }
  visited_voxels.push_back(current_voxel);
  if (neg_ray) {
    current_voxel+=diff;
    visited_voxels.push_back(current_voxel);
  }

so if 2 negrays for example first 0,0,0 second -1, -1, 0

Why need this first move by neg_ray?

iperov avatar Dec 22 '16 13:12 iperov

Think of this in 2D and picture a point in the center of a cell. The computation before this code finds the origin of the next cell, both X and Y. But you're really trying to figure out where you're first crossing both the X and Y axes and this isn't always up and to the right. If your vector goes up and to the left, you're first going to cross the vertical grid line at the Y coordinate of the CURRENT cell's origin, not that of next cell. The same goes for the other X and Z directions. So you have to subtract 1 to get back to the current cell's index in cases where you're moving in a "negative" direction.

abellgithub avatar Dec 15 '17 00:12 abellgithub