public HitHandHandler(IUnitOfWorkFactory unit_of_work_factory,
                       HitHand dealer,
                       IRepository <BlackJackTable> blackjack_table_repository)
 {
     _unit_of_work_factory = unit_of_work_factory;
     _dealer = dealer;
     _blackjack_table_repository = blackjack_table_repository;
 }
Esempio n. 2
0
        public AppModel()
        {
            KinectManager.SensorConnected
            .Subscribe(sensor =>
            {
                sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
                sensor.DepthStream.Enable(DepthImageFormat.Resolution320x240Fps30);
                sensor.SkeletonStream.EnableWithDefaultSmoothing();

                try
                {
                    sensor.Start();
                }
                catch (Exception ex)
                {
                    // センサーが他のプロセスに既に使用されている場合に発生します。
                    Debug.WriteLine(ex);
                }
            });
            KinectManager.SensorDisconnected
            .Subscribe(sensor => sensor.Stop());
            KinectManager.Initialize();

            // フレームのデータ。
            var frameData = Observable.Interval(FramesInterval)
                            .Select(_ => new
            {
                Sensor    = KinectManager.Sensor.Value,
                ColorData = KinectManager.Sensor.Value.GetColorData(FramesInterval),
                DepthData = KinectManager.Sensor.Value.GetDepthDataInInt16(FramesInterval),
                BodyData  = KinectManager.Sensor.Value.GetSkeletonData(FramesInterval),
            })
                            .ToReadOnlyReactiveProperty(null, ReactivePropertyMode.DistinctUntilChanged);

            // ターゲットの人物。
            TargetBody = frameData
                         .Where(_ => _.BodyData != null)
                         .Select(_ => GetTargetBody(_.BodyData, TargetBody.Value))
                         .ToReadOnlyReactiveProperty(null, ReactivePropertyMode.DistinctUntilChanged);

            // ターゲットの人物が存在するかどうか。
            HasTargetBody = TargetBody
                            .Select(b => b != null)
                            .ToReadOnlyReactiveProperty();

            // ヒット ゾーン内の手。z 要素は体からの差分。
            HitHand = TargetBody
                      .Select(b => GetHitHand(b, HitHand.Value))
                      .ToReadOnlyReactiveProperty(null, ReactivePropertyMode.DistinctUntilChanged);

            // ヒット ゾーン内かどうか。
            IsHandHit = HitHand
                        .Select(_ => _.HasValue)
                        .ToReadOnlyReactiveProperty();

            AreHandsAbove = TargetBody.Select(GetAreHandsAbove).ToReadOnlyReactiveProperty();
            IsSquat       = TargetBody.Select(GetIsSquat).ToReadOnlyReactiveProperty();
            IsJumping     = TargetBody.Select(GetIsJumping).ToReadOnlyReactiveProperty();

            BodyOrientation = TargetBody.Select(GetBodyOrientation).ToReadOnlyReactiveProperty();
            IsLeftOriented  = BodyOrientation.Select(x => x < -0.35).ToReadOnlyReactiveProperty();
            IsRightOriented = BodyOrientation.Select(x => x > 0.35).ToReadOnlyReactiveProperty();

            JawLower = TargetBody
                       .Select(body =>
            {
                if (body == null)
                {
                    return(0);
                }

                var data = frameData.Value;
                if (data.ColorData == null || data.DepthData == null || data.BodyData == null)
                {
                    return(0);
                }

                if (faceTracker == null)
                {
                    faceTracker = new FaceTracker(data.Sensor);
                }

                var faceFrame = faceTracker.Track(data.Sensor.ColorStream.Format, data.ColorData, data.Sensor.DepthStream.Format, data.DepthData, body);
                if (!faceFrame.TrackSuccessful)
                {
                    return(0);
                }

                var animationUnits = faceFrame.GetAnimationUnitCoefficients();
                return(animationUnits[AnimationUnit.JawLower]);
            })
                       .ToReadOnlyReactiveProperty();
            IsMouthOpen = JawLower.Select(x => x > 0.35).ToReadOnlyReactiveProperty();
        }