예제 #1
0
 bool IMyCubeGrid.CanMergeCubes(IMyCubeGrid gridToMerge, VRageMath.Vector3I gridOffset)
 {
     if (gridToMerge is MyCubeGrid)
     {
         return(CanMergeCubes(gridToMerge as MyCubeGrid, gridOffset));
     }
     return(false);
 }
예제 #2
0
 IMyCubeGrid IMyCubeGrid.MergeGrid_MergeBlock(IMyCubeGrid gridToMerge, VRageMath.Vector3I gridOffset)
 {
     if (gridToMerge is MyCubeGrid)
     {
         return(MergeGrid_MergeBlock(gridToMerge as MyCubeGrid, gridOffset));
     }
     return(null);
 }
예제 #3
0
        protected override MyProceduralCell GenerateProceduralCell(ref VRageMath.Vector3I cellId)
        {
            MyProceduralCell cell = new MyProceduralCell(cellId, this.CELL_SIZE);

            ProfilerShort.Begin("GenerateProceduralCell");

            IMyModule densityFunctionFilled = GetCellDensityFunctionFilled(cell.BoundingVolume);

            if (densityFunctionFilled == null)
            {
                ProfilerShort.End();
                return(null);
            }
            IMyModule densityFunctionRemoved = GetCellDensityFunctionRemoved(cell.BoundingVolume);

            int cellSeed = GetCellSeed(ref cellId);
            var random   = MyRandom.Instance;

            using (random.PushSeed(cellSeed))
            {
                Vector3D position = new Vector3D(random.NextDouble(), random.NextDouble(), random.NextDouble());
                position *= (CELL_SIZE - 2 * OBJECT_SEED_RADIUS) / CELL_SIZE;
                position += OBJECT_SEED_RADIUS / CELL_SIZE;
                position += (Vector3D)cellId;
                position *= CELL_SIZE;

                if (MyEntities.IsInsideWorld(position))
                {
                    ProfilerShort.Begin("GetValue");
                    var value = densityFunctionFilled.GetValue(position.X, position.Y, position.Z);
                    ProfilerShort.End();

                    if (value < m_objectDensity) // -1..+1
                    {
                        var size       = MathHelper.Lerp(PLANET_SIZE_MIN, PLANET_SIZE_MAX, random.NextDouble());
                        var objectSeed = new MyObjectSeed(cell, position, size);
                        objectSeed.Params.Type  = MyObjectSeedType.Planet;
                        objectSeed.Params.Seed  = random.Next();
                        objectSeed.Params.Index = 0;
                        objectSeed.UserData     = new MySphereDensityFunction(position, PLANET_SIZE_MAX / 2.0 * GRAVITY_SIZE_MULTIPLIER + FALLOFF, FALLOFF);

                        int index = 1;
                        GenerateObject(cell, objectSeed, ref index, random, densityFunctionFilled, densityFunctionRemoved);
                    }
                }
            }

            ProfilerShort.End();
            return(cell);
        }
예제 #4
0
 public void Inflate(int size)
 {
     this.Max += new Vector3I(size);
     this.Min -= new Vector3I(size);
 }
예제 #5
0
        public float Volume()
        {
            Vector3I vectori = this.Max - this.Min;

            return((float)((vectori.X * vectori.Y) * vectori.Z));
        }
예제 #6
0
 public BoundingBoxI(BoundingBox box)
 {
     this.Min = new Vector3I(box.Min);
     this.Max = new Vector3I(box.Max);
 }
예제 #7
0
 VRageMath.MatrixI IMyCubeGrid.CalculateMergeTransform(IMyCubeGrid gridToMerge, VRageMath.Vector3I gridOffset)
 {
     if (gridToMerge is MyCubeGrid)
     {
         return(CalculateMergeTransform(gridToMerge as MyCubeGrid, gridOffset));
     }
     return(new MatrixI());
 }
예제 #8
0
 public static Direction GetDirection(Vector3I vec)
 {
     return(GetDirection(ref vec));
 }
예제 #9
0
 public static Direction GetDirection(Vector3I vec) =>
 GetDirection(ref vec);
예제 #10
0
 public void Contains(ref Vector3I point, out ContainmentType result)
 {
     result = ((((this.Min.X > point.X) || (point.X > this.Max.X)) || ((this.Min.Y > point.Y) || (point.Y > this.Max.Y))) || ((this.Min.Z > point.Z) || (point.Z > this.Max.Z))) ? ContainmentType.Disjoint : ContainmentType.Contains;
 }
