Exemplo n.º 1
0
            private void UpdateSlimBlock()
            {
                var grid = _root as IMyCubeGrid;

                _block = grid?.FirstBlock(_hit.Position,
                                          _hit.Position + _maxPrediction * _ray.Direction);
                if (_block == null)
                {
                    return;
                }

                Vector3 halfExtents;

                _block.ComputeScaledHalfExtents(out halfExtents);
                Vector3D center;

                _block.ComputeScaledCenter(out center);
                var   bb = new BoundingBoxD(center - halfExtents, center + halfExtents);
                LineD l;
                var   m = grid.WorldMatrixNormalizedInv;

                l.From      = Vector3D.Transform(_ray.From, ref m);
                l.To        = Vector3D.Transform(_ray.To, ref m);
                l.Direction = Vector3D.TransformNormal(_ray.Direction, ref m);
                l.Length    = _ray.Length;
                double t1, t2;

                if (bb.Intersect(ref l, out t1, out t2))
                {
                    _hitPosition = _ray.From + _ray.Direction * t1;
                }
                else
                {
                    _hitPosition = _ray.From + (Vector3.Transform(center, grid.WorldMatrix) - _ray.From).Dot(_ray.Direction) * _ray.Direction;
                }
            }