public void startWalk(final Ray3 walkRay) {
// store ray
_walkRay.set(walkRay);
// simplify access to direction
final ReadOnlyVector3 direction = _walkRay.getDirection();
// Move start point to grid space
final Vector3 start = _walkRay.getOrigin().subtract(_gridOrigin, null);
_gridLocation[0] = (int) MathUtils.floor(start.getX() / _gridSpacing.getX());
_gridLocation[1] = (int) MathUtils.floor(start.getZ() / _gridSpacing.getZ());
final double invDirX = 1.0 / direction.getX();
final double invDirZ = 1.0 / direction.getZ();
// Check which direction on the X world axis we are moving.
if (direction.getX() > BresenhamYUpGridTracer.TOLERANCE) {
_distToNextXIntersection = ((_gridLocation[0] + 1) * _gridSpacing.getX() - start.getX()) * invDirX;
_distBetweenXIntersections = _gridSpacing.getX() * invDirX;
_stepXDirection = 1;
} else if (direction.getX() < -BresenhamYUpGridTracer.TOLERANCE) {
_distToNextXIntersection = (start.getX() - _gridLocation[0] * _gridSpacing.getX()) * -direction.getX();
_distBetweenXIntersections = -_gridSpacing.getX() * invDirX;
_stepXDirection = -1;
} else {
_distToNextXIntersection = Double.MAX_VALUE;
_distBetweenXIntersections = Double.MAX_VALUE;
_stepXDirection = 0;
}
// Check which direction on the Z world axis we are moving.
if (direction.getZ() > BresenhamYUpGridTracer.TOLERANCE) {
_distToNextZIntersection = ((_gridLocation[1] + 1) * _gridSpacing.getZ() - start.getZ()) * invDirZ;
_distBetweenZIntersections = _gridSpacing.getZ() * invDirZ;
_stepZDirection = 1;
} else if (direction.getZ() < -BresenhamYUpGridTracer.TOLERANCE) {
_distToNextZIntersection = (start.getZ() - _gridLocation[1] * _gridSpacing.getZ()) * -direction.getZ();
_distBetweenZIntersections = -_gridSpacing.getZ() * invDirZ;
_stepZDirection = -1;
} else {
_distToNextZIntersection = Double.MAX_VALUE;
_distBetweenZIntersections = Double.MAX_VALUE;