예제 #11
0
 internal void SupportMapping(ref Vector3I v, out Vector3I result)
 {
     result.X = (v.X >= 0.0) ? this.Max.X : this.Min.X;
     result.Y = (v.Y >= 0.0) ? this.Max.Y : this.Min.Y;
     result.Z = (v.Z >= 0.0) ? this.Max.Z : this.Min.Z;
 }
예제 #12
0
 public BoundingBoxI(int min, int max)
 {
     this.Min = new Vector3I(min);
     this.Max = new Vector3I(max);
 }
예제 #13
0
        public float Distance(Vector3I point)
        {
            Vector3I vectori2 = Vector3I.Clamp(point, this.Min, this.Max) - point;

            return((float)vectori2.Length());
        }
예제 #14
0
 public BoundingBoxI(Vector3I min, Vector3I max)
 {
     this.Min = min;
     this.Max = max;
 }
예제 #15
0
        public bool IntersectsTriangle(ref Vector3I v0, ref Vector3I v1, ref Vector3I v2)
        {
            Vector3I vectori;
            Vector3I vectori2;
            Vector3I vectori5;
            int      num;
            PlaneIntersectionType type;

            Vector3I.Min(ref v0, ref v1, out vectori);
            Vector3I.Min(ref vectori, ref v2, out vectori);
            Vector3I.Max(ref v0, ref v1, out vectori2);
            Vector3I.Max(ref vectori2, ref v2, out vectori2);
            if (vectori.X > this.Max.X)
            {
                return(false);
            }
            if (vectori2.X < this.Min.X)
            {
                return(false);
            }
            if (vectori.Y > this.Max.Y)
            {
                return(false);
            }
            if (vectori2.Y < this.Min.Y)
            {
                return(false);
            }
            if (vectori.Z > this.Max.Z)
            {
                return(false);
            }
            if (vectori2.Z < this.Min.Z)
            {
                return(false);
            }
            Vector3I vectori3 = v1 - v0;
            Vector3I vectori4 = v2 - v1;

            Vector3I.Cross(ref vectori3, ref vectori4, out vectori5);
            Vector3I.Dot(ref v0, ref vectori5, out num);
            Plane plane = new Plane((Vector3)vectori5, (float)-num);

            this.Intersects(ref plane, out type);
            switch (type)
            {
            case PlaneIntersectionType.Back:
                return(false);

            case PlaneIntersectionType.Front:
                return(false);
            }
            Vector3I     center      = this.Center;
            BoundingBoxI xi          = new BoundingBoxI(this.Min - center, this.Max - center);
            Vector3I     halfExtents = xi.HalfExtents;
            Vector3I     vectori8    = v0 - v2;
            Vector3I     vectori9    = v0 - center;
            Vector3I     vectori10   = v1 - center;
            Vector3I     vectori11   = v2 - center;
            float        num2        = (halfExtents.Y * Math.Abs(vectori3.Z)) + (halfExtents.Z * Math.Abs(vectori3.Y));
            float        num3        = (vectori9.Z * vectori10.Y) - (vectori9.Y * vectori10.Z);
            float        num5        = (vectori11.Z * vectori3.Y) - (vectori11.Y * vectori3.Z);

            if ((Math.Min(num3, num5) > num2) || (Math.Max(num3, num5) < -num2))
            {
                return(false);
            }
            num2 = (halfExtents.X * Math.Abs(vectori3.Z)) + (halfExtents.Z * Math.Abs(vectori3.X));
            num3 = (vectori9.X * vectori10.Z) - (vectori9.Z * vectori10.X);
            num5 = (vectori11.X * vectori3.Z) - (vectori11.Z * vectori3.X);
            if ((Math.Min(num3, num5) > num2) || (Math.Max(num3, num5) < -num2))
            {
                return(false);
            }
            num2 = (halfExtents.X * Math.Abs(vectori3.Y)) + (halfExtents.Y * Math.Abs(vectori3.X));
            num3 = (vectori9.Y * vectori10.X) - (vectori9.X * vectori10.Y);
            num5 = (vectori11.Y * vectori3.X) - (vectori11.X * vectori3.Y);
            if ((Math.Min(num3, num5) > num2) || (Math.Max(num3, num5) < -num2))
            {
                return(false);
            }
            num2 = (halfExtents.Y * Math.Abs(vectori4.Z)) + (halfExtents.Z * Math.Abs(vectori4.Y));
            float num4 = (vectori10.Z * vectori11.Y) - (vectori10.Y * vectori11.Z);

            num3 = (vectori9.Z * vectori4.Y) - (vectori9.Y * vectori4.Z);
            if ((Math.Min(num4, num3) > num2) || (Math.Max(num4, num3) < -num2))
            {
                return(false);
            }
            num2 = (halfExtents.X * Math.Abs(vectori4.Z)) + (halfExtents.Z * Math.Abs(vectori4.X));
            num4 = (vectori10.X * vectori11.Z) - (vectori10.Z * vectori11.X);
            num3 = (vectori9.X * vectori4.Z) - (vectori9.Z * vectori4.X);
            if ((Math.Min(num4, num3) > num2) || (Math.Max(num4, num3) < -num2))
            {
                return(false);
            }
            num2 = (halfExtents.X * Math.Abs(vectori4.Y)) + (halfExtents.Y * Math.Abs(vectori4.X));
            num4 = (vectori10.Y * vectori11.X) - (vectori10.X * vectori11.Y);
            num3 = (vectori9.Y * vectori4.X) - (vectori9.X * vectori4.Y);
            if ((Math.Min(num4, num3) > num2) || (Math.Max(num4, num3) < -num2))
            {
                return(false);
            }
            num2 = (halfExtents.Y * Math.Abs(vectori8.Z)) + (halfExtents.Z * Math.Abs(vectori8.Y));
            num5 = (vectori11.Z * vectori9.Y) - (vectori11.Y * vectori9.Z);
            num4 = (vectori10.Z * vectori8.Y) - (vectori10.Y * vectori8.Z);
            if ((Math.Min(num5, num4) > num2) || (Math.Max(num5, num4) < -num2))
            {
                return(false);
            }
            num2 = (halfExtents.X * Math.Abs(vectori8.Z)) + (halfExtents.Z * Math.Abs(vectori8.X));
            num5 = (vectori11.X * vectori9.Z) - (vectori11.Z * vectori9.X);
            num4 = (vectori10.X * vectori8.Z) - (vectori10.Z * vectori8.X);
            if ((Math.Min(num5, num4) > num2) || (Math.Max(num5, num4) < -num2))
            {
                return(false);
            }
            num2 = (halfExtents.X * Math.Abs(vectori8.Y)) + (halfExtents.Y * Math.Abs(vectori8.X));
            num5 = (vectori11.Y * vectori9.X) - (vectori11.X * vectori9.Y);
            num4 = (vectori10.Y * vectori8.X) - (vectori10.X * vectori8.Y);
            return((Math.Min(num5, num4) <= num2) && (Math.Max(num5, num4) >= -num2));
        }
