Search code examples
c#wiimote

C# coding problems with Wiimote


Currently working on creating a VR head tracking using Wii remotes have faced a error.

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.

I have split the code in different pages however I receive the same error. This is the code I'm working on:

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 ),
        };
    }
}

Thanks


Solution

  • Move Point2D to the bottom of the file. Best practices state you should have only one class per file, so taking Stuart's advice and moving it to another file would be best.

    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;
            }
        }
    }