コード例 #1
0
        public OrbitIconBase(EntityState entityState, List <List <UserOrbitSettings> > settings) : base(entityState.Entity.GetDataBlob <PositionDB>())
        {
            BodyType = entityState.BodyType;

            entityState.OrbitIcon = this;
            _mgr = entityState.Entity.Manager;
            _userOrbitSettingsMtx = settings;
            _orbitDB = entityState.Entity.GetDataBlob <OrbitDB>();
            if (entityState.Entity.HasDataBlob <OrbitUpdateOftenDB>())
            {
                _orbitDB = entityState.Entity.GetDataBlob <OrbitUpdateOftenDB>();
            }
            BodyPositionDB = entityState.Position; //entityState.Entity.GetDataBlob<PositionDB>();
            if (_orbitDB.Parent == null)           //primary star
            {
                _positionDB = BodyPositionDB;
            }
            else
            {
                _positionDB = _orbitDB.Parent.GetDataBlob <PositionDB>(); //orbit's position is parent's body position.
            }

            SemiMaj = (float)_orbitDB.SemiMajorAxis_AU;

            SemiMinor = (float)EllipseMath.SemiMinorAxis(_orbitDB.SemiMajorAxis_AU, _orbitDB.Eccentricity);



            _linearEccentricity = (float)(_orbitDB.Eccentricity * _orbitDB.SemiMajorAxis_AU); //linear ecentricity


            if (_orbitDB.Inclination_Degrees > 90 && _orbitDB.Inclination_Degrees < 270) //orbitDB is in degrees.
            {
                IsRetrogradeOrbit = true;
                //_loP_Degrees = (float)(_orbitDB.LongitudeOfAscendingNode - _orbitDB.ArgumentOfPeriapsis);
            }

            /*
             * else
             * {
             *
             *  _loP_Degrees = (float)(_orbitDB.LongitudeOfAscendingNode + _orbitDB.ArgumentOfPeriapsis);
             * }
             * _loP_radians = (float)(Angle.ToRadians(_loP_Degrees));
             */
            var i    = _orbitDB.Inclination;
            var _aoP = _orbitDB.ArgumentOfPeriapsis;
            var loan = _orbitDB.LongitudeOfAscendingNode;
            var lop  = OrbitMath.GetLongditudeOfPeriapsis(i, _aoP, loan);

            _loP_radians = (float)lop;
            _loP_Degrees = (float)Angle.ToDegrees(lop);
        }
コード例 #2
0
        public OrbitOrderWiget(OrbitDB orbitDB) : base(orbitDB.Parent.GetDataBlob <PositionDB>())
        {
            var targetEntity = orbitDB.Parent;

            _bodyPositionDB = targetEntity.GetDataBlob <PositionDB>();

            OrbitEllipseSemiMaj_m = (float)orbitDB.SemiMajorAxis;
            _eccentricity         = orbitDB.Eccentricity;
            EllipseMath.SemiMinorAxis(OrbitEllipseSemiMaj_m, _eccentricity);
            _linearEccentricity_m = (float)(orbitDB.Eccentricity * OrbitEllipseSemiMaj_m);

            _soiWorldRadius_AU    = OrbitProcessor.GetSOI_AU(targetEntity);
            _targetWorldRadius_AU = targetEntity.GetDataBlob <MassVolumeDB>().RadiusInAU;
            Setup();
        }
コード例 #3
0
ファイル: OrbitOrderWiget.cs プロジェクト: UberWaffe/Pulsar4x
        public OrbitOrderWiget(OrbitDB orbitDB) : base(orbitDB.Parent.GetDataBlob <PositionDB>())
        {
            var targetEntity = orbitDB.Parent;

            _bodyPositionDB = targetEntity.GetDataBlob <PositionDB>();

            OrbitEllipseSemiMaj = (float)orbitDB.SemiMajorAxis;
            _eccentricity       = orbitDB.Eccentricity;
            EllipseMath.SemiMinorAxis(OrbitEllipseSemiMaj, _eccentricity);
            _linearEccentricity = (float)(orbitDB.Eccentricity * OrbitEllipseSemiMaj);

            _soiWorldRadius = GMath.GetSOI(targetEntity);

            Setup();
        }
コード例 #4
0
        public void TestAngles()
        {
            var    e          = 0.5;
            var    a          = 100;
            var    p          = EllipseMath.SemiLatusRectum(a, e);
            double angleDelta = 0.00001;
            var    i          = 0;

            for (double angle = 0; angle < Math.PI; angle += 0.0174533)
            {
                var r     = OrbitMath.RadiusAtAngle(angle, p, e);
                var theta = OrbitMath.AngleAtRadus(r, p, e);
                Assert.AreEqual(angle, theta, angleDelta, "inc: " + i + " r: " + r);
                i++;
            }
        }
