Beispiel #1
0
    // Use this for initialization
    void Start()
    {
        _sensor = KinectSensor.GetDefault();

        // Create bodyDrawer and body from prefab
        GameObject body = (GameObject)Instantiate(Resources.Load("Prefabs/Body"));

        bodyDrawer = new BodyDrawer(body);


        if (_sensor != null)
        {
            _reader = _sensor.BodyFrameSource.OpenReader();

            if (!_sensor.IsOpen)
            {
                _sensor.Open();
            }
        }
    }
        /// <summary>
        /// Initializes a new instance of the MainWindow class.
        /// </summary>
        public MainWindow()
        {
            // initialize the joint pairs (one steady and one moving per pair)
            JointPairMappings.Initialize();

            // initialize the instruments used for each joint pair
            InstrumentMappings.Initialize();

            // records of previous joint positions
            jointRecords = new JointRecords();

            // initialize time signature
            timeSignature = new TimeSignature();

            // one sensor is currently supported
            this.kinectSensor = KinectSensor.GetDefault();

            drawer = new BodyDrawer(this.kinectSensor.CoordinateMapper,
                                    this.kinectSensor.DepthFrameSource.FrameDescription,
                                    new DrawingGroup());

            // open the reader for the body frames
            this.bodyFrameReader = this.kinectSensor.BodyFrameSource.OpenReader();

            // set IsAvailableChanged event notifier
            this.kinectSensor.IsAvailableChanged += this.Sensor_IsAvailableChanged;

            // open the sensor
            this.kinectSensor.Open();

            this.imageSource = new DrawingImage(drawer.drawingGroup);

            // set the status text
            this.StatusText = this.kinectSensor.IsAvailable ? Properties.Resources.RunningStatusText
                                                            : Properties.Resources.NoSensorStatusText;


            // use the window object as the view model in this simple example
            this.DataContext = this;

            // initialize the components (controls) of the window
            this.InitializeComponent();
        }