コード例 #1
0
ファイル: RingController.cs プロジェクト: Storm-23/Planets
    public void Build(OrbitalBodyDescription desc, OrbitalBody body)
    {
        this.body = body;

        Random.InitState(desc.RandomSeed);
        var rend = GetComponent <MeshRenderer>();
        var mat  = rend.material;

        var type   = (int)(Random.value * 5);
        var height = Random.value * 4;

        if (type == 3)
        {
            height /= 10;
        }

        mat.SetFloat("_Smoothness", Random.value * Random.value * 0.7f);
        mat.SetFloat("_Frequency", 1 + Random.value * 4);
        mat.SetFloat("_WaterLevel", Random.value);
        mat.SetFloat("_RandomSeed", Random.value * 1000);
        mat.SetFloat("_HeightScale", height);
        mat.SetFloat("_Palette", Random.value * 16);
        mat.SetFloat("_WaterPalette", Random.value * 16);
        mat.SetFloat("_WaterSmoothness", 0.5f + Random.value * 0.5f);
        mat.SetFloat("_Type", type);

        if (Random.value > 0.3 || height < 0.5)
        {
            rend.materials = new Material[1] {
                mat
            }
        }
        ;
    }
}
コード例 #2
0
ファイル: AstBeltController.cs プロジェクト: Storm-23/Planets
    public void Build(OrbitalBodyDescription desc, OrbitalBody body)
    {
        this.body = body;

        Random.InitState(desc.RandomSeed);
        var period = 2 * Mathf.PI * body.OrbitRadius / body.OrbitalSpeed;

        if (maxDeltaTime > period / 10)
        {
            maxDeltaTime = (float)period / 10;
        }

        //build objects
        for (int i = 0; i < ASTEROIDS_COUNT; i++)
        {
            var ast  = Instantiate(AsteroidPrefab, this.transform);
            var info = new AsteroidInfo();
            info.Object       = ast;
            info.DeltaTime    = (Random.value * 2 - 1) * maxDeltaTime;
            info.DeltaTime2   = (3 + Random.value) * 3000;
            info.Offset       = Random.insideUnitSphere * (float)(200 * body.Radius / Constants.EARTH_RADIUS);
            info.Scale        = (0.05f + Random.value * Random.value) * 50;
            info.AddRotation  = Random.rotation;
            info.AddRotation2 = Random.insideUnitSphere * 30;
            asteroids.Add(info);

            InitShader(info.Object);
        }
    }
コード例 #3
0
    public override void _PhysicsProcess(float delta)
    {
        OrbitalBody center = SceneManager.Instance.Center;

        /*KinematicCollision collision = MoveAndCollide(GetVelocityRelativeTo(center) * delta, true, true, true);
         *
         * if (collision != null)
         * {
         *      Vector3d newPosition = (Vector3)GetPositionRelativeTo(center) - collision.Remainder + collision.Remainder.Bounce(collision.Normal);
         *      SetPositionRelativeTo(center, newPosition);
         *      float damp = 0.2f;
         *      Vector3 dv = (Vector3)GetVelocityRelativeTo(center) - collision.ColliderVelocity;
         *      Vector3 newSpeed = damp * (dv.Bounce(collision.Normal));
         *      SetVelocityRelativeTo(center, newSpeed + collision.ColliderVelocity);
         * }*/
        Vector3 p = GetPositionRelativeTo(center);

        if (p.Length() < 50000)
        {
            Transform = new Transform(Transform.basis, p);
        }
        else
        {
        }
    }
コード例 #4
0
    private IEnumerator TimerToPosition(OrbitalBody orbitalBody, float time, Trajectory trajectory, SourceIntersections sourceIntersectionsEntry, int segmentIndex)
    {
        // Waits until interval expires, then sets bool back to false
        yield return(new WaitForSeconds(time));

        // Recalculate time of flight for orbitalBody to reach orbitalBodyPosition and then source's predicted position
        UpdateIntersectionSprites(orbitalBody, trajectory, sourceIntersectionsEntry, segmentIndex);
    }