コード例 #5
0
        public OrbitIconBase(EntityState entityState, List <List <UserOrbitSettings> > settings) : base(entityState.Entity.GetDataBlob <PositionDB>())
        {
            BodyType = entityState.BodyType;

            entityState.OrbitIcon = this;
            _mgr = entityState.Entity.Manager;
            _userOrbitSettingsMtx = settings;
            _orbitDB       = entityState.Entity.GetDataBlob <OrbitDB>();
            BodyPositionDB = entityState.Position; //entityState.Entity.GetDataBlob<PositionDB>();
            if (_orbitDB.Parent == null)           //primary star
            {
                _positionDB = BodyPositionDB;
            }
            else
            {
                _positionDB = _orbitDB.Parent.GetDataBlob <PositionDB>(); //orbit's position is parent's body position.
            }

            SemiMaj = (float)_orbitDB.SemiMajorAxis;

            SemiMinor = (float)EllipseMath.SemiMinorAxis(_orbitDB.SemiMajorAxis, _orbitDB.Eccentricity);



            _linearEccentricity = (float)(_orbitDB.Eccentricity * _orbitDB.SemiMajorAxis); //linear ecentricity

            /*
             * if (_orbitDB.Inclination > 90 && _orbitDB.Inclination < 270) //orbitDB is in degrees.
             * {
             *  IsClockwiseOrbit = false;
             *  _loP_Degrees = (float)(_orbitDB.LongitudeOfAscendingNode - _orbitDB.ArgumentOfPeriapsis);
             * }
             * else
             * {
             *
             *  _loP_Degrees = (float)(_orbitDB.LongitudeOfAscendingNode + _orbitDB.ArgumentOfPeriapsis);
             * }
             * _loP_radians = (float)(Angle.ToRadians(_loP_Degrees));
             */
            var i    = Angle.ToRadians(_orbitDB.Inclination);
            var aop  = Angle.ToRadians(_orbitDB.ArgumentOfPeriapsis);
            var loan = Angle.ToRadians(_orbitDB.LongitudeOfAscendingNode);
            var lop  = OrbitMath.GetLongditudeOfPeriapsis(i, aop, loan);

            _loP_radians = (float)lop;
            _loP_Degrees = (float)Angle.ToDegrees(lop);
        }
コード例 #6
0
ファイル: OrbitIcon.cs プロジェクト: UberWaffe/Pulsar4x
        internal OrbitIcon(ref EntityState entityState, UserOrbitSettings settings) : base(entityState.Entity.GetDataBlob <PositionDB>())
        {
            entityState.OrbitIcon = this;

            _userSettings   = settings;
            _orbitDB        = entityState.Entity.GetDataBlob <OrbitDB>();
            _bodyPositionDB = entityState.Entity.GetDataBlob <PositionDB>();
            if (_orbitDB.Parent == null) //primary star
            {
                _positionDB = _bodyPositionDB;
            }
            else
            {
                _positionDB = _orbitDB.Parent.GetDataBlob <PositionDB>(); //orbit's position is parent's body position.
            }

            _orbitEllipseSemiMaj   = (float)_orbitDB.SemiMajorAxis;
            _orbitEllipseMajor     = _orbitEllipseSemiMaj * 2;
            _orbitEllipseSemiMinor = (float)EllipseMath.SemiMinorAxis(_orbitDB.SemiMajorAxis, _orbitDB.Eccentricity);
            _orbitEllipseMinor     = _orbitEllipseSemiMinor * 2;


            _linearEccentricity = (float)(_orbitDB.Eccentricity * _orbitDB.SemiMajorAxis); //linear ecentricity

            if (_orbitDB.Inclination > 90 && _orbitDB.Inclination < 270)                   //orbitDB is in degrees.
            {
                IsClockwiseOrbit   = false;
                _orbitAngleDegrees = (float)(_orbitDB.LongitudeOfAscendingNode - _orbitDB.ArgumentOfPeriapsis);
            }
            else
            {
                _orbitAngleDegrees = (float)(_orbitDB.LongitudeOfAscendingNode + _orbitDB.ArgumentOfPeriapsis);
            }
            _orbitAngleRadians = (float)(Angle.ToRadians(_orbitAngleDegrees));

            UpdateUserSettings();
            CreatePointArray();

            OnPhysicsUpdate();
        }
