void CheckAndChangeDepthShader(int kinectIndex) { bool colorize = false; bool scale = false; if (server.serverMasterOptions.kinectOptionsList[kinectIndex].version == KinectVersion.KinectV1) { colorize = ((KinectV1Wrapper.Settings)server.serverMasterOptions.kinectOptionsList[kinectIndex]).colorizeDepth; scale = ((KinectV1Wrapper.Settings)server.serverMasterOptions.kinectOptionsList[kinectIndex]).scaleDepthToReliableRange; } else if (server.serverMasterOptions.kinectOptionsList[kinectIndex].version == KinectVersion.KinectV2) { colorize = ((KinectV2Wrapper.Settings)server.serverMasterOptions.kinectOptionsList[kinectIndex]).colorizeDepth; scale = ((KinectV2Wrapper.Settings)server.serverMasterOptions.kinectOptionsList[kinectIndex]).scaleDepthToReliableRange; } //If the options have changed for the shader, we need to setup the new shader if (scale != scaleDepth || colorize != colorDepth) { //Set the variables so we can check if the shader is set right later scaleDepth = scale; colorDepth = colorize; if (scale && colorize) { Shaders.ColorScaleEffect effect = new Shaders.ColorScaleEffect(); effect.Minimum = depthMin; effect.Maximum = depthMax; depthEffect = effect; } else if (scale && !colorize) { Shaders.DepthScalingEffect effect = new Shaders.DepthScalingEffect(); effect.Minimum = depthMin; effect.Maximum = depthMax; depthEffect = effect; } else if (!scale && colorize) { Shaders.ColorDepthEffect effect = new Shaders.ColorDepthEffect(); effect.Minimum = depthMin; effect.Maximum = depthMax; depthEffect = effect; } else //Convert from the bgr32 back to a gray16, but don't do any shading otherwise { depthEffect = new Shaders.NoScalingEffect(); } DepthImage.Effect = depthEffect; } }
public void Draw(Texture2D texture, Vector2 position, DoubleRectangle? sourceRectangle, ShaderEffect shaderEffect, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) { if (sourceRectangle == null || sourceRectangle.Value.IsEmpty) { SpriteImage d = GetSprite(texture); if (d.ZIndex < zIndex) { d.ZIndex = zIndex; } else { zIndex = d.ZIndex; } zIndex++; d.InUse = true; d.PositionX = position.X; d.PositionY = position.Y; d.Scale = new Vector2((float)scale.X, (float)scale.Y); d.Rotation = rotation; d.Origin = origin; d.Effects = effects; d.CustomEffect = shaderEffect; } else { ClippedSpriteImage d = GetClippedSprite(texture); if (d.ZIndex < zIndex) { d.ZIndex = zIndex; } else { zIndex = d.ZIndex; } zIndex++; d.InUse = true; d.SourceRectangle = sourceRectangle.Value; d.PositionX = position.X; d.PositionY = position.Y; d.Scale = new Vector2((float)scale.X, (float)scale.Y); d.Rotation = rotation; d.Origin = origin; d.Effects = effects; d.CustomEffect = shaderEffect; } }
private void Window_Initialized(object sender, EventArgs e) { //Report to the log which Kinect versions are unavaliable if (!avaliableDLLs.HasKinectV1) { HelperMethods.WriteToLog("Warning: Kinect v1 support is unvaliable due to missing DLLs!", this); } if (!avaliableDLLs.HasKinectV2) { HelperMethods.WriteToLog("Warning: Kinect v2 support is unvaliable due to missing DLLs!", this); } if (!avaliableDLLs.HasNetworkedKinect) { HelperMethods.WriteToLog("Warning: Networked Kinect support is unvaliable due to missing DLLs!", this); //Remove the option to add a networked kinect if the dll isn't avaliable nkStackPanel.Visibility = System.Windows.Visibility.Collapsed; AddNKButton.IsEnabled = false; } //Setup the timer to update the GUI with the server runtime uptimeUpdateTimer = new System.Timers.Timer(); uptimeUpdateTimer.Interval = 500; uptimeUpdateTimer.Elapsed += new System.Timers.ElapsedEventHandler(uptimeUpdateTimer_Elapsed); KinectBase.MasterSettings tempSettings = new KinectBase.MasterSettings(); //Create the server core (this does NOT start the server) server = new ServerCore(verbose, tempSettings, this); //Set all the data for the data grids VoiceButtonDataGrid.ItemsSource = server.serverMasterOptions.voiceButtonCommands; VoiceTextDataGrid.ItemsSource = server.serverMasterOptions.voiceTextCommands; if (startupFile != null && startupFile != "") { try { server.serverMasterOptions = HelperMethods.LoadSettings(startupFile); UpdateGUISettings(); } catch { MessageBox.Show("Error: The startup settings file failed to load!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); HelperMethods.WriteToLog("Startup settings (" + startupFile + ") failed to load."); } } //TODO: Handle starting Kinects based on the loaded settings file //Initialize the data for the available Kinect v1s if (avaliableDLLs.HasKinectV1) { KinectV1Wrapper.StatusEventArgs[] currentStatuses = KinectV1Wrapper.StatusHelper.GetAllKinectsStatus(); for (int i = 0; i < currentStatuses.Length; i++) { AvailableKinectData tempData = new AvailableKinectData(); tempData.UniqueID = currentStatuses[i].UniqueKinectID; tempData.Status = currentStatuses[i].Status; tempData.KinectTypeString = GetKinectTypeString(currentStatuses[i].Status, currentStatuses[i].isXBox360Kinect); tempData.kinectType = KinectVersion.KinectV1; if (i == 0 && tempData.Status == KinectStatus.Connected) { tempData.UseKinect = true; tempData.KinectID = 0; server.serverMasterOptions.kinectOptionsList.Add((IKinectSettings)(new KinectV1Wrapper.Settings(tempData.UniqueID, (int)tempData.KinectID))); server.kinects.Add((new KinectV1Wrapper.Core(ref server.serverMasterOptions, true, (int)tempData.KinectID))); tempData.ServerStatus = "Running"; } else { tempData.UseKinect = false; tempData.KinectID = null; } tempData.PropertyChanged += useKinect_PropertyChanged; availableKinects.Add(tempData); } } //Initialize the data for the available Kinect v2s if (avaliableDLLs.HasKinectV2) { KinectV2Wrapper.StatusHelper.StartKinectV2Service(); KinectV2Wrapper.StatusEventArgs[] currentStatuses2 = KinectV2Wrapper.StatusHelper.GetAllKinectsStatus(); for (int i = 0; i < currentStatuses2.Length; i++) { AvailableKinectData tempData = new AvailableKinectData(); tempData.UniqueID = currentStatuses2[i].UniqueKinectID; tempData.Status = currentStatuses2[i].Status; tempData.KinectTypeString = "Kinect v2"; tempData.kinectType = KinectVersion.KinectV2; //Note: Unlike the Kinect v1, we don't automatically launch a Kinect v2 tempData.UseKinect = false; tempData.KinectID = null; tempData.PropertyChanged += useKinect_PropertyChanged; availableKinects.Add(tempData); } } KinectStatusBlock.Text = availableKinects.Count.ToString(); kinectsAvailableDataGrid.ItemsSource = availableKinects; UpdatePageListing(); GenerateImageSourcePickerLists(); if (avaliableDLLs.HasKinectV1) { //Subscribe to the v1 status changed event KinectV1Wrapper.StatusHelper v1StatusHelper = new KinectV1Wrapper.StatusHelper(); v1StatusHelper.StatusChanged += v1StatusHelper_KinectV1StatusChanged; } if (avaliableDLLs.HasKinectV2) { //Subscribe to the v2 status changed event KinectV2Wrapper.StatusHelper v2StatusHelper = new KinectV2Wrapper.StatusHelper(); v2StatusHelper.StatusChanged += v2StatusHelper_KinectV2StatusChanged; } //Populate the skeleton data and set the binding for the data grid GenerateSkeletonDataGridData(); SkeletonSettingsDataGrid.ItemsSource = server.serverMasterOptions.mergedSkeletonOptions.individualSkeletons; //Populate and setup the voice recognition lists GenerateVoiceRecogEngineList(); GenerateAudioSourceList(); VoiceKinectComboBox.SelectedIndex = 0; //Set defaults where needed FeedbackJointTypeComboBox.SelectedIndex = 0; SkelSortModeComboBox.SelectedIndex = 5; //Set the items source for the servers display grid ServersDataGrid.ItemsSource = configuredServers; //Set the initial shader for the depth image depthEffect = new Shaders.NoScalingEffect(); DepthImage.Effect = depthEffect; if (startOnLaunch) { startServerButton_Click(this, new RoutedEventArgs()); } }