Esempio n. 1
0
    private void SpawnGridLikeThing()
    {
        int howManyAround = 18;

        for (int j = 0; j < howManyAround; ++j)
        {
            int howManyUp = 10;
            for (int i = 0; i < howManyUp; ++i)
            {
                float phi   = j * 2 * Mathf.PI / howManyAround;
                float theta = i * Mathf.PI / 2.0f / howManyUp;

                GameObject starGO = PrefabLoader.Instance.InstantiateSynchronous(this._starPrefabPath, this.transform);

                starGO.transform.localPosition = StarFieldUtils.GetPositionFromPhiTheta(phi, theta, this._starfieldDistance);
                starGO.name = i.ToString();
                starGO.transform.localScale = new Vector3(10.0f, 10.0f, 10.0f);

                Lookat starLookat = starGO.GetComponent <Lookat>();
                if (starLookat != null)
                {
                    starLookat.Target = this._targetCamera;
                }
            }
        }
    }
Esempio n. 2
0
    private void GenerateVerticesForOneStar(StarData starData, int starIndex,
                                            Vector3[] vertices, int[] triangles, Vector2[] uvs)
    {
        float apparentMagnitudeNormalized = Mathf.InverseLerp(this._apparentMagnitudeDimmest, this._apparentMagnitudeBrightest, starData.apparent_magnitude);
        float scaleByBrightness           = Mathf.Lerp(this._scaleDimmest, this._scaleBrightest, apparentMagnitudeNormalized) / 2.0f;

        // TODO: Remove extra scaling for stars with common names
        if (!string.IsNullOrEmpty(starData.common_name))
        {
            scaleByBrightness *= 2;
        }

        Vector3    position   = StarFieldUtils.GetPositionFromRaDec(starData.right_ascension, starData.declination, STARFIELD_DISTANCE);
        Quaternion quaternion = Quaternion.LookRotation(position - this.transform.position);
        Vector3    scale      = new Vector3(scaleByBrightness, scaleByBrightness, scaleByBrightness);

        Matrix4x4 transformMatrix = Matrix4x4.TRS(position, quaternion, scale);

        vertices[starIndex * 4 + 0] = transformMatrix.MultiplyPoint3x4(topright);
        vertices[starIndex * 4 + 1] = transformMatrix.MultiplyPoint3x4(topleft);
        vertices[starIndex * 4 + 2] = transformMatrix.MultiplyPoint3x4(bottomleft);
        vertices[starIndex * 4 + 3] = transformMatrix.MultiplyPoint3x4(bottomright);

        triangles[starIndex * 6 + 0] = starIndex * 4 + 0;
        triangles[starIndex * 6 + 1] = starIndex * 4 + 2;
        triangles[starIndex * 6 + 2] = starIndex * 4 + 1;
        //
        triangles[starIndex * 6 + 3] = starIndex * 4 + 0;
        triangles[starIndex * 6 + 4] = starIndex * 4 + 3;
        triangles[starIndex * 6 + 5] = starIndex * 4 + 2;

        uvs[starIndex * 4 + 0] = new Vector2(1.0f, 1.0f);
        uvs[starIndex * 4 + 1] = new Vector2(0.0f, 1.0f);
        uvs[starIndex * 4 + 2] = new Vector2(0.0f, 0.0f);
        uvs[starIndex * 4 + 3] = new Vector2(1.0f, 0.0f);

        // TODO: Add normals if we are going to use any lighting on these?
    }
Esempio n. 3
0
    private void SpawnStars()
    {
        StarData someStar   = null;
        var      enumerator = AppDataModel.Instance.StarsData.GetStarsWithCommonNames().GetEnumerator();

        while (enumerator.MoveNext())
        {
            if (!string.IsNullOrEmpty(enumerator.Current.common_name))
            {
                someStar = enumerator.Current;

                GameObject starGO = PrefabLoader.Instance.InstantiateSynchronous(this._starPrefabPath, this.transform);

                starGO.transform.localPosition = StarFieldUtils.GetPositionFromRaDec(someStar.right_ascension,
                                                                                     someStar.declination, this._starfieldDistance);
                if (!string.IsNullOrEmpty(someStar.common_name))
                {
                    starGO.name = someStar.common_name;
                    if (someStar.common_name == "Polaris" || someStar.common_name == "Mintaka")
                    {
                        starGO.transform.localScale = new Vector3(10.0f, 10.0f, 10.0f);
                    }
                    else
                    {
                        starGO.transform.localScale = new Vector3(4.0f, 4.0f, 4.0f);
                    }
                }

                Lookat starLookat = starGO.GetComponent <Lookat>();
                if (starLookat != null)
                {
                    starLookat.Target = this._targetCamera;
                }
            }
        }
    }