Esempio n. 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 = 0.57
            };                                             //Halley's Comet at periapse aprox
            Vector3 velocity = new Vector3()
            {
                Y = Distance.KmToAU(54)
            };

            BaseDataBlob[] parentblobs = new BaseDataBlob[3];
            parentblobs[0] = new PositionDB(man.ManagerGuid)
            {
                X = 0, Y = 0, Z = 0
            };
            parentblobs[1] = new MassVolumeDB()
            {
                Mass = parentMass
            };
            parentblobs[2] = new OrbitDB();
            Entity parentEntity = new Entity(man, parentblobs);
            double sgp          = GameConstants.Science.GravitationalConstant * (parentMass + objMass) / 3.347928976e33;

            OrbitDB objOrbit  = OrbitDB.FromVector(parentEntity, objMass, parentMass, sgp, position, velocity, new DateTime());
            Vector3 resultPos = OrbitProcessor.GetPosition_AU(objOrbit, new DateTime());
        }
Esempio n. 2
0
 void Entity_ChangeEvent(EntityChangeData.EntityChangeType changeType, BaseDataBlob db)
 {
     if (changeType == EntityChangeData.EntityChangeType.DBAdded)
     {
         if (db is OrbitDB)
         {
             _orbitDB = (OrbitDB)db;
             var i    = Angle.ToRadians(_orbitDB.Inclination);
             var aop  = Angle.ToRadians(_orbitDB.ArgumentOfPeriapsis);
             var loan = Angle.ToRadians(_orbitDB.LongitudeOfAscendingNode);
             _lop = (float)OrbitMath.GetLongditudeOfPeriapsis(i, aop, loan);
         }
         else if (db is TranslateMoveDB)
         {
             _tlmoveDB = (TranslateMoveDB)db;
         }
     }
     else if (changeType == EntityChangeData.EntityChangeType.DBRemoved)
     {
         if (db is OrbitDB)
         {
             _orbitDB = null;
         }
         else if (db is TranslateMoveDB)
         {
             _tlmoveDB = null;
         }
     }
 }
Esempio n. 3
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());
        }
Esempio n. 4
0
        void HandleDatablob(NetIncomingMessage message)
        {
            Guid   entityGuid = new Guid(message.ReadBytes(16));
            string name       = message.ReadString();
            int    typeIndex  = message.ReadInt32();
            //int hash = message.ReadInt32();
            int len = message.ReadInt32();

            byte[] data = message.ReadBytes(len);

            var    mStream = new MemoryStream(data);
            Entity entity;

            if (!this.Game.GlobalManager.FindEntityByGuid(entityGuid, out entity))
            {
                Messages.Add("DatablobImportFail: No Entity for ID: " + entityGuid);
            }
            else
            {
                string fullName = "Pulsar4X.ECSLib." + name;
                Type   dbType   = Type.GetType(fullName);
                if (dbType == null)
                {
                    throw new Exception("DataBlob " + fullName + " not found. " +
                                        "Either the client game version does not match the server, " +
                                        "or the datablob is not in the expected namespace. " +
                                        "This section of code does not support datablobs not in the Pulsar4X.ECSLib namespace, " +
                                        "either fix this code or ensure the datablob is in the appropriate namespace");
                }
                BaseDataBlob db = SerializationManager.ImportDatablob(Game, entity, dbType, mStream);
            }
        }
Esempio n. 5
0
 void Entity_ChangeEvent(EntityChangeData.EntityChangeType changeType, BaseDataBlob db)
 {
     if (changeType == EntityChangeData.EntityChangeType.DBAdded)
     {
         if (db is OrbitDB)
         {
             _orbitDB = (OrbitDB)db;
             var i    = _orbitDB.Inclination;
             var aop  = _orbitDB.ArgumentOfPeriapsis;
             var loan = _orbitDB.LongitudeOfAscendingNode;
             _lop = (float)OrbitMath.GetLongditudeOfPeriapsis(i, aop, loan);
         }
         else if (db is WarpMovingDB)
         {
             _warpMoveDB = (WarpMovingDB)db;
         }
     }
     else if (changeType == EntityChangeData.EntityChangeType.DBRemoved)
     {
         if (db is OrbitDB)
         {
             _orbitDB = null;
         }
         else if (db is WarpMovingDB)
         {
             _warpMoveDB = null;
         }
     }
 }
