27 July 2012 0 Comments

Parte 3.4 Moviendo la Cámara con Unity3D

Vamos a preparar Unity3D con opciones para el movimiento de la cámara.

Abrimos el Unity3d y colocamos el siguiente código en KinectUnityInterface.cs

[sourcecode language="cpp"] /* Description: */ using System; using UnityEngine; using System.Collections; using System.Runtime.InteropServices; using Assets.Kinect.Scripts; public class KinectUnityInterface : MonoBehaviour { public static KinectUnityInterface SP; //Singleton public bool mbTwoPlayer = false; private float mfLastCameraAngleChange = -30.0f; private bool NUIisReady = false; /***************************************** Unity3D Methods **************************************/ // Use this for initialization void Start () { //Tests(); SP = this; NUIisReady = false; NUIisReady = KinectWrapper.NuiContextInit(mbTwoPlayer); //initialize Kinect sensor //display messages if (NUIisReady) Debug.Log("Sensor Initialized."); else Debug.Log("Could Not Initialize Sensor."); KinectWrapper.SetCameraAngle(-20); } // Update is called once per frame void Update () { } /***************************************** User Methods **************************************/ // returns current Kinect camera angle from horizontal public float GetCameraAngle() { float lfCameraAngle = 0; KinectWrapper.GetCameraAngle(ref lfCameraAngle); return (lfCameraAngle); } public bool SetCameraAngle(int liAngle) { /* DO NOT CHANGE CAMERA ANGLE MORE OFTEN THAN ONCE * EVERY 30 SECONDS, IT COULD DAMAGE THE KINECT * SENSOR (SEE KINECT SDK DOCUMENTATION). */ if (Time.time – mfLastCameraAngleChange > 30) { mfLastCameraAngleChange = Time.time; return (KinectWrapper.SetCameraAngle(liAngle)); } else { return (false); } } /***************************************** Tests **************************************/ private void Tests() { int liTest = KinectWrapper.GetANumber(); print (liTest); IntPtr mpString = KinectWrapper.GetAString(); string lsTest = Marshal.PtrToStringAnsi(mpString); print(lsTest); } } [/sourcecode]

Ahora tenemos que asignar este script a la Main Camera de la Escena, para ello simplemente en Unity cojemos el KinectUnityInteface.cs del Project y lo arrastramos a la Main Camera en Hierarchy. Esto si no loa habíamos hecho con anterioridad. Recordad que nuestra escena está en el directorio Scene que creamos

Si le damos Play vemos como se nos inicializa el sensor en Console y se mueve la cámara los ángulos que le hayamos puesto

25 July 2012 0 Comments

(Español) Parte 3.3. Moviendo El rotor o ángulo de Kinect

25 July 2012 0 Comments

(Español) Parte 3.2: Inicializando Kinect en C++

25 July 2012 0 Comments

(Español) Parte 3.1 Introducción Kinect con Dll

Sorry, this entry is only available in Español.

14 July 2012 0 Comments

(Español) 2.4 WPF con DLL en C++

14 July 2012 4 Comments

(Español) 2.3 Unity3D con dll en C++

14 July 2012 0 Comments

(Español) 2.2 Dll en C++

14 July 2012 0 Comments

(Español) 2.1: Introducción Unity3D y Kinect

14 July 2012 8 Comments

(Español) 1.5 Integración Unity3D y Microsfot SDK

14 July 2012 0 Comments

(Español) 1.4 Kinect