コード例 #5
0
 public override void _Ready()
 {
     simbody          = new OrbitalBody();
     simbody.mass     = mass;
     simbody.position = positionInKilometers * 1000;
     simbody.velocity = velocity;
     Simulation.Instance.AddBody(simbody);
 }
コード例 #6
0
 public void AddBody(OrbitalBody body)
 {
     bodies.Add(body);
     if (body.bodyClass == OrbitalBody.BodyClass.CELESTIAL)
     {
         nBodies.Add(body);
     }
 }
コード例 #7
0
    private void StartNewIntersectionCoroutine(OrbitalBody orbitalBody, float timeOfFlight, Trajectory trajectory, SourceIntersections sourceIntersectionsEntry, int segmentIndex)
    {
        IEnumerator timeOfFlightEnum = TimerToPosition(orbitalBody, timeOfFlight, trajectory, sourceIntersectionsEntry, segmentIndex);

        StartCoroutine(timeOfFlightEnum);

        // Adding reference to this source intersections entry
        sourceIntersectionsEntry.intersectionCoroutines[segmentIndex] = timeOfFlightEnum;
    }
コード例 #8
0
ファイル: OrbitalBody.cs プロジェクト: Generalfil/PlanetClAUk
 /// <summary>
 /// SetBodyReference to OrbitalBody is barely used, please use BodySaveData instead
 /// </summary>
 public void SetBodyReference(OrbitalBody o)
 {
     m_id        = o.ID;
     m_x_value   = o.X_value;
     m_y_value   = o.Y_value;
     m_z_value   = o.Z_value;
     m_data_date = DateTime.Parse(o.Data_Date.ToString());
     cScale      = transform.localScale;
 }
コード例 #9
0
    protected override void OnDisable()
    {
        base.OnDisable();
        OrbitalBody orbitalBody = GetComponentInParent <OrbitalBody>();

        if (orbitalBody != null)                               // Prevent error on end of play
        {
            orbitalBody.OnOrbitCalculationEvent -= DrawCircle; // Hack to listen to base class event
        }
    }
コード例 #10
0
 public void BodyClassChanged(OrbitalBody body)
 {
     if (body.bodyClass == OrbitalBody.BodyClass.CELESTIAL)
     {
         nBodies.Add(body);
     }
     else
     {
         nBodies.Remove(body);
     }
 }
コード例 #11
0
ファイル: PlanetController.cs プロジェクト: Storm-23/Planets
    public void Build(OrbitalBodyDescription desc, OrbitalBody body)
    {
        this.body = body;

        Random.InitState(desc.RandomSeed);
        switch (desc.SurfaceType)
        {
        case SurfaceType.RockPlanet: BuildRockPlanet(); break;

        case SurfaceType.GasPlanet: BuildGasPlanet(); break;
        }
    }
コード例 #12
0
    private void ComputeBodyMovement(OrbitalBody body, double dt)
    {
        // Using RK4 to compute the body movement
        Vector3d k1_v = dt * (ComputeGravity(body, body.position) + body.acceleration);
        Vector3d k1_x = dt * body.velocity;
        Vector3d k2_v = dt * (ComputeGravity(body, body.position + k1_x / 2) + body.acceleration);
        Vector3d k2_x = dt * (body.velocity + k1_v);
        Vector3d k3_v = dt * (ComputeGravity(body, body.position + k2_x / 2) + body.acceleration);
        Vector3d k3_x = dt * (body.velocity + k2_v);
        Vector3d k4_v = dt * (ComputeGravity(body, body.position + k3_x) + body.acceleration);
        Vector3d k4_x = dt * (body.velocity + k3_v);

        body.position += (k1_x + 2 * k2_x + 2 * k3_x + k4_x) / 6;
        body.velocity += (k1_v + 2 * k2_v + 2 * k3_v + k4_v) / 6;
    }
コード例 #13
0
    private Vector3d ComputeGravity(OrbitalBody body, Vector3d position)
    {
        Vector3d force = new Vector3d();

        foreach (OrbitalBody nBody in nBodies)
        {
            if (nBody != body)
            {
                double l = (nBodiesData[nBody] - position).Length();
                double p = nBody.mass * ((GMe / l) / l);
                force += p * (nBodiesData[nBody] - position) / l;
            }
        }
        return(force);
    }
