Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the AvateeringXNA class.
        /// </summary>
        public AvateeringXNA()
        {
            this.Window.Title = "Avateering";
            this.IsFixedTimeStep = false;
            this.IsMouseVisible = true;

            // Setup the graphics device for rendering
            this.graphics = new GraphicsDeviceManager(this);
            this.SetScreenMode();
            this.graphics.PreparingDeviceSettings += this.GraphicsDevicePreparingDeviceSettings;
            this.graphics.SynchronizeWithVerticalRetrace = true;

            Content.RootDirectory = "Content";

            // The Kinect sensor will use 640x480 for the color stream (default) and 320x240 for depth
            this.chooser = new KinectChooser(this, ColorImageFormat.RgbResolution640x480Fps30, DepthImageFormat.Resolution320x240Fps30);
            this.Services.AddService(typeof(KinectChooser), this.chooser);

            // Optionally set near mode for close range avateering (0.4m up to 3m)
            this.chooser.NearMode = false;

            // Optionally set seated mode for upper-body only tracking here (typically used with near mode for close to camera tracking)
            this.chooser.SeatedMode = false;

            // Adding these objects as XNA Game components enables automatic calls to the overridden LoadContent, Update, etc.. methods
            this.Components.Add(this.chooser);

            // Create a ground plane for the model to stand on
            this.planarXzGrid = new GridXz(this, new Vector3(0, 0, 0), new Vector2(500, 500), new Vector2(10, 10), Color.Black);
            this.Components.Add(this.planarXzGrid);
            this.drawGrid = true;

            this.worldAxes = new CoordinateCross(this, 500);
            this.Components.Add(this.worldAxes);

            // Create the avatar animator
            this.animator = new AvatarAnimator(this, this.RetargetMatrixHierarchyToAvatarMesh);

            this.Components.Add(this.animator);

            // Create the bag animator
            this.bagAnimator = new BagAnimator(this);
            this.Components.Add(this.bagAnimator);

            // Drawing options
            this.setSeatedPostureInSeatedMode = true;
            this.drawAvatarOnlyWhenPlayerDetected = true;
            this.skeletonDetected = false;
            this.leanAdjust = true;

            // Here we can force the avatar to be drawn at fixed height in the XNA virtual world.
            // The reason we may use this is because the sensor height above the physical floor
            // and the feet locations are not always known. Hence the avatar cannot be correctly
            // placed on the ground plane or will be very jumpy.
            // Note: this will prevent the avatar from jumping and crouching.
            this.fixAvatarHipCenterDrawHeight = true;
            this.avatarHipCenterDrawHeight = 0.8f;  // in meters

            // Setup the depth stream
            this.depthStream = new DepthStreamRenderer(this);

            // Setup the skeleton stream the same as depth stream
            this.skeletonStream = new SkeletonStreamRenderer(this, this.SkeletonToDepthMap);

            // Update Depth and Skeleton Stream size and location based on the back-buffer
            this.UpdateStreamSizeAndLocation();

            this.previousKeyboard = Keyboard.GetState();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes une nouvelle instance de la classe AvateeringXNA.
        /// </summary>
        public AvateeringXNA()
        {
            this.Window.Title = "Avateering";
            this.IsFixedTimeStep = false;
            this.IsMouseVisible = true;

            // Configure le périphérique graphique pour le rendu
            this.graphics = new GraphicsDeviceManager(this);
            this.SetScreenMode();
            this.graphics.PreparingDeviceSettings += this.GraphicsDevicePreparingDeviceSettings;
            this.graphics.SynchronizeWithVerticalRetrace = true;

            Content.RootDirectory = "Content";

            //Le capteur de la kinect utilisera 640*480 pour le flux de couleur (par défaut) et 320*240 pour la profondeur
            this.chooser = new KinectChooser(this, ColorImageFormat.RgbResolution640x480Fps30, DepthImageFormat.Resolution320x240Fps30);
            this.Services.AddService(typeof(KinectChooser), this.chooser);

            // Met Optionellement le mode de près pour vue de près (de 0.4m à 3m)
            this.chooser.NearMode = false;

            // Pour Optionnellement régler le mode assis pour le haut du corps seulement (généralement utilisé avec le mode de près de la caméra)
            this.chooser.SeatedMode = false;

            // Ajouter ces objets comme des composants de jeux XNA établit des appels automatiques aux méthodes LoadContent, Update, etc..
            this.Components.Add(this.chooser);

            // Créele plan sur lequel se tient le modèle.
            this.planarXzGrid = new GridXz(this, new Vector3(0, 0, 0), new Vector2(500, 500), new Vector2(10, 10), Color.Black);
            this.Components.Add(this.planarXzGrid);
            this.drawGrid = true;

            this.worldAxes = new CoordinateCross(this, 500);
            this.Components.Add(this.worldAxes);

            // Crée l'animateur du modèle.
            this.animator = new AvatarAnimator(this, this.RetargetMatrixHierarchyToAvatarMesh, AvateeringXNA.SkeletonTranslationScaleFactor);
            this.Components.Add(this.animator);

            // Options de dessin.
            this.setSeatedPostureInSeatedMode = true;
            this.drawAvatarOnlyWhenPlayerDetected = true;
            this.skeletonDetected = false;
            this.leanAdjust = true;

            // Ici, on peut forcer l'avatar à être dessiné à une hauteur fixe dans le monde virtuel XNA.
            // La raison pour laquelle on utilise ceci est que la hauteur par rapport au plancher n'est pas toujours connue,
            // et si l'avatar n'est pas correctement placé, il ne fera que sautiller.
            this.fixAvatarHipCenterDrawHeight = true;
            this.avatarHipCenterDrawHeight = 0.8f;  // in meters

            // Met en place le flux de profondeur.
            this.depthStream = new DepthStreamRenderer(this);

            //Pour la couleur
            this.colorStream = new ColorStreamRenderer(this);

            // Met en place le flux du squelette.
            this.skeletonStream = new SkeletonStreamRenderer(this, this.SkeletonToDepthMap);

            //Met à jour la profondeur, la taille du squelette et la location
            this.UpdateStreamSizeAndLocation();

            this.previousKeyboard = Keyboard.GetState();
        }
        /// <summary>
        /// Initializes a new instance of the AvatarAnimator class.
        /// </summary>
        /// <param name="game">The related game object.</param>
        /// <param name="retarget">The avatar mesh re-targeting method to convert from the Kinect skeleton.</param>
        public AvatarAnimator(Game game, RetargetMatrixHierarchyToAvatarMesh retarget)
            : base(game)
        {
            if (null == game)
            {
                return;
            }

            this.retargetMethod = retarget;
            this.SkeletonDrawn = true;
            this.useKinectAvateering = true;
            this.AvatarHipCenterHeight = 0;

            // Create local axes inside the model to draw at each joint
            this.localAxes = new CoordinateCross(this.Game, 2f);
            this.drawLocalAxes = false;
            game.Components.Add(this.localAxes);

            // If we draw the Kinect 3D skeleton in BoneOrientationConstraints, we can offset it from the original
            // hip center position, so as not to draw over the top of the Avatar. Offset defined in m.
            this.kinectLineSkeletonWorldOffsetMatrix = Matrix.CreateTranslation(40.0f, 0.75f * 40.0f, 0);
            this.drawBoneConstraintsSkeleton = false;

            // Skeleton fixups
            this.frameTimer = new Timer();
            this.lastNuiTime = 0;
            this.FloorClipPlane = new Tuple<float, float, float, float>(0, 0, 0, 0);
            this.clippedLegs = new SkeletonJointsFilterClippedLegs();
            this.sensorOffsetCorrection = new SkeletonJointsSensorOffsetCorrection();
            this.jointPositionFilter = new SkeletonJointsPositionDoubleExponentialFilter();
            this.boneOrientationConstraints = new BoneOrientationConstraints(game);
            this.boneOrientationFilter = new BoneOrientationDoubleExponentialFilter();

            this.filterClippedLegs = true;
            this.tiltCompensate = true;
            this.floorOffsetCompensate = false;
            this.selfIntersectionConstraints = true;
            this.mirrorView = true;
            this.boneConstraints = true;
            this.filterBoneOrientations = true;

            // For many applications we would enable the
            // automatic joint smoothing, however, in this
            // Avateering sample, we perform skeleton joint
            // position corrections, so we will manually
            // filter here after these are complete.

            // Typical smoothing parameters for the joints:
            var jointPositionSmoothParameters = new TransformSmoothParameters
            {
                Smoothing = 0.25f,
                Correction = 0.25f,
                Prediction = 0.75f,
                JitterRadius = 0.1f,
                MaxDeviationRadius = 0.04f
            };

            this.jointPositionFilter.Init(jointPositionSmoothParameters);

            // Setup the bone orientation constraint system
            this.boneOrientationConstraints.AddDefaultConstraints();
            game.Components.Add(this.boneOrientationConstraints);

            // Typical smoothing parameters for the bone orientations:
            var boneOrientationSmoothparameters = new TransformSmoothParameters
            {
                Smoothing = 0.5f,
                Correction = 0.8f,
                Prediction = 0.75f,
                JitterRadius = 0.1f,
                MaxDeviationRadius = 0.1f
            };

            this.boneOrientationFilter.Init(boneOrientationSmoothparameters);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the AvatarAnimator class.
        /// </summary>
        /// <param name="game">The related game object.</param>
        /// <param name="retarget">The avatar mesh re-targeting method to convert from the Kinect skeleton.</param>
        public AvatarAnimator(Game game, RetargetMatrixHierarchyToAvatarMesh retarget, Vector3 skeletonTranslationScaleFactor)
            : base(game)
        {
            if (null == game)
            {
                return;
            }

            this.SkeletonTranslationScaleFactor = skeletonTranslationScaleFactor;
            this.retargetMethod        = retarget;
            this.SkeletonDrawn         = true;
            this.useKinectAvateering   = true;
            this.AvatarHipCenterHeight = 0;

            // Create local axes inside the model to draw at each joint
            this.localAxes     = new CoordinateCross(this.Game, 2f);
            this.drawLocalAxes = false;
            game.Components.Add(this.localAxes);

            // If we draw the Kinect 3D skeleton in BoneOrientationConstraints, we can offset it from the original
            // hip center position, so as not to draw over the top of the Avatar. Offset defined in m.
            this.kinectLineSkeletonWorldOffsetMatrix = Matrix.CreateTranslation(this.SkeletonTranslationScaleFactor.X, 0.75f * this.SkeletonTranslationScaleFactor.Y, 0);
            this.drawBoneConstraintsSkeleton         = false;

            // Skeleton fixups
            this.frameTimer                 = new Timer();
            this.lastNuiTime                = 0;
            this.FloorClipPlane             = new Tuple <float, float, float, float>(0, 0, 0, 0);
            this.clippedLegs                = new SkeletonJointsFilterClippedLegs();
            this.sensorOffsetCorrection     = new SkeletonJointsSensorOffsetCorrection();
            this.jointPositionFilter        = new SkeletonJointsPositionDoubleExponentialFilter();
            this.boneOrientationConstraints = new BoneOrientationConstraints(game, this.SkeletonTranslationScaleFactor);
            this.boneOrientationFilter      = new BoneOrientationDoubleExponentialFilter();

            this.filterClippedLegs           = true;
            this.tiltCompensate              = true;
            this.floorOffsetCompensate       = false;
            this.selfIntersectionConstraints = true;
            this.mirrorView             = true;
            this.boneConstraints        = true;
            this.filterBoneOrientations = true;

            // For many applications we would enable the
            // automatic joint smoothing, however, in this
            // Avateering sample, we perform skeleton joint
            // position corrections, so we will manually
            // filter here after these are complete.

            // Typical smoothing parameters for the joints:
            var jointPositionSmoothParameters = new TransformSmoothParameters
            {
                Smoothing          = 0.25f,
                Correction         = 0.25f,
                Prediction         = 0.75f,
                JitterRadius       = 0.1f,
                MaxDeviationRadius = 0.04f
            };

            this.jointPositionFilter.Init(jointPositionSmoothParameters);

            // Setup the bone orientation constraint system
            this.boneOrientationConstraints.AddDefaultConstraints();
            game.Components.Add(this.boneOrientationConstraints);

            // Typical smoothing parameters for the bone orientations:
            var boneOrientationSmoothparameters = new TransformSmoothParameters
            {
                Smoothing          = 0.5f,
                Correction         = 0.8f,
                Prediction         = 0.75f,
                JitterRadius       = 0.1f,
                MaxDeviationRadius = 0.1f
            };

            this.boneOrientationFilter.Init(boneOrientationSmoothparameters);
        }
Ejemplo n.º 5
0
        /// Initializes a new instance of the AvateeringXNA class.
        public AvateeringXNA()
        {
            Window.Title = "Test1";
            IsFixedTimeStep = false;
            IsMouseVisible = true;

            //    Components.Add(new FrameRateCounter(this));  - откл. т.к. вызывает баг - меняет порядок отрисовки 3Д объектов

            // Setup the graphics device for rendering
            graphics = new GraphicsDeviceManager(this);
            presentationParameters = new PresentationParameters();
            SetScreenMode();
            graphics.PreparingDeviceSettings += GraphicsDevicePreparingDeviceSettings;
            graphics.SynchronizeWithVerticalRetrace = true;
            graphics.PreferMultiSampling = true;     // включили anti-aliasing
            graphics.SynchronizeWithVerticalRetrace = true;
              //  presentationParameters.MultiSampleCount = 4;

            Content.RootDirectory = "Content";

            // The Kinect sensor will use 640x480 for the color stream (default) and 640x480 for depth
            chooser = new KinectChooser(this, ColorImageFormat.RgbResolution640x480Fps30, DepthImageFormat.Resolution640x480Fps30);
            Services.AddService(typeof(KinectChooser), chooser);

            // Optionally set near mode for close range avateering (0.4m up to 3m)
            chooser.NearMode = true;

            // Optionally set seated mode for upper-body only tracking here (typically used with near mode for close to camera tracking)
            chooser.SeatedMode = true;

            // Adding these objects as XNA Game components enables automatic calls to the overridden LoadContent, Update, etc.. methods
            Components.Add(chooser);

            // Create a ground plane for the model to stand on
            //planarXzGrid = new GridXz(this, new Vector3(0, 0, 0), new Vector2(500, 500), new Vector2(10, 10), Color.Black);
            //Components.Add(planarXzGrid);
            //drawGrid = false;

            worldAxes = new CoordinateCross(this, 500);
            Components.Add(worldAxes);

            // Create the avatar animator
            //animator = new AvatarAnimator(this, RetargetMatrixHierarchyToAvatarMesh, AvateeringXNA.skeletonTranslationScaleFactor);
            //Components.Add(animator);

            // Drawing options

            skeletonDetected = true;

            // Setup the depth stream
            depthStream = new DepthStreamRenderer(this);

            // Setup the skeleton stream the same as depth stream
            skeletonStream = new SkeletonStreamRenderer(this, SkeletonToDepthMap);

            // Update Depth and Skeleton Stream size and location based on the back-buffer
            UpdateStreamSizeAndLocation();

            previousKeyboard = Keyboard.GetState();

            previousCollideResult2 = ContainmentType.Disjoint;

            CursorRight = new Cursor(this, "cursor_ball");

            CursorLeft = new Cursor(this, "cursor_ball");

              //  Video_box2 = new IconBoxVideo(this, "wildlife1");

              //  iconboxAudio1 = new IconBoxAudio(this, "Kalimba");

              //  iconboxPicture1 = new IconBoxPicture(this, "Lighthouse");

              //  iconboxText1 = new IconBoxText(this);

            BossPanel = new MainOperatorPanel(this);

            CurrentTask[0] = new Task(this, Task.MediaType.Audio, Task.ManagerStatus.Assigned, Task.ProgressStatus.New, Task.PresentationType.PanelIcon, "Kalimba", 12);
            CurrentTask[0].LoadContent(this);

            CurrentTask[1] = new Task(this, Task.MediaType.Video, Task.ManagerStatus.NotAssigned, Task.ProgressStatus.New, Task.PresentationType.PanelIcon, "wildlife1", 4);
            CurrentTask[1].LoadContent(this);

            CurrentTask[2] = new Task(this, Task.MediaType.Picture, Task.ManagerStatus.Finished, Task.ProgressStatus.New, Task.PresentationType.PanelIcon, "Lighthouse", 37);
            CurrentTask[2].LoadContent(this);
        }