예제 #16
0
 public bool IntersectsTriangle(Vector3I v0, Vector3I v1, Vector3I v2) =>
 this.IntersectsTriangle(ref v0, ref v1, ref v2);
예제 #17
0
        public static IEnumerable <Vector3I> IterateDifference(BoundingBoxI left, BoundingBoxI right)
        {
            Vector3I iteratorVariable0;
            Vector3I min = left.Min;
            int      x   = Math.Min(left.Max.X, right.Min.X);
            Vector3I max = new Vector3I(x, left.Max.Y, left.Max.Z);

            iteratorVariable0.X = min.X;
            while (iteratorVariable0.X < max.X)
            {
                iteratorVariable0.Y = min.Y;
                while (iteratorVariable0.Y < max.Y)
                {
                    iteratorVariable0.Z = min.Z;
                    while (iteratorVariable0.Z < max.Z)
                    {
                        yield return(iteratorVariable0);

                        iteratorVariable0.Z++;
                    }
                    iteratorVariable0.Y++;
                }
                iteratorVariable0.X++;
            }
            int introduced2 = Math.Max(left.Min.X, right.Max.X);

            min = new Vector3I(introduced2, left.Min.Y, left.Min.Z);
            max = left.Max;
            iteratorVariable0.X = min.X;
            while (iteratorVariable0.X < max.X)
            {
                iteratorVariable0.Y = min.Y;
                while (iteratorVariable0.Y < max.Y)
                {
                    iteratorVariable0.Z = min.Z;
                    while (iteratorVariable0.Z < max.Z)
                    {
                        yield return(iteratorVariable0);

                        iteratorVariable0.Z++;
                    }
                    iteratorVariable0.Y++;
                }
                iteratorVariable0.X++;
            }
            left.Min.X = Math.Max(left.Min.X, right.Min.X);
            left.Max.X = Math.Min(left.Max.X, right.Max.X);
            min        = left.Min;
            int y = Math.Min(left.Max.Y, right.Min.Y);

            max = new Vector3I(left.Max.X, y, left.Max.Z);
            iteratorVariable0.Y = min.Y;
            while (iteratorVariable0.Y < max.Y)
            {
                iteratorVariable0.X = min.X;
                while (iteratorVariable0.X < max.X)
                {
                    iteratorVariable0.Z = min.Z;
                    while (iteratorVariable0.Z < max.Z)
                    {
                        yield return(iteratorVariable0);

                        iteratorVariable0.Z++;
                    }
                    iteratorVariable0.X++;
                }
                iteratorVariable0.Y++;
            }
            int introduced4 = Math.Max(left.Min.Y, right.Max.Y);

            min = new Vector3I(left.Min.X, introduced4, left.Min.Z);
            max = left.Max;
            iteratorVariable0.Y = min.Y;
            while (iteratorVariable0.Y < max.Y)
            {
                iteratorVariable0.X = min.X;
                while (iteratorVariable0.X < max.X)
                {
                    iteratorVariable0.Z = min.Z;
                    while (iteratorVariable0.Z < max.Z)
                    {
                        yield return(iteratorVariable0);

                        iteratorVariable0.Z++;
                    }
                    iteratorVariable0.X++;
                }
                iteratorVariable0.Y++;
            }
            left.Min.Y          = Math.Max(left.Min.Y, right.Min.Y);
            left.Max.Y          = Math.Min(left.Max.Y, right.Max.Y);
            min                 = left.Min;
            max                 = new Vector3I(left.Max.X, left.Max.Y, Math.Min(left.Max.Z, right.Min.Z));
            iteratorVariable0.Z = min.Z;
            while (iteratorVariable0.Z < max.Z)
            {
                iteratorVariable0.Y = min.Y;
                while (iteratorVariable0.Y < max.Y)
                {
                    iteratorVariable0.X = min.X;
                    while (iteratorVariable0.X < max.X)
                    {
                        yield return(iteratorVariable0);

                        iteratorVariable0.X++;
                    }
                    iteratorVariable0.Y++;
                }
                iteratorVariable0.Z++;
            }
            min = new Vector3I(left.Min.X, left.Min.Y, Math.Max(left.Min.Z, right.Max.Z));
            max = left.Max;
            iteratorVariable0.Z = min.Z;
            while (iteratorVariable0.Z < max.Z)
            {
                iteratorVariable0.Y = min.Y;
                while (iteratorVariable0.Y < max.Y)
                {
                    iteratorVariable0.X = min.X;
                    while (iteratorVariable0.X < max.X)
                    {
                        yield return(iteratorVariable0);

                        iteratorVariable0.X++;
                    }
                    iteratorVariable0.Y++;
                }
                iteratorVariable0.Z++;
            }
        }
