Skip to content

Commit

Permalink
Fixed offset of planets when spawning
Browse files Browse the repository at this point in the history
  • Loading branch information
thorwin99 committed Mar 1, 2020
1 parent 55e5a62 commit 8e62737
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
23 changes: 3 additions & 20 deletions SEWorldGenPlugin/GUI/PluginAdminMenu.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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()
{
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Sandbox.Definitions;
using Sandbox.Engine.Voxels;
using Sandbox.Game.Entities;
using Sandbox.Game.World;
using SEWorldGenPlugin.Generator.Asteroids;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<MyPlanetGeneratorDefinition>(MyStringHash.GetOrCompute(name));
Expand Down
2 changes: 1 addition & 1 deletion SEWorldGenPlugin/Generator/SystemGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions SEWorldGenPlugin/Session/PluginItemsClipboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 8e62737

Please sign in to comment.