Esempio n. 6
0
        //maybe this should be done in the SystemState?
        void On_entityChangeEvent(EntityChangeData.EntityChangeType changeType, BaseDataBlob db)
        {
            _changesNextFrame.Add(new EntityChangeData()
            {
                ChangeType = changeType, Datablob = db, Entity = Entity
            });
            switch (changeType)
            {
            case EntityChangeData.EntityChangeType.DBAdded:
                DataBlobs[db.GetType()] = db;
                break;

            case EntityChangeData.EntityChangeType.DBRemoved:
                DataBlobs.Remove(db.GetType());
                break;

            case EntityChangeData.EntityChangeType.EntityRemoved:
                DataBlobs.Clear();
                IsDestroyed = true;
                break;

            default:
                break;
            }
        }
Esempio n. 7
0
        void SendDatablob(NetConnection recipient, Entity entity, BaseDataBlob datablob)
        {
            Messages.Add("Sending " + datablob.GetType().Name);
            NetOutgoingMessage msg = NetPeerObject.CreateMessage();

            msg.Write((byte)ToClientMsgType.SendDatablob);      //message type
            NetServerObject.SendMessage(msg, recipient, NetDeliveryMethod.ReliableOrdered);
        }
Esempio n. 8
0
        static void DisplayDBSpecifics(BaseDataBlob db)
        {
            Type type = db.GetType();

            switch (db)
            {
            case SensorProfileDB dbtype:
                DebugDisplaySensorProfile.Display(dbtype);
                break;
            }
        }
Esempio n. 9
0
        public void TestNewtonTrajectory()
        {
            Game          game         = new Game();
            EntityManager mgr          = new EntityManager(game, false);
            Entity        parentEntity = TestingUtilities.BasicEarth(mgr);

            PositionDB pos1 = new PositionDB(mgr.ManagerGuid)
            {
                X = 0, Y = 8.52699302490434E-05, Z = 0
            };

            BaseDataBlob[] objBlobs1 = new BaseDataBlob[3];
            objBlobs1[0] = pos1;
            objBlobs1[1] = new MassVolumeDB()
            {
                Mass = 10000
            };
            objBlobs1[2] = new NewtonMoveDB(parentEntity)
            {
                CurrentVector_kms = new Vector3(-10.0, 0, 0)
            };
            Entity     objEntity1 = new Entity(mgr, objBlobs1);
            PositionDB pos2       = new PositionDB(mgr.ManagerGuid)
            {
                X = 0, Y = 8.52699302490434E-05, Z = 0
            };

            BaseDataBlob[] objBlobs2 = new BaseDataBlob[3];
            objBlobs2[0] = pos2;
            objBlobs2[1] = new MassVolumeDB()
            {
                Mass = 10000
            };
            objBlobs2[2] = new NewtonMoveDB(parentEntity)
            {
                CurrentVector_kms = new Vector3(-10.0, 0, 0)
            };
            Entity objEntity2 = new Entity(mgr, objBlobs2);

            var seconds = 100;

            for (int i = 0; i < seconds; i++)
            {
                NewtonionMovementProcessor.NewtonMove(objEntity1, 1);
            }
            NewtonionMovementProcessor.NewtonMove(objEntity2, seconds);
            var distance1 = Distance.AuToKm(pos1.AbsolutePosition_AU.Length());
            var distance2 = Distance.AuToKm(pos2.AbsolutePosition_AU.Length());

            //this test is currently failing and I'm unsure why. right now the code is using a 1s timestep so it should come out exact...
            //it looks ok graphicaly though so I'm not *too* conserned about this one right now.
            Assert.AreEqual(distance1, distance2); //if we put the variable timstep which is related to the speed of the object in we'll have to give this a delta
        }