コード例 #14
0
ファイル: TrajectoryHandler.cs プロジェクト: rtoole13/Orbital
    private void Awake()
    {
        orbitalBody = GetComponent <OrbitalBody>();
        orbitalBody.OnOrbitCalculationEvent += UpdateTrajectory;

        // Instantiate prefab if null
        trajectoryObject  = Instantiate(trajectoryObjectPrefab);
        trajectoryPlotter = trajectoryObject.GetComponent <TrajectoryPlotter>();
        if (trajectoryPlotter == null)
        {
            throw new UnityException("Expecting trajectory prefab to have a TrajectoryPlotter script");
        }
        trajectoryPlotter.SetGradient(trajectoryGradient);
        intersectionCalculator = trajectoryObject.GetComponent <IntersectionCalculator>();
    }
コード例 #15
0
    private void UpdateIntersectionSprites(OrbitalBody orbitalBody, Trajectory trajectory, SourceIntersections sourceIntersectionsEntry, int segmentIndex)
    {
        // Calculate time of flight to next closest point -- FIXME: Still needed?????
        if (trajectory.TrajectoryType != OrbitalMechanics.Globals.TrajectoryType.Ellipse)
        {
            sourceIntersectionsEntry.HideIntersectionObjects(segmentIndex);
            return;
        }
        // Use trajectory period as timeOfFlight
        float timeOfFlight = trajectory.Period;

        Vector2 predictedWorldPosition = sourceIntersectionsEntry.Source.PredictPosition(timeOfFlight);

        sourceIntersectionsEntry.InitiateIntersectionSprite(segmentIndex, predictedWorldPosition, false);
        StartNewIntersectionCoroutine(orbitalBody, trajectory.Period, trajectory, sourceIntersectionsEntry, segmentIndex);
    }
コード例 #16
0
    public void PlotNearestSourceIntersections(OrbitalBody orbitalBody, Vector2 orbitalPosition, Vector2 orbitalVelocity, float timeToPosition, Trajectory trajectory)
    {
        // orbitalPosition/Velocity are not necessarily equivalent to orbitalBody.orbitalPosition/Velocity (ManeuverNode predicted trajectories for instance)

        // Update sources considered candidates for intersection
        UpdateNearbySourceIntersections(trajectory.ParentGravitySource);

        for (int i = 0; i < sourceIntersections.Count; i++)
        {
            Color intersectionColor = sourceIntersectionColors[MathUtilities.IntModulo(i, sourceIntersectionColorCount)];
            SourceIntersections sourceIntersectionsEntry = sourceIntersections[i];
            for (int j = 0; j < sourceIntersectionsEntry.SegmentIntersections.Length; j++)
            {
                PredictIntersection(sourceIntersectionsEntry, j, orbitalBody, orbitalPosition, orbitalVelocity, timeToPosition, trajectory, intersectionColor);
            }
        }
    }
コード例 #17
0
    public void Build(OrbitalBodyDescription desc, OrbitalBody body)
    {
        this.body = body;
        //
        Random.InitState(desc.RandomSeed);
        var rend   = GetComponent <MeshRenderer>();
        var mat    = rend.material;
        var colors = new Color[]
        {
            //new Color(1, 0.95f, 0.37f),
            new Color(0.9622642f, 0.9327608f, 0.5492168f),
            new Color(0.365655f, 0.5355415f, 0.7830189f),
            new Color(0.8962264f, 0.3677911f, 0.3677911f),
            new Color(0.9f, 0.9f, 0.9f),
        };

        mat.color = colors[Random.Range(0, colors.Length)];
    }
コード例 #18
0
ファイル: TreeView.cs プロジェクト: ktyldev/type-ii
    private TreeViewItem BuildNode(OrbitalBody body)
    {
        var node = Instantiate(treeViewItem, transform).GetComponent <TreeViewItem>();

        node.transform.Translate(indentAmount * _tree.GetDepth(body), 0, 0);
        node.Body = body;

        AddRow(node.gameObject);
        _nodes.Add(node, body);

        node.OnExpand.AddListener(() =>
        {
            _tree
            .GetChildren(body)
            .ForEach(c => BuildNode(c));
        });

        node.Expand();
        Invalidate();
        return(node);
    }