コード例 #7
0
        internal void CreatePointArray()
        {
            _dv = _newtonMoveDB.DeltaVForManuver_m.Length();
            Vector3 vel          = Distance.MToAU(_newtonMoveDB.CurrentVector_ms);
            Vector3 pos          = myPosDB.RelativePosition_AU;
            Vector3 eccentVector = OrbitMath.EccentricityVector(_sgp, pos, vel);
            double  e            = eccentVector.Length();
            double  r            = pos.Length();
            double  v            = vel.Length();
            double  a            = 1 / (2 / r - Math.Pow(v, 2) / _sgp); //semiMajor Axis
            double  b            = -a *Math.Sqrt(Math.Pow(e, 2) - 1);   //semiMinor Axis

            double linierEccentricity = e * a;
            double soi = OrbitProcessor.GetSOI_AU(_newtonMoveDB.SOIParent);

            //longditudeOfPeriapsis;
            double _lop = Math.Atan2(eccentVector.Y, eccentVector.X);

            if (Vector3.Cross(pos, vel).Z < 0) //anti clockwise orbit
            {
                _lop = Math.PI * 2 - _lop;
            }

            double p = EllipseMath.SemiLatusRectum(a, e);
            double angleToSOIPoint = Math.Abs(OrbitMath.AngleAtRadus(soi, p, e));
            //double thetaMax = angleToSOIPoint;

            double maxX = soi * Math.Cos(angleToSOIPoint);
            //maxX = maxX - a + linierEccentricity;
            double foo      = maxX / a;
            double thetaMax = Math.Log(foo + Math.Sqrt(foo * foo - 1));


            if (_numberOfPoints % 2 == 0)
            {
                _numberOfPoints += 1;
            }
            int    ctrIndex = _numberOfPoints / 2;
            double dtheta   = thetaMax / (ctrIndex - 1);
            double fooA     = Math.Cosh(dtheta);
            double fooB     = (a / b) * Math.Sinh(dtheta);
            double fooC     = (b / a) * Math.Sinh(dtheta);
            double xn       = a;
            double yn       = 0;

            var points = new PointD[ctrIndex + 1];

            points[0] = new PointD()
            {
                X = xn, Y = yn
            };
            for (int i = 1; i < ctrIndex + 1; i++)
            {
                var lastx = xn;
                var lasty = yn;
                xn        = fooA * lastx + fooB * lasty;
                yn        = fooC * lastx + fooA * lasty;
                points[i] = new PointD()
                {
                    X = xn, Y = yn
                };
            }


            _points           = new PointD[_numberOfPoints];
            _points[ctrIndex] = new PointD()
            {
                X = ((points[0].X - linierEccentricity) * Math.Cos(_lop)) - (points[0].Y * Math.Sin(_lop)),
                Y = ((points[0].X - linierEccentricity) * Math.Sin(_lop)) + (points[0].Y * Math.Cos(_lop))
            };
            for (int i = 1; i < ctrIndex + 1; i++)
            {
                double x   = points[i].X - linierEccentricity; //adjust for the focal point
                double ya  = points[i].Y;
                double yb  = -points[i].Y;
                double x2a = (x * Math.Cos(_lop)) - (ya * Math.Sin(_lop)); //rotate to loan
                double y2a = (x * Math.Sin(_lop)) + (ya * Math.Cos(_lop));
                double x2b = (x * Math.Cos(_lop)) - (yb * Math.Sin(_lop));
                double y2b = (x * Math.Sin(_lop)) + (yb * Math.Cos(_lop));
                _points[ctrIndex + i] = new PointD()
                {
                    X = x2a,
                    Y = y2a
                };

                _points[ctrIndex - i] = new PointD()
                {
                    X = x2b,
                    Y = y2b
                };
            }
        }
