public VoxelMarcher(Vector3I worldSize)
 {
     _worldSize      = worldSize;
     _colliding      = false;
     _position       = new Vector3I();
     _distanceToNext = new Vector3M();
 }
Exemple #2
0
        private void Update()
        {
            if (_path == null || !_path.Any())
            {
                _path = null;
            }

            if (_path != null)
            {
                int moves = 0;
                _timeSummer += Time.deltaTime;
                while (_timeSummer >= TimePerMove)
                {
                    _timeSummer -= TimePerMove;
                    moves++;
                }

                while (moves != 0 && _path.Any())
                {
                    Vector3M pos = _path[_path.Count - 1];
                    Map[pos.V.x, pos.V.y].Renderer.material.color = Color.green;
                    _path.RemoveAt(_path.Count - 1);
                    moves--;
                }
            }
        }
 public bool CalculateNextPosition()
 {
     if (_colliding)
     {
         _distanceToNext -= _marchingDirection.Abs() * CalculateCheapestStep();
         for (int i = 0; i <= 2; i++)
         {
             if (_distanceToNext[i] == 0.0m)
             {
                 _distanceToNext[i] = 1.0m;
                 _position[i]      += Math.Sign(_marchingDirection[i]);
             }
         }
     }
     _colliding = PositionIsInsideWorld(_position) || PositionIsUnderWorld(_position);
     return(_colliding);
 }
        private void SetStartPosition(Vector3 position)
        {
            Vector3M fraction = (Vector3M)position;

            _position       = (Vector3I)fraction.Floor();
            _distanceToNext = fraction - _position;

            for (int i = 0; i <= 2; i++)
            {
                if (_marchingDirection[i] < 0)
                {
                    if (_distanceToNext[i] == 0.0m)
                    {
                        _position[i]--;
                        _distanceToNext[i] = 1.0m;
                    }
                }
                else
                {
                    _distanceToNext[i] = 1 - _distanceToNext[i];
                }
            }
        }
 public bool InitializeStartPosition(Vector3 rayStartPosition, Vector3 rayDirection)
 {
     _marchingDirection = (Vector3M)rayDirection;
     _colliding         = CalculateStartPosition(rayStartPosition, rayDirection);
     return(_colliding);
 }