KinectManager.Start C# (CSharp) Method

Start() public method

public Start ( ) : void
return void
    void Start()
    {
        CalibrationText = GameObject.Find("CalibrationText");

        try
        {
            // Make sure we have the Open NI file.
            uint rc = KinectWrapper.Init(new StringBuilder("OpenNI.xml"));

            if (rc != 0)
            {
                throw new Exception(String.Format("Error initing OpenNI: {0}", Marshal.PtrToStringAnsi(KinectWrapper.GetStatusString(rc))));
            }

            // Initialize depth & label map related stuff
            usersMapSize = KinectWrapper.GetDepthWidth() * KinectWrapper.GetDepthHeight();
            usersLblTex = new Texture2D(KinectWrapper.GetDepthWidth(), KinectWrapper.GetDepthHeight());
            usersMapColors = new Color[usersMapSize];
            usersMapRect = new Rect(Screen.width - usersLblTex.width / 2, Screen.height - usersLblTex.height / 2, usersLblTex.width / 2, usersLblTex.height / 2);
            usersLabelMap = new short[usersMapSize];
            usersDepthMap = new short[usersMapSize];
            usersHistogramMap = new float[5000];

            // Initialize user list to contain ALL users.
            allUsers = new List<uint>();

            // Initialize user callbacks.
            NewUser = new KinectWrapper.UserDelegate(OnNewUser);
            CalibrationStarted = new KinectWrapper.UserDelegate(OnCalibrationStarted);
            CalibrationFailed = new KinectWrapper.UserDelegate(OnCalibrationFailed);
            CalibrationSuccess = new KinectWrapper.UserDelegate(OnCalibrationSuccess);
            UserLost = new KinectWrapper.UserDelegate(OnUserLost);

            // Pull the AvatarController from each of the players Avatars.
            Player1Controllers = new List<AvatarController>();
            Player2Controllers = new List<AvatarController>();

            // Add each of the avatars' controllers into a list for each player.
            foreach(GameObject avatar in Player1Avatars)
            {
                Player1Controllers.Add(avatar.GetComponent<AvatarController>());
            }

            foreach(GameObject avatar in Player2Avatars)
            {
                Player2Controllers.Add(avatar.GetComponent<AvatarController>());
            }

            // GUI Text.
            if(CalibrationText != null)
            {
                CalibrationText.guiText.text = "MATCH POSE TO CALIBRATE";
            }

            // Start looking for users.
            KinectWrapper.StartLookingForUsers(NewUser, CalibrationStarted, CalibrationFailed, CalibrationSuccess, UserLost);
            Debug.Log("Waiting for users to calibrate");

            // Set the default smoothing for the Kinect.
            KinectWrapper.SetSkeletonSmoothing(0.7);

            instance = this;
            OpenNIInitialized = true;
        }
        catch(DllNotFoundException ex)
        {
            Debug.LogError(ex.ToString());
            if(CalibrationText != null)
                CalibrationText.guiText.text = "Please check the OpenNI and NITE installations.";
        }
        catch (Exception ex)
        {
            Debug.LogError(ex.ToString());
            if(CalibrationText != null)
                CalibrationText.guiText.text = ex.Message;
        }
    }

Usage Example

Example #1
0
        public Form1()
        {
            InitializeComponent();

            controls = new Control[4][] { new Control[] { label1, identifyButton1, orientationTrackBar1, comboBox1, bottomLabel1, selectedMachineLabel1 }, new Control[] { label2, identifyButton2, orientationTrackBar2, comboBox2, bottomLabel2, selectedMachineLabel2 }, new Control[] { label3, identifyButton3, orientationTrackBar3, comboBox3, bottomLabel3, selectedMachineLabel3 }, new Control[] { label4, identifyButton4, orientationTrackBar4, comboBox4, bottomLabel4, selectedMachineLabel4 } };

            km.Start(this);
        }
All Usage Examples Of KinectManager::Start