public static AsteroidRingShape CreateFromRingItem(MyPlanetRingItem ring) { AsteroidRingShape shape = new AsteroidRingShape(); shape.center = ring.Center; 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); double angleY = 2 * Math.PI / 360 * (ring.AngleDegreesY); double angleX = 2 * Math.PI / 360 * (ring.AngleDegreesX); //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); }
public void AddRingToPlanet(string name, MyPlanetRingItem ring) { if (!m_handshakeDone) { NetUtil.PingServer(delegate //Handshake needed to check, if plugin is installed on the server, since it would crash the server to send data to it without it knowing what to do. { m_handshakeDone = true; PluginEventHandler.Static.RaiseStaticEvent(SendAddRingToPlanet, name, ring, null); }); } else { PluginEventHandler.Static.RaiseStaticEvent(SendAddRingToPlanet, name, ring, null); } }
static void SendAddRingToPlanet(string planetName, MyPlanetRingItem ringBase) { if (Static.TryGetObject(planetName, out MySystemItem obj)) { if (obj.Type == SystemObjectType.PLANET) { MyPlanetItem planet = (MyPlanetItem)obj; if (planet.PlanetRing == null) { ringBase.Center = planet.CenterPosition; planet.PlanetRing = ringBase; } } } }
private MyPlanetRingItem GenerateRing(float surfaceGravity, float planetSize) { if (MyRandom.Instance.NextFloat() > m_settings.PlanetSettings.RingSettings.PlanetRingProbability * surfaceGravity) { return(null); } MyPlanetRingItem ring = new MyPlanetRingItem(); ring.Type = SystemObjectType.RING; ring.RoidSize = MyRandom.Instance.Next(64, Math.Min((int)(Math.Max(surfaceGravity * 0.5 * 128, 64)), 512)); ring.Width = MyRandom.Instance.Next(m_settings.PlanetSettings.RingSettings.MinPlanetRingWidth, m_settings.PlanetSettings.RingSettings.MaxPlanetRingWidth); ring.Height = MyRandom.Instance.Next(m_settings.PlanetSettings.RingSettings.MinPlanetRingWidth / 10, ring.Width / 10); ring.AngleDegrees = MyRandom.Instance.Next(-20, 20); ring.Radius = MyRandom.Instance.Next((int)(planetSize * 0.75), (int)(planetSize * 2)); ring.DisplayName = ""; return(ring); }
static void SendAddRingToPlanet(string planetName, MyPlanetRingItem ringBase, ulong callback, ulong client) { if (Static.TryGetObject(planetName, out MySystemItem obj)) { if (obj.Type == SystemObjectType.PLANET) { MyPlanetItem planet = (MyPlanetItem)obj; if (planet.PlanetRing == null) { ringBase.Center = planet.CenterPosition; planet.PlanetRing = ringBase; PluginEventHandler.Static.RaiseStaticEvent(SendAddCallbackClient, true, callback, client); return; } } } PluginEventHandler.Static.RaiseStaticEvent(SendAddCallbackClient, false, callback, client); }
private MyPlanetRingItem GenerateRingItem() { if (m_selectedPlanet.PlanetRing != null) { return(m_selectedPlanet.PlanetRing); } MyPlanetRingItem item = new MyPlanetRingItem(); item.Type = SystemObjectType.RING; item.DisplayName = ""; item.AngleDegrees = m_ringAngleZSlider.Value; item.AngleDegreesX = m_ringAngleXSlider.Value; item.AngleDegreesY = m_ringAngleYSlider.Value; item.Radius = m_ringDistanceSlider.Value + m_selectedPlanet.Size / 2f; item.Width = (int)m_ringWidthSlider.Value; item.Height = item.Width / 10; item.RoidSize = (int)m_ringRoidSizeSlider.Value; item.RoidSizeMax = (int)m_ringRoidSizeMaxSlider.Value; item.Center = m_selectedPlanet.CenterPosition; return(item); }
public void UpdateGps(MyEntityTracker tracker) { foreach (MySystemItem p in SystemGenerator.Static.m_objects) { if (p.Type != SystemObjectType.PLANET || ((MyPlanetItem)p).PlanetRing == null) { continue; } MyPlanetRingItem ring = ((MyPlanetItem)p).PlanetRing; Vector3D entityPos = tracker.Entity.PositionComp.GetPosition(); string pre = ((MyPlanetItem)p).DisplayName; var center = ((MyPlanetItem)p).CenterPosition; int l = (int)(Math.Sqrt(center.X * center.X + center.Y * center.Y + center.Z * center.Z)) % 1000; pre = Regex.Replace(pre, @"-[\d\w]+$| \d+ \d+ - \w+$", " " + l.ToString()); string name = pre + " Ring"; if (Vector3D.Subtract(ring.Center, entityPos).Length() > 5000000) { GlobalGpsManager.Static.RemoveDynamicGps(name, ((MyCharacter)tracker.Entity).GetPlayerIdentityId()); continue; } AsteroidRingShape shape = AsteroidRingShape.CreateFromRingItem(ring); if (shape.Contains(tracker.LastPosition) == ContainmentType.Contains) { GlobalGpsManager.Static.RemoveDynamicGps(name, ((MyCharacter)tracker.Entity).GetPlayerIdentityId()); continue; } Vector3D pos = shape.ClosestPointAtRingCenter(entityPos); GlobalGpsManager.Static.AddOrUpdateDynamicGps(name, ((MyCharacter)tracker.Entity).GetPlayerIdentityId(), pos, Color.Gold); } }
private bool ObstructedPlace(Vector3D position, List <Vector3D> other, float minDistance, MyPlanetRingItem ring) { foreach (var obj in other) { if (Vector3D.Subtract(position, obj).Length() < minDistance) { return(true); } if (ring != null) { AsteroidRingShape shape = AsteroidRingShape.CreateFromRingItem(ring); return(shape.Contains(position) != ContainmentType.Disjoint); } } return(false); }
/// <summary> /// Adds a ring to a planet on the server. /// </summary> /// <param name="name">Name of the planet to add the ring to</param> /// <param name="ring">Ring data to add</param> public void AddRingToPlanet(string name, MyPlanetRingItem ring, Action <bool> callback = null) { m_addActionsCallbacks.Add(++m_currentAddIndex, callback); PluginEventHandler.Static.RaiseStaticEvent(SendAddRingToPlanet, name, ring, m_currentAddIndex, Sync.MyId, null); }
static void SendGetRingClient(bool success, MyPlanetRingItem item, ulong callback) { Static.m_getActionCallbacks[callback](success, item); Static.m_getActionCallbacks.Remove(callback); }