internal OrbitOrderWiget(Entity targetEntity) : base(targetEntity.GetDataBlob <PositionDB>()) { _bodyPositionDB = targetEntity.GetDataBlob <PositionDB>(); OrbitEllipseSemiMaj = 20000; OrbitEllipseSemiMinor = 20000; _linearEccentricity = 0; _soiWorldRadius = OrbitProcessor.GetSOI(targetEntity); _targetWorldRadius = targetEntity.GetDataBlob <MassVolumeDB>().Radius; Setup(); }
void TargetSelected() { TargetEntity = _state.LastClickedEntity; _state.Camera.PinToEntity(TargetEntity.Entity); _targetRadiusAU = TargetEntity.Entity.GetDataBlob <MassVolumeDB>().Radius; _targetRadiusKM = TargetEntity.Entity.GetDataBlob <MassVolumeDB>().RadiusInKM; var soiWorldRad_AU = OrbitProcessor.GetSOI(TargetEntity.Entity); _apMax = soiWorldRad_AU; float soiViewUnits = _state.Camera.ViewDistance(soiWorldRad_AU); _massTargetBody = TargetEntity.Entity.GetDataBlob <MassVolumeDB>().Mass; _stdGravParamTargetBody = GameConstants.Science.GravitationalConstant * (_massTargetBody + _massOrderingEntity) / 3.347928976e33; InsertionCalcs(); System.Numerics.Vector2 viewPortSize = _state.Camera.ViewPortSize; float windowLen = Math.Min(viewPortSize.X, viewPortSize.Y); if (soiViewUnits < windowLen * 0.5) { //zoom so soi fills ~3/4 screen. var soilenwanted = windowLen * 0.375; _state.Camera.ZoomLevel = (float)(soilenwanted / _apMax); } if (_orbitWidget != null) { _orbitWidget = new OrbitOrderWiget(TargetEntity.Entity); _state.SelectedSysMapRender.UIWidgets[nameof(_orbitWidget)] = _orbitWidget; } else { _orbitWidget = new OrbitOrderWiget(TargetEntity.Entity); _state.SelectedSysMapRender.UIWidgets.Add(nameof(_orbitWidget), _orbitWidget); } OrderingEntity.DebugOrbitOrder = _orbitWidget; _moveWidget.SetArrivalTarget(TargetEntity.Entity); _tooltipText = "Select Insertion Point"; CurrentState = States.NeedsInsertionPoint; }
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 = OrbitProcessor.GetSOI(targetEntity); _targetWorldRadius = targetEntity.GetDataBlob <MassVolumeDB>().Radius; Setup(); }
internal void CreatePointArray() { Vector3 vel = Distance.KmToAU(_newtonMoveDB.CurrentVector_kms); 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(_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 }; } }
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; }