示例#1
0
文件: CubeSphere.cs 项目: ku4er/test1
    private void SetVertex(int i, int x, int y, int z)
    {
        Vector3 v  = new Vector3(x, y, z) * 2f / gridSize - Vector3.one;
        float   x2 = v.x * v.x;
        float   y2 = v.y * v.y;
        float   z2 = v.z * v.z;
        Vector3 s;

        s.x        = v.x * Mathf.Sqrt(1f - y2 / 2f - z2 / 2f + y2 * z2 / 3f);
        s.y        = v.y * Mathf.Sqrt(1f - x2 / 2f - z2 / 2f + x2 * z2 / 3f);
        s.z        = v.z * Mathf.Sqrt(1f - x2 / 2f - y2 / 2f + x2 * y2 / 3f);
        normals[i] = s;

        vertices[i] = normals[i] * Radius;
        cubeUV[i]   = new Color32((byte)x, (byte)y, (byte)z, 0);
        //
        var   coord = CameraControl.CartesianToPolar(vertices[i]);
        float uvX   = (coord.y + 180f) / 360f;
        float uvY   = (coord.x + 90f) / 180f;

        _uv[i] = new Vector2(uvX, uvY);

        //Debug.Log(vertices[i] + " => " + coord + " => " + _uv[i] + " : " + cubeUV[i]);
    }