コード例 #8
0
        public void TestOrbitDBFromVectors(double parentMass, double objMass, Vector3 position, Vector3 velocity)
        {
            double         angleΔ = 0.0000000001;
            double         sgp_m  = OrbitMath.CalculateStandardGravityParameterInM3S2(objMass, parentMass);
            KeplerElements ke     = OrbitMath.KeplerFromPositionAndVelocity(sgp_m, position, velocity, new DateTime());

            Game          game = new Game();
            EntityManager man  = new EntityManager(game, false);

            BaseDataBlob[] parentblobs = new BaseDataBlob[3];
            parentblobs[0] = new PositionDB(man.ManagerGuid)
            {
                X_AU = 0, Y_AU = 0, Z_AU = 0
            };
            parentblobs[1] = new MassVolumeDB()
            {
                Mass = parentMass
            };
            parentblobs[2] = new OrbitDB();
            Entity parentEntity = new Entity(man, parentblobs);


            OrbitDB objOrbit  = OrbitDB.FromVector(parentEntity, objMass, parentMass, sgp_m, position, velocity, new DateTime());
            Vector3 resultPos = OrbitProcessor.GetPosition_AU(objOrbit, new DateTime());

            //check LoAN
            var objLoAN        = objOrbit.LongitudeOfAscendingNode;
            var keLoAN         = ke.LoAN;
            var loANDifference = objLoAN - keLoAN;

            Assert.AreEqual(keLoAN, objLoAN, angleΔ);

            //check AoP
            var objAoP     = objOrbit.ArgumentOfPeriapsis;
            var keAoP      = ke.AoP;
            var difference = objAoP - keAoP;

            Assert.AreEqual(keAoP, objAoP, angleΔ);


            //check MeanAnomalyAtEpoch
            var objM0 = objOrbit.MeanAnomalyAtEpoch;
            var keM0  = ke.MeanAnomalyAtEpoch;

            Assert.AreEqual(keM0, objM0, angleΔ);
            Assert.AreEqual(objM0, OrbitMath.GetMeanAnomalyFromTime(objM0, objOrbit.MeanMotion_DegreesSec, 0), "meanAnomalyError");

            //checkEpoch
            var objEpoch = objOrbit.Epoch;
            var keEpoch  = ke.Epoch;

            Assert.AreEqual(keEpoch, objEpoch);



            //check EccentricAnomaly:
            var objE = (OrbitProcessor.GetEccentricAnomaly(objOrbit, objOrbit.MeanAnomalyAtEpoch_Degrees));
            //var keE =   (OrbitMath.Gete(position, ke.SemiMajorAxis, ke.LinearEccentricity, ke.AoP));

            /*
             * if (objE != keE)
             * {
             *  var dif = objE - keE;
             *  Assert.AreEqual(keE, objE, angleΔ);
             * }
             */
            //check trueAnomaly
            var orbTrueAnom         = OrbitProcessor.GetTrueAnomaly(objOrbit, new DateTime());
            var orbtaDeg            = Angle.ToDegrees(orbTrueAnom);
            var differenceInRadians = orbTrueAnom - ke.TrueAnomalyAtEpoch;
            var differenceInDegrees = Angle.ToDegrees(differenceInRadians);

            if (ke.TrueAnomalyAtEpoch != orbTrueAnom)
            {
                Vector3 eccentVector = OrbitMath.EccentricityVector(sgp_m, position, velocity);
                var     tacalc1      = OrbitMath.TrueAnomaly(eccentVector, position, velocity);
                var     tacalc2      = OrbitMath.TrueAnomaly(sgp_m, position, velocity);

                var diffa = differenceInDegrees;
                var diffb = Angle.ToDegrees(orbTrueAnom - tacalc1);
                var diffc = Angle.ToDegrees(orbTrueAnom - tacalc2);

                var ketaDeg = Angle.ToDegrees(tacalc1);
            }

            Assert.AreEqual(0, Angle.DifferenceBetweenRadians(ke.TrueAnomalyAtEpoch, orbTrueAnom), angleΔ,
                            "more than " + angleΔ + " radians difference, at " + differenceInRadians + " \n " +
                            "(more than " + Angle.ToDegrees(angleΔ) + " degrees difference at " + differenceInDegrees + ")" + " \n " +
                            "ke Angle: " + ke.TrueAnomalyAtEpoch + " obj Angle: " + orbTrueAnom + " \n " +
                            "ke Angle: " + Angle.ToDegrees(ke.TrueAnomalyAtEpoch) + " obj Angle: " + Angle.ToDegrees(orbTrueAnom));

            Assert.AreEqual(ke.Eccentricity, objOrbit.Eccentricity);
            Assert.AreEqual(ke.SemiMajorAxis, objOrbit.SemiMajorAxis);


            var lenke1 = ke.SemiMajorAxis * 2;
            var lenke2 = ke.Apoapsis + ke.Periapsis;

            Assert.AreEqual(lenke1, lenke2, 1.0E-10);
            var lendb1 = objOrbit.SemiMajorAxis_AU * 2;
            var lendb2 = objOrbit.Apoapsis_AU + objOrbit.Periapsis_AU;

            Assert.AreEqual(lendb1, lendb2, 1.0E-10);
            Assert.AreEqual(lenke1, lendb1, 1.0E-10);
            Assert.AreEqual(lenke2, lendb2, 1.0E-10);



            var ke_apkm   = Distance.AuToKm(ke.Apoapsis);
            var db_apkm   = Distance.AuToKm(objOrbit.Apoapsis_AU);
            var differnce = ke_apkm - db_apkm;

            Assert.AreEqual(ke.Apoapsis, objOrbit.Apoapsis_AU, 1.0E-10);
            Assert.AreEqual(ke.Periapsis, objOrbit.Periapsis_AU, 1.0E-10);

            Vector3 posKM    = Distance.AuToKm(position);
            Vector3 resultKM = Distance.AuToKm(resultPos);

            double  keslr       = EllipseMath.SemiLatusRectum(ke.SemiMajorAxis, ke.Eccentricity);
            double  keradius    = OrbitMath.RadiusAtAngle(ke.TrueAnomalyAtEpoch, keslr, ke.Eccentricity);
            Vector3 kemathPos   = OrbitMath.GetRalitivePosition(ke.LoAN, ke.AoP, ke.Inclination, ke.TrueAnomalyAtEpoch, keradius);
            Vector3 kemathPosKM = Distance.AuToKm(kemathPos);

            Assert.AreEqual(kemathPosKM.Length(), posKM.Length(), 0.01);

            Assert.AreEqual(posKM.Length(), resultKM.Length(), 0.01, "TA: " + orbtaDeg);
            Assert.AreEqual(posKM.X, resultKM.X, 0.01, "TA: " + orbtaDeg);
            Assert.AreEqual(posKM.Y, resultKM.Y, 0.01, "TA: " + orbtaDeg);
            Assert.AreEqual(posKM.Z, resultKM.Z, 0.01, "TA: " + orbtaDeg);

            if (velocity.Z == 0)
            {
                Assert.IsTrue(ke.Inclination == 0);
                Assert.IsTrue(objOrbit.Inclination_Degrees == 0);
            }

            //var speedVectorAU = OrbitProcessor.PreciseOrbitalVector(sgp, position, ke.SemiMajorAxis);
            //var speedVectorAU2 = OrbitProcessor.PreciseOrbitalVector(objOrbit, new DateTime());
            //Assert.AreEqual(speedVectorAU, speedVectorAU2);
        }
