Example #1
0
        public static void GetSegmentCount(float latitude, float longitude, out float latitudeCount, out float longitudeCount)
        {
            latitudeCount = latitude / 6.2831855f * currentGrid.segment;
            int latitudeIndex = Mathf.FloorToInt(Mathf.Abs(latitudeCount));
            int segmentCount  = PlanetGrid.DetermineLongitudeSegmentCount(latitudeIndex, currentGrid.segment);

            longitudeCount = longitude / 6.2831855f * segmentCount;
        }
Example #2
0
        public static int GetSegmentsCount(this Vector2 vector)
        {
            int segments = GameMain.localPlanet.aux.mainGrid.segment;

            float rawLatitudeIndex = (vector.x - Mathf.PI / 2) / 6.2831855f * segments;
            int   latitudeIndex    = Mathf.FloorToInt(Mathf.Max(0f, Mathf.Abs(rawLatitudeIndex) - 0.1f));

            return(PlanetGrid.DetermineLongitudeSegmentCount(latitudeIndex, segments));
        }
Example #3
0
        public static int GetSegmentsCount(this Vector2 vector)
        {
            float planetRadius = GameMain.localPlanet.realRadius;

            float rawLatitudeIndex = (vector.x - Mathf.PI / 2) / 6.2831855f * planetRadius;
            int   latitudeIndex    = Mathf.FloorToInt(Mathf.Max(0f, Mathf.Abs(rawLatitudeIndex) - 0.1f));

            return(PlanetGrid.DetermineLongitudeSegmentCount(latitudeIndex, (int)planetRadius));
        }
Example #4
0
        public static void PasteBelt(int index, BeltCopy belt, Vector2 targetSpr, float yaw)
        {
            Vector2 newRelative = belt.cursorRelativePos.Rotate(yaw * Mathf.Deg2Rad, belt.originalSegmentCount);
            Vector2 sprPos      = newRelative + targetSpr;

            float rawLatitudeIndex = (sprPos.x - Mathf.PI / 2) / 6.2831855f * 200;
            int   latitudeIndex    = Mathf.FloorToInt(Mathf.Max(0f, Mathf.Abs(rawLatitudeIndex) - 0.1f));
            int   newSegmentCount  = PlanetGrid.DetermineLongitudeSegmentCount(latitudeIndex, 200);

            float sizeDeviation = belt.originalSegmentCount / (float)newSegmentCount;

            sprPos = new Vector2(newRelative.x, newRelative.y * sizeDeviation) + targetSpr;

            Vector3 absoluteBeltPos = sprPos.SnapToGrid(belt.altitude * 1.3333333f / 2);

            // belts have always 0 yaw
            Quaternion absoluteBeltRot = Maths.SphericalRotation(absoluteBeltPos, 0f);

            BuildPreview bp = BuildPreview.CreateSingle(belt.itemProto, belt.itemProto.prefabDesc, false);

            bp.lpos           = absoluteBeltPos;
            bp.lrot           = absoluteBeltRot;
            bp.outputToSlot   = -1;
            bp.outputFromSlot = 0;

            bp.inputFromSlot = -1;
            bp.inputToSlot   = 1;

            bp.outputOffset = 0;
            bp.inputOffset  = 0;

            Pose pose = new Pose(absoluteBeltPos, absoluteBeltRot);

            int objId = InserterPoses.AddOverride(pose, belt.itemProto);

            pastedEntities.Add(belt.originalId, new PastedEntity()
            {
                type         = EPastedType.BELT,
                index        = index,
                pose         = pose,
                objId        = objId,
                buildPreview = bp,
            });

            previews.Add(bp);
        }
