Exemplo 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);
        }