コード例 #9
0
        internal override void Display()
        {
            _isRunningFrame = true;
            if (IsActive)
            {
                SetFrameRateArray();
                if (ImGui.Begin("debug", ref IsActive))
                {
                    ImGui.Text(_state.PrimarySystemDateTime.ToString());
                    ImGui.Text("Cursor World Coordinate:");
                    var mouseWorldCoord = _state.Camera.MouseWorldCoordinate();
                    ImGui.Text("x" + mouseWorldCoord.X);
                    ImGui.SameLine();
                    ImGui.Text("y" + mouseWorldCoord.Y);

                    if (ImGui.CollapsingHeader("FrameRates", ImGuiTreeNodeFlags.CollapsingHeader))
                    {
                        //plot vars: (label, values, valueOffset, overlayText, scaleMin, scaleMax, graphSize, Stride)
                        //core game processing rate.
                        //ImGui.PlotHistogram("##GRHistogram", _gameRatesDisplay, 10, _timeSpan.TotalSeconds.ToString(), 0, 1f, new ImVec2(0, 80), sizeof(float));
                        //ImGui.PlotHistogram("##GRHistogram1", _gameRatesDisplay, 0 , _timeSpan.TotalSeconds.ToString(), 0, 1f, new ImVec2(0, 80), sizeof(float));
                        //string label, ref float values...
                        //ImGui.PlotHistogram(
                        ImGui.PlotHistogram("Game Tick ##GTHistogram", ref _gameRates[0], _gameRates.Length, _gameRateIndex, _currentGFPS.ToString(), 0f, largestGFPS, new Vector2(248, 60), sizeof(float));
                        ImGui.PlotLines("Game Tick ##GTPlotlines", ref _gameRates[0], _gameRates.Length, _gameRateIndex, _currentGFPS.ToString(), 0, largestGFPS, new Vector2(248, 60), sizeof(float));
                        //current star system processing rate.
                        ImGui.PlotHistogram("System Tick ##STHistogram", ref _systemRates[0], _systemRates.Length, _systemRateIndex, _currentSFPS.ToString(), 0f, 1f, new Vector2(248, 60), sizeof(float));
                        ImGui.PlotLines("System Tick ##STPlotlines", ref _systemRates[0], _systemRates.Length, _systemRateIndex, _currentSFPS.ToString(), 0, 1, new Vector2(248, 60), sizeof(float));
                        //ui framerate
                        ImGui.PlotHistogram("Frame Rate ##FPSHistogram", ref _frameRates[0], _frameRates.Length, _frameRateIndex, _currentFPS.ToString(), 0f, 10000, new Vector2(248, 60), sizeof(float));

                        foreach (var item in _systemState.StarSystem.ManagerSubpulses.ProcessTime)
                        {
                            ImGui.Text(item.Key.Name);
                            ImGui.SameLine();
                            ImGui.Text(item.Value.ToString());
                        }
                    }

                    if (ImGui.CollapsingHeader("GraphicTests", ImGuiTreeNodeFlags.CollapsingHeader))
                    {
                        var window = GraphicDebugWindow.GetWindow(_state);
                        window.Display();
                        window.Enable(true, _state);
                    }

                    ImGui.Text("Selected Star System: " + _state.SelectedStarSysGuid);
                    ImGui.Text("Number Of Entites: " + _state.SelectedSystem.NumberOfEntites);
                    if (ImGui.CollapsingHeader("Log"))
                    {
                        ImGui.BeginChild("LogChild", new Vector2(800, 300), true);
                        ImGui.Columns(4, "Events", true);
                        ImGui.Text("DateTime");
                        ImGui.NextColumn();
                        ImGui.Text("Faction");
                        ImGui.NextColumn();
                        ImGui.Text("Entity");
                        ImGui.NextColumn();
                        ImGui.Text("Event Message");
                        ImGui.NextColumn();

                        foreach (var gameEvent in StaticRefLib.EventLog.GetAllEvents())
                        {
                            string entityStr = "";
                            if (gameEvent.Entity != null)
                            {
                                if (gameEvent.Entity.HasDataBlob <NameDB>())
                                {
                                    entityStr = gameEvent.Entity.GetDataBlob <NameDB>().DefaultName;
                                }
                                else
                                {
                                    entityStr = gameEvent.Entity.Guid.ToString();
                                }
                            }
                            string factionStr = "";
                            if (gameEvent.Faction != null)
                            {
                                if (gameEvent.Faction.HasDataBlob <NameDB>())
                                {
                                    factionStr = gameEvent.Faction.GetDataBlob <NameDB>().DefaultName;
                                }
                                else
                                {
                                    factionStr = gameEvent.Faction.Guid.ToString();
                                }
                            }

                            ImGui.Separator();
                            ImGui.Text(gameEvent.Time.ToString());
                            ImGui.NextColumn();
                            ImGui.Text(factionStr);
                            ImGui.NextColumn();
                            ImGui.Text(entityStr);
                            ImGui.NextColumn();
                            ImGui.TextWrapped(gameEvent.Message);

                            ImGui.NextColumn();
                        }
                        //ImGui.Separator();
                        //ImGui.Columns();
                        ImGui.EndChild();
                    }
                    if (ImGui.CollapsingHeader("Entity List"))
                    {
                        List <Entity> factionOwnedEntites = _state.SelectedSystem.GetEntitiesByFaction(_state.Faction.Guid);
                        List <string> entityNames         = new List <string>();
                        foreach (var entity in factionOwnedEntites)
                        {
                            var name = entity.GetDataBlob <NameDB>();
                            if (name != null)
                            {
                                entityNames.Add(name.GetName(_state.Faction.Guid));
                            }
                        }
                        int item = 0;
                        ImGui.ListBox("Entites", ref item, entityNames.ToArray(), entityNames.Count);
                    }
                    if (_selectedEntityState != null && _selectedEntityState.Name != null && _selectedEntity.IsValid)
                    {
                        if (ImGui.CollapsingHeader("Selected Entity: " + _state.LastClickedEntity.Name + "###NameHeader", ImGuiTreeNodeFlags.CollapsingHeader))
                        {
                            ImGui.Text(_state.LastClickedEntity.Entity.Guid.ToString());
                            if (_selectedEntity.HasDataBlob <PositionDB>())
                            {
                                var positiondb = _selectedEntity.GetDataBlob <PositionDB>();
                                var posv4      = positiondb.AbsolutePosition_AU;
                                ImGui.Text("x: " + posv4.X);
                                ImGui.Text("y: " + posv4.Y);
                                ImGui.Text("z: " + posv4.Z);
                                if (positiondb.Parent != null)
                                {
                                    ImGui.Text("Parent: " + positiondb.Parent.GetDataBlob <NameDB>().DefaultName);
                                    ImGui.Text("Dist: " + Distance.AuToKm(positiondb.RelativePosition_AU.Length()));
                                }
                            }
                            if (_selectedEntity.HasDataBlob <MassVolumeDB>())
                            {
                                if (ImGui.CollapsingHeader("MassVolumeDB: ###MassVolDBHeader", ImGuiTreeNodeFlags.CollapsingHeader))
                                {
                                    MassVolumeDB mvdb = _selectedEntity.GetDataBlob <MassVolumeDB>();
                                    ImGui.Text("Mass " + mvdb.Mass + "Kg");
                                    ImGui.Text("Volume " + mvdb.Volume + "Km^3");
                                    ImGui.Text("Density " + mvdb.Density + "g/cm^3");
                                    ImGui.Text("Radius " + mvdb.Radius + "Km");
                                }
                            }
                            if (_selectedEntity.HasDataBlob <OrbitDB>())
                            {
                                if (ImGui.Checkbox("Draw SOI", ref _drawSOI))
                                {
                                    SimpleCircle cir;
                                    if (_drawSOI)
                                    {
                                        var soiradius = OrbitProcessor.GetSOI(_selectedEntity);
                                        var colour    = new SDL2.SDL.SDL_Color()
                                        {
                                            r = 0, g = 255, b = 0, a = 100
                                        };
                                        cir = new SimpleCircle(_selectedEntity.GetDataBlob <PositionDB>(), soiradius, colour);

                                        _state.SelectedSysMapRender.UIWidgets.Add(nameof(cir), cir);
                                    }
                                    else
                                    {
                                        _state.SelectedSysMapRender.UIWidgets.Remove(nameof(cir));
                                    }
                                }

                                if (ImGui.CollapsingHeader("OrbitDB: ###OrbitDBHeader", ImGuiTreeNodeFlags.CollapsingHeader))
                                {
                                    OrbitDB orbitDB = _selectedEntity.GetDataBlob <OrbitDB>();

                                    //if (_state.CurrentSystemDateTime != lastDate)
                                    //{
                                    pos        = OrbitProcessor.GetAbsolutePosition_AU(orbitDB, _state.PrimarySystemDateTime);
                                    truAnomoly = OrbitProcessor.GetTrueAnomaly(orbitDB, _state.PrimarySystemDateTime);
                                    lastDate   = _state.PrimarySystemDateTime;
                                    //}

                                    ImGui.Text("x: " + pos.X);
                                    ImGui.Text("y: " + pos.Y);
                                    ImGui.Text("z: " + pos.Z);
                                    ImGui.Text("Eccentricity: " + orbitDB.Eccentricity);
                                    ImGui.Text("AoP:" + orbitDB.ArgumentOfPeriapsis);
                                    ImGui.Text("TrueAnomaly: " + truAnomoly);
                                    ImGui.Text("MeanMotion: " + orbitDB.MeanMotion + " in Deg/s");
                                    ImGui.Text("MeanVelocity: " + OrbitMath.MeanOrbitalVelocityInAU(orbitDB) + "Au/s");
                                    ImGui.Text("MeanVelocity: " + Distance.AuToKm(OrbitMath.MeanOrbitalVelocityInAU(orbitDB)) + "Km/s");
                                    ImGui.Text("SOI Radius: " + Distance.AuToKm(OrbitProcessor.GetSOI(_state.LastClickedEntity.Entity)));
                                    ImGui.Text("Orbital Period:" + orbitDB.OrbitalPeriod);
                                    ImGui.Text("SemiMajAxis: " + orbitDB.SemiMajorAxis);
                                    ImGui.Text("Periapsis: " + Distance.AuToKm(orbitDB.Periapsis).ToString("g3") + " Km");
                                    ImGui.Text("Appoapsis: " + Distance.AuToKm(orbitDB.Apoapsis).ToString("g3") + " Km");
                                    if (orbitDB.Parent != null)
                                    {
                                        ImGui.Text("Parent: " + orbitDB.Parent.GetDataBlob <NameDB>().DefaultName);
                                    }
                                    if (orbitDB.Children.Count > 0)
                                    {
                                        foreach (var item in orbitDB.Children)
                                        {
                                            ImGui.Text(item.GetDataBlob <NameDB>().DefaultName);
                                        }
                                    }
                                }
                            }

                            if (_selectedEntity.HasDataBlob <NewtonMoveDB>())
                            {
                                if (ImGui.Checkbox("Draw Parent SOI", ref _drawParentSOI))
                                {
                                    SimpleCircle psoi;
                                    SimpleLine   psoilin;
                                    if (_drawParentSOI)
                                    {
                                        var myPos  = _selectedEntity.GetDataBlob <PositionDB>();
                                        var parent = myPos.Parent;
                                        var pObt   = parent.GetDataBlob <OrbitDB>();
                                        var cnmve  = _selectedEntity.GetDataBlob <NewtonMoveDB>();

                                        var soiradius = OrbitProcessor.GetSOI(parent);
                                        var colour    = new SDL2.SDL.SDL_Color()
                                        {
                                            r = 0, g = 255, b = 0, a = 100
                                        };
                                        psoi = new SimpleCircle(parent.GetDataBlob <PositionDB>(), soiradius, colour);
                                        var pmass  = parent.GetDataBlob <MassVolumeDB>().Mass;
                                        var mymass = _selectedEntity.GetDataBlob <MassVolumeDB>().Mass;

                                        var    sgp          = GameConstants.Science.GravitationalConstant * (pmass + mymass) / 3.347928976e33;
                                        var    vel          = Distance.KmToAU(cnmve.CurrentVector_kms);
                                        var    cpos         = myPos.RelativePosition_AU;
                                        var    eccentVector = OrbitMath.EccentricityVector(sgp, cpos, vel);
                                        double ce           = eccentVector.Length();
                                        var    r            = cpos.Length();
                                        var    v            = vel.Length();

                                        var ca = 1 / (2 / r - Math.Pow(v, 2) / sgp);
                                        var cp = EllipseMath.SemiLatusRectum(ca, ce);

                                        var cAoP = Math.Atan2(eccentVector.Y, eccentVector.X);

                                        /*
                                         * var pa = pObt.SemiMajorAxis;
                                         * var pe = pObt.Eccentricity;
                                         * var pp = EllipseMath.SemiLatusRectum(pa, pe);
                                         */
                                        double θ = OrbitMath.AngleAtRadus(soiradius, cp, ce);
                                        θ += cAoP;

                                        var x = soiradius * Math.Cos(θ);
                                        var y = soiradius * Math.Sin(θ);
                                        psoilin = new SimpleLine(parent.GetDataBlob <PositionDB>(), new PointD()
                                        {
                                            X = x, Y = y
                                        }, colour);

                                        _state.SelectedSysMapRender.UIWidgets.Add(nameof(psoi), psoi);
                                        _state.SelectedSysMapRender.UIWidgets.Add(nameof(psoilin), psoilin);
                                    }
                                    else
                                    {
                                        _state.SelectedSysMapRender.UIWidgets.Remove(nameof(psoi));
                                        _state.SelectedSysMapRender.UIWidgets.Remove(nameof(psoilin));
                                    }
                                }
                            }

                            if (_state.LastClickedEntity.OrbitIcon != null)
                            {
                                if (ImGui.CollapsingHeader("OrbitIcon: ###OrbitIconHeader", ImGuiTreeNodeFlags.CollapsingHeader))
                                {
                                    OrbitDB orbitDB = _selectedEntity.GetDataBlob <OrbitDB>();

                                    //string startRadian = _state.LastClickedEntity.OrbitIcon._ellipseStartArcAngleRadians.ToString();
                                    //string startDegrees = Angle.ToDegrees(_state.LastClickedEntity.OrbitIcon._ellipseStartArcAngleRadians).ToString();
                                    //ImGui.Text("StartAngleRadians: " + startRadian);
                                    //ImGui.Text("StartAngleDegrees: " + startDegrees);
                                    if (ImGui.CollapsingHeader("OrbitIconLines", ImGuiTreeNodeFlags.CollapsingHeader))
                                    {
                                        var window = OrbitalDebugWindow.GetWindow(_state.LastClickedEntity);
                                        window.Display();
                                        window.Enable(true, _state);
                                    }
                                }
                            }

                            if (_selectedEntity.HasDataBlob <PropulsionAbilityDB>())
                            {
                                if (ImGui.CollapsingHeader("Propulsion: ###PropulsionHeader", ImGuiTreeNodeFlags.CollapsingHeader))
                                {
                                    PropulsionAbilityDB propulsionDB = _selectedEntity.GetDataBlob <PropulsionAbilityDB>();
                                    ImGui.Text("NonNewt Engine Power: " + propulsionDB.TotalEnginePower);
                                    ImGui.Text("Max Speed: " + propulsionDB.MaximumSpeed_MS);
                                    ImGui.Text("CurrentVector: " + propulsionDB.CurrentVectorMS);
                                    ImGui.Text("Current Speed: " + ECSLib.Vector3.Magnitude(propulsionDB.CurrentVectorMS));
                                    if (_state.LastClickedEntity.Entity.HasDataBlob <CargoStorageDB>())
                                    {
                                        var fuelsGuid = propulsionDB.FuelUsePerKM;
                                        var storage   = _state.LastClickedEntity.Entity.GetDataBlob <CargoStorageDB>();
                                        foreach (var fuelItemGuid in fuelsGuid.Keys)
                                        {
                                            var fuel = _state.Game.StaticData.GetICargoable(fuelItemGuid);
                                            ImGui.Text(fuel.Name);
                                            ImGui.SameLine();
                                            ImGui.Text(StorageSpaceProcessor.GetAmount(storage, fuel).ToString());
                                        }
                                    }
                                }
                                if (_state.LastClickedEntity.Entity.HasDataBlob <TranslateMoveDB>())
                                {
                                    var db = _state.LastClickedEntity.Entity.GetDataBlob <TranslateMoveDB>();
                                    if (ImGui.CollapsingHeader("Transit: ###TransitHeader", ImGuiTreeNodeFlags.CollapsingHeader))
                                    {
                                        ImGui.Text("EntryPoint " + db.TranslateEntryPoint_AU);
                                        ImGui.Text("ExitPoint  " + db.TranslateExitPoint_AU);
                                        ImGui.Text("EDA " + db.PredictedExitTime.ToString());
                                        double distance = Distance.DistanceBetween(db.TranslateEntryPoint_AU, db.TranslateExitPoint_AU);
                                        ImGui.Text("Distance " + distance + " AU");
                                        ImGui.SameLine();
                                        double distancekm = Distance.AuToKm(distance);
                                        ImGui.Text(distancekm.ToString() + " KM");
                                        var timeToTarget = db.PredictedExitTime - _state.PrimarySystemDateTime;
                                        ImGui.Text("Remaining TTT " + timeToTarget);
                                        var totalTime = db.PredictedExitTime - db.EntryDateTime;
                                        ImGui.Text("Total TTT  " + totalTime);
                                        double speed = ((distancekm * 1000) / totalTime.TotalSeconds);
                                        ImGui.Text("speed2 " + speed);
                                        ImGui.Text("LastDateTime: ");
                                        ImGui.Text(db.LastProcessDateTime.ToString());
                                        ImGui.Text("Time Since Last: ");
                                        var timelen = _state.PrimarySystemDateTime - db.LastProcessDateTime;
                                        ImGui.Text(timelen.ToString());
                                    }
                                }
                            }
                            if (_selectedEntity.HasDataBlob <SensorInfoDB>())
                            {
                                var actualEntity = _selectedEntity.GetDataBlob <SensorInfoDB>().DetectedEntity;
                                if (actualEntity.IsValid && actualEntity.HasDataBlob <AsteroidDamageDB>())
                                {
                                    var dmgDB = actualEntity.GetDataBlob <AsteroidDamageDB>();
                                    ImGui.Text("Remaining HP: " + dmgDB.Health.ToString());
                                }
                            }
                        }
                    }
                }
                //else IsActive = false;
                ImGui.End();
            }
            _isRunningFrame           = false;
            _dateChangeSinceLastFrame = false;
        }