Example #5
0
        public static void PasteBuilding(int index, BuildingCopy building, Vector2 targetSpr, float yaw)
        {
            Vector2 newRelative = building.cursorRelativePos.Rotate(yaw * Mathf.Deg2Rad, building.originalSegmentCount);
            Vector2 sprPos      = newRelative + targetSpr;

            float rawLatitudeIndex = (sprPos.x - Mathf.PI / 2) / 6.2831855f * 200;
            int   latitudeIndex    = Mathf.FloorToInt(Mathf.Max(0f, Mathf.Abs(rawLatitudeIndex) - 0.1f));
            int   newSegmentCount  = PlanetGrid.DetermineLongitudeSegmentCount(latitudeIndex, 200);

            float sizeDeviation = building.originalSegmentCount / (float)newSegmentCount;

            sprPos = new Vector2(newRelative.x, newRelative.y * sizeDeviation) + targetSpr;

            Vector3 absoluteBuildingPos = sprPos.SnapToGrid();

            Quaternion   absoluteBuildingRot = Maths.SphericalRotation(absoluteBuildingPos, yaw + building.cursorRelativeYaw);
            PrefabDesc   desc = GetPrefabDesc(building);
            BuildPreview bp   = BuildPreview.CreateSingle(building.itemProto, desc, true);

            bp.ResetInfos();
            bp.desc     = desc;
            bp.item     = building.itemProto;
            bp.recipeId = building.recipeId;
            bp.lpos     = absoluteBuildingPos;
            bp.lrot     = absoluteBuildingRot;

            Pose pose = new Pose(absoluteBuildingPos, absoluteBuildingRot);

            int objId = InserterPoses.AddOverride(pose, building.itemProto);

            pastedEntities.Add(building.originalId, new PastedEntity()
            {
                type           = EPastedType.BUILDING,
                index          = index,
                sourceBuilding = building,
                pose           = pose,
                objId          = objId,
                buildPreview   = bp
            });

            ActivateColliders(absoluteBuildingPos);
            previews.Add(bp);
        }
Example #6
0
        public static Vector3 SnapModifiedInternal(this PlanetGrid grid, Vector3 pos)
        {
            pos.Normalize();
            float latitude  = BlueprintUtils.GetLatitudeRad(pos);
            float longitude = BlueprintUtils.GetLongitudeRad(pos);

            float latitudeCount         = latitude / 6.28318548202515f * grid.segment;
            float longitudeSegmentCount = PlanetGrid.DetermineLongitudeSegmentCount(Mathf.FloorToInt(Mathf.Max(0.0f, Mathf.Abs(latitudeCount) - 0.1f)), grid.segment);

            float longitudeCount = longitude / 6.283185f * longitudeSegmentCount;

            float snappedLatitude  = SnapWithOffset(latitudeCount, currentGridData, 1);
            float snappedLongitude = SnapWithOffset(longitudeCount, currentGridData, 0);

            float latRad  = snappedLatitude / grid.segment * 6.28318548202515f;
            float longRad = snappedLongitude / longitudeSegmentCount * 6.28318548202515f;

            return(BlueprintUtils.GetDir(longRad, latRad));
        }