Esempio n. 10
0
        public static Entity BasicEarth(EntityManager mgr)
        {
            double parentMass = 5.97237e24;

            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();
            return(new Entity(mgr, parentblobs));
        }
Esempio n. 11
0
        public static Entity BasicSol(EntityManager mgr)
        {
            double parentMass = 1.989e30;

            BaseDataBlob[] parentblobs = new BaseDataBlob[3];
            parentblobs[0] = new PositionDB(mgr.ManagerGuid)
            {
                X = 0, Y = 0, Z = 0
            };
            parentblobs[1] = new MassVolumeDB()
            {
                Mass = parentMass
            };
            parentblobs[2] = new OrbitDB();
            return(new Entity(mgr, parentblobs));
        }
Esempio n. 12
0
        public static void DBDisplay(BaseDataBlob dataBlob)
        {
            Type dbType = dataBlob.GetType();

            MemberInfo[] memberInfos = dbType.GetMembers();

            var _totalHeight = _numLines * _heightMultiplyer;

            _numLines = memberInfos.Length;
            var size = new Vector2(ImGui.GetContentRegionAvail().X, _totalHeight);

            ImGui.BeginChild("InnerColomns", size);

            ImGui.Columns(2);

            RecursiveReflection(dataBlob);


            ImGui.Columns(0);

            ImGui.EndChild();
            DisplayDBSpecifics(dataBlob);
        }
Esempio n. 13
0
 void Entity_ChangeEvent(EntityChangeData.EntityChangeType changeType, BaseDataBlob db)
 {
 }
Esempio n. 14
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");
        }
Esempio n. 15
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);
        }
Esempio n. 16
0
        NetOutgoingMessage DatablobDataMessage(NetOutgoingMessage msg, Entity entity, BaseDataBlob datablob)
        {
            var mStream = new MemoryStream();

            //int typeIndex = EntityManager.DataBlobTypes[datablobtype];
            //var datablob = entity.GetDataBlob<BaseDataBlob>(typeIndex);

            //Messages.Add("GetType().ToSTring(): " + datablob.GetType().ToString());
            //Messages.Add("GetType().Name: " + datablob.GetType().Name);
            //Messages.Add("GetType().AssemblyQualifiedName: " + datablob.GetType().AssemblyQualifiedName);
            //Messages.Add("GetType().FullName: " + datablob.GetType().FullName);
            //Messages.Add("pulsarTypeIndex: " + typeIndex);

            SerializationManager.Export(Game, mStream, datablob);
            byte[] systemByteArray = mStream.ToArray();
            int    len             = systemByteArray.Length;

            msg.Write(entity.Guid.ToByteArray());                       //entityGuid
            msg.Write(datablob.GetType().Name);                         //datablob name
            msg.Write(EntityManager.DataBlobTypes[datablob.GetType()]); //datablob typeIndex
            msg.Write(len);                                             //stream length
            msg.Write(systemByteArray);                                 //encoded data.
            mStream.Close();
            return(msg);
        }
