public MainWindow() { // one sensor is currently supported this.kinectSensor = KinectSensor.GetDefault(); // get the coordinate mapper this.coordinateMapper = this.kinectSensor.CoordinateMapper; // open the reader for the body frames this.bodyFrameReader = this.kinectSensor.BodyFrameSource.OpenReader(); this.colorFrameReader = this.kinectSensor.ColorFrameSource.OpenReader(); this.audioReader = this.kinectSensor.AudioSource.OpenReader(); // get the depth (display) extents FrameDescription jointFrameDescription = this.kinectSensor.DepthFrameSource.FrameDescription; FrameDescription colorFrameDescription = this.kinectSensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra); FrameDescription infraredFrameDescription = this.kinectSensor.InfraredFrameSource.FrameDescription; colorRenderer = new ColorFrameRenderer(colorFrameDescription.Width, colorFrameDescription.Height, jointFrameDescription.Width, jointFrameDescription.Height, infraredFrameDescription.Width, infraredFrameDescription.Height); var drawingGroup = new DrawingGroup(); var drawingImage = new DrawingImage(drawingGroup); hudRenderer = new HudRenderer(drawingGroup, drawingImage, colorFrameDescription.Width, colorFrameDescription.Height); AudioSource audioSource = this.kinectSensor.AudioSource; // Allocate 1024 bytes to hold a single audio sub frame. Duration sub frame // is 16 msec, the sample rate is 16khz, which means 256 samples per sub frame. // With 4 bytes per sample, that gives us 1024 bytes. this.audioBuffer = new byte[audioSource.SubFrameLengthInBytes]; this.colorFrameReader.FrameArrived += this.Reader_ColorFrameArrived; this.audioReader.FrameArrived += audioReader_FrameArrived; //on startup hide the audio meter AudioMeterVisibility = Visibility.Hidden; this.infraredFrameReader = this.kinectSensor.InfraredFrameSource.OpenReader(); //Infrared // open the reader for the depth frames this.infraredFrameReader = this.kinectSensor.InfraredFrameSource.OpenReader(); // wire handler for frame arrival this.infraredFrameReader.FrameArrived += this.colorRenderer.Reader_InfraredFrameArrived; // set IsAvailableChanged event notifier this.kinectSensor.IsAvailableChanged += this.Sensor_IsAvailableChanged; // open the sensor this.kinectSensor.Open(); // set the status text TODO: change namespace name in resources this.StatusText = this.kinectSensor.IsAvailable ? Microsoft.Samples.Kinect.BodyBasics.Properties.Resources.RunningStatusText : Microsoft.Samples.Kinect.BodyBasics.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(); //register the code which will tell the system what to do when keys are pressed SetupKeyHandlers(); //initialize panTilt = PanTiltController.GetOrCreatePanTiltController(); firingControl = FiringController.GetOrCreateFiringController(); var panTiltErr = panTilt.TryInitialize(); var firingErr = firingControl.TryInitialize(); if (panTiltErr != null) { //crash the app. we can't do anything if it doesn't intialize throw panTiltErr; } if (firingErr != null) { //crash the app. we can't do anything if it doesn't intialize throw firingErr; } string safetyText; if (this.firingControl.VirtualSafetyOn) { safetyText = Microsoft.Samples.Kinect.BodyBasics.Properties.Resources.SafetyDisengagedText; } else { safetyText = Microsoft.Samples.Kinect.BodyBasics.Properties.Resources.SafetyEngagedText; } panTilt.TryInitialize(); //draw the headsup display initially this.hudRenderer.RenderHud(new HudRenderingParameters() { CannonX = this.CannonX, CannonY = this.CannonY, //CannonTheta = this.CannonTheta, StatusText = this.statusText, SystemReady = (this.kinectSensor.IsAvailable && this.kinectSensor.IsOpen && this.panTilt.IsReady), FrameRate = this.FrameRate, TrackingMode = this.trackingMode, FiringSafety = this.firingControl.VirtualSafetyOn, FiringSafetyText = safetyText }); //set voice synth to Hazel this.voiceSynth.SelectVoice("Microsoft Hazel Desktop"); this.voiceSynth.SpeakAsync("Kinect Cannon Fully Initialized"); //debug start frame rate counter FPSTimerStart(); // Try to use the controller }