Beispiel #1
0
 public Vector3[] RotateVertices(Vector3[] vertices, PlanetSide side)
 {
     for (int v = 0; v < vertices.Length; v++)
     {
         Quaternion rotation = Quaternion.AngleAxis(
             (int)side.sideAxis.magnitude, side.sideAxis.normalized
             );
         Vector3 vector2 = vertices[v] - Vector3.zero;
         vector2     = rotation * vector2;
         vertices[v] = Vector3.zero + vector2;
     }
     return(vertices);
 }
Beispiel #2
0
        private void CreatePlanet()
        {
            planetInfo.name            = "Planet";
            planetInfo.sideResolution  = 10;
            planetInfo.radius          = 100;
            planetInfo.gameObject      = new GameObject(planetInfo.name);
            planetInfo.defaultMaterial = defaultMaterial;

            float[,] heightData = GetHeightData();

            //sides = new PlanetSide[1];
            sides[0] = new PlanetSide(this, planetInfo, new Vector3(0, 0, 0), heightData);
            sides[1] = new PlanetSide(this, planetInfo, new Vector3(0, 90, 0), heightData);
            sides[2] = new PlanetSide(this, planetInfo, new Vector3(0, 180, 0), heightData);
            sides[3] = new PlanetSide(this, planetInfo, new Vector3(0, -90, 0), heightData);
            sides[4] = new PlanetSide(this, planetInfo, new Vector3(90, 0, 1), heightData);
            sides[5] = new PlanetSide(this, planetInfo, new Vector3(-90, 0, -1), heightData);
        }
Beispiel #3
0
        public Vector3[] SpherizeSide(Vector3[] vertices, PlanetSide side)
        {
            int vSize = (int)Mathf.Sqrt(vertices.Length);

            for (int y = 0, i = 0; y < vSize; y++)
            {
                for (int x = 0; x < vSize; x++, i++)
                {
                    Vector3 v  = new Vector3(x, y, 0) * 2f / (vSize - 1f) - Vector3.one;
                    float   x2 = v.x * v.x;
                    float   y2 = v.y * v.y;
                    float   z2 = v.z * v.z;
                    Vector3 n  = new Vector3(
                        v.x * Mathf.Sqrt(1f - y2 / 2f - z2 / 2f + y2 * z2 / 3f),
                        v.y * Mathf.Sqrt(1f - x2 / 2f - z2 / 2f + x2 * z2 / 3f),
                        v.z * Mathf.Sqrt(1f - x2 / 2f - y2 / 2f + x2 * y2 / 3f)
                        );
                    vertices[i] = n * side.planet.radius;
                }
            }
            return(vertices);
        }