Wiimote 的 C# 编码问题

C# coding problems with Wiimote

目前正在使用 Wii 遥控器创建 VR 头部跟踪时遇到错误。

The class *** can be designed, but is not the first class in the file.Visual Studio requires that designers use the first class in the file. Move the class code so that it is the first class in the file and try loading the designer again.

我已将代码拆分到不同的页面中,但我收到了同样的错误。这是我正在处理的代码:

namespace WiiDesktopVR
{
    class Point2D
    {
        public float x = 0.0f;
        public float y = 0.0f;
        public void set(float x, float y)
        {
            this.x = x;
            this.y = y;
        }
    }

    public class WiiDesktopVR : Form
    {
        struct Vertex
        {
            float x, y, z;
            float tu, tv;

            public Vertex(float _x, float _y, float _z, float _tu, float _tv)
            {
                x = _x; y = _y; z = _z;
                tu = _tu; tv = _tv;
            }

            public static readonly VertexFormats FVF_Flags = VertexFormats.Position | VertexFormats.Texture1;
        };

        Vertex[] targetVertices =
        {
            new Vertex(-1.0f, 1.0f,.0f,  0.0f,0.0f ),
            new Vertex( 1.0f, 1.0f,.0f,  1.0f,0.0f ),
            new Vertex(-1.0f,-1.0f,.0f,  0.0f,1.0f ),
            new Vertex( 1.0f,-1.0f,.0f,  1.0f,1.0f ),
        };
    }
}

谢谢

Point2D移动到文件底部。最佳实践表明每个文件应该只有一个 class,因此最好听取 Stuart 的建议并将其移动到另一个文件。

namespace WiiDesktopVR
{
    public class WiiDesktopVR : Form
    {
        struct Vertex
        {
            float x, y, z;
            float tu, tv;

            public Vertex(float _x, float _y, float _z, float _tu, float _tv)
            {
                x = _x; y = _y; z = _z;
                tu = _tu; tv = _tv;
            }

            public static readonly VertexFormats FVF_Flags = VertexFormats.Position | VertexFormats.Texture1;
        };

        Vertex[] targetVertices =
        {
            new Vertex(-1.0f, 1.0f,.0f,  0.0f,0.0f ),
            new Vertex( 1.0f, 1.0f,.0f,  1.0f,0.0f ),
            new Vertex(-1.0f,-1.0f,.0f,  0.0f,1.0f ),
            new Vertex( 1.0f,-1.0f,.0f,  1.0f,1.0f ),
        };
    }

    class Point2D
    {
        public float x = 0.0f;
        public float y = 0.0f;
        public void set(float x, float y)
        {
            this.x = x;
            this.y = y;
        }
    }
}