/// <summary> /// Resolves the dependencies needed for this instance to work. /// </summary> protected override void ResolveDependencies() { base.ResolveDependencies(); this.kinectService = WaveServices.GetService <KinectService>(); this.colorFactorX = 1; this.colorFactorY = 1; this.depthFactorX = 1; this.depthFactorY = 1; ////if (this.kinectService != null) ////{ //// if (WaveServices.ViewportManager != null && WaveServices.ViewportManager.IsActivated) //// { //// this.colorFactorX = (float)WaveServices.ViewportManager.VirtualWidth / (float)this.kinectService.ColorTexture.Width; //// this.colorFactorY = (float)WaveServices.ViewportManager.VirtualHeight / (float)this.kinectService.ColorTexture.Height; //// this.depthFactorX = (float)WaveServices.ViewportManager.VirtualWidth / (float)this.kinectService.DepthTexture.Width; //// this.depthFactorY = (float)WaveServices.ViewportManager.VirtualHeight / (float)this.kinectService.DepthTexture.Height; //// } //// else //// { //// this.colorFactorX = (float)WaveServices.Platform.ScreenWidth / (float)this.kinectService.ColorTexture.Width; //// this.colorFactorY = (float)WaveServices.Platform.ScreenHeight / (float)this.kinectService.ColorTexture.Height; //// this.depthFactorX = (float)WaveServices.Platform.ScreenWidth / (float)this.kinectService.DepthTexture.Width; //// this.depthFactorY = (float)WaveServices.Platform.ScreenHeight / (float)this.kinectService.DepthTexture.Height; //// } ////} this.DrawPoints2DProjected = new List <Vector2>(); this.DrawPoints3D = new List <Vector3>(); this.DrawLines = new List <Line>(); this.DrawOrientations = new List <Line>(); }
/// <summary> /// Performs further custom initialization for this instance. /// </summary> /// <remarks> /// By default this method does nothing. /// </remarks> protected override void Initialize() { base.Initialize(); this.kinectService = WaveServices.GetService <KinectService>(); this.outPosition = new Vector2(-500, -500); }
public void CheckNoSkeleton() { Skeleton[] skeletons = new Microsoft.Kinect.Skeleton[2]; skeletons[0] = new Skeleton(); skeletons[1] = new Skeleton(); Skeleton skeleton = KinectService.GetPrimarySkeleton(skeletons); Assert.IsNull(skeleton); }
public void CheckNoKinectExceptionHandlingText() { KinectService s = new KinectService(); s.Initialize(); string message = "Proszę podłączyć Kinect"; Assert.AreEqual(message, s.ErrorGridMessage); }
/// <summary> /// Resolves the dependencies needed for this instance to work. /// </summary> protected override void ResolveDependencies() { base.ResolveDependencies(); this.kinectService = WaveServices.GetService <KinectService>(); this.DrawPoints2DProjected = new List <Vector2>(); this.DrawPoints3D = new List <Vector3>(); this.DrawLines = new List <Line>(); this.DrawOrientations = new List <Line>(); }
public override void Initialize(IApplication application) { base.Initialize(application); // Register KinectServices var kinectService = new KinectService(); WaveServices.RegisterService(kinectService); kinectService.StartSensor(KinectSources.Color | KinectSources.Body);//| KinectSources.Face); ScreenContext screenContext = new ScreenContext(new MyScene()); WaveServices.ScreenContextManager.To(screenContext); }
public override void Initialize(IApplication application) { base.Initialize(application); // Register KinectServices var kinectService = new KinectService(); WaveServices.RegisterService(kinectService); kinectService.StartSensor(KinectSources.Color | KinectSources.Body | KinectSources.Face); ScreenContext screenContext = new ScreenContext(new MyScene()); WaveServices.ScreenContextManager.To(screenContext); }
public void GetDistanceBetweenJoinPoints() { var leftJoint = new Point(0, 0); var rightJoint = new Point(SystemParameters.PrimaryScreenWidth, 0); var distanceFull = KinectService.CalculateDistanceBetweenJoints(rightJoint, leftJoint); var distanceFull2 = KinectService.CalculateDistanceBetweenJoints(rightJoint, leftJoint); var distanceZero = KinectService.CalculateDistanceBetweenJoints(leftJoint, leftJoint); Assert.AreNotEqual(new Point(0, 0), distanceFull); Assert.AreNotEqual(new Point(0, 0), distanceFull2); Assert.AreEqual(distanceFull2, distanceFull); Assert.AreEqual(new Point(0, 0), distanceZero); }
/// <summary> /// Creates the skeleton model. /// </summary> /// <param name="skeleton">The skeleton.</param> /// <param name="brush">Brush.</param> /// <param name="joints">Joints to create skeleton model from.</param> /// <param name="sensor">The sensor.</param> /// <param name="width">The width of the canvas.</param> /// <param name="height">The height of the canvas.</param> /// <returns>Skeleton model as a polyline</returns> private Polyline CreateFigure(Skeleton skeleton, Brush brush, IEnumerable <JointType> joints , KinectSensor sensor, double width, double height) { var figure = new Polyline { StrokeThickness = 8, Stroke = brush }; foreach (var joint in joints) { var jointPoint = KinectService.GetJointPoint(skeleton.Joints[joint], sensor, width, height); figure.Points.Add(new Point(jointPoint.X, jointPoint.Y)); } return(figure); }
/// <summary> /// Set position for part of set /// </summary> /// <param name="skeleton">Recognised skeleton</param> /// <param name="sensor">Kinect sensor</param> /// <param name="width">Kinect image width</param> /// <param name="height">Kinect image height</param> private void TrackSkeletonParts(Skeleton skeleton, KinectSensor sensor, double width, double height) { Angle = TrackJointsRotation(sensor, skeleton.Joints[LeftJointToTrackAngle], skeleton.Joints[RightJointToTrackAngle]); var joint = KinectService.GetJointPoint(skeleton.Joints[JointToTrackPosition], sensor, width, height); var point3D = Point2DtoPoint3D(new Point(joint.X, joint.Y * DeltaPosition)); FitModelToBody(skeleton.Joints[LeftJointToTrackScale], skeleton.Joints[RightJointToTrackScale], sensor, width, height); var transform = new Transform3DGroup(); transform.Children.Add(ScaleTransformation); transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), Angle))); transform.Children.Add(new TranslateTransform3D(point3D.X, point3D.Y, point3D.Z)); Model.Transform = transform; }
/// <summary> /// Fit width of model to width of body /// </summary> /// <param name="joint1">The first joint.</param> /// <param name="joint2">The second joint.</param> /// <param name="sensor">The sensor.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> private void FitModelToBody(Joint joint1, Joint joint2, KinectSensor sensor, double width, double height) { if (joint1.TrackingState == JointTrackingState.NotTracked || joint2.TrackingState == JointTrackingState.NotTracked) { return; } var joint1Position = KinectService.GetJointPoint(joint1, sensor, width, height); var joint2Position = KinectService.GetJointPoint(joint2, sensor, width, height); var location = _basicBounds.Location; Point leftBound = Point3DtoPoint2D(location); Point rightBound = Point3DtoPoint2D(new Point3D(location.X + _basicBounds.SizeX, location.Y + _basicBounds.SizeY , location.Z + _basicBounds.SizeZ)); double ratio = (Math.Abs(joint1Position.Y - joint2Position.Y) / Math.Abs(leftBound.Y - rightBound.Y)); _widthModelScale = _heightModelScale = ratio * Tolerance; SetScaleTransformation(); }
/// <summary> /// Resolves the dependencies needed for this instance to work. /// </summary> protected override void ResolveDependencies() { base.ResolveDependencies(); this.kinectService = WaveServices.GetService<KinectService>(); this.colorFactorX = 1; this.colorFactorY = 1; this.depthFactorX = 1; this.depthFactorY = 1; ////if (this.kinectService != null) ////{ //// if (WaveServices.ViewportManager != null && WaveServices.ViewportManager.IsActivated) //// { //// this.colorFactorX = (float)WaveServices.ViewportManager.VirtualWidth / (float)this.kinectService.ColorTexture.Width; //// this.colorFactorY = (float)WaveServices.ViewportManager.VirtualHeight / (float)this.kinectService.ColorTexture.Height; //// this.depthFactorX = (float)WaveServices.ViewportManager.VirtualWidth / (float)this.kinectService.DepthTexture.Width; //// this.depthFactorY = (float)WaveServices.ViewportManager.VirtualHeight / (float)this.kinectService.DepthTexture.Height; //// } //// else //// { //// this.colorFactorX = (float)WaveServices.Platform.ScreenWidth / (float)this.kinectService.ColorTexture.Width; //// this.colorFactorY = (float)WaveServices.Platform.ScreenHeight / (float)this.kinectService.ColorTexture.Height; //// this.depthFactorX = (float)WaveServices.Platform.ScreenWidth / (float)this.kinectService.DepthTexture.Width; //// this.depthFactorY = (float)WaveServices.Platform.ScreenHeight / (float)this.kinectService.DepthTexture.Height; //// } ////} this.DrawPoints2DProjected = new List<Vector2>(); this.DrawPoints3D = new List<Vector3>(); this.DrawLines = new List<Line>(); this.DrawOrientations = new List<Line>(); }
/// <summary> /// Creates the scene. /// </summary> /// <remarks> /// This method is called before all /// <see cref="T:WaveEngine.Framework.Entity" /> instances in this instance are initialized. /// </remarks> protected override void CreateScene() { // Services this.kinectService = WaveServices.GetService <KinectService>(); // Scene Behaviors this.AddSceneBehavior(new GameSceneBehavior(), SceneBehavior.Order.PostUpdate); // Create a 2D camera var camera2D = new FixedCamera2D("Camera2D") { ClearFlags = ClearFlags.DepthAndStencil }; // Transparent background need this clearFlags. this.EntityManager.Add(camera2D); // Initializes Players this.Players = new Player[this.kinectService.BodyCount]; for (var i = 0; i < this.Players.Length; i++) { this.Players[i] = new Player(this) { PlayerBody = this.kinectService.Bodies[i] }; } // Initializes Smoke Emitters this.explosionEmitterCollection = new ExplosionEmitter[10]; for (int i = 0; i < this.explosionEmitterCollection.Length; i++) { this.explosionEmitterCollection[i] = new ExplosionEmitter(); this.EntityManager.Add(this.explosionEmitterCollection[i]); } // Timer this.TimeCounter = new TimeCounter(); this.EntityManager.Add(this.TimeCounter); this.TimeCounter.CountDownBehavior.Start(); // Points this.PointsCounter = new PointsCounter(); this.EntityManager.Add(this.PointsCounter); this.PointsCounter.PointCounterBehavior.ResetPoints(); // Falling Things Initializer!!! this.fallingBodies = new List <FallingBody>(); int createdBodies = 0; Timer timer = null; timer = WaveServices.TimerFactory.CreateTimer( "CreateBallTimer", TimeSpan.FromSeconds(2f), () => { // Calculates the next interval to drop a falling body. timer.Interval = TimeSpan.FromSeconds(WaveServices.Random.NextDouble()); // Calculates the X position var fallingX = WaveServices.Random.Next((int)WaveServices.ViewportManager.LeftEdge + this.margin, (int)WaveServices.ViewportManager.RightEdge - this.margin); // Gets the first free body in pool var fallingBody = this.fallingBodies.FirstOrDefault(fb => !fb.IsInUse); // If there are not any free body we'll create one if (fallingBody == null) { fallingBody = new FallingBody(fallingX, 1, createdBodies++); this.EntityManager.Add(fallingBody); this.fallingBodies.Add(fallingBody); } // Fall!!! I Command!!! fallingBody.Fall(fallingX); }); }
/// <summary> /// Creates the scene. /// </summary> /// <remarks> /// This method is called before all /// <see cref="T:WaveEngine.Framework.Entity" /> instances in this instance are initialized. /// </remarks> protected override void CreateScene() { // Services this.kinectService = WaveServices.GetService<KinectService>(); // Scene Behaviors this.AddSceneBehavior(new GameSceneBehavior(), SceneBehavior.Order.PostUpdate); // Create a 2D camera var camera2D = new FixedCamera2D("Camera2D") { ClearFlags = ClearFlags.DepthAndStencil }; // Transparent background need this clearFlags. this.EntityManager.Add(camera2D); // Initializes Players this.Players = new Player[this.kinectService.BodyCount]; for (var i = 0; i < this.Players.Length; i++) { this.Players[i] = new Player(this) { PlayerBody = this.kinectService.Bodies[i] }; } // Initializes Smoke Emitters this.explosionEmitterCollection = new ExplosionEmitter[10]; for (int i = 0; i < this.explosionEmitterCollection.Length; i++) { this.explosionEmitterCollection[i] = new ExplosionEmitter(); this.EntityManager.Add(this.explosionEmitterCollection[i]); } // Timer this.TimeCounter = new TimeCounter(); this.EntityManager.Add(this.TimeCounter); this.TimeCounter.CountDownBehavior.Start(); // Points this.PointsCounter = new PointsCounter(); this.EntityManager.Add(this.PointsCounter); this.PointsCounter.PointCounterBehavior.ResetPoints(); // Falling Things Initializer!!! this.fallingBodies = new List<FallingBody>(); int createdBodies = 0; Timer timer = null; timer = WaveServices.TimerFactory.CreateTimer( "CreateBallTimer", TimeSpan.FromSeconds(2f), () => { // Calculates the next interval to drop a falling body. timer.Interval = TimeSpan.FromSeconds(WaveServices.Random.NextDouble()); // Calculates the X position var fallingX = WaveServices.Random.Next((int)WaveServices.ViewportManager.LeftEdge + this.margin, (int)WaveServices.ViewportManager.RightEdge - this.margin); // Gets the first free body in pool var fallingBody = this.fallingBodies.FirstOrDefault(fb => !fb.IsInUse); // If there are not any free body we'll create one if (fallingBody == null) { fallingBody = new FallingBody(fallingX, 1, createdBodies++); this.EntityManager.Add(fallingBody); this.fallingBodies.Add(fallingBody); } // Fall!!! I Command!!! fallingBody.Fall(fallingX); }); }
/// <summary> /// Resolves the dependencies needed for this instance to work. /// </summary> protected override void ResolveDependencies() { base.ResolveDependencies(); this.kinectService = WaveServices.GetService <KinectService>(); }
/// <summary> /// Performs further custom initialization for this instance. /// </summary> /// <remarks> /// By default this method does nothing. /// </remarks> protected override void Initialize() { base.Initialize(); this.kinectService = WaveServices.GetService <KinectService>(); }
/// <summary> /// Performs further custom initialization for this instance. /// </summary> /// <remarks> /// By default this method does nothing. /// </remarks> protected override void Initialize() { base.Initialize(); this.kinectService = WaveServices.GetService<KinectService>(); }
/// <summary> /// Initializes a new instance of the <see cref="KinectViewModelLoader"/> class. /// </summary> public KinectViewModelLoader() { _kinectService = new KinectService(); _kinectService.Initialize(); }
/// <summary> /// Performs further custom initialization for this instance. /// </summary> /// <remarks> /// By default this method does nothing. /// </remarks> protected override void Initialize() { base.Initialize(); this.kinectService = WaveServices.GetService<KinectService>(); this.outPosition = new Vector2(-500, -500); }
/// <summary> /// Resolves the dependencies needed for this instance to work. /// </summary> protected override void ResolveDependencies() { this.kinectService = WaveServices.GetService<KinectService>(); }