Esempio n. 17
0
        public void TestNewtonTrajectory()
        {
            Game          game         = new Game();
            EntityManager mgr          = new EntityManager(game, false);
            Entity        parentEntity = TestingUtilities.BasicEarth(mgr);

            PositionDB pos1 = new PositionDB(mgr.ManagerGuid, parentEntity)
            {
                X_AU = 0, Y_AU = 8.52699302490434E-05, Z_AU = 0
            };
            var newt1 = new NewtonMoveDB(parentEntity, new Vector3(-10.0, 0, 0))
            {
                DeltaVForManuver_FoRO_m = new Vector3(0, 1, 0)
            };

            BaseDataBlob[] objBlobs1 = new BaseDataBlob[4];
            objBlobs1[0] = pos1;
            objBlobs1[1] = new MassVolumeDB()
            {
                MassDry = 10000
            };
            objBlobs1[2] = new NewtonThrustAbilityDB(mgr.ManagerGuid);
            objBlobs1[3] = newt1;
            Entity objEntity1 = new Entity(mgr, objBlobs1);


            PositionDB pos2 = new PositionDB(mgr.ManagerGuid, parentEntity)
            {
                X_AU = 0, Y_AU = 8.52699302490434E-05, Z_AU = 0
            };
            var newt2 = new NewtonMoveDB(parentEntity, new Vector3(-10.0, 0, 0))
            {
                DeltaVForManuver_FoRO_m = new Vector3(0, 1, 0)
            };

            BaseDataBlob[] objBlobs2 = new BaseDataBlob[4];
            objBlobs2[0] = pos2;
            objBlobs2[1] = new MassVolumeDB()
            {
                MassDry = 10000
            };
            objBlobs2[2] = new NewtonThrustAbilityDB(mgr.ManagerGuid);
            objBlobs2[3] = newt2;
            Entity objEntity2 = new Entity(mgr, objBlobs2);

            var seconds = 100;

            for (int i = 0; i < seconds; i++)
            {
                NewtonionMovementProcessor.NewtonMove(objEntity1, 1);

                //this is a hacky way to allow us to increment each second,
                //since the above method looks at the manager datetime and we're not updating that.
                newt1.LastProcessDateTime -= TimeSpan.FromSeconds(1);
            }
            NewtonionMovementProcessor.NewtonMove(objEntity2, seconds);
            var distance1 = (pos1.RelativePosition_m.Length());
            var distance2 = (pos2.RelativePosition_m.Length());

            Assert.AreEqual(distance1, distance2); //if we put the variable timstep which is related to the speed of the object in we'll have to give this a delta
        }
Esempio n. 18
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 = 0, Y = 0, Z = 0
            };
            parentblobs[1] = new MassVolumeDB()
            {
                Mass = parentMass
            };
            parentblobs[2] = new OrbitDB();
            Entity parentEntity = new Entity(mgr, parentblobs);

            Vector3 currentPos = new Vector3 {
                X = -0.77473184638034, Y = 0.967145228951685
            };
            Vector3 currentVelocity = new Vector3 {
                Y = Distance.KmToAU(40)
            };
            double nonNewtSpeed = Distance.KmToAU(283.018);

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


            double sgp = GameConstants.Science.GravitationalConstant * (parentMass + myMass) / 3.347928976e33;
            //KeplerElements ke = OrbitMath.KeplerFromVelocityAndPosition(sgp, targetObjPosition, targetObjVelocity);

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

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



            var intercept = InterceptCalcs.GetInterceptPosition2(currentPos, nonNewtSpeed, targetOrbit, currentDateTime);

            var futurePos1 = Distance.AuToKm(OrbitProcessor.GetAbsolutePosition_AU(targetOrbit, intercept.Item2));

            var futurePos2 = Distance.AuToKm(intercept.Item1);



            Assert.AreEqual(futurePos1.Length(), futurePos2.Length(), 0.01);
            Assert.AreEqual(futurePos1.X, futurePos2.X, 0.01);
            Assert.AreEqual(futurePos1.Y, futurePos2.Y, 0.01);
            Assert.AreEqual(futurePos1.Z, futurePos2.Z, 0.01);
            var time = intercept.Item2 - currentDateTime;

            var distance   = (currentPos - intercept.Item1).Length();
            var distancekm = Distance.AuToKm(distance);

            var speed  = distance / time.TotalSeconds;
            var speed2 = distancekm / time.TotalSeconds;

            var distb   = nonNewtSpeed * time.TotalSeconds;
            var distbKM = Distance.AuToKm(distb);
            var timeb   = distance / nonNewtSpeed;

            Assert.AreEqual(nonNewtSpeed, speed, 1.0e-10);

            var dif = distancekm - distbKM;

            Assert.AreEqual(distancekm, distbKM, 0.25);
        }