Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        // Get current speed multiplier from Date & Time
        DateTimeDisplay dateObj = date.GetComponent("DateTimeDisplay") as DateTimeDisplay;

        speed = dateObj.speed;

        // Rotate Earth about axis
        transform.Rotate(Vector3.up, (float)(-rotPerSec * speed * Time.deltaTime));

        // Compute Earth's position as function of t
        // E initially approximates the number of radians Earth has orbited since the perihelion
        E = t / tRev * 2 * Math.PI;

        // Iterate through Newton's Method 3 times to get progressively more precise values for E
        E = NewtonsMethod(E, 3);

        xPos = 1495.96329 * Math.Cos(E) - 24.9825869;
        zPos = 1495.75469 * Math.Sqrt(1 - (Math.Pow(1495.96329 * Math.Cos(E), 2) / 2237906.17));

        if (t % tRev > tRev / 2 && t > 0 || t % tRev > -tRev / 2 && t < 0)
        {
            zPos = -zPos;
        }

        transform.position = new Vector3((float)xPos, 0, (float)zPos);

        // Illuminate earth surface that's facing the sun
        sunDist = -transform.position;          //sunDist is earth-to-sun vector
        mat.SetVector("_SunDir", sunDist.normalized);

        // Adjust scale based on view mode
        CamBehavior camObj = cam.GetComponent("CamBehavior") as CamBehavior;

        if (camObj.GetView() == 3)
        {
            scaleFactor          = 1000;
            transform.localScale = scaleFactor * iniScale;
        }
        else
        {
            transform.localScale = iniScale;
        }

        t += speed * Time.deltaTime;
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        CamBehavior camObj = cam.GetComponent("CamBehavior") as CamBehavior;

        // Adjust scale based on view mode
        int i = 0;

        if (camObj.GetView() == 3)
        {
            scaleFactor          = 20;
            transform.localScale = scaleFactor * iniScale;
            foreach (Transform child in transform)
            {
                child.localScale = scaleFactor * sunScales[i];
                i++;
            }
        }
        else if (camObj.GetView() == 0)
        {
            scaleFactor          = 10;
            transform.localScale = scaleFactor * iniScale;
            foreach (Transform child in transform)
            {
                child.localScale = scaleFactor * sunScales[i];
                i++;
            }
        }
        else
        {
            transform.localScale = iniScale;
            foreach (Transform child in transform)
            {
                child.localScale = sunScales[i];
            }
        }
    }
Exemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        // Get current speed multiplier from Date & Time
        DateTimeDisplay dateObj = date.GetComponent("DateTimeDisplay") as DateTimeDisplay;

        speed = dateObj.speed;

        // Rotation about axis
        transform.Rotate(Vector3.up, (float)(-rotPerSec * speed * Time.deltaTime));

        // Get t from EarthBehavior
        EarthBehavior earthObj = earth.GetComponent("EarthBehavior") as EarthBehavior;

        t = earthObj.GetT();

        T   = tIni + t / secPerCent;
        L_0 = Frac(0.606433 + 1336.851344 * T);                         // Mean longitude
        l   = 2 * Math.PI * Frac(0.374897 + 1325.552410 * T);           // Moon's mean anomaly
        lp  = 2 * Math.PI * Frac(0.993133 + 99.997361 * T);             // Sun's mean anomaly
        D   = 2 * Math.PI * Frac(0.827361 + 1236.853086 * T);           // Diff. long. Moon-Sun
        F   = 2 * Math.PI * Frac(0.259086 + 1342.227825 * T);           // Argument of latitude

        // Compute Earth-Moon distance
        r = 3.85 - 0.20905 * Math.Cos(l) - 0.03699 * Math.Cos(2 * D - l) - 0.02956 * Math.Cos(2 * D) - 0.0057 * Math.Cos(2 * l) + 0.00246 * Math.Cos(2 * l - 2 * D) - 0.00205 * Math.Cos(lp - 2 * D) - 0.00171 * Math.Cos(l + 2 * D) - 0.00152 * Math.Cos(l + lp - 2 * D);

        CamBehavior camObj = cam.GetComponent("CamBehavior") as CamBehavior;

        // Greatly exaggerate Earth-Moon distance if in top-down view
        if (camObj.GetView() == 3)
        {
            r *= 100;
        }

        // Compute right ascension
        dL = 22640 * Math.Sin(l) - 4586 * Math.Sin(l - 2 * D) + 2370 * Math.Sin(2 * D) + 769 * Math.Sin(2 * l) - 668 * Math.Sin(lp) - 412 * Math.Sin(2 * F) - 212 * Math.Sin(2 * l - 2 * D) - 206 * Math.Sin(l + lp - 2 * D) + 192 * Math.Sin(l + 2 * D)
             - 165 * Math.Sin(lp - 2 * D) + 148 * Math.Sin(l - lp) - 125 * Math.Sin(D) - 110 * Math.Sin(l + lp) - 55 * Math.Sin(2 * F - 2 * D);
        L = 2 * Math.PI * Frac(L_0 + dL / 1296000);

        // Compute declination
        S = F + (dL + 412 * Math.Sin(2 * F) + 541 * Math.Sin(lp)) / arcs;
        h = F - 2 * D;
        N = -526 * Math.Sin(h) + 44 * Math.Sin(l + h) - 31 * Math.Sin(h - l) - 25 * Math.Sin(F - 2 * l) - 23 * Math.Sin(lp + h) + 21 * Math.Sin(F - l) + 11 * Math.Sin(h - lp);
        B = (18520 * Math.Sin(S) + N) / arcs;

        // Compute (x,y,z) position of moon w.r.t. Earth
        y = r * Math.Sin(B);
        x = Math.Sqrt((Math.Pow(r, 2) - Math.Pow(y, 2))) * Math.Sin(L - 0.250434);
        z = -Math.Sqrt((Math.Pow(r, 2) - Math.Pow(y, 2))) * Math.Cos(L - 0.250434);

        earthDist = new Vector3((float)x, (float)y, (float)z);
        earthPos  = earthObj.GetPosition();

        transform.position = earthPos + earthDist;

        // Illuminate moon surface that's facing the sun
        mat.SetVector("_LightDir", -transform.position.normalized / 2);

        // Adjust scale based on view mode
        if (camObj.GetView() == 3)
        {
            scaleFactor          = 1000;
            transform.localScale = scaleFactor * iniScale;
        }
        else if (camObj.GetView() == 0)
        {
            scaleFactor          = 10;
            transform.localScale = scaleFactor * iniScale;
        }
        else if (camObj.GetView() == 1)
        {
            transform.localScale = iniScale;
        }
        else
        {
            scaleFactor          = 78;
            transform.localScale = scaleFactor * iniScale;
        }
    }
Exemplo n.º 4
0
 // Start is called before the first frame update
 void Start()
 {
     ani      = this.GetComponent <Animator>();
     Instance = this;
 }