コード例 #1
0
        public void TestOrbitEpoch()
        {
            Game          game = new Game();
            EntityManager man  = new EntityManager(game, false);

            double  parentMass = 1.989e30;
            double  objMass    = 2.2e+15;
            Vector3 position   = new Vector3()
            {
                X = Distance.AuToMt(0.57)
            };                                                              //Halley's Comet at periapse aprox
            Vector3 velocity = new Vector3()
            {
                Y = 54000
            };

            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);
            double sgp_m        = OrbitMath.CalculateStandardGravityParameterInM3S2(parentMass, objMass);

            OrbitDB objOrbit  = OrbitDB.FromVector(parentEntity, objMass, parentMass, sgp_m, position, velocity, new DateTime());
            Vector3 resultPos = OrbitProcessor.GetPosition_AU(objOrbit, new DateTime());
        }
コード例 #2
0
        public void FailingOrbitsFromVectorTests()
        {
            double  parentMass = 1.989e30;
            double  objMass    = 10000;
            Vector3 position   = new Vector3()
            {
                X = Distance.AuToMt(0.25), Y = Distance.AuToMt(0.25)
            };
            Vector3 velocity = new Vector3()
            {
                X = Distance.KmToM(0), Y = Distance.KmToM(1)
            };                                                                                 //passes

            TestOrbitDBFromVectors(parentMass, objMass, position, velocity);

            velocity = new Vector3()
            {
                X = Distance.KmToM(0), Y = -Distance.KmToAU(2)
            };                                                                           //fails
            TestOrbitDBFromVectors(parentMass, objMass, position, velocity);

            velocity = new Vector3()
            {
                X = Distance.KmToM(1), Y = Distance.KmToAU(0)
            };                                                                          //fails
            TestOrbitDBFromVectors(parentMass, objMass, position, velocity);

            velocity = new Vector3()
            {
                X = Distance.KmToM(-1), Y = Distance.KmToAU(0)
            };                                                                           //fails
            TestOrbitDBFromVectors(parentMass, objMass, position, velocity);
        }
コード例 #3
0
        void Calcs()
        {
            double x = (_radialDV * Math.Cos(_origionalAngle)) - (_progradeDV * Math.Sin(_origionalAngle));
            double y = (_radialDV * Math.Sin(_origionalAngle)) + (_progradeDV * Math.Cos(_origionalAngle));

            _deltaV_MS = new ECSLib.Vector3(x, y, 0);


            _newOrbitalVelocity = _orbitalVelocityAtChange + Distance.MToAU(_deltaV_MS);
            _newOrbitalSpeed    = _newOrbitalVelocity.Length();
            var spdmps = Distance.AuToMt(_newOrbitalSpeed);

            _newAngle = Math.Atan2(_newOrbitalVelocity.X, _newOrbitalVelocity.Y);


            var ke = OrbitMath.KeplerFromPositionAndVelocity(_stdGravParam, _positonAtChange_AU, _newOrbitalVelocity, _actionDateTime);

            _ke = ke;

            _orbitWidget.SetParametersFromKeplerElements(ke, _positonAtChange_AU);

            /*
             * var sgpCBAU = GameConstants.Science.GravitationalConstant * (_massCurrentBody + _massOrderingEntity) / 3.347928976e33;// (149597870700 * 149597870700 * 149597870700);
             * var ralPosCBAU = OrderingEntity.Entity.GetDataBlob<PositionDB>().RelativePosition_AU;
             * var smaCurrOrbtAU = OrderingEntity.Entity.GetDataBlob<OrbitDB>().SemiMajorAxis;
             * var velAU = OrbitProcessor.PreciseOrbitalVector(sgpCBAU, ralPosCBAU, smaCurrOrbtAU);
             */
        }
コード例 #4
0
        public void OrbitsFromVectorTests()
        {
            double  parentMass = 5.97237e24;
            double  objMass    = 7.342e22;
            Vector3 position   = new Vector3()
            {
                X = Distance.KmToM(405400)
            };                                                               //moon at apoapsis
            Vector3 velocity = new Vector3()
            {
                Y = 970
            };                                            //approx velocity of moon at apoapsis

            TestOrbitDBFromVectors(parentMass, objMass, position, velocity);

            //test high eccentricity orbit
            parentMass = 1.989e30;
            objMass    = 2.2e+15;
            position   = new Vector3()
            {
                X = Distance.AuToMt(0.57)
            };                                                      //Halley's Comet at periapse aprox
            velocity = new Vector3()
            {
                Y = Distance.KmToM(54)
            };
            TestOrbitDBFromVectors(parentMass, objMass, position, velocity);



            parentMass = 1.989e30;
            objMass    = 2.2e+15;
            position   = new Vector3()
            {
                X = Distance.AuToMt(0.25), Y = Distance.AuToMt(0.25)
            };
            velocity = new Vector3()
            {
                Y = Distance.KmToM(54)
            };
            TestOrbitDBFromVectors(parentMass, objMass, position, velocity);

            parentMass = 1.989e30;
            objMass    = 10000;
            position   = new Vector3()
            {
                X = Distance.AuToMt(0.25), Y = Distance.AuToMt(0.25)
            };
            velocity = new Vector3()
            {
                X = Distance.KmToM(0), Y = Distance.KmToM(1)
            };
            TestOrbitDBFromVectors(parentMass, objMass, position, velocity);
        }
