Пример #1
0
    private void Update()
    {
        movement.TargetPosition = BackendHelpers.UnityVectorFromNumerics(Node.TargetPosition);

        Node.Position = BackendHelpers.NumericsVectorFromUnity(transform.position);
        text.text     = Node.Id.ToString() + "\n" + Node.State.ToString();
    }
Пример #2
0
    // Start is called before the first frame update
    void Start()
    {
        _satellitePrefab = SatellitePrefab;

        Constants.EarthRadius = (GetComponent <SphereCollider>().radius *transform.localScale.x);
        float constellationAltitude = Constants.EarthRadius + Constants.ScaleToSize(SatelliteAltitude);
        float constellationRadius   = constellationAltitude / 2;


        List <ConstellationPlanEntry> entries = new List <ConstellationPlanEntry>();

        List <INode> nodes = new List <INode>();

        for (int i = 0; i < PlaneNum; i++)
        {
            float yAngle = Mathf.PI / PlaneNum * i;


            for (uint?j = 0; j < SatellitesPerPlane; j++)
            {
                float angle = (int)j * Mathf.PI * 2f / SatellitesPerPlane;


                Vector3 instantiationPos = new Vector3(
                    Mathf.Cos(angle) * constellationRadius,
                    Mathf.Sin(yAngle / SatellitesPerPlane * (int)j) * constellationRadius,
                    Mathf.Sin(angle) * constellationRadius);

                //Create a vector from earth center to the desired position
                Vector3 instantiationVector = (instantiationPos - transform.position).normalized * constellationAltitude;

                GameObject satellite = Instantiate(SatellitePrefab, transform.position + instantiationVector, Quaternion.identity);
                CommsSim   sim       = satellite.AddComponent <CommsSim>();

                INode node = new Node(j, BackendHelpers.NumericsVectorFromUnity(satellite.transform.position));
                node.TargetPosition = node.Position;
                node.CommsModule    = sim;
                node.PlaneNormalDir = BackendHelpers.NumericsVectorFromUnity(Vector3.up);

                satellite.name = "P(" + i + "), S(" + j + ")";
                satellite.GetComponent <SatelliteComms>().Node = node;
                satellite.GetComponent <SatelliteComms>().Node.AutoChecksAllowed = CanvasHandler.AutoChecksAllowed;

                List <ConstellationPlanField> fields = new List <ConstellationPlanField> {
                    new ConstellationPlanField("DeltaV", 0, (x, y) => x.CompareTo(y))
                };
                ConstellationPlanEntry entry = new ConstellationPlanEntry(node.Position, fields, (x, y) => 1);
                entry.NodeID = node.Id;
                entries.Add(entry);
                nodes.Add(node);

                SatManager._instance.SatIndex++;
            }
        }

        ConstellationPlan plan = new ConstellationPlan(entries);

        nodes.ForEach(node => { node.ActivePlan = plan; node.GenerateRouter(); });
    }
Пример #3
0
    private void Update()
    {
        sleepCount          = comms.Node.SleepCount;
        comms.Node.Position = BackendHelpers.NumericsVectorFromUnity(transform.position);

        ReachableNodes = comms.Node.Router.ReachableSats(comms.Node).Select(node => (uint)node).ToList();

        if (Constants.EnableDebug)
        {
            logs.ForEach(Debug.LogWarning);
            logs.Clear();
        }
    }
Пример #4
0
    public static void InstantiateSatellite(Vector3 instantiationPoisition)
    {
        GameObject satellite = Instantiate(_satellitePrefab, instantiationPoisition, Quaternion.identity);
        CommsSim   sim       = satellite.AddComponent <CommsSim>();

        int satIndex = SatManager._instance.SatIndex;

        INode node = new Node((uint?)satIndex, BackendHelpers.NumericsVectorFromUnity(satellite.transform.position));

        node.TargetPosition = node.Position;
        node.CommsModule    = sim;
        node.PlaneNormalDir = BackendHelpers.NumericsVectorFromUnity(Vector3.up);

        satellite.name = "P(" + 0 + "), S(" + (satIndex) + ")";
        satellite.GetComponent <SatelliteComms>().Node = node;
        SatManager._instance.SatIndex++;
        node.AutoChecksAllowed = CanvasHandler.AutoChecksAllowed;
        node.GenerateRouter();
    }
    public void GenerateTargetConstellation(INode RequesterNode)
    {
        System.Random r = new System.Random(RandomSeed);

        TargetPositions.Clear();

        //If the constellation altitude input from textfield isn't numbers, return
        if (float.TryParse(ConstellationAltitudeInput, out float constellationAltitude) == false)
        {
            return;
        }

        //Set the constellation altitude based on the input textfield
        constellationAltitude = Constants.EarthRadius + Constants.ScaleToSize(constellationAltitude);


        //Get reference to satellites
        Sats = GameObject.FindGameObjectsWithTag("Satellite").ToList();

        List <uint?> reachableNodes = RequesterNode.Router.ReachableSats(RequesterNode).ToList();

        Sats.RemoveAll(sat => reachableNodes.Contains(sat.GetComponent <SatelliteComms>().Node.Id) == false);


        //Remove old location Placeholders
        GameObject.FindGameObjectsWithTag("LocationPlaceholder")?.ToList().ForEach(Destroy);


        for (int i = 0; i < Sats.Count; i++)
        {
            //Create random angle for position of Targetposition
            float angle = (360 / Sats.Count) * i;

            Vector3 instantiationPos = Quaternion.Euler(0, angle, 0) * Vector3.forward;

            //Set it relative to the earth
            Vector3 instantiationVector = (instantiationPos - Vector3.zero).normalized * constellationAltitude;

            //Store for propagation
            TargetPositions.Add(instantiationVector);
            Instantiate(SatLocationPlaceholderPrefab, instantiationVector, Quaternion.identity);
        }

        List <ConstellationPlanEntry> entries = new List <ConstellationPlanEntry>();

        foreach (Vector3 pos in TargetPositions)
        {
            Vector3 position = new Vector3(pos.x, pos.y, pos.z);
            List <ConstellationPlanField> fields = new List <ConstellationPlanField> {
                new ConstellationPlanField("DeltaV", 0, (x, y) => x.CompareTo(y))
            };
            ConstellationPlanEntry entry = new ConstellationPlanEntry(BackendHelpers.NumericsVectorFromUnity(position), fields, (x, y) => 1);
            entries.Add(entry);
        }

        plan = new ConstellationPlan(entries);

        //Send the targetconstellation to random sat
        INode       targetSat = RequesterNode;
        PlanRequest request   = new PlanRequest {
            Command          = Request.Commands.GENERATE,
            SourceID         = targetSat.Id,
            DestinationID    = targetSat.Id,
            SenderID         = 42,
            Dir              = Router.CommDir.CW,
            AckExpected      = true,
            MessageIdentifer = "42",
            Plan             = plan
        };

        PlanGenerator.GeneratePlan(targetSat, request);
    }