From 55e5a6242901e734e14d63fb2f377610907f621a Mon Sep 17 00:00:00 2001 From: Thorwin Vogt Date: Sat, 29 Feb 2020 17:33:16 +0100 Subject: [PATCH] Finalized rendering of the sphere for planet spawning --- SEWorldGenPlugin/Draw/RenderSphere.cs | 5 +- SEWorldGenPlugin/GUI/PluginAdminMenu.cs | 36 ++++++-- .../Session/PluginItemsClipboard.cs | 86 ++++++++++++++++++- 3 files changed, 118 insertions(+), 9 deletions(-) diff --git a/SEWorldGenPlugin/Draw/RenderSphere.cs b/SEWorldGenPlugin/Draw/RenderSphere.cs index e37e97e..69b2156 100644 --- a/SEWorldGenPlugin/Draw/RenderSphere.cs +++ b/SEWorldGenPlugin/Draw/RenderSphere.cs @@ -1,5 +1,7 @@ using VRage.Game; +using VRage.Utils; using VRageMath; +using VRageRender; namespace SEWorldGenPlugin.Draw { @@ -19,7 +21,8 @@ public RenderSphere(Vector3D position, float radius, Color color) public void Draw() { MatrixD wm = MatrixD.CreateWorld(m_position); - MySimpleObjectDraw.DrawTransparentSphere(ref wm, m_radius, ref m_color, MySimpleObjectRasterizer.Solid, 20); + MySimpleObjectDraw.DrawTransparentSphere(ref wm, m_radius, ref m_color, MySimpleObjectRasterizer.SolidAndWireframe, 100, lineMaterial: MyStringId.GetOrCompute("GizmoDrawLine"), lineThickness: 1000); + //MyRenderProxy.DebugDrawSphere(m_position, m_radius * 1.1f, m_color.ToVector3(), 1.0f, true, true); } } } diff --git a/SEWorldGenPlugin/GUI/PluginAdminMenu.cs b/SEWorldGenPlugin/GUI/PluginAdminMenu.cs index 3b05129..414f26a 100644 --- a/SEWorldGenPlugin/GUI/PluginAdminMenu.cs +++ b/SEWorldGenPlugin/GUI/PluginAdminMenu.cs @@ -558,11 +558,6 @@ private void UpdateRingVisual() PluginDrawSession.Static.AddRenderObject(m_selectedPlanet.GetHashCode(), new RenderHollowCylinder(shape.worldMatrix, (float)shape.radius + shape.width, (float)shape.radius, shape.height, Color.LightGreen.ToVector4())); } - private void UpdatePlanetVisual() - { - - } - private void OnTeleportToRingButton(MyGuiControlButton button) { if(MySession.Static.CameraController != MySession.Static.LocalCharacter) @@ -777,7 +772,7 @@ private void OnSpawnPlanetButton(MyGuiControlButton button) { if (m_planetDefListBox.SelectedItems.Count > 0) { - Vector3 camForward = MySector.MainCamera.ForwardVector; + /*Vector3 camForward = MySector.MainCamera.ForwardVector; float planetSize = m_planetSizeSlider.Value * 1000; Vector3 pos = Vector3.Add(Vector3.Multiply(camForward, planetSize), MySector.MainCamera.Position); @@ -794,12 +789,39 @@ private void OnSpawnPlanetButton(MyGuiControlButton button) CenterPosition = Vector3D.Zero }; - SystemGenerator.Static.AddPlanet(planet); + SystemGenerator.Static.AddPlanet(planet);*/ + + float size = m_planetSizeSlider.Value * 1000; + MyPlanetItem planet = new MyPlanetItem() + { + OffsetPosition = Vector3D.Zero, + DefName = m_selectedDefinition.Id.SubtypeId.ToString(), + DisplayName = m_selectedDefinition.Id.SubtypeId.ToString() + "_" + size + "_" + MyRandom.Instance.Next(), + Generated = false, + PlanetMoons = new MyPlanetMoonItem[0], + PlanetRing = null, + Size = size, + Type = SystemObjectType.PLANET, + CenterPosition = Vector3D.Zero + }; + + PluginItemsClipboard.Static.Activate(planet, SpawnPlanet, size); CloseScreenNow(); } } + private void SpawnPlanet(MySystemItem planet, Vector3D position) + { + if(planet.Type == SystemObjectType.PLANET) + { + MyPlanetItem p = (MyPlanetItem)planet; + p.OffsetPosition = position; + + SystemGenerator.Static.AddPlanet(p); + } + } + private void ClearControls() { List keep = new List(); diff --git a/SEWorldGenPlugin/Session/PluginItemsClipboard.cs b/SEWorldGenPlugin/Session/PluginItemsClipboard.cs index 924ddc4..5646c5b 100644 --- a/SEWorldGenPlugin/Session/PluginItemsClipboard.cs +++ b/SEWorldGenPlugin/Session/PluginItemsClipboard.cs @@ -1,14 +1,98 @@ -using System; +using Sandbox.Game.World; +using SEWorldGenPlugin.Draw; +using SEWorldGenPlugin.ObjectBuilders; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using VRage.Game; using VRage.Game.Components; +using VRage.Input; +using VRageMath; namespace SEWorldGenPlugin.Session { [MySessionComponentDescriptor(MyUpdateOrder.BeforeSimulation)] public class PluginItemsClipboard : MySessionComponentBase { + public static PluginItemsClipboard Static; + + private MySystemItem m_copiedItem = null; + private Action m_callback; + private bool m_isActive = false; + private float m_distanceToCam; + private Vector3D m_currentPos; + + public override void Init(MyObjectBuilder_SessionComponent sessionComponent) + { + base.Init(sessionComponent); + Static = this; + } + + public void Activate(MySystemItem item, Action callback, float distanceToCam) + { + m_copiedItem = item; + m_callback = callback; + m_isActive = true; + m_distanceToCam = distanceToCam; + } + + public override void HandleInput() + { + base.HandleInput(); + if (MyInput.Static.IsNewKeyPressed(MyKeys.Escape)) + { + if (m_isActive) + { + PluginDrawSession.Static.RemoveRenderObject(m_copiedItem.GetHashCode()); + m_copiedItem = null; + m_callback = null; + m_distanceToCam = 0; + m_isActive = false; + } + + } + if (MyInput.Static.IsNewLeftMousePressed()) + { + if (m_isActive) + { + PluginDrawSession.Static.RemoveRenderObject(m_copiedItem.GetHashCode()); + m_callback?.Invoke(m_copiedItem, m_currentPos); + m_copiedItem = null; + m_callback = null; + m_distanceToCam = 0; + m_isActive = false; + } + } + } + + public override void UpdateBeforeSimulation() + { + if (m_isActive) + { + PluginDrawSession.Static.RemoveRenderObject(m_copiedItem.GetHashCode()); + MatrixD wm = GetPasteMatrix(); + + Vector3D posGlobal = wm.Forward * m_distanceToCam; + + m_currentPos = wm.Translation + posGlobal; + + PluginDrawSession.Static.AddRenderObject(m_copiedItem.GetHashCode(), new RenderSphere(m_currentPos, ((MyPlanetItem)m_copiedItem).Size / 2, Color.LightGreen)); + } + } + + private static MatrixD GetPasteMatrix() + { + if (MySession.Static.ControlledEntity != null && + (MySession.Static.GetCameraControllerEnum() == MyCameraControllerEnum.Entity || MySession.Static.GetCameraControllerEnum() == MyCameraControllerEnum.ThirdPersonSpectator)) + { + return MySession.Static.ControlledEntity.GetHeadMatrix(true); + } + else + { + return MySector.MainCamera.WorldMatrix; + } + } } }