예제 #18
0
 public BoundingBoxI Translate(Vector3I vctTranlsation)
 {
     this.Min += vctTranlsation;
     this.Max += vctTranlsation;
     return(this);
 }
예제 #19
0
 public Vector3B(Vector3I vec)
 {
     this.X = (sbyte)vec.X;
     this.Y = (sbyte)vec.Y;
     this.Z = (sbyte)vec.Z;
 }
예제 #20
0
 public BoundingBoxI Include(Vector3I point) =>
 this.Include(ref point);
예제 #21
0
 public static bool IsBaseDirection(ref Vector3I vec) =>
 (((((vec.X * vec.X) + (vec.Y * vec.Y)) + (vec.Z * vec.Z)) - 1) == 0);
예제 #22
0
 public BoundingBoxI Include(Vector3I p0, Vector3I p1, Vector3I p2) =>
 this.Include(ref p0, ref p1, ref p2);
예제 #23
0
 public static bool IsBaseDirection(ref Vector3I vec)
 {
     return((vec.X * vec.X + vec.Y * vec.Y + vec.Z * vec.Z) - 1 == 0);
 }
예제 #24
0
 IMySlimBlock IMyCubeGrid.GetCubeBlock(VRageMath.Vector3I pos)
 {
     return(GetCubeBlock(pos));
 }
        protected override MyProceduralCell GenerateProceduralCell(ref VRageMath.Vector3I cellId)
        {
            MyProceduralCell cell = new MyProceduralCell(cellId, this);

            ProfilerShort.Begin("GenerateObjectSeedsCell");

            IMyModule densityFunctionFilled = GetCellDensityFunctionFilled(cell.BoundingVolume);

            if (densityFunctionFilled == null)
            {
                ProfilerShort.End();
                return(null);
            }
            IMyModule densityFunctionRemoved = GetCellDensityFunctionRemoved(cell.BoundingVolume);

            int cellSeed = GetCellSeed(ref cellId);
            var random   = MyRandom.Instance;

            using (random.PushSeed(cellSeed))
            {
                int      index     = 0;
                Vector3I subCellId = Vector3I.Zero;
                Vector3I max       = new Vector3I(SUBCELLS - 1);
                for (var iter = new Vector3I.RangeIterator(ref Vector3I.Zero, ref max); iter.IsValid(); iter.GetNext(out subCellId))
                {
                    // there is a bug in the position calculation which can very rarely cause overlaping objects but backwards compatibility so meh
                    Vector3D position = new Vector3D(random.NextDouble(), random.NextDouble(), random.NextDouble());
                    position += (Vector3D)subCellId / SUBCELL_SIZE;
                    position += cellId;
                    position *= CELL_SIZE;

                    if (!MyEntities.IsInsideWorld(position))
                    {
                        continue;
                    }

                    ProfilerShort.Begin("Density functions");
                    double valueRemoved = -1;
                    if (densityFunctionRemoved != null)
                    {
                        valueRemoved = densityFunctionRemoved.GetValue(position.X, position.Y, position.Z);

                        if (valueRemoved <= -1)
                        {
                            ProfilerShort.End();
                            continue;
                        }
                    }

                    var valueFilled = densityFunctionFilled.GetValue(position.X, position.Y, position.Z);

                    if (densityFunctionRemoved != null)
                    {
                        if (valueRemoved < valueFilled)
                        {
                            ProfilerShort.End();
                            continue;
                        }
                    }
                    ProfilerShort.End();

                    if (valueFilled < m_objectDensity) // -1..+1
                    {
                        var objectSeed = new MyObjectSeed(cell, position, GetObjectSize(random.NextDouble()));
                        objectSeed.Type  = GetSeedType(random.NextDouble());
                        objectSeed.Seed  = random.Next();
                        objectSeed.Index = index++;

                        GenerateObject(cell, objectSeed, ref index, random, densityFunctionFilled, densityFunctionRemoved);
                    }
                }
            }

            ProfilerShort.End();
            return(cell);
        }
