예제 #1
0
    static SkyComponent()
    {
        // 円周方向の分割数
        const int Slices = 16;

        // Y方向の分割数
        const int Stacks = 8;

        List <Vector3> positions = new List <Vector3>();

        for (int i = 0; i < Stacks + 1; i++)
        {
            float y = 1.0f - 2.0f * (float)i / Stacks;
            float r = sqrt(1 - y * y);
            for (int j = 0; j < Slices + 1; j++)
            {
                float   t = (float)j / Slices * 3.14159f * 2;
                float   x = r * cos(t);
                float   z = r * sin(t);
                Vector3 v = new Vector3(x / 2, y / 2, z / 2);
                positions.Add(v);
            }
        }
        VertexBuffer.Create(positions.ToArray(), Accessibility.None);

        List <int> indices = new List <int>();

        for (int i = 0; i < Stacks; i++)
        {
            for (int j = 0; j < Slices; j++)
            {
                int i0 = (Slices + 1) * i + j;
                int i1 = i0 + 1;
                int i2 = (Slices + 1) * (i + 1) + j;
                int i3 = i2 + 1;
                indices.Add(i0);
                indices.Add(i2);
                indices.Add(i1);
                indices.Add(i1);
                indices.Add(i2);
                indices.Add(i3);
            }
        }
        IndexBuffer.Create(indices.ToArray(), Accessibility.None);

        Texture.CreateCubeMap("res/texture/skybox.dds", Accessibility.None);

        VertexShader.CreateFromFile("res/shader/SkyVertexShader.hlsl");
        PixelShader.CreateFromFile("res/shader/SkyPixelShader.hlsl");

        VertexLayout.Create(new VertexElement[]
        {
            new VertexElement("POSITION", 0, Format.Float3, 0, 0, VertexElement.Classification.VertexData, 0),
        }, VertexShader);
    }