Exemple #1
0
        static void GetIntVectorsInSphere(MyCubeGrid grid, Vector3I center, double radius, List <RadiatedBlock> points)
        {
            points.Clear();
            radius *= grid.GridSizeR;
            double radiusSq = radius * radius;
            int    radiusCeil = (int)Math.Ceiling(radius);
            int    i, j, k;

            for (i = -radiusCeil; i <= radiusCeil; ++i)
            {
                for (j = -radiusCeil; j <= radiusCeil; ++j)
                {
                    for (k = -radiusCeil; k <= radiusCeil; ++k)
                    {
                        if (i * i + j * j + k * k < radiusSq)
                        {
                            var          vector3I = center + new Vector3I(i, j, k);
                            IMySlimBlock slim     = grid.GetCubeBlock(vector3I);

                            if (slim != null)
                            {
                                var radiatedBlock = new RadiatedBlock
                                {
                                    Center = center, Slim = slim, Position = vector3I
                                };
                                points.Add(radiatedBlock);
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
        public void GetBlocksInsideSphereBrute(MyCubeGrid grid, Vector3I center, ref BoundingSphereD sphere, bool sorted)
        {
            if (grid.PositionComp == null)
            {
                return;
            }

            if (sorted)
            {
                _slimsSortedList.Clear();
            }
            else
            {
                _slimsSet.Clear();
            }

            var      matrixNormalizedInv = grid.PositionComp.WorldMatrixNormalizedInv;
            Vector3D result;

            Vector3D.Transform(ref sphere.Center, ref matrixNormalizedInv, out result);
            var localSphere = new BoundingSphere(result, (float)sphere.Radius);

            foreach (IMySlimBlock cube in grid.CubeBlocks)
            {
                if (new BoundingBox(cube.Min * grid.GridSize - grid.GridSizeHalf, cube.Max * grid.GridSize + grid.GridSizeHalf).Intersects(localSphere))
                {
                    var radiatedBlock = new RadiatedBlock
                    {
                        Center   = center,
                        Slim     = cube,
                        Position = cube.Position,
                    };
                    if (sorted)
                    {
                        _slimsSortedList.Add(radiatedBlock);
                    }
                    else
                    {
                        _slimsSet.Add(cube);
                    }
                }
            }
            if (sorted)
            {
                _slimsSortedList.Sort((x, y) => Vector3I.DistanceManhattan(x.Position, x.Slim.Position).CompareTo(Vector3I.DistanceManhattan(y.Position, y.Slim.Position)));
            }
        }
Exemple #3
0
        private void GetIntVectorsInSphere2(MyCubeGrid grid, Vector3I center, double radius)
        {
            _slimsSortedList.Clear();
            radius *= grid.GridSizeR;
            var      gridMin = grid.Min;
            var      gridMax = grid.Max;
            double   radiusSq = radius * radius;
            int      radiusCeil = (int)Math.Ceiling(radius);
            int      i, j, k;
            Vector3I max = Vector3I.Min(Vector3I.One * radiusCeil, gridMax - center);
            Vector3I min = Vector3I.Max(Vector3I.One * -radiusCeil, gridMin - center);

            for (i = min.X; i <= max.X; ++i)
            {
                for (j = min.Y; j <= max.Y; ++j)
                {
                    for (k = min.Z; k <= max.Z; ++k)
                    {
                        if (i * i + j * j + k * k < radiusSq)
                        {
                            var          vector3I = center + new Vector3I(i, j, k);
                            IMySlimBlock slim     = grid.GetCubeBlock(vector3I);

                            if (slim != null && slim.Position == vector3I)
                            {
                                var radiatedBlock = new RadiatedBlock
                                {
                                    Center = center, Slim = slim, Position = vector3I
                                };
                                _slimsSortedList.Add(radiatedBlock);
                            }
                        }
                    }
                }
            }
            _slimsSortedList.Sort((a, b) => Vector3I.Dot(a.Position, a.Position).CompareTo(Vector3I.Dot(b.Position, b.Position)));
        }
Exemple #4
0
        public void GetBlocksInsideSphere(MyCubeGrid grid, Dictionary <Vector3I, IMySlimBlock> cubes, ref BoundingSphereD sphere, bool sorted, Vector3I center, bool checkTriangles = false)
        {
            if (grid.PositionComp == null)
            {
                return;
            }

            if (sorted)
            {
                _slimsSortedList.Clear();
            }
            else
            {
                _slimsSet.Clear();
            }

            var      matrixNormalizedInv = grid.PositionComp.WorldMatrixNormalizedInv;
            Vector3D result;

            Vector3D.Transform(ref sphere.Center, ref matrixNormalizedInv, out result);
            var localSphere = new BoundingSphere(result, (float)sphere.Radius);
            var fromSphere2 = BoundingBox.CreateFromSphere(localSphere);
            var min         = (Vector3D)fromSphere2.Min;
            var max         = (Vector3D)fromSphere2.Max;
            var vector3I1   = new Vector3I((int)Math.Round(min.X * grid.GridSizeR), (int)Math.Round(min.Y * grid.GridSizeR), (int)Math.Round(min.Z * grid.GridSizeR));
            var vector3I2   = new Vector3I((int)Math.Round(max.X * grid.GridSizeR), (int)Math.Round(max.Y * grid.GridSizeR), (int)Math.Round(max.Z * grid.GridSizeR));
            var start       = Vector3I.Min(vector3I1, vector3I2);
            var end         = Vector3I.Max(vector3I1, vector3I2);

            if ((end - start).Volume() < cubes.Count)
            {
                var vector3IRangeIterator = new Vector3I_RangeIterator(ref start, ref end);
                var next = vector3IRangeIterator.Current;
                while (vector3IRangeIterator.IsValid())
                {
                    IMySlimBlock cube;
                    if (cubes.TryGetValue(next, out cube))
                    {
                        if (new BoundingBox(cube.Min * grid.GridSize - grid.GridSizeHalf, cube.Max * grid.GridSize + grid.GridSizeHalf).Intersects(localSphere))
                        {
                            var radiatedBlock = new RadiatedBlock
                            {
                                Center   = center,
                                Slim     = cube,
                                Position = cube.Position,
                            };
                            if (sorted)
                            {
                                _slimsSortedList.Add(radiatedBlock);
                            }
                            else
                            {
                                _slimsSet.Add(cube);
                            }
                        }
                    }
                    vector3IRangeIterator.GetNext(out next);
                }
            }
            else
            {
                foreach (var cube in cubes.Values)
                {
                    if (new BoundingBox(cube.Min * grid.GridSize - grid.GridSizeHalf, cube.Max * grid.GridSize + grid.GridSizeHalf).Intersects(localSphere))
                    {
                        var radiatedBlock = new RadiatedBlock
                        {
                            Center   = center,
                            Slim     = cube,
                            Position = cube.Position,
                        };
                        if (sorted)
                        {
                            _slimsSortedList.Add(radiatedBlock);
                        }
                        else
                        {
                            _slimsSet.Add(cube);
                        }
                    }
                }
            }
            if (sorted)
            {
                _slimsSortedList.Sort((x, y) => Vector3I.DistanceManhattan(x.Position, x.Slim.Position).CompareTo(Vector3I.DistanceManhattan(y.Position, y.Slim.Position)));
            }
        }