예제 #26
0
 public MatrixI(ref Vector3I position, ref Vector3 forward, ref Vector3 up) :
     this(ref position, Base6Directions.GetDirection(ref forward), Base6Directions.GetDirection(ref up))
 {
 }
예제 #27
0
 public BoundingBoxI Include(ref BoundingBoxI box)
 {
     this.Min = Vector3I.Min(this.Min, box.Min);
     this.Max = Vector3I.Max(this.Max, box.Max);
     return(this);
 }
예제 #28
0
 public void GetNext(out Vector3I next)
 {
     MoveNext();
     next = Current;
 }
예제 #29
0
        public float SurfaceArea()
        {
            Vector3I vectori = this.Max - this.Min;

            return((float)(2 * (((vectori.X * vectori.Y) + (vectori.X * vectori.Z)) + (vectori.Y * vectori.Z))));
        }
예제 #30
0
 /// <summary>
 /// Tests whether the BoundingBoxI contains a point.
 /// </summary>
 /// <param name="point">The point to test for overlap.</param><param name="result">[OutAttribute] Enumeration indicating the extent of overlap.</param>
 public void Contains(ref Vector3I point, out ContainmentType result)
 {
     result = (double)this.Min.X > (double)point.X || (double)point.X > (double)this.Max.X || ((double)this.Min.Y > (double)point.Y || (double)point.Y > (double)this.Max.Y) || ((double)this.Min.Z > (double)point.Z || (double)point.Z > (double)this.Max.Z) ? ContainmentType.Disjoint : ContainmentType.Contains;
 }