/// <summary> /// Creates a bew asteroid ring shape from a MyPlanetRingItem. /// A ring has a radius, a rotation and a width. /// </summary> /// <param name="ring">The ring to create a shape representation for.</param> /// <returns>An AsteroidRingShape representing the given ring in worldspace</returns> public static MyAsteroidObjectShapeRing CreateFromRingItem(MyAsteroidRingData ring) { MyAsteroidObjectShapeRing shape = new MyAsteroidObjectShapeRing(); shape.center = ring.CenterPosition; shape.radius = ring.Radius; shape.width = ring.Width; shape.height = ring.Height; shape.rotation = new Vector3D(1, 0, 0); shape.normal = new Vector3D(0, 0, 1); double angleZ = 2 * Math.PI / 360 * (ring.AngleDegrees.Z); double angleY = 2 * Math.PI / 360 * (ring.AngleDegrees.Y); double angleX = 2 * Math.PI / 360 * (ring.AngleDegrees.X); //shape.rotation.X = Math.Cos(angleZ); //shape.rotation.Y = Math.Sin(angleZ); MatrixD mx = MatrixD.CreateRotationX(angleX); MatrixD my = MatrixD.CreateRotationY(angleY); MatrixD mz = MatrixD.CreateRotationZ(angleZ); MatrixD.Multiply(ref mx, ref my, out MatrixD mxy); MatrixD.Multiply(ref mxy, ref mz, out MatrixD mxyz); Vector3D.Rotate(ref shape.rotation, ref mxyz, out Vector3D newRotation); Vector3D.Rotate(ref shape.normal, ref mxyz, out Vector3D newNormal); shape.rotation = Vector3D.Normalize(newRotation); shape.normal = Vector3D.Normalize(newNormal); shape.worldMatrix = MatrixD.CreateWorld(shape.center, shape.rotation, shape.normal); return(shape); }
/// <summary> /// Returns the Asteroid data generated from the gui elements. /// </summary> /// <returns>The asteroid ring data generated</returns> private MyAsteroidRingData GetAsteroidDataFromGui() { Vector3D center; if (m_currentSelectedAsteroid == null) { if (m_parentObjectListBox.SelectedItems.Count <= 0) { return(null); } var selected = m_parentObjectListBox.SelectedItems[m_parentObjectListBox.SelectedItems.Count - 1]; center = (selected.UserData as MySystemObject).CenterPosition + m_offset; } else { center = m_currentSelectedAsteroid.CenterPosition; } MyAsteroidRingData ring = new MyAsteroidRingData(); ring.CenterPosition = center; ring.Width = m_widthSlider.Value * 1000; ring.Height = m_heightSlider.Value * 1000; ring.Radius = m_radiusSlider.Value * 1000; ring.AngleDegrees = new Vector3D(m_angleXSlider.Value, m_angleYSlider.Value, m_angleZSlider.Value); return(ring); }
/// <summary> /// Updates the visual representaion of the current ring edited in the spawn menu /// </summary> private void UpdateRingVisual(MyAsteroidRingData ring) { if (ring == null) { return; } var shape = MyAsteroidObjectShapeRing.CreateFromRingItem(ring); MyPluginDrawSession.Static.RemoveRenderObject(PREVIEW_RENDER_ID); MyPluginDrawSession.Static.AddRenderObject(PREVIEW_RENDER_ID, new RenderHollowCylinder(shape.worldMatrix, (float)shape.radius + (float)shape.width, (float)shape.radius, (float)shape.height, Color.LightGreen.ToVector4(), (float)shape.radius / 200f)); }
/// <summary> /// Generates an asteroid ring from the current slider values in the spawn menu /// </summary> /// <returns>The generated system ring data</returns> private MyAsteroidRingData GenerateAsteroidRing() { if (m_parentObjectListBox.SelectedItems.Count <= 0) { return(null); } var selected = m_parentObjectListBox.SelectedItems[m_parentObjectListBox.SelectedItems.Count - 1]; MySystemObject parent = selected.UserData as MySystemObject; MyAsteroidRingData ring = new MyAsteroidRingData(); ring.CenterPosition = parent.CenterPosition + m_offset; ring.Width = m_widthSlider.Value * 1000; ring.Height = m_heightSlider.Value * 1000; ring.Radius = m_radiusSlider.Value * 1000; ring.AngleDegrees = new Vector3D(m_angleXSlider.Value, m_angleYSlider.Value, m_angleZSlider.Value); return(ring); }
/// <summary> /// Generates the whole data for the currently edited asteroid ring from the values in the spawn menu /// </summary> /// <param name="ringData">The out value for the ring data</param> /// <param name="systemObject">The out value for the system object</param> private void GenerateAsteroidData(out MyAsteroidRingData ringData, out MySystemAsteroids systemObject) { if (m_parentObjectListBox.SelectedItems.Count <= 0) { ringData = null; systemObject = null; return; } var selectedParent = m_parentObjectListBox.SelectedItems[m_parentObjectListBox.SelectedItems.Count - 1]; var parentItem = selectedParent.UserData as MySystemObject; StringBuilder name = new StringBuilder(); m_nameBox.GetText(name); systemObject = new MySystemAsteroids(); systemObject.AsteroidTypeName = MyAsteroidRingProvider.Static.GetTypeName(); systemObject.CenterPosition = parentItem.CenterPosition + m_offset; systemObject.AsteroidSize = new MySerializableMinMax((int)m_asteroidSizesSlider.CurrentMin, (int)m_asteroidSizesSlider.CurrentMax); systemObject.DisplayName = name.ToString(); systemObject.ParentId = parentItem.Id; ringData = GenerateAsteroidRing(); }
/// <summary> /// Sets all slider values to reflect the instance asteroid object /// </summary> /// <param name="instance">The instance of the asteroid object</param> private void SetSliderValues(MySystemAsteroids instance) { if (instance.AsteroidTypeName != MyAsteroidRingProvider.TYPE_NAME) { return; } MyAsteroidRingData data = MyAsteroidRingProvider.Static.GetInstanceData(instance) as MyAsteroidRingData; var planet = m_fetchedStarSytem.GetObjectById(instance.ParentId) as MySystemPlanet; if (planet == null) { var settings = MySettingsSession.Static.Settings.GeneratorSettings; m_radiusSlider.MinValue = settings.MinMaxOrbitDistance.Min / 1000; m_radiusSlider.MaxValue = settings.WorldSize < 0 ? int.MaxValue / 1000 : settings.WorldSize / 1000; m_radiusSlider.Value = m_radiusSlider.MinValue + (m_radiusSlider.MaxValue - m_radiusSlider.MinValue) / 2; m_radiusSlider.Enabled = true; m_widthSlider.MinValue = settings.MinMaxOrbitDistance.Min / 2000; m_widthSlider.MaxValue = settings.MinMaxOrbitDistance.Max / 1000; m_widthSlider.Value = m_widthSlider.MinValue + (m_widthSlider.MaxValue - m_widthSlider.MinValue) / 2; m_widthSlider.Enabled = true; m_heightSlider.MinValue = m_widthSlider.MinValue / 10; m_heightSlider.MaxValue = m_widthSlider.MaxValue / 10; m_heightSlider.Value = m_heightSlider.MinValue + (m_heightSlider.MaxValue - m_heightSlider.MinValue) / 2; m_heightSlider.Enabled = true; m_asteroidSizesSlider.Enabled = true; m_asteroidSizesSlider.SetValues(32, 1024); m_angleXSlider.Enabled = true; m_angleXSlider.Value = 0; m_angleYSlider.Enabled = true; m_angleYSlider.Value = 0; m_angleZSlider.Enabled = true; m_angleZSlider.Value = 0; return; } m_radiusSlider.MinValue = (int)planet.Diameter / 1000 * 0.75f; m_radiusSlider.MaxValue = (int)planet.Diameter / 1000 * 2f; m_radiusSlider.Value = (float)data.Radius / 1000; m_radiusSlider.Enabled = true; m_widthSlider.MinValue = (int)planet.Diameter / 1000 / 20f; m_widthSlider.MaxValue = (int)planet.Diameter / 1000 / 1.25f; m_widthSlider.Value = (float)data.Width / 1000; m_widthSlider.Enabled = true; m_heightSlider.MinValue = m_widthSlider.MinValue / 10; m_heightSlider.MaxValue = m_widthSlider.MaxValue / 10; m_heightSlider.Value = (float)data.Height / 1000; m_heightSlider.Enabled = true; m_asteroidSizesSlider.Enabled = true; m_asteroidSizesSlider.SetValues(instance.AsteroidSize.Min, instance.AsteroidSize.Max); m_angleXSlider.Enabled = true; m_angleXSlider.Value = (float)data.AngleDegrees.x; m_angleYSlider.Enabled = true; m_angleYSlider.Value = (float)data.AngleDegrees.y; m_angleZSlider.Enabled = true; m_angleZSlider.Value = (float)data.AngleDegrees.z; }