diff --git a/SEWorldGenPlugin/GUI/PluginAdminMenu.cs b/SEWorldGenPlugin/GUI/PluginAdminMenu.cs index 414f26a..890bda4 100644 --- a/SEWorldGenPlugin/GUI/PluginAdminMenu.cs +++ b/SEWorldGenPlugin/GUI/PluginAdminMenu.cs @@ -1,6 +1,7 @@ using Sandbox.Definitions; using Sandbox.Engine.Multiplayer; using Sandbox.Engine.Utils; +using Sandbox.Engine.Voxels; using Sandbox.Game.Entities; using Sandbox.Game.Gui; using Sandbox.Game.Multiplayer; @@ -19,6 +20,7 @@ using VRage.Game; using VRage.Game.Entity; using VRage.Game.SessionComponents; +using VRage.Game.Voxels; using VRage.Library.Utils; using VRage.Utils; using VRageMath; @@ -772,25 +774,6 @@ private void OnSpawnPlanetButton(MyGuiControlButton button) { if (m_planetDefListBox.SelectedItems.Count > 0) { - /*Vector3 camForward = MySector.MainCamera.ForwardVector; - float planetSize = m_planetSizeSlider.Value * 1000; - - Vector3 pos = Vector3.Add(Vector3.Multiply(camForward, planetSize), MySector.MainCamera.Position); - MyPlanetItem planet = new MyPlanetItem() - { - OffsetPosition = new Vector3D(pos.X, pos.Y, pos.Z), - DefName = m_selectedDefinition.Id.SubtypeId.ToString(), - DisplayName = m_selectedDefinition.Id.SubtypeId.ToString() + "_" + planetSize + "_" + MyRandom.Instance.Next(), - Generated = false, - PlanetMoons = new MyPlanetMoonItem[0], - PlanetRing = null, - Size = planetSize, - Type = SystemObjectType.PLANET, - CenterPosition = Vector3D.Zero - }; - - SystemGenerator.Static.AddPlanet(planet);*/ - float size = m_planetSizeSlider.Value * 1000; MyPlanetItem planet = new MyPlanetItem() { @@ -816,7 +799,7 @@ private void SpawnPlanet(MySystemItem planet, Vector3D position) if(planet.Type == SystemObjectType.PLANET) { MyPlanetItem p = (MyPlanetItem)planet; - p.OffsetPosition = position; + p.CenterPosition = position; SystemGenerator.Static.AddPlanet(p); } diff --git a/SEWorldGenPlugin/Generator/ProceduralGen/ProceduralPlanetModule.cs b/SEWorldGenPlugin/Generator/ProceduralGen/ProceduralPlanetModule.cs index 4f71382..a9285b3 100644 --- a/SEWorldGenPlugin/Generator/ProceduralGen/ProceduralPlanetModule.cs +++ b/SEWorldGenPlugin/Generator/ProceduralGen/ProceduralPlanetModule.cs @@ -1,4 +1,5 @@ using Sandbox.Definitions; +using Sandbox.Engine.Voxels; using Sandbox.Game.Entities; using Sandbox.Game.World; using SEWorldGenPlugin.Generator.Asteroids; @@ -7,6 +8,7 @@ using System; using System.Collections.Generic; using VRage.Game.Entity; +using VRage.Game.Voxels; using VRage.Library.Utils; using VRage.Utils; using VRageMath; @@ -40,7 +42,11 @@ public void GeneratePlanets() if (definition == null) continue; long id = MyRandom.Instance.NextLong(); string name = (planet.DisplayName + " - " + definition.Id.SubtypeId).Replace(" ", "_"); - MyPlanet generatedPlanet = MyWorldGenerator.AddPlanet(name, planet.DisplayName, planet.DefName, Vector3D.Subtract(planet.OffsetPosition, new Vector3D(planet.Size)), m_seed, planet.Size, true, id, false, true); + if (planet.CenterPosition.Equals(Vector3D.Zero)) + { + planet.CenterPosition = planet.OffsetPosition; + } + MyPlanet generatedPlanet = MyWorldGenerator.AddPlanet(name, planet.DisplayName, planet.DefName, planet.CenterPosition - GetPlanetOffset(definition, planet.Size), m_seed, planet.Size, true, id, false, true); planet.CenterPosition = generatedPlanet.PositionComp.GetPosition(); generatedPlanet.DisplayNameText = planet.DisplayName; generatedPlanet.AsteroidName = planet.DisplayName; @@ -79,6 +85,15 @@ public void GeneratePlanets() } } + private Vector3D GetPlanetOffset(MyPlanetGeneratorDefinition definition, float size) + { + MyPlanetStorageProvider myPlanetStorageProvider = new MyPlanetStorageProvider(); + myPlanetStorageProvider.Init(0, definition, size / 2f); + IMyStorage myStorage = new MyOctreeStorage(myPlanetStorageProvider, myPlanetStorageProvider.StorageSize); + + return myStorage.Size / 2.0f; + } + private MyPlanetGeneratorDefinition GetDefinition(string name) { return MyDefinitionManager.Static.GetDefinition(MyStringHash.GetOrCompute(name)); diff --git a/SEWorldGenPlugin/Generator/SystemGenerator.cs b/SEWorldGenPlugin/Generator/SystemGenerator.cs index 4903b23..a8a860f 100644 --- a/SEWorldGenPlugin/Generator/SystemGenerator.cs +++ b/SEWorldGenPlugin/Generator/SystemGenerator.cs @@ -189,7 +189,7 @@ private void GeneratePlanet(int index, long distance, int totalObjects, ref int planet.Size = SizeByGravity(def.SurfaceGravity); planet.PlanetRing = GenerateRing(def.SurfaceGravity, planet.Size); planet.OffsetPosition = pos; - planet.CenterPosition = Vector3D.Zero; + planet.CenterPosition = pos; planet.PlanetMoons = GenerateMoons(planet.Size, def.SurfaceGravity, planet.DisplayName); planet.Generated = false; diff --git a/SEWorldGenPlugin/Session/PluginItemsClipboard.cs b/SEWorldGenPlugin/Session/PluginItemsClipboard.cs index 5646c5b..ef3dcb2 100644 --- a/SEWorldGenPlugin/Session/PluginItemsClipboard.cs +++ b/SEWorldGenPlugin/Session/PluginItemsClipboard.cs @@ -72,6 +72,7 @@ public override void UpdateBeforeSimulation() if (m_isActive) { PluginDrawSession.Static.RemoveRenderObject(m_copiedItem.GetHashCode()); + MatrixD wm = GetPasteMatrix(); Vector3D posGlobal = wm.Forward * m_distanceToCam;