コード例 #19
0
ファイル: Label.cs プロジェクト: blueknightone/Ersiss-System
 // Called when the node enters the scene tree for the first time.
 public override void _Ready()
 {
     body       = GetNode <Node>($@"{orbitalBodyRootPath}{bodyName}") as OrbitalBody;
     anchorBody = SceneManager.Instance.Anchor;
 }
コード例 #20
0
 public void AddToLocalObjects(OrbitalBody body)
 {
     localObjects.Add(body);
 }
コード例 #21
0
 public Vector3d GetPositionRelativeTo(OrbitalBody b, double scale)
 {
     return((position - b.position) / scale);
 }
コード例 #22
0
    private void PredictIntersection(SourceIntersections sourceIntersectionsEntry, int segmentIndex, OrbitalBody orbitalBody, Vector2 orbitalPosition, Vector2 orbitalVelocity, float timeToPosition, Trajectory trajectory, Color intersectionColor)
    {
        // Calculate time of flight of current object to destination
        Vector2 worldDestination = sourceIntersectionsEntry.SegmentIntersections[segmentIndex].ClosestPoint;
        Vector2 localDestination = (worldDestination - trajectory.ParentGravitySource.Position).RotateVector(-trajectory.ArgumentOfPeriapsis);

        float timeOfFlight = timeToPosition + OrbitalMechanics.UniversalVariableMethod.CalculateTimeOfFlight(orbitalPosition, orbitalVelocity, localDestination, trajectory.EccentricityVector, trajectory.ParentGravitySource.Mass);

        if (float.IsNaN(timeOfFlight))
        {
            // timeOfFlight not properly calculated. hide sprites.
            sourceIntersectionsEntry.HideIntersectionObjects(segmentIndex);
            return;
        }

        // Plot current object's future position
        sourceIntersectionsEntry.InitiateIntersectionSprite(segmentIndex, sourceIntersectionsEntry.SegmentIntersections[segmentIndex].ClosestPoint, intersectionColor, true);

        // Plot this source object's position at timeOfFlight
        Vector2 predictedWorldPosition = sourceIntersectionsEntry.Source.PredictPosition(timeOfFlight);

        sourceIntersectionsEntry.InitiateIntersectionSprite(segmentIndex, predictedWorldPosition, intersectionColor, false);

        StartNewIntersectionCoroutine(orbitalBody, timeOfFlight, trajectory, sourceIntersectionsEntry, segmentIndex);
    }
コード例 #23
0
 public void SetVelocityRelativeTo(OrbitalBody b, Vector3d relativeVelocity)
 {
     velocity = b.velocity + relativeVelocity;
 }
コード例 #24
0
 public void PlotNearestSourceIntersections(OrbitalBody orbitalBody)
 {
     // Called by TrajectoryHandlers AND by coroutines on intersection update
     PlotNearestSourceIntersections(orbitalBody, orbitalBody.OrbitalPosition, orbitalBody.OrbitalVelocity, 0f, orbitalBody.Trajectory);
 }
コード例 #25
0
 public void SetPositionRelativeTo(OrbitalBody b, Vector3d relativePosition)
 {
     position = b.position + relativePosition;
 }
コード例 #26
0
 public Orbit(OrbitalBody parent, Transform child, float distance)
 {
     _centre   = parent.transform;
     _speed    = Mathf.Sqrt(parent.mass / distance);
     _distance = distance;
 }
コード例 #27
0
 public void Build(OrbitalBodyDescription desc, OrbitalBody body)
 {
     this.body = body;
 }
コード例 #28
0
 public void SetPositionRelativeTo(OrbitalBody b, Vector3d relativePosition, double scale)
 {
     position = b.position + scale * relativePosition;
 }
コード例 #29
0
 public Double DistanceTo(OrbitalBody b)
 {
     return((position - b.position).Length());
 }
コード例 #30
0
 public Vector3d GetVelocityRelativeTo(OrbitalBody b)
 {
     return(velocity - b.velocity);
 }