コード例 #1
0
    void StartInteraction()
    {
        int hr = 0;

        try
        {
            // initialize Kinect sensor as needed
            hr = InteractionWrapper.InitKinectSensor();
            if (hr != 0)
            {
                throw new Exception("Initialization of Kinect sensor failed");
            }

            // initialize Kinect interaction
            hr = InteractionWrapper.InitKinectInteraction();
            if (hr != 0)
            {
                throw new Exception("Initialization of KinectInteraction failed");
            }

            // kinect interaction was successfully initialized
            interactionInited = true;
        }
        catch (DllNotFoundException ex)
        {
            Debug.LogError(ex.ToString());
            if (handGuiText != null)
            {
                handGuiText.GetComponent <GUIText>().text = "Please check the Kinect SDK installation.";
            }
        }
        catch (Exception ex)
        {
            string message = ex.Message + " - " + InteractionWrapper.GetNuiErrorString(hr);
            Debug.LogError(ex.ToString());

            if (handGuiText != null)
            {
                handGuiText.GetComponent <GUIText>().text = message;
            }

            return;
        }

//		// transform matrix - kinect to world
//		Quaternion quatTiltAngle = new Quaternion();
//		int sensorAngle = InteractionWrapper.GetKinectElevationAngle();
//		quatTiltAngle.eulerAngles = new Vector3(-sensorAngle, 0.0f, 0.0f);
//
//		float heightAboveHips = SensorHeight - 1.0f;
//		kinectToWorld.SetTRS(new Vector3(0.0f, heightAboveHips, 0.0f), quatTiltAngle, Vector3.one);

        // load cursor textures once
        gripHandTexture    = (Texture)Resources.Load("GripCursor");
        releaseHandTexture = (Texture)Resources.Load("ReleaseCursor");
        normalHandTexture  = (Texture)Resources.Load("HandCursor");

        // don't destroy the object on loading levels
        DontDestroyOnLoad(gameObject);
    }
コード例 #2
0
    void StartInteraction()
    {
        int hr = 0;

        try {
            // initialize Kinect sensor as needed
            hr = InteractionWrapper.InitKinectSensor((int)InteractionWrapper.Constants.ColorImageResolution, (int)InteractionWrapper.Constants.DepthImageResolution, InteractionWrapper.Constants.IsNearMode);
            if (hr != 0)
            {
                throw new Exception("Initialization of Kinect sensor failed");
            }

            // initialize Kinect interaction
            hr = InteractionWrapper.InitKinectInteraction();
            if (hr != 0)
            {
                throw new Exception("Initialization of KinectInteraction failed");
            }

            // kinect interaction was successfully initialized
            instance          = this;
            interactionInited = true;
        } catch (DllNotFoundException ex) {
            Debug.LogError(ex.ToString());
            if (debugText != null)
            {
                debugText.GetComponent <GUIText> ().text = "Please check the Kinect SDK installation.";
            }
        } catch (Exception ex) {
            string message = ex.Message + " - " + InteractionWrapper.GetNuiErrorString(hr);
            Debug.LogError(ex.ToString());
            Debug.Log("Kinect não conectado! Desabilitando o component InteractonManager...");
            GetComponent <InteractionManager> ().enabled = false;
            handCursor.SetActive(false);

            if (debugText != null)
            {
                debugText.GetComponent <GUIText> ().text = message;
            }

            return;
        }

//		// transform matrix - kinect to world
//		Quaternion quatTiltAngle = new Quaternion();
//		int sensorAngle = InteractionWrapper.GetKinectElevationAngle();
//		quatTiltAngle.eulerAngles = new Vector3(-sensorAngle, 0.0f, 0.0f);
//
//		float heightAboveHips = SensorHeight - 1.0f;
//		kinectToWorld.SetTRS(new Vector3(0.0f, heightAboveHips, 0.0f), quatTiltAngle, Vector3.one);

//		// load cursor textures once
//		if(!gripHandTexture)
//		{
//			gripHandTexture = (Texture)Resources.Load("GripCursor");
//		}
//		if(!releaseHandTexture)
//		{
//			releaseHandTexture = (Texture)Resources.Load("ReleaseCursor");
//		}
//		if(!normalHandTexture)
//		{
//			normalHandTexture = (Texture)Resources.Load("HandCursor");
//		}

        // don't destroy the object on loading levels
        DontDestroyOnLoad(gameObject);
    }