public GeometryMenuItem( Game game, SpriteBatch spriteBatch, Rectangle position, GeometricPrimitive icon)
     : base(game,spriteBatch, position)
 {
     _icon = icon;
 }
Example #2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            SpriteBatchSingleton.Instance = new SpriteBatch(GraphicsDevice);

            if (Runtime.Kinects.Count != 0)
            {
                //use first Kinect
                nui = Runtime.Kinects[0];         //Initialize to do skeletal tracking
                try
                {
                    nui.Initialize(RuntimeOptions.UseSkeletalTracking);
                }
                catch (InvalidOperationException)
                {

                }
            }

            _mTracker = new MovementTracker(nui);
            View = Matrix.CreateLookAt(new Vector3(0, 0, 5f), Vector3.Zero, Vector3.Up);
            Projection = Matrix.CreatePerspectiveFieldOfView(1, GraphicsDevice.Viewport.AspectRatio, 1, 10);

            Geometry.Model model = new Geometry.Model(this);
            Components.Add(model);

            var conePrimitive = new ConePrimitive(GraphicsDevice);
            var cubePrimitive = new CubePrimitive(GraphicsDevice);
            var cylinderPrimitive = new CylinderPrimitive(GraphicsDevice);
            var spherePrimitive = new SpherePrimitive(GraphicsDevice);
            var torusPrimitive = new TorusPrimitive(GraphicsDevice);

            model.AddPrimitives
                (
                    conePrimitive,
                    cubePrimitive,
                    cylinderPrimitive,
                    spherePrimitive,
                    torusPrimitive
                );

            KinectMouse mouse = new KinectMouse(this, _mTracker, JointID.HandRight);

            Components.Add(new FrameRateCounter(this));
            _speechRecognition.AddCommand(
                /* new CommandSpeechRecognition("select cone", () =>
                                                          {
                                                              speech = "cone";
                                                              _primitive = model.GetSingletonPrimitiveInstance<ConePrimitive>();

                                                          }),
                 new CommandSpeechRecognition("select cube", () =>
                                                     {
                                                        speech = "cube";
                                                        _primitive = model.GetSingletonPrimitiveInstance<CubePrimitive>();
                                                     }),
                 new CommandSpeechRecognition("select cylinder",() =>
                                                                    {
                                                                        speech = "cylinder";
                                                                        _primitive =model.GetSingletonPrimitiveInstance<CylinderPrimitive>();
                                                                    }),
                 new CommandSpeechRecognition("select sphere", () =>
                 {
                     speech = "sphere";
                     _primitive = model.GetSingletonPrimitiveInstance<SpherePrimitive>();
                 }),*/
                /*new CommandSpeechRecognition("delete all", () =>
                                                    {
                                                        speech = "delete all"; model.ClearAll();
                                                    }),*/
                new CommandSpeechRecognition("Insert", () =>
                                                        {
                                                            if (_switchedGesture) return;
                                                         speech = "Add";
                                                        model.PrimitiveFreeze(_primitive, world, Color.Yellow);
                                                            _primitive = null;
                                                            mouse.Enable();

                                                        })
            );

            _mTracker.AddMovementHandler(MovementType.Any, 0.01f, OnSkeletonMovement, JointID.Head);
            //
            _speechRecognition.InicializeSpeechRecognize();
            _speechRecognition.Start();
            //*/

            Exiting += (s, arg) =>
                           {
                               nui.Uninitialize();
                               _speechRecognition.Stop();
                           };

            _rotateGesture = new RotateGesture(this, _mTracker);
            _translationGesture = new TranslationGesture(this, _mTracker);
            _scaleGesture = new ScaleGesture(this, _mTracker);
            _scaleGesture.Register();

            Components.Add(_translationGesture);
            //Components.Add(_rotateGesture);
            // Components.Add(_scaleGesture);
            //_rotateGesture.Register();
            _translationGesture.Register();

            int width = 120, height = 400;

            RightMenu rightMenu = new RightMenu(this, new Rectangle(graphics.PreferredBackBufferWidth - width, (graphics.PreferredBackBufferHeight - height) / 2, width, height));
            Components.Add(rightMenu);
            SkeletonTracker tracker = new SkeletonTracker(this, _mTracker);
            //Components.Add(tracker);

            KinectMouseSelection mouseSelection = new KinectMouseSelection(this);
            Components.Add(mouse);
            Components.Add(mouseSelection);

            _mTracker.OnSkeletonOnViewChange += (s, args) =>
            {
                _foundSkeleton = args.State == SkeletonOnViewType.Entered;
                if(_foundSkeleton)
                    mouse.Enable();
            };

            /*/
            var token = mouseSelection.GetMouseToken();
            _mTracker.AddMovementHandler(MovementType.Any,1f,(obj,args)=>
                                                                 {
                                                                     if (KinectMouse.MouseCoordinates.Y > 220)
                                                                     {
                                                                         mouseSelection.FeedSelection(token);
                                                                     }
                                                                     else
                                                                     {
                                                                         token = mouseSelection.GetMouseToken();
                                                                     }

                                                                     if (mouseSelection.IsSelected())
                                                                     {
                                                                         token = mouseSelection.GetMouseToken();
                                                                     }
                                                                 },
                                                                 JointID.HandRight);
            //*/
            rightMenu.OnSelectedGeometry += (state) =>
                                                {
                                                    if (state is CubePrimitive)
                                                        _primitive =
                                                            model.GetSingletonPrimitiveInstance<CubePrimitive>();
                                                    else if (state is CylinderPrimitive)
                                                        _primitive =
                                                            model.GetSingletonPrimitiveInstance<CylinderPrimitive>();
                                                    else if (state is ConePrimitive)
                                                        _primitive =
                                                            model.GetSingletonPrimitiveInstance<ConePrimitive>();
                                                    else if (state is SpherePrimitive)
                                                        _primitive =
                                                            model.GetSingletonPrimitiveInstance<SpherePrimitive>();
                                                    else
                                                    {
                                                        return;
                                                    }
                                                    mouse.Disable();
                                                };
            _currGesture = _translationGesture;

            base.Initialize();
        }