Example #1
0
    // Use this for initialization
    void Start()
    {
        //handCtr = gameObject.GetComponent<HandCtrl>();

        sw = GameObject.Find("/KinectPrefab").GetComponent <SkeletonWrapper>();

        motion = MotionFactory.CreateHandleChain();
    }
Example #2
0
 private void win_ges_Loaded(object sender, RoutedEventArgs e)
 {
     try
     {
         // 创建处理链
         _motion = MotionFactory.CreateHandleChain();
     }
     catch (System.Exception ex)
     {
         MessageBox.Show(ex.Message);
         Application.Current.Shutdown();
     }
     KinectStart();
     StartColorFrame();
     this.txt_filename.Text = ConfigurationSettings.AppSettings["FileName"];
 }
Example #3
0
    void Start()
    {
        //_adaptiveUi = GameObject.Find("Cube").GetComponent<AdaptiveUi>(); // Waterstrong

        int hr = 0;

        try
        {
            hr = KinectWrapper.NuiInitialize(KinectWrapper.NuiInitializeFlags.UsesDepthAndPlayerIndex |
                                             KinectWrapper.NuiInitializeFlags.UsesSkeleton |
                                             KinectWrapper.NuiInitializeFlags.UsesColor);
            if (hr != 0)
            {
                throw new Exception("NuiInitialize Failed.");
            }

            hr = KinectWrapper.NuiSkeletonTrackingEnable(IntPtr.Zero, 8);              // 0, 12,8
            if (hr != 0)
            {
                throw new Exception("Cannot initialize Skeleton Data.");
            }

            depthStreamHandle = IntPtr.Zero;
            hr = KinectWrapper.NuiImageStreamOpen(KinectWrapper.NuiImageType.DepthAndPlayerIndex,
                                                  KinectWrapper.Constants.ImageResolution, 0, 2, IntPtr.Zero, ref depthStreamHandle);
//			if (hr != 0)
//			{
//				throw new Exception("Cannot open depth stream.");
//			}

            colorStreamHandle = IntPtr.Zero;
            hr = KinectWrapper.NuiImageStreamOpen(KinectWrapper.NuiImageType.Color,
                                                  KinectWrapper.Constants.ImageResolution, 0, 2, IntPtr.Zero, ref colorStreamHandle);
//			if (hr != 0)
//			{
//				throw new Exception("Cannot open color stream.");
//			}

            // set kinect elevation angle
            KinectWrapper.NuiCameraSetAngle((long)KinectAngle);

            // init skeleton structures
            skeletonFrame = new KinectWrapper.NuiSkeletonFrame()
            {
                SkeletonData = new KinectWrapper.NuiSkeletonData[KinectWrapper.Constants.NuiSkeletonCount]
            };

            // values used to pass to smoothing function
            smoothParameters                     = new KinectWrapper.NuiTransformSmoothParameters();
            smoothParameters.fSmoothing          = 0.7f;  //0.5f;
            smoothParameters.fCorrection         = 0.0f;  //0.5f;
            smoothParameters.fPrediction         = 0.0f;  //0.5f;
            smoothParameters.fJitterRadius       = 0.05f;
            smoothParameters.fMaxDeviationRadius = 0.05f; // 0.04f;

            //                 Smoothing = 0.3f,
            //                 Correction = 0.0f,
            //                 Prediction = 0.0f,
            //                 JitterRadius = 1.0f,
            //                 MaxDeviationRadius = 0.5f
            //Smoothing = 1.0f,
            //Correction = 0.1f,
            //Prediction = 0.1f,
            //JitterRadius = 0.05f,
            //MaxDeviationRadius = 0.05f



            // create arrays for joint positions and joint orientations
            int skeletonJointsCount = (int)KinectWrapper.NuiSkeletonPositionIndex.Count;
            player1JointsTracked = new bool[skeletonJointsCount];
            player2JointsTracked = new bool[skeletonJointsCount];

            player1JointsPos = new Vector3[skeletonJointsCount];
            player2JointsPos = new Vector3[skeletonJointsCount];

            player1JointsOri = new Matrix4x4[skeletonJointsCount];
            player2JointsOri = new Matrix4x4[skeletonJointsCount];

            //create the transform matrix that converts from kinect-space to world-space
            Quaternion quat = new Quaternion();
            quat.eulerAngles = new Vector3(-KinectAngle, 0.0f, 0.0f);

            // transform matrix - kinect to world
            kinectToWorld.SetTRS(new Vector3(0.0f, SensorHeight, 0.0f), quat, Vector3.one);
            //quatToWorld = Quaternion.LookRotation(kinectToWorld.GetColumn(2), kinectToWorld.GetColumn(1));

            instance = this;
            DontDestroyOnLoad(gameObject);
            Debug.Log("success kinect.");

            // Waterstrong Add
            _motion = MotionFactory.CreateHandleChain();
            Debug.Log("motion chain success.");
        }
        catch (Exception e)
        {
            Debug.Log(e.Message + ", hr=" + hr.ToString());
            return;
        }

        // 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);
         */

        usersMapRect = new Rect(Screen.width - 10,
                                Screen.height - 240 - 10,
                                -320,
                                240);

        if (DisplayColorMap)
        {
            usersClrTex = new Texture2D(KinectWrapper.GetDepthWidth(), KinectWrapper.GetDepthHeight());
            //usersClrColors = new Color[usersMapSize];
            usersClrRect    = new Rect(Screen.width /**- usersLblTex.width / 2*/ /**- usersClrTex.width / 2*/, Screen.height - usersClrTex.height / 2, -usersClrTex.width / 2, usersClrTex.height / 2);
            usersMapRect.x -= usersLblTex.width / 2;

            colorImage = new Color32[usersMapSize];
        }

        usersDepthMap     = new short[usersMapSize];
        usersHistogramMap = new float[5000];

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

        // 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.
        CalibrationText = GameObject.Find("CalibrationText");
        if (CalibrationText != null)
        {
            CalibrationText.guiText.text = "WAITING FOR USERS";
        }

        Debug.Log("Waiting for users.");

        KinectInitialized = true;
    }