Example #7
0
        public static Vector3 SnapToGrid(this Vector2 sprPos, float altitude = 0)
        {
            float planetRadius = GameMain.localPlanet.realRadius;

            //Both with +90 deg from physics definition
            float theta = sprPos.x - Mathf.PI / 2;
            float phi   = sprPos.y - Mathf.PI / 2;

            float rawLatitudeIndex = theta / 6.2831855f * planetRadius;
            int   latitudeIndex    = Mathf.FloorToInt(Mathf.Max(0f, Mathf.Abs(rawLatitudeIndex) - 0.1f));
            float segmentCount     = PlanetGrid.DetermineLongitudeSegmentCount(latitudeIndex, (int)planetRadius);

            float newPhi = phi / 6.2831855f * segmentCount;

            rawLatitudeIndex = Mathf.Round(rawLatitudeIndex * 5f) / 5f;
            newPhi           = Mathf.Round(newPhi * 5f) / 5f;
            theta            = rawLatitudeIndex / planetRadius * 6.2831855f;
            phi = newPhi / segmentCount * 6.2831855f;

            return(new Vector2(theta + Mathf.PI / 2, phi + Mathf.PI / 2).ToCartesian(planetRadius + 0.2f + altitude));
        }
        public static bool SnapTo(ref PlanetGrid __instance, Vector3 pos, ref Vector3 __result)
        {
            pos.Normalize();
            var num1 = Mathf.Asin(pos.y);
            var num2 = Mathf.Atan2(pos.x, -pos.z);
            var f1   = num1 / 6.283185f * __instance.segment;
            //  float f1 = num1 / (2 * (float)Math.PI) * (float) __instance.segment;
            float longitudeSegmentCount = PlanetGrid.DetermineLongitudeSegmentCount(Mathf.RoundToInt(Mathf.Max(0.0f, Mathf.Abs(f1) - 0.1f)), __instance.segment);
            var   num3 = num2 / 6.283185f * longitudeSegmentCount;
            //  float num3 = num2 / (2 * (float)Math.PI)* longitudeSegmentCount;
            var num4 = Mathf.Round(f1 * 5f) / 5f;
            var num5 = Mathf.Round(num3 * 5f) / 5f;
            //float f2 = (float) ((double) num4 / (double) __instance.segment * 2 * (float)Math.PI);
            //float f3 = (float) ((double) num5 / (double) longitudeSegmentCount *2 * (float)Math.PI);
            var f2   = (float)(num4 / (double)__instance.segment * 6.283185f);
            var f3   = (float)(num5 / (double)longitudeSegmentCount * 6.283185f);
            var y    = Mathf.Sin(f2);
            var num6 = Mathf.Cos(f2);
            var num7 = Mathf.Sin(f3);
            var num8 = Mathf.Cos(f3);

            __result = new Vector3(num6 * num7, y, num6 * -num8);
            return(false);
        }
