psmove_tracker_settings_set_default() private method

private psmove_tracker_settings_set_default ( PSMoveTrackerSettings &settings ) : void
settings PSMoveTrackerSettings
return void
Ejemplo n.º 1
0
        private static bool WorkerContextSetupTracking(
            PSMoveWorkerSettings WorkerSettings,
            WorkerContext context)
        {
            bool success = true;

            // Clear out the tracking state
            // Reset the shared worker data
            context.Reset();

            Debug.WriteLine("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.camera_mirror        = PSMove_Bool.PSMove_True;
                settings.color_list_start_ind = (int)WorkerSettings.InitialTrackingColor;
                context.PSMoveTracker         = PSMoveAPI.psmove_tracker_new_with_settings(ref settings);
            }

            if (context.PSMoveTracker != IntPtr.Zero)
            {
                Debug.WriteLine("PSMove tracker initialized.");

                PSMoveAPI.PSMoveTrackerSmoothingSettings smoothing_settings = new PSMoveAPI.PSMoveTrackerSmoothingSettings();
                PSMoveAPI.psmove_tracker_get_smoothing_settings(context.PSMoveTracker, ref smoothing_settings);
                smoothing_settings.filter_do_2d_r  = 0;
                smoothing_settings.filter_do_2d_xy = 0;
                smoothing_settings.filter_3d_type  = WorkerSettings.Filter3DType;
                PSMoveAPI.psmove_tracker_set_smoothing_settings(context.PSMoveTracker, ref smoothing_settings);

                PSMoveAPI.psmove_tracker_get_size(context.PSMoveTracker, ref context.TrackerWidth, ref context.TrackerHeight);
                Debug.WriteLine("Camera Dimensions: {0} x {1}", context.TrackerWidth, context.TrackerHeight);
            }
            else
            {
                PSMoveTracker_ErrorCode errorCode = PSMoveAPI.psmove_tracker_get_last_error();

                Debug.WriteLine("PSMove tracker failed to initialize: {0}", errorCode.ToString());
                success = false;
            }

            // Initialize fusion API if the tracker started
            if (success)
            {
                context.PSMoveFusion = PSMoveAPI.psmove_fusion_new(context.PSMoveTracker, 1.0f, 1000.0f);

                if (context.PSMoveFusion != IntPtr.Zero)
                {
                    Debug.WriteLine("PSMove fusion initialized.");
                }
                else
                {
                    Debug.WriteLine("PSMove failed to initialize.");
                    success = false;
                }
            }

            if (!success)
            {
                WorkerContextTeardownTracking(context);
            }

            return(success);
        }
Ejemplo n.º 2
0
    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);
    }