Example #1
0
 public void DoSelectItem(object item)
 {
     if(item != null)
     {
         string tmp = NewMotionController.Name;
         NewMotionController = (MotionControllerModel)item;
         NewMotionController.Name = tmp;
         MotionControllerService mcs = new MotionControllerService();
         mcs.Initialize(NewMotionController);
     }
 }
        public void AddAvailableMotionControllers()
        {

            int count = PsMoveApi.count_connected();

            for(int i = 0; i < count; i++)
            {
                IMotionControllerService mcs = new MotionControllerService();
                MotionControllerModel mc = mcs.Initialize(i);
                mc.Name = "MC " + i;
                new MotionControllerViewModel(mc, mcs);
            }
            Refresh();
        }
Example #3
0
        public void DoRefresh()
        {
            ObservableCollection<MotionControllerModel> existingControllers = new ObservableCollection<MotionControllerModel>();
            AvailableMotionControllers.Clear();
            NewMotionController = new MotionControllerModel();
            NewMotionController.Name = null;
            NewControllersDetected = false;

            int connectedCount = PsMoveApi.count_connected();
            if(connectedCount > 0)
            {
                foreach (MotionControllerViewModel mcvw in SimpleIoc.Default.GetAllCreatedInstances<MotionControllerViewModel>())
                {
                    existingControllers.Add(mcvw.MotionController);
                }

                MotionControllerService motionControllerService = new MotionControllerService();
                for (int i = 0; i < connectedCount; i++)
                {
                    MotionControllerModel tmp = motionControllerService.Initialize(i);

                    if(existingControllers.Count > 0)
                    {
                        bool duplicate = false;
                        foreach (MotionControllerModel mcw in existingControllers)
                        {
                            if (tmp.ConnectStatus == PSMoveConnectStatus.OK)
                            {
                                if (tmp.Serial.Equals(mcw.Serial))
                                {
                                    duplicate = true;
                                    break;
                                }
                            }
                        } // end foreach
                        if (!duplicate) AvailableMotionControllers.Add(tmp);
                    }
                    else
                    {
                        if (tmp.ConnectStatus == PSMoveConnectStatus.OK)
                        {
                            AvailableMotionControllers.Add(tmp);
                        }
                    }
                } // end for
            }

            if (AvailableMotionControllers.Count > 0) NewControllersDetected = true;
        } // DoRefresh
Example #4
0
        /// <summary>
        /// Initializes a new instance of the MotionControllerViewModel class.
        /// </summary>
        public MotionControllerViewModel(MotionControllerModel mc, IMotionControllerService mcs)
        {
            if (!IsInDesignMode)
            {
                _motionController = mc;
                _motionControllerService = mcs;
                Palette = Palette.Create(new RGBColorWheel(), System.Windows.Media.Colors.Red, PaletteSchemaType.Analogous, 1);

                MotionControllerService.Initialize(MotionController);
                DoSelectColor(Palette);

                Messenger.Default.Register<AddCameraMessage>(this,
                    message =>
                    {
                        // initialize entries for newly added camera
                        if (!MotionController.Tracking.ContainsKey(message.Camera))
                        {
                            MotionController.TrackerStatus.Add(message.Camera, PSMoveTrackerStatus.NotCalibrated);
                            MotionController.Tracking.Add(message.Camera, false);
                            MotionController.RawPosition.Add(message.Camera, Float3.Zero);
                            MotionController.WorldPosition.Add(message.Camera, Float3.Zero);
                            MotionController.CameraPosition.Add(message.Camera, Float3.Zero);
                            MotionController.FusionPosition.Add(message.Camera, Float3.Zero);
                            MotionController.PositionHistory.Add(message.Camera, new Vector3[5]);
                        }
                    });

                Messenger.Default.Register<RemoveCameraMessage>(this,
                    message =>
                    {
                        // remove entries corresponding to recently removed camera
                        MotionController.TrackerStatus.Remove(message.Camera);
                        MotionController.Tracking.Remove(message.Camera);
                        MotionController.RawPosition.Remove(message.Camera);
                        MotionController.WorldPosition.Remove(message.Camera);
                        MotionController.CameraPosition.Remove(message.Camera);
                        MotionController.FusionPosition.Remove(message.Camera);
                        MotionController.PositionHistory.Remove(message.Camera);
                    });

                if (mc.Serial != null)
                {
                    // register with service locator
                    SimpleIoc.Default.Register(() => this, mc.Serial, true);
                    // notify existing cameras to add this controller
                    Messenger.Default.Send(new AddMotionControllerMessage(MotionController));
                }

                // initialize existing cameras
                foreach (CameraViewModel scvm in SimpleIoc.Default.GetAllCreatedInstances<CameraViewModel>())
                {
                    MotionController.RawPosition.Add(scvm.Camera, Float3.Zero);
                    MotionController.FusionPosition.Add(scvm.Camera, Float3.Zero);
                    MotionController.CameraPosition.Add(scvm.Camera, Float3.Zero);
                    MotionController.WorldPosition.Add(scvm.Camera, Float3.Zero);
                    MotionController.Tracking.Add(scvm.Camera, false);
                    MotionController.TrackerStatus.Add(scvm.Camera, PSMoveTrackerStatus.NotCalibrated);
                    MotionController.PositionHistory.Add(scvm.Camera, new Vector3[5]);
                }
            }
        }