Example #9
0
        public static void CalculateOffset(this PlanetAuxData auxData, Vector3 pos, GridData gridData)
        {
            if (auxData.activeGridIndex >= auxData.customGrids.Count)
            {
                return;
            }

            PlanetGrid grid = auxData.customGrids[auxData.activeGridIndex];

            pos.Normalize();
            float latitude  = BlueprintUtils.GetLatitudeRad(pos);
            float longitude = BlueprintUtils.GetLongitudeRad(pos);

            float latitudeCount         = latitude / 6.28318548202515f * grid.segment;
            float longitudeSegmentCount =
                PlanetGrid.DetermineLongitudeSegmentCount(Mathf.FloorToInt(Mathf.Max(0.0f, Mathf.Abs(latitudeCount) - 0.1f)), grid.segment);

            float longtitudeCount = longitude / 6.283185f * longitudeSegmentCount;

            float offsetLat  = Snap(latitudeCount) * 5f;
            float offsetLong = Snap(longtitudeCount) * 5f;

            gridData.snapOffset = new Vector2(offsetLong % gridData.snapGrid.x, offsetLat % gridData.snapGrid.y);
        }
        public static bool ReformSnapTo(
            ref PlanetGrid __instance,
            Vector3 pos,
            int reformSize,
            int reformType,
            int reformColor,
            Vector3[] reformPoints,
            int[] reformIndices,
            PlatformSystem platform,
            out Vector3 reformCenter,
            ref int __result)
        {
            pos.Normalize();

            var num1 = Mathf.Asin(pos.y);
            var num2 = Mathf.Atan2(pos.x, -pos.z);
            //float f1 = num1 / ( 2 * (float)Math.PI) * (float) __instance.segment;
            var f1 = num1 / 6.283185f * __instance.segment;
            var longitudeSegmentCount = PlanetGrid.DetermineLongitudeSegmentCount(Mathf.RoundToInt(Mathf.Abs(f1)), __instance.segment);


            float num3 = longitudeSegmentCount;
            var   f2   = num2 / 6.283185f * num3;
            //float f2 = num2 / ( 2 * (float)Math.PI) * num3;
            var f3   = Mathf.Round(f1 * 10f);
            var f4   = Mathf.Round(f2 * 10f);
            var num4 = Mathf.Abs(f3);
            var num5 = Mathf.Abs(f4);
            var num6 = reformSize % 2;

            if (num4 % 2.0 != num6)
            {
                num4 = Mathf.FloorToInt(Mathf.Abs(f1) * 10f);
                if (num4 % 2.0 != num6)
                {
                    ++num4;
                }
            }

            var num7 = (double)f3 < 0.0 ? -num4 : num4;

            if (num5 % 2.0 != num6)
            {
                num5 = Mathf.FloorToInt(Mathf.Abs(f2) * 10f);
                if (num5 % 2.0 != num6)
                {
                    ++num5;
                }
            }


            var num8 = (double)f4 < 0.0 ? -num5 : num5;
            // float f5 = (float) ((double) num7 / 10.0 / (double) __instance.segment * 2 * (float)Math.PI);
            // float f6 = (float) ((double) num8 / 10.0 / (double) num3 * 2 * (float)Math.PI);
            var f5    = (float)(num7 / 10.0 / __instance.segment * 6.28318548202515);
            var f6    = (float)(num8 / 10.0 / num3 * 6.28318548202515);
            var y1    = Mathf.Sin(f5);
            var num9  = Mathf.Cos(f5);
            var num10 = Mathf.Sin(f6);
            var num11 = Mathf.Cos(f6);

            reformCenter = new Vector3(num9 * num10, y1, num9 * -num11);
            var   num12  = 1 - reformSize;
            var   num13  = 1 - reformSize;
            var   index1 = 0;
            var   num14  = 0;
            float num15  = platform.latitudeCount / 10;

            for (var index2 = 0; index2 < reformSize * reformSize; ++index2)
            {
                ++num14;
                var num16         = (float)((num7 + (double)num12) / 10.0);
                var _longitudeSeg = (float)((num8 + (double)num13) / 10.0);

                num13 += 2;
                if (num14 % reformSize == 0)
                {
                    num13  = 1 - reformSize;
                    num12 += 2;
                }

                if (num16 >= (double)num15 || num16 <= -(double)num15)
                {
                    reformIndices[index2] = -1;
                }
                else
                {
                    var latitudeIndex = Mathf.RoundToInt(Mathf.Abs(num16));

                    if (longitudeSegmentCount != PlanetGrid.DetermineLongitudeSegmentCount(latitudeIndex, __instance.segment))
                    {
                        reformIndices[index2] = -1;
                    }
                    else
                    {
                        var reformIndexForSegment = platform.GetReformIndexForSegment(num16, _longitudeSeg);


                        reformIndices[index2] = reformIndexForSegment;
                        var reformType1  = platform.GetReformType(reformIndexForSegment);
                        var reformColor1 = platform.GetReformColor(reformIndexForSegment);
                        if (!platform.IsTerrainReformed(reformType1) && (reformType1 != reformType || reformColor1 != reformColor))
                        {
                            var f7 = (float)(num16 / (double)__instance.segment * 6.28318548202515);
                            // float f7 = (float) ((double) num16 / (double) __instance.segment *  ( 2 * (float)Math.PI));
                            var f8 = (float)(_longitudeSeg / (double)num3 * 6.28318548202515);
                            //float f8 = (float) ((double) _longitudeSeg / (double) num3 *  ( 2 * (float)Math.PI));
                            var y2    = Mathf.Sin(f7);
                            var num17 = Mathf.Cos(f7);
                            var num18 = Mathf.Sin(f8);
                            var num19 = Mathf.Cos(f8);
                            reformPoints[index1] = new Vector3(num17 * num18, y2, num17 * -num19);
                            ++index1;
                        }
                    }
                }
            }

            __result = index1;

            return(false);
        }