private static void ControllerUpdatePositions( PSMoveWorkerSettings WorkerSettings, IntPtr[] psmove_trackers, // PSMoveTracker* IntPtr[] psmove_fusions, // PSMoveFusion* int tracker_count, IntPtr position_filter, IntPtr psmove, // PSMove* PSMoveRawControllerData_Base controllerData) { // Update the tracked position of the psmove for each tracker for (int tracker_index = 0; tracker_index < tracker_count; ++tracker_index) { PSMoveAPI.psmove_tracker_update(psmove_trackers[tracker_index], psmove); } // Compute the triangulated camera position PSMoveAPI.PSMove_3AxisVector measured_position = new PSMoveAPI.PSMove_3AxisVector(); controllerData.IsSeenByTracker = PSMoveAPI.psmove_fusion_get_multicam_tracking_space_location( psmove_fusions, tracker_count, psmove, ref measured_position.x, ref measured_position.y, ref measured_position.z) == PSMove_Bool.PSMove_True; // Update the position of the controller if (controllerData.IsSeenByTracker) { // Update the filtered position PSMoveAPI.psmove_position_filter_update( ref measured_position, controllerData.IsSeenByTracker ? PSMove_Bool.PSMove_True : PSMove_Bool.PSMove_False, position_filter); // Get the filtered position PSMoveAPI.PSMove_3AxisVector filtered_position = PSMoveAPI.psmove_position_filter_get_position(position_filter); // [Store the controller position] // Remember the position the ps move controller in either its native space // or in a transformed space if a transform file existed. controllerData.PSMovePosition = new Vector3( filtered_position.x + WorkerSettings.PSMoveOffset.x, filtered_position.y + WorkerSettings.PSMoveOffset.y, filtered_position.z + WorkerSettings.PSMoveOffset.z); } }
private static void ControllerUpdatePositions( PSMoveWorkerSettings WorkerSettings, IntPtr[] psmove_trackers, // PSMoveTracker* IntPtr[] psmove_fusions, // PSMoveFusion* int tracker_count, IntPtr position_filter, IntPtr psmove, // PSMove* PSMoveRawControllerData_Base controllerData) { // Update the tracked position of the psmove for each tracker for (int tracker_index = 0; tracker_index < tracker_count; ++tracker_index) { PSMoveAPI.psmove_tracker_update(psmove_trackers[tracker_index], psmove); } // Compute the triangulated camera position PSMoveAPI.PSMove_3AxisVector measured_position = new PSMoveAPI.PSMove_3AxisVector(); controllerData.IsSeenByTracker = PSMoveAPI.psmove_fusion_get_multicam_tracking_space_location( psmove_fusions, tracker_count, psmove, ref measured_position.x, ref measured_position.y, ref measured_position.z) == PSMove_Bool.PSMove_True; // Update the position of the controller if (controllerData.IsSeenByTracker) { // Update the filtered position PSMoveAPI.psmove_position_filter_update( ref measured_position, controllerData.IsSeenByTracker ? PSMove_Bool.PSMove_True : PSMove_Bool.PSMove_False, position_filter); // Get the filtered position PSMoveAPI.PSMove_3AxisVector filtered_position = PSMoveAPI.psmove_position_filter_get_position(position_filter); // [Store the controller position] // Remember the position the ps move controller in either its native space // or in a transformed space if a transform file existed. controllerData.PSMovePosition = new Vector3( filtered_position.x + WorkerSettings.PSMoveOffset.x, filtered_position.y + WorkerSettings.PSMoveOffset.y, filtered_position.z + WorkerSettings.PSMoveOffset.z); } }
private static bool WorkerContextSetupTracking( PSMoveWorkerSettings WorkerSettings, WorkerContext context) { bool success = true; // Clear out the tracking state // Reset the shared worker data context.Reset(); UnityEngine.Debug.Log("Setting up PSMove Tracking Context"); // Initialize and configure the psmove_tracker. { PSMoveAPI.PSMoveTrackerSettings settings = new PSMoveAPI.PSMoveTrackerSettings(); PSMoveAPI.psmove_tracker_settings_set_default(ref settings); settings.color_mapping_max_age = 0; // Don't used cached color mapping file if (WorkerSettings.bUseManualExposure) { settings.exposure_mode = PSMoveTracker_Exposure.Exposure_MANUAL; settings.camera_exposure = (int)(Math.Max(Math.Min(WorkerSettings.ManualExposureValue, 1.0f), 0.0f) * 65535.0f); } else { settings.exposure_mode = PSMoveTracker_Exposure.Exposure_LOW; } settings.use_fitEllipse = 1; settings.filter_do_2d_r = 0; settings.filter_do_2d_xy = 0; settings.camera_mirror = PSMove_Bool.PSMove_True; settings.color_list_start_ind = (int)WorkerSettings.InitialTrackingColor; context.TrackerCount = 0; for (int tracker_index = 0; tracker_index < WorkerContext.MAX_TRACKER_COUNT; ++tracker_index) { context.PSMoveTrackers[tracker_index] = PSMoveAPI.psmove_tracker_new_with_camera_and_settings(tracker_index, ref settings); if (context.PSMoveTrackers[tracker_index] != IntPtr.Zero) { UnityEngine.Debug.Log(string.Format("PSMove tracker({0}) initialized.", tracker_index)); ++context.TrackerCount; PSMoveAPI.psmove_tracker_get_size( context.PSMoveTrackers[tracker_index], ref context.TrackerWidth, ref context.TrackerHeight); UnityEngine.Debug.Log(string.Format("Camera Dimensions: {0} x {1}", context.TrackerWidth, context.TrackerHeight)); } else { PSMoveTracker_ErrorCode errorCode = PSMoveAPI.psmove_tracker_get_last_error(); UnityEngine.Debug.Log(string.Format("PSMove tracker({0}) not available: {1}", tracker_index, errorCode.ToString())); break; } } if (context.TrackerCount <= 0) { UnityEngine.Debug.LogError(string.Format("Failed to open any trackers")); success = false; } } // Initialize fusion API if the tracker started if (success) { for (int tracker_index = 0; tracker_index < context.TrackerCount; ++tracker_index) { context.PSMoveFusions[tracker_index] = PSMoveAPI.psmove_fusion_new(context.PSMoveTrackers[tracker_index], 1.0f, 1000.0f); if (context.PSMoveFusions[tracker_index] != IntPtr.Zero) { UnityEngine.Debug.Log(string.Format("PSMove fusion({0}) initialized.", tracker_index)); } else { UnityEngine.Debug.LogError(string.Format("PSMove fusion({0}) failed to initialize.", tracker_index)); success = false; break; } } } // Initialize a position filter to smooth out the tracking data if (success) { context.PSMovePositionFilter = PSMoveAPI.psmove_position_filter_new(); if (context.PSMovePositionFilter != IntPtr.Zero) { UnityEngine.Debug.Log("PSMove position filter initialized."); PSMoveAPI.PSMove_3AxisVector initial_position = new PSMoveAPI.PSMove_3AxisVector() { x = 0.0f, y = 0.0f, z = 0.0f, }; PSMoveAPI.PSMovePositionFilterSettings filter_settings = new PSMoveAPI.PSMovePositionFilterSettings(); PSMoveAPI.psmove_position_filter_get_default_settings(ref filter_settings); filter_settings.filter_type = WorkerSettings.FilterType; PSMoveAPI.psmove_position_filter_init(ref filter_settings, ref initial_position, context.PSMovePositionFilter); } else { UnityEngine.Debug.LogError(string.Format("Failed to allocate PSMove Position Filter")); success = false; } } if (!success) { WorkerContextTeardownTracking(context); } return success; }
private static bool WorkerContextSetupTracking( PSMoveWorkerSettings WorkerSettings, WorkerContext context) { bool success = true; // Clear out the tracking state // Reset the shared worker data context.Reset(); UnityEngine.Debug.Log("Setting up PSMove Tracking Context"); // Initialize and configure the psmove_tracker. { PSMoveAPI.PSMoveTrackerSettings settings = new PSMoveAPI.PSMoveTrackerSettings(); PSMoveAPI.psmove_tracker_settings_set_default(ref settings); settings.color_mapping_max_age = 0; // Don't used cached color mapping file if (WorkerSettings.bUseManualExposure) { settings.exposure_mode = PSMoveTracker_Exposure.Exposure_MANUAL; settings.camera_exposure = (int)(Math.Max(Math.Min(WorkerSettings.ManualExposureValue, 1.0f), 0.0f) * 65535.0f); } else { settings.exposure_mode = PSMoveTracker_Exposure.Exposure_LOW; } settings.use_fitEllipse = 1; settings.filter_do_2d_r = 0; settings.filter_do_2d_xy = 0; settings.camera_mirror = PSMove_Bool.PSMove_True; settings.color_list_start_ind = (int)WorkerSettings.InitialTrackingColor; context.TrackerCount = 0; for (int tracker_index = 0; tracker_index < WorkerContext.MAX_TRACKER_COUNT; ++tracker_index) { context.PSMoveTrackers[tracker_index] = PSMoveAPI.psmove_tracker_new_with_camera_and_settings(tracker_index, ref settings); if (context.PSMoveTrackers[tracker_index] != IntPtr.Zero) { UnityEngine.Debug.Log(string.Format("PSMove tracker({0}) initialized.", tracker_index)); ++context.TrackerCount; PSMoveAPI.psmove_tracker_get_size( context.PSMoveTrackers[tracker_index], ref context.TrackerWidth, ref context.TrackerHeight); UnityEngine.Debug.Log(string.Format("Camera Dimensions: {0} x {1}", context.TrackerWidth, context.TrackerHeight)); } else { PSMoveTracker_ErrorCode errorCode = PSMoveAPI.psmove_tracker_get_last_error(); UnityEngine.Debug.Log(string.Format("PSMove tracker({0}) not available: {1}", tracker_index, errorCode.ToString())); break; } } if (context.TrackerCount <= 0) { UnityEngine.Debug.LogError(string.Format("Failed to open any trackers")); success = false; } } // Initialize fusion API if the tracker started if (success) { for (int tracker_index = 0; tracker_index < context.TrackerCount; ++tracker_index) { context.PSMoveFusions[tracker_index] = PSMoveAPI.psmove_fusion_new(context.PSMoveTrackers[tracker_index], 1.0f, 1000.0f); if (context.PSMoveFusions[tracker_index] != IntPtr.Zero) { UnityEngine.Debug.Log(string.Format("PSMove fusion({0}) initialized.", tracker_index)); } else { UnityEngine.Debug.LogError(string.Format("PSMove fusion({0}) failed to initialize.", tracker_index)); success = false; break; } } } // Initialize a position filter to smooth out the tracking data if (success) { context.PSMovePositionFilter = PSMoveAPI.psmove_position_filter_new(); if (context.PSMovePositionFilter != IntPtr.Zero) { UnityEngine.Debug.Log("PSMove position filter initialized."); PSMoveAPI.PSMove_3AxisVector initial_position = new PSMoveAPI.PSMove_3AxisVector() { x = 0.0f, y = 0.0f, z = 0.0f, }; PSMoveAPI.PSMovePositionFilterSettings filter_settings = new PSMoveAPI.PSMovePositionFilterSettings(); PSMoveAPI.psmove_position_filter_get_default_settings(ref filter_settings); filter_settings.filter_type = WorkerSettings.FilterType; PSMoveAPI.psmove_position_filter_init(ref filter_settings, ref initial_position, context.PSMovePositionFilter); } else { UnityEngine.Debug.LogError(string.Format("Failed to allocate PSMove Position Filter")); success = false; } } if (!success) { WorkerContextTeardownTracking(context); } return(success); }