コード例 #5
0
ファイル: Camera.cs プロジェクト: Moth-Tolias/Pulsar4x
        public ECSLib.Vector3 MouseWorldCoordinate_m()
        {
            //Vector2 mouseCoord = ImGui.GetMousePos();
            //double x = ((mouseCoord.X - ViewPortCenter.X) / (ZoomLevel / GameConstants.Units.MetersPerAu) + CameraWorldPosition_m.X);
            //double y = -(((mouseCoord.Y - ViewPortCenter.Y) / (ZoomLevel/ GameConstants.Units.MetersPerAu) - CameraWorldPosition_m.Y));

            var    mwcau = MouseWorldCoordinate_AU();
            double x     = Distance.AuToMt(mwcau.X);
            double y     = Distance.AuToMt(mwcau.Y);

            return(new ECSLib.Vector3(x, y, 0));
        }
コード例 #6
0
        public void OrbitMath_CalculateAngularMomentum_When_ZeroXNegativeYVelocity_Should_GiveCorrectResults()
        {
            // To determine what the Kepler Elements should be, use : http://orbitsimulator.com/formulas/OrbitalElements.html
            Vector3 position = new Vector3()
            {
                X = Distance.AuToMt(0.25), Y = Distance.AuToMt(0.25)
            };
            Vector3 velocity = new Vector3()
            {
                X = 0, Y = Distance.KmToM(-1)
            };
            var expectedResult = new Vector3(
                0,
                0,
                -37399467675000.0d
                );
            var calculatedResult = OrbitMath.CalculateAngularMomentum(position, velocity);

            Assert.IsTrue(TestVectorsAreEqual(expectedResult, calculatedResult, 1.0d));
        }
コード例 #7
0
        public void TestIntercept()
        {
            double        myMass     = 10000;
            double        parentMass = 1.989e30; //solar mass.
            Game          game       = new Game();
            EntityManager mgr        = new EntityManager(game, false);

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

            Vector3 currentPos_m = new Vector3 {
                X = Distance.AuToMt(-0.77473184638034), Y = Distance.AuToMt(0.967145228951685)
            };
            Vector3 currentVelocity_m = new Vector3 {
                Y = Distance.KmToM(40)
            };
            double nonNewtSpeed_m = Distance.KmToM(283.018);

            Vector3 targetObjPosition = new Vector3 {
                X = Distance.AuToMt(0.149246434443459), Y = Distance.AuToMt(-0.712107888348067)
            };
            Vector3 targetObjVelocity = new Vector3 {
                Y = Distance.KmToM(35)
            };


            double sgp_m = OrbitMath.CalculateStandardGravityParameterInM3S2(myMass, parentMass);
            //KeplerElements ke = OrbitMath.KeplerFromVelocityAndPosition(sgp, targetObjPosition, targetObjVelocity);

            var currentDateTime = new DateTime(2000, 1, 1);

            OrbitDB targetOrbit = OrbitDB.FromVector(parentEntity, myMass, parentMass, sgp_m, targetObjPosition, targetObjVelocity, currentDateTime);



            var intercept_m = OrbitMath.GetInterceptPosition_m(currentPos_m, nonNewtSpeed_m, targetOrbit, currentDateTime);

            var futurePos1_m = OrbitProcessor.GetAbsolutePosition_m(targetOrbit, intercept_m.Item2);

            var futurePos2_m = intercept_m.Item1;



            Assert.AreEqual(futurePos1_m.Length(), futurePos2_m.Length(), 0.01);
            Assert.AreEqual(futurePos1_m.X, futurePos2_m.X, 0.01);
            Assert.AreEqual(futurePos1_m.Y, futurePos2_m.Y, 0.01);
            Assert.AreEqual(futurePos1_m.Z, futurePos2_m.Z, 0.01);
            var time       = intercept_m.Item2 - currentDateTime;
            var distance_m = (currentPos_m - intercept_m.Item1).Length();
            var speed      = distance_m / time.TotalSeconds;
            var distb_m    = nonNewtSpeed_m * time.TotalSeconds;

            var timeb = distance_m / nonNewtSpeed_m;

            Assert.AreEqual(nonNewtSpeed_m, speed, 1.0e-4);

            var dif = distance_m - distb_m;

            Assert.AreEqual(distance_m, distb_m, 100.0, "Out by a difference of " + dif + " meters");
        }
コード例 #8
0
 public void Distance_AuToMt_When_Given1_Should_Give149597870700()
 {
     Assert.AreEqual(149597870700d, Distance.AuToMt(1.0d));
 }
コード例 #9
0
ファイル: Camera.cs プロジェクト: Moth-Tolias/Pulsar4x
 /// <summary>
 /// Returns the Distance in World-Coordinates
 /// </summary>
 /// <param name="dist"> in Pixels</param>
 /// <returns></returns>
 public double WorldDistance_m(float dist)
 {
     return(Distance.AuToMt(dist / ZoomLevel));
 }
コード例 #10
0
        internal override void Display()
        {
            if (IsActive)
            {
                var size = new System.Numerics.Vector2(200, 100);
                var pos  = new System.Numerics.Vector2(_state.MainWinSize.X / 2 - size.X / 2, _state.MainWinSize.Y / 2 - size.Y / 2);

                ImGui.SetNextWindowSize(size, ImGuiCond.FirstUseEver);
                ImGui.SetNextWindowPos(pos, ImGuiCond.FirstUseEver);

                if (ImGui.Begin(_displayText, ref IsActive, _flags))
                {
                    //put calcs that needs refreshing each frame in here. (ie calculations from mouse cursor position)
                    if (_orbitWidget != null)
                    {
                        switch (CurrentState)
                        {
                        case States.NeedsEntity:

                            break;

                        case States.NeedsTarget:
                        {
                        }

                        break;

                        case States.NeedsInsertionPoint:
                        {
                            var maxprogradeDV = _maxDV - Math.Abs(_radialDV);
                            var maxradialDV   = _maxDV - Math.Abs(_progradeDV);
                            if (ImGui.SliderFloat("Prograde DV", ref _progradeDV, -maxprogradeDV, maxprogradeDV))
                            {
                                InsertionCalcs();
                            }
                            if (ImGui.SliderFloat("Radial DV", ref _radialDV, -maxradialDV, maxradialDV))
                            {
                                InsertionCalcs();
                            }

                            var mousePos = ImGui.GetMousePos();

                            var mouseWorldPos = _state.Camera.MouseWorldCoordinate();
                            _targetInsertionPoint_AU = (mouseWorldPos - GetTargetPosition());         //ralitive to the target body

                            _moveWidget.SetArrivalPosition(_targetInsertionPoint_AU);

                            //var velAU = OrbitProcessor.PreciseOrbitalVector(sgpCBAU, ralPosCBAU, smaCurrOrbtAU);


                            var ke = OrbitMath.KeplerFromPositionAndVelocity(_stdGravParamTargetBody, _targetInsertionPoint_AU, _insertionOrbitalVelocity, _departureDateTime);
                            _ke = ke;

                            _orbitWidget.SetParametersFromKeplerElements(ke, _targetInsertionPoint_AU);
                            _apoapsisKm   = Distance.AuToKm(ke.Apoapsis);
                            _periapsisKM  = Distance.AuToKm(ke.Periapsis);
                            _eccentricity = ke.Eccentricity;
                            break;
                        }

                        /*
                         * case States.NeedsSecondApsis:
                         * {
                         *   TODO: when we've got newtonion engines, allow second apsis choice and expend Dv.
                         *  var mousePos = ImGui.GetMousePos();
                         *
                         *  var mouseWorldPos = _state.Camera.MouseWorldCoordinate();
                         *
                         *  var ralitivePos = (GetTargetPosition() - mouseWorldPos);
                         *  _orbitWidget.SetPeriapsis(ralitivePos.X, ralitivePos.Y);
                         *
                         *  //_periapsisKM = Distance.AuToKm((GetTargetPosition() - mouseWorldPos).Length());
                         *  var distanceSelected = Distance.AuToKm((GetTargetPosition() - mouseWorldPos).Length());
                         *  var d1 = Math.Max(_peMin, distanceSelected); //can't be lower than body radius
                         *  _periapsisKM = Math.Min(d1, _apoapsisKm);  //can't be higher than apoapsis.
                         *
                         *  break;
                         * }*/
                        case States.NeedsActioning:
                        {
                            var maxprogradeDV = _maxDV - Math.Abs(_radialDV);
                            var maxradialDV   = _maxDV - Math.Abs(_progradeDV);
                            if (ImGui.SliderFloat("Prograde DV", ref _progradeDV, -maxprogradeDV, maxprogradeDV))
                            {
                                InsertionCalcs();
                            }
                            if (ImGui.SliderFloat("Radial DV", ref _radialDV, -maxradialDV, maxradialDV))
                            {
                                InsertionCalcs();
                            }
                            var ke = OrbitMath.KeplerFromPositionAndVelocity(_stdGravParamTargetBody, _targetInsertionPoint_AU, _insertionOrbitalVelocity, _departureDateTime);
                            _ke = ke;
                            _orbitWidget.SetParametersFromKeplerElements(ke, _targetInsertionPoint_AU);
                            _apoapsisKm   = Distance.AuToKm(ke.Apoapsis);
                            _periapsisKM  = Distance.AuToKm(ke.Periapsis);
                            _eccentricity = ke.Eccentricity;
                            break;
                        }

                        default:
                            break;
                        }
                    }


                    ImGui.SetTooltip(_tooltipText);
                    ImGui.Text("Target: ");
                    if (TargetEntity != null)
                    {
                        ImGui.SameLine();
                        ImGui.Text(TargetEntity.Name);
                    }
                    ImGui.Text("Apoapsis: ");
                    ImGui.SameLine();
                    ImGui.Text(_apoapsisKm.ToString("g3") + " (Alt: " + _apAlt.ToString("g3") + ")");

                    ImGui.Text("Periapsis: ");
                    ImGui.SameLine();
                    ImGui.Text(_periapsisKM.ToString("g3") + " (Alt: " + _peAlt.ToString("g3") + ")");

                    ImGui.Text("DepartureVelocity: ");
                    //ImGui.SameLine();
                    ImGui.Text(_departureOrbitalSpeed.ToString() + " AU");
                    ImGui.Text(Distance.AuToKm(_departureOrbitalSpeed).ToString() + " KM");

                    ImGui.Text("InsertionVelocity: ");
                    //ImGui.SameLine();
                    ImGui.Text(_insertionOrbitalSpeed.ToString() + " AU");
                    ImGui.Text(Distance.AuToKm(_insertionOrbitalSpeed).ToString() + " KM");

                    ImGui.Text("Eccentricity: ");
                    ImGui.Text(_eccentricity.ToString("g3"));

                    ImGui.Text("Departure Vector: ");
                    ImGui.SameLine();
                    ImGui.Text(_departureOrbitalVelocity.ToString("g3"));
                    ImGui.Text(Distance.AuToMt(_departureOrbitalVelocity).ToString("N") + "m/s");

                    ImGui.Text("Departure Angle: ");
                    ImGui.SameLine();
                    ImGui.Text(_departureAngle.ToString("g3") + " radians or " + Angle.ToDegrees(_departureAngle).ToString("F") + " deg ");

                    var pc = OrbitProcessor.InstantaneousOrbitalVelocityPolarCoordinate(_orderEntityOrbit, _departureDateTime);

                    ImGui.Text("Departure Polar Coordinates: ");
                    ImGui.Text(pc.Item1.ToString() + " AU or " + Distance.AuToMt(pc.Item1).ToString("F") + " m/s");
                    ImGui.Text(pc.Item2.ToString("g3") + " radians or " + Angle.ToDegrees(pc.Item2).ToString("F") + " deg ");;


                    ImGui.Text("Insertion Vector: ");
                    ImGui.SameLine();
                    ImGui.Text(_insertionOrbitalVelocity.ToString("g3"));

                    ImGui.Text("LoAN: ");
                    ImGui.SameLine();
                    ImGui.Text(_ke.LoAN.ToString("g3"));

                    ImGui.Text("AoP: ");
                    ImGui.SameLine();
                    ImGui.Text(_ke.AoP.ToString("g3"));

                    ImGui.Text("LoP Angle: ");
                    ImGui.SameLine();
                    ImGui.Text((_ke.LoAN + _ke.AoP).ToString("g3") + " radians or " + Angle.ToDegrees(_ke.LoAN + _ke.AoP).ToString("F") + " deg ");

                    if (_orbitWidget != null)
                    {
                        ImGui.Text("Clockwise " + _orbitWidget.IsClockwiseOrbit.ToString());
                    }



                    //if (CurrentState != States.NeedsActioning) //use alpha on the button if it's not useable.
                    //ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * 0.5f);
                    if (ImGui.Button("Action Order") && CurrentState == States.NeedsActioning) //only do suff if clicked if it's usable.
                    {
                        fsm[(byte)CurrentState, (byte)Events.ClickedAction].Invoke();
                        //ImGui.PopStyleVar();
                    }

                    if (_smMode)
                    {
                        ImGui.SameLine();
                        if (ImGui.Button("Add OrbitDB"))
                        {
                            ActionAddDB();
                        }
                    }

                    ImGui.End();
                }
            }
        }