private static void Init() { sInitialised = true; sLeftHand = Nui.joint(Nui.Hand_Left); sRightHand = Nui.joint(Nui.Hand_Right); sLeftElbow = Nui.joint(Nui.Elbow_Left); sRightElbow = Nui.joint(Nui.Elbow_Right); sLeftShoulder = Nui.joint(Nui.Shoulder_Left); sRightShoulder = Nui.joint(Nui.Shoulder_Right); sLeftHip = Nui.joint(Nui.Hip_Left); sRightHip = Nui.joint(Nui.Hip_Right); sLeftKnee = Nui.joint(Nui.Knee_Left); sRightKnee = Nui.joint(Nui.Knee_Right); sLeftAnkle = Nui.joint(Nui.Ankle_Left); sRightAnkle = Nui.joint(Nui.Ankle_Right); sLeftFoot = Nui.joint(Nui.Foot_Left); sRightFoot = Nui.joint(Nui.Foot_Right); sCentreHip = Nui.joint(Nui.Hip_Centre); sCentreShoulder = Nui.joint(Nui.Shoulder_Centre); sHead = Nui.joint(Nui.Head); Nui.SkeletonSwitched += new SkeletonTrackDelegate(Nui_SkeletonSwitched); Nui.SkeletonLost += new SkeletonTrackDelegate(Nui_SkeletonLost); Nui.Tick += new ChangeDelegate(Nui_Tick); }
public KinectImageStream(Nui.NuiImageType type, Nui.NuiImageResolution resolution, IntPtr waitHandle):base(1000) { Nui.Import.NuiImageStreamOpen(type, resolution , 0, 2, waitHandle, out _phStreamHandle); switch (resolution) { case NuiImageResolution.resolution1280x1024: _width = 1280; _height = 1024; break; case NuiImageResolution.resolution320x240: _width = 320; _height = 240; break; case NuiImageResolution.resolution640x480: _width = 640; _height = 480; break; case NuiImageResolution.resolution80x60: _width = 80; _height = 60; break; default: break; } }
public RaiseArmTrigger(XmlNode node) { mHeightThreshold = Nui.magnitude(Nui.joint(Nui.Shoulder_Centre) - Nui.joint(Nui.Hip_Centre)); mAngleThreshold = Scalar.Create(.48f); mDepthThreshold = Scalar.Create(GetFloat(node, 3.6f, "DepthThreshold")); mWidthThreshold = Scalar.Create(GetFloat(node, 1f, "WidthThreshold")); mBody = Nui.joint(Nui.Hip_Centre); Condition inWidth = Nui.abs(Nui.x(Nui.joint(Nui.Hip_Centre))) < mWidthThreshold; Condition inDepth = Nui.z(Nui.joint(Nui.Hip_Centre)) < mDepthThreshold; Condition inRange = C.And(inWidth, inDepth); Vector up = Vector.Create(0f, 1f, 0f); mArmR = Nui.joint(Nui.Hand_Right) - Nui.joint(Nui.Shoulder_Right); mArmL = Nui.joint(Nui.Hand_Left) - Nui.joint(Nui.Shoulder_Left); mAngleR = Nui.dot(up, mArmR); mAngleL = Nui.dot(up, mArmL); mTriggerR = C.And(Nui.y(mArmR) > mHeightThreshold, mAngleR > mAngleThreshold); mTriggerL = C.And(Nui.y(mArmL) > mHeightThreshold, mAngleL > mAngleThreshold); mTrigger = C.And(C.Or(mTriggerR, mTriggerL), inRange); mTrigger.OnChange += new ChangeDelegate(mTrigger_OnChange); }
/// <summary> /// Will be called from constructor. To re-set up after setting up constructor variables call again. /// </summary> protected void Init() { mCross = Nui.cross(A, B); mRaw = Nui.acos(Nui.dot(Nui.normalize(A), Nui.normalize(B))); //mRaw = dot * Sign * (180f / (float)Math.PI); //mRaw = Nui.acos(Nui.dot(A, B)) * (180f / (float) Math.PI); //mValue = Nui.ifScalar(Active, mRaw, 0f); }
private void Init() { //mX = mConstrainedX * (float)mManager.Monitor.Bounds.Width; //mY = (float) mManager.Monitor.Bounds.Height - (mConstrainedY * (float)mManager.Monitor.Bounds.Height); mX = Nui.ifScalar(C.And(mOnScreenConditionLeft, !mOnScreenConditionRight), mConstrainedXLeft, mConstrainedXRight); mY = 1f - Nui.ifScalar(C.And(mOnScreenConditionLeft, !mOnScreenConditionRight), mConstrainedYLeft, mConstrainedYRight); //mY = 1f - mConstrainedYRight; }
private void OnGetScreenList(List <Screen> screenList) { this.Screens = screenList; Logger.Debug($"received {screenList.Count} screens"); Nui.SendMessage(Events.GetScreenList, screenList); }
private void OnDeleteScreen(string screenName) { Nui.SendMessage(Events.DeleteScreen, screenName); var eventArgs = new ScreenDeletedEventArgs() { ScreenName = screenName }; this.OnScreenDeleted(eventArgs); }
public KinectSensor() { Nui.NuiInitialize(Nui.NuiInitializeFlags.UsesColor | Nui.NuiInitializeFlags.UsesDepthAndPlayerIndex | Nui.NuiInitializeFlags.UsesSkeleton); _initialized = true; Int32 angle; Nui.NuiCameraElevationGetAngle(out angle); _angle = angle; }
public CrouchAxis(AxisBinding binding) : base("Crouch", binding) { Scalar hip = Nui.y(Nui.joint(Nui.Hip_Centre)); Scalar feet = Nui.y((Nui.joint(Nui.Ankle_Left) + Nui.joint(Nui.Ankle_Right))) / 2f; //How far pushing forward Scalar raw = feet - hip; Scalar anchor = Nui.smooth(Nui.magnitude(Nui.joint(Nui.Shoulder_Centre) - Nui.joint(Nui.Hip_Centre)), 50); mRaw = (anchor * 3) + raw; mRaw *= -1f; }
protected async void OnNuiCharacterDelete(dynamic id, CallbackDelegate callback) { Guid deletedId = await Server.Event(RpcEvents.CharacterDelete) .Attach(new Guid(id.ToString())) .Request <Guid>(); Character character = Client.Instance.Controllers.First <CharacterController>().Characters.First(c => c.Id == deletedId); Client.Instance.Controllers.First <CharacterController>().Characters.Remove(character); Nui.Send("characters", Client.Instance.Controllers.First <CharacterController>().Characters); await Show(); callback("ok"); }
public static bool Init() { //From a merge between master and working //Nui.Init(); //Nui.SetAutoPoll(true); if (mInit) { return(true); } int attempt = 1; int wait = mConfig.InitialRetryWait; while (!Nui.Init()) { if (attempt > mConfig.RetryAttempts) { return(false); } LogManager.GetLogger("Kinect").Warn(String.Format("NuiLib unable to initialise Kinect after attempt {0}. Waiting {1}s and retrying.", attempt, (wait / 1000))); Thread.Sleep(wait); attempt++; float newWait = wait * mConfig.RetryWaitMultiplier; wait = (int)newWait; } Nui.SetAutoPoll(true); mInit = true; Vector hipR = Nui.joint(Nui.Hip_Right); Vector handR = Nui.joint(Nui.Hand_Right); Vector handL = Nui.joint(Nui.Hand_Left); Condition heightThresholdR = Nui.y(handR) > Nui.y(hipR); Condition heightThresholdL = Nui.y(handL) > Nui.y(hipR); Condition heightThreshold = C.Or(heightThresholdL, heightThresholdR); Scalar dist = Nui.magnitude(Nui.joint(Nui.Shoulder_Centre) - Nui.joint(Nui.Hip_Centre)); Condition distanceThresholdR = Nui.x(handR - Nui.joint(Nui.Hip_Right)) > dist; Condition distanceThresholdL = Nui.x(Nui.joint(Nui.Hip_Left) - handL) > dist; //Condition distanceThresholdR = Nui.magnitude(handR - hipR) > dist; //Condition distanceThresholdL = Nui.magnitude(hipL - handL) > dist; Condition distanceThreshold = C.Or(distanceThresholdL, distanceThresholdR); sActiveConditionR = C.Or(heightThresholdR, distanceThresholdR); sActiveConditionL = C.Or(heightThresholdL, distanceThresholdL); return(true); }
private void Nui_Tick() { Image oldFrame = null; BeginInvoke(new Action(() => oldFrame = frameImage.Image)); if (mEnabled) { Bitmap frame = mDepth ? Nui.DepthFrame : Nui.ColourFrame; Func <Vector, Point> toP = v => { Point p = mDepth ? Nui.SkeletonToDepth(v) : Nui.SkeletonToColour(v); return(new Point(p.X - R, p.Y - R)); }; if (Nui.HasSkeleton) { using (Graphics g = Graphics.FromImage(frame)) { using (Pen p = new Pen(Color.Red, R / 2)) { g.DrawEllipse(p, new Rectangle(toP(mHead), mSize)); g.DrawEllipse(p, new Rectangle(toP(mHandL), mSize)); g.DrawEllipse(p, new Rectangle(toP(mHandR), mSize)); g.DrawEllipse(p, new Rectangle(toP(mWristL), mSize)); g.DrawEllipse(p, new Rectangle(toP(mWristR), mSize)); g.DrawEllipse(p, new Rectangle(toP(mElbowL), mSize)); g.DrawEllipse(p, new Rectangle(toP(mElbowL), mSize)); g.DrawEllipse(p, new Rectangle(toP(mShoulderL), mSize)); g.DrawEllipse(p, new Rectangle(toP(mShoulderR), mSize)); g.DrawEllipse(p, new Rectangle(toP(mShoulderC), mSize)); g.DrawEllipse(p, new Rectangle(toP(mHipC), mSize)); g.DrawEllipse(p, new Rectangle(toP(mHipL), mSize)); g.DrawEllipse(p, new Rectangle(toP(mHipR), mSize)); g.DrawEllipse(p, new Rectangle(toP(mKneeL), mSize)); g.DrawEllipse(p, new Rectangle(toP(mKneeR), mSize)); g.DrawEllipse(p, new Rectangle(toP(mAnkleL), mSize)); g.DrawEllipse(p, new Rectangle(toP(mAnkleR), mSize)); g.DrawEllipse(p, new Rectangle(toP(mFootL), mSize)); g.DrawEllipse(p, new Rectangle(toP(mFootR), mSize)); } } } BeginInvoke(new Action(() => { frameImage.Image = frame; if (oldFrame != null) { oldFrame.Dispose(); } })); } }
public CharacterSelectScreen() { // Events Client.Instance.OnClientReady += (sender, args) => Nui.Send("client", args.Information); Client.Instance.OnUserLoaded += (sender, args) => Nui.Send("user", args.User); Client.Instance.OnCharactersList += (sender, args) => Nui.Send("characters", args.Characters); Client.Instance.OnCharactersList += OnCharactersList; // NUI events Nui.RegisterCallback("rules-agreed", OnNuiRulesAgreed); Nui.RegisterCallback("character-create", OnNuiCharacterCreate); Nui.RegisterCallback("character-load", OnNuiCharacterLoad); Nui.RegisterCallback("character-delete", OnNuiCharacterDelete); Nui.RegisterCallback("disconnect", OnNuiDisconnect); }
public TAxis(bool right, AxisBinding binding) : base((right ? "T-Right" : "T-Left"), binding, Perspective.Z) { mRight = right; Vector h = Nui.joint(mRight ? Nui.Hand_Right : Nui.Hand_Left); Vector s = Nui.joint(mRight ? Nui.Shoulder_Right : Nui.Shoulder_Left); mB = h - s; mActive = C.And(mRight ? G.ActiveR : G.ActiveL, Nui.abs(Nui.x(B)) > Nui.abs(Nui.z(B)) * 2f); mB = Nui.limit(mB, true, true, false); Init(); }
public override async Task Show() { if (this.Visible) { return; } // HUD Client.Instance.Managers.First <HudManager>().Visible = false; API.SetNuiFocus(true, true); // Show Nui.Send("element:inventory:show"); this.Visible = true; }
public EyeTrackerPlugin() { EyeTrackerConfig cfg = new EyeTrackerConfig(); mOrientationChangeHandler = new EventHandler(mKinectOrientation_Changed); mKinectPosition = cfg.Position; mKinectOrientation = new Rotation(cfg.Pitch, cfg.Yaw); mControlX = cfg.ControlX; mKinectOrientation.Changed += new EventHandler(mKinectOrientation_Changed); Nui.SkeletonLost += new SkeletonTrackDelegate(Nui_SkeletonLost); mHead = Nui.joint(Nui.Head); mHead.OnChange += new ChangeDelegate(mHead_OnChange); }
void GestureDone(object sender, Nui.NuiEventArgs e) { var tr = transitions_.Transitions.Where((x) => x.Gesture == e.Gesture).First(); switch (tr.Method) { case TransitionMethod.NextSlide: win_.View.Next(); break; case TransitionMethod.PreviousSlide: win_.View.Previous(); break; case TransitionMethod.TargetSlide: win_.View.GotoSlide(tr.TargetSlide.SlideIndex); break; } }
public SimpleKinectCursor() { GlobalConditions.Init(); mTickListener = new ChangeDelegate(Nui_Tick); mSmoothingFactor = Scalar.Create(mConfig.CursorSmoothing); /* * mHandR = test ? Vector.Create("HandR", 0f, 0f, 0f) : Nui.smooth(Nui.joint(Nui.Hand_Right), mSmoothingFactor); * mHandL = test ? Vector.Create("HandL", 0f, 0f, 0f) : Nui.smooth(Nui.joint(Nui.Hand_Left), HAND_SMOOTHING_FRAMES); * mAnchor = test ? Vector.Create("Anchor", 0f, 0f, 0f) : Nui.smooth(Nui.joint(Nui.Hip_Centre), ANCHOR_SMOOTHING_FRAMES); */ mHandR = Nui.smooth(Nui.joint(Nui.Hand_Right), mSmoothingFactor); mHandL = Nui.smooth(Nui.joint(Nui.Hand_Left), mSmoothingFactor); mAnchor = Nui.smooth(Nui.joint(Nui.Hip_Centre), ANCHOR_SMOOTHING_FRAMES); mLeftShift = Scalar.Create("Left Shift", .0f); mUpShift = Scalar.Create("Up Shift", .0f); mWidth = Scalar.Create("Width", .5f); mHeight = Scalar.Create("Height", .5f); //mWidth = headShoulderDiff * mWidthScale; //mHeight = headShoulderDiff * mHeightScale; mTopLeftX = Nui.x(mAnchor) - (mWidth * mLeftShift); mTopLeftY = Nui.y(mAnchor) + (mHeight * mUpShift); mRawXRight = Nui.x(mHandR) - mTopLeftX; mRawYRight = Nui.y(mHandR) - mTopLeftY; Condition xActiveRight = C.And(mRawXRight >= 0f, mRawXRight <= mWidth); Condition yActiveRight = C.And(mRawYRight >= 0f, mRawYRight <= mHeight); mConstrainedXRight = Nui.constrain(mRawXRight, .01f, mWidth, .10f, false); mConstrainedYRight = Nui.constrain(mRawYRight, .01f, mHeight, .10f, false); mOnScreenConditionRight = C.And(xActiveRight, yActiveRight); mLeftHandShift = Scalar.Create("LeftHandShift", .5f); mRawXLeft = (Nui.x(mHandL) + mLeftHandShift) - mTopLeftX; mRawYLeft = Nui.y(mHandL) - mTopLeftY; Condition xActiveLeft = C.And(mRawXLeft >= 0f, mRawXLeft <= mWidth); Condition yActiveLeft = C.And(mRawYLeft >= 0f, mRawYLeft <= mHeight); mConstrainedXLeft = Nui.constrain(mRawXLeft, .01f, mWidth, .10f, false); mConstrainedYLeft = Nui.constrain(mRawYLeft, .01f, mHeight, .10f, false); mOnScreenConditionLeft = C.And(xActiveLeft, yActiveLeft); }
public override async Task Hide() { if (!this.Visible) { return; } Client.Log("Inventory Hide called!"); // HUD Client.Instance.Managers.First <HudManager>().Visible = true; API.SetNuiFocus(false, false); // Hide Client.Log("Sending Inventory NUI Hide"); Nui.Send("element:inventory:hide"); this.Visible = false; }
protected async void OnNuiCharacterCreate(dynamic character, CallbackDelegate callback) { Character newCharacter = await Server.Event(RpcEvents.CharacterCreate) .Attach(new Character { Forename = character.forename, Middlename = character.middlename, Surname = character.surname, Gender = (short)character.gender, DateOfBirth = DateTime.Parse(character.dob) }) .Request <Character>(); Client.Instance.Controllers.First <CharacterController>().Characters.Add(newCharacter); Nui.Send("characters", Client.Instance.Controllers.First <CharacterController>().Characters); await Show(); callback("ok"); }
public StandAxis(bool forward, AxisBinding binding) : base("Stand" + (forward ? "X" : "Y"), binding) { mStandConfig = new StandConfig(); Vector handR = Nui.joint(Nui.Hand_Right); Vector handL = Nui.joint(Nui.Hand_Left); Vector zeroPoint = Vector.Create("ZeroPoint", mStandConfig.ZeroPosition.X, mStandConfig.ZeroPosition.Y, mStandConfig.ZeroPosition.Z); //How far pushing forward Vector diff = zeroPoint - Nui.joint(Nui.Hip_Centre); mRaw = forward ? Nui.z(diff) : Nui.x(diff); //Whether the push gesture could be active mActive = C.And(Nui.abs(mRaw) > Deadzone.Value, Nui.abs(mRaw) < mStandConfig.Maximum); //mActive = C.And(mActive, Nui.y(hand) > Nui.y(elbow)); //The value for the push gesture mValue = Nui.ifScalar(mActive, mRaw, 0f); }
public ArmYawAxis(bool right, AxisBinding binding) : base("ArmYaw" + (right ? "Right" : "Left"), binding, Perspective.Y) { mRight = right; Vector diff = Nui.joint(mRight ? Nui.Shoulder_Right : Nui.Shoulder_Left) - Nui.joint(mRight ? Nui.Hand_Right : Nui.Hand_Left); mActive = Condition.And( mRight ? GlobalConditions.ActiveR : GlobalConditions.ActiveL, Condition.And( Nui.z(diff) > Nui.abs(Nui.x(diff)), Nui.z(diff) > Nui.abs(Nui.y(diff)))); mB = Nui.limit(diff, true, false, true); Init(); }
public CrossArmsLowTrigger(XmlNode node) { mHeightThreshold = Nui.magnitude(Nui.joint(Nui.Shoulder_Centre) - Nui.joint(Nui.Hip_Centre)); mAngleThreshold = Scalar.Create(.48f); mDepthThreshold = Scalar.Create(GetFloat(node, 3.6f, "DepthThreshold")); mWidthThreshold = Scalar.Create(GetFloat(node, 1f, "WidthThreshold")); mBody = Nui.joint(Nui.Hip_Centre); Condition inWidth = Nui.abs(Nui.x(Nui.joint(Nui.Hip_Centre))) < mWidthThreshold; Condition inDepth = Nui.z(Nui.joint(Nui.Hip_Centre)) < mDepthThreshold; Condition inRange = C.And(inWidth, inDepth); mTriggerHeight = C.And(Nui.y(Nui.joint(Nui.Hand_Left)) < Nui.y(Nui.joint(Nui.Elbow_Left)), Nui.y(Nui.joint(Nui.Hand_Right)) < Nui.y(Nui.joint(Nui.Elbow_Right))); mArmsCrossed = Nui.x(Nui.joint(Nui.Hand_Right)) < Nui.x(Nui.joint(Nui.Hand_Left)); mTrigger = C.And(C.And(mTriggerHeight, mArmsCrossed), inRange); mTrigger.OnChange += new ChangeDelegate(mTrigger_OnChange); }
// Protected implementation of Dispose pattern. protected virtual void Dispose(bool disposing) { if (disposed) { return; } if (disposing) { if (_initialized) { // Free any other managed objects here. Nui.NuiShutdown(); } } // Free any unmanaged objects here. // disposed = true; }
public PushSingleAxis(bool forward, AxisBinding binding) : base("Push" + (forward ? "+" : "-"), binding) { mMirror = false; Vector handR = Nui.joint(Nui.Hand_Right); Vector handL = Nui.joint(Nui.Hand_Left); //How far pushing forward mRaw = Nui.z(handR - Nui.joint(Nui.Hip_Centre)) + Nui.z(handL - Nui.joint(Nui.Hip_Centre)); if (forward) { mRaw *= -1f; } //Whether the push gesture could be active mActive = C.And(C.Or(GlobalConditions.ActiveR, GlobalConditions.ActiveL), !C.And(GlobalConditions.ActiveR, GlobalConditions.ActiveL)); //mActive = C.And(mActive, Nui.y(hand) > Nui.y(elbow)); //The value for the push gesture mValue = Nui.ifScalar(mActive, mRaw, 0f); }
public PushSingleAxis(bool right, bool forward, AxisBinding binding) : base("Push" + (right ? "Right" : "Left") + (forward ? "+" : "-"), binding) { mMirror = false; Vector hand = Nui.joint(right ? Nui.Hand_Right : Nui.Hand_Left); Vector elbow = Nui.joint(right ? Nui.Elbow_Right : Nui.Elbow_Left); //How far pushing forward mRaw = Nui.z(hand - Nui.joint(Nui.Hip_Centre)); if (forward) { mRaw *= -1f; } //Whether the push gesture could be active mActive = right ? GlobalConditions.ActiveR : GlobalConditions.ActiveL; //mActive = C.And(mActive, Nui.y(hand) > Nui.y(elbow)); //The value for the push gesture mValue = Nui.ifScalar(mActive, mRaw, 0f); }
private void ConfigureFromWindow() { mWorldW.Value = (float)mFrame.Width; mWorldH.Value = (float)mFrame.Height; mScreenW.Value = mFrame.Monitor.Bounds.Width; mScreenH.Value = mFrame.Monitor.Bounds.Height; Vector3 topLeft = mFrame.TopLeft; //TODO - this should be set as property topLeft -= Vector3.Zero; topLeft *= mOrientation.Quaternion; Vector3 normal = mFrame.Orientation.LookAtVector * mOrientation.Quaternion; mPlaneTopLeft.Set(topLeft.Y, topLeft.Z, topLeft.X); mPlaneNormal.Set(normal.Y, normal.Z, normal.X); Nui.Poll(); Tick(); }
/* * private static void SendPackets(object param) { * ProxyControllerBase controller = (ProxyControllerBase)param; * SetFollowCamPropertiesPacket packet = MakePacket(); * Thread.Sleep(10000); * Console.WriteLine("Sending packets"); * while (true) { * for (int i = 0; i < 4; i++) { * float xInc = .2f; * float yInc = 0f; * float zInc = 0f; * switch (i) { * case 1: xInc = 0; yInc = .2f; zInc = .022f; break; * case 2: xInc = -.2f; yInc = 0f; break; * case 3: xInc = 0; yInc = -.2f; zInc = -.022f; break; * } * for (int x = 0; x < 320; x++) { * controller.InjectPacket(packet); * Vector3 pos = mCoordinator.Position; * pos.X += xInc; * pos.Y += yInc; * pos.Z += zInc; * mCoordinator.Update(pos, Vector3.Zero, GetRot(pos), Rotation.Zero); * controller.SetCamera(); * Thread.Sleep(20); * } * } * } * } */ /* * DotNetConfigSource dotnet = new DotNetConfigSource(); * ArgvConfigSource arg = new ArgvConfigSource(args); * * dotnet.Merge(arg); * * arg.AddSwitch("Test", "Test", "t"); * * string test = arg.Configs["Test"].Get("Test"); * string test2 = dotnet.Configs["appSettings"].Get("Test"); * * Console.WriteLine(test); * * mPointStart = Vector.Create("PointStart", 0f, 0f, 0f); * mPointDir = Vector.Create("PointDir", 0f, 0f, 0f); * * //Init(); * Nui.Init(); * Nui.SetAutoPoll(true); * * GC.Collect(); * * * Window window = new Window("Test Window"); * window.Width = 2000; * window.Height = 1500; * window.TopLeft = new Vector3(0f, -1000f, 750f); * * IKinectCursor cursor = new PointCursor(); * //IKinectCursor cursor = new SimpleCursor(); * * //Form = new TestForm(mPlaneTopLeft, mPlaneNormal, mTop, mSide, mPointStart, mPointDir, mIntersection, mW, mH, mX, mY); * //Form form = new KinectMovementForm(); * //form.Begin(); * Form form = new KinectCursorForm(cursor, window); * ProcessWrangler.BlockingRunForm(form, null); */ private static void InitNui() { Nui.Init(); Nui.SetAutoPoll(true); Vector pointEnd = Nui.joint(Nui.Hand_Right); mPointStart = Nui.joint(Nui.Shoulder_Right); mPointDir = mPointStart - pointEnd; mPlaneTopLeft = Vector.Create("PlanePoint", 1f, 1f, 0f); mPlaneNormal = Vector.Create("PlaneNormal", 0f, 0f, -1f); mW = Scalar.Create("W", 2f); mH = Scalar.Create("H", 2f); Vector vertical = Vector.Create(0f, 1f, 0f); // Vertical //Calculate the intersection of the plane defined by the point mPlaneTopLeft and the normal mPlaneNormal and the line defined by the point mPointStart and the direction mPointDir. mIntersection = Nui.intersect(mPlaneTopLeft, Nui.normalize(mPlaneNormal), mPointStart, Nui.normalize(mPointDir)); //Calculate a vector that represents the orientation of the top of the input. mTop = Nui.scale(Nui.cross(vertical, mPlaneNormal), mW); //Calculate a vector that represents the orientation of the side of the input. mSide = Nui.scale(Nui.cross(mPlaneNormal, mTop), mH); //Calculate the vector (running along the plane) between the top left corner and the point of intersection. Vector diff = mIntersection - mPlaneTopLeft; //Project the diff line onto the top and side vectors to get x and y values. mX = Nui.project(diff, mTop); mY = Nui.project(diff, mSide); mX.OnChange += () => { if (mX.Value > 0 && mX.Value < mW.Value) { Console.WriteLine(mX.Value); } }; mPointStart.Set(1f, 0f, 0f); }
public ArmPitchAxis(bool right, AxisBinding binding) : base("ArmPitch" + (right ? "Right" : "Left"), binding, Perspective.X) { mRight = right; Vector shoulders = Nui.joint(Nui.Shoulder_Left) - Nui.joint(Nui.Shoulder_Right); Vector diff = Nui.joint(mRight ? Nui.Shoulder_Right : Nui.Shoulder_Left) - Nui.joint(mRight ? Nui.Hand_Right : Nui.Hand_Left); mActive = Condition.And( mRight ? GlobalConditions.ActiveR : GlobalConditions.ActiveL, /*Condition.And( * Nui.z(diff) > Nui.abs(Nui.x(diff)), * Nui.z(diff) > Nui.abs(Nui.y(diff)))*/ Nui.z(diff) > Nui.abs(Nui.magnitude(shoulders)) ); mB = Nui.limit(diff, false, true, true); Init(); }
void KinectPanel_HandleCreated(object sender, EventArgs e) { mHead = Nui.joint(Nui.Head); mHandR = Nui.joint(Nui.Hand_Right); mHandL = Nui.joint(Nui.Hand_Left); mWristR = Nui.joint(Nui.Wrist_Right); mWristL = Nui.joint(Nui.Wrist_Left); mElbowR = Nui.joint(Nui.Elbow_Right); mElbowL = Nui.joint(Nui.Elbow_Left); mShoulderR = Nui.joint(Nui.Shoulder_Right); mShoulderL = Nui.joint(Nui.Shoulder_Left); mShoulderC = Nui.joint(Nui.Shoulder_Centre); mHipC = Nui.joint(Nui.Hip_Centre); mHipR = Nui.joint(Nui.Hip_Right); mHipL = Nui.joint(Nui.Hip_Left); mKneeR = Nui.joint(Nui.Knee_Right); mKneeL = Nui.joint(Nui.Knee_Left); mAnkleR = Nui.joint(Nui.Ankle_Right); mAnkleL = Nui.joint(Nui.Ankle_Left); mFootR = Nui.joint(Nui.Foot_Right); mFootL = Nui.joint(Nui.Foot_Left); Nui.Tick += mKinectTick; }
void NuiProviderCaptureEnd(object sender, Nui.NuiEventArgs e) { recordGesture_.Gesture.JointRecords = nuiProvider_.GetCapture(); nuiProvider_.AddOrUpdateGesture(recordGesture_.Gesture); recordGesture_.Recorded = true; StatusText = "Gesture recorded: " + recordGesture_.Gesture.Name; captureMode_ = false; }
void NuiProviderCaptureProgress(object sender, Nui.NuiEventArgs e) { StatusText = "Recording... " + (int)(100 * (float)e.RecordedFrameCount / Nui.Provider.BufferSize) + "%"; }
void NuiProviderGestureDone(object sender, Nui.NuiEventArgs e) { if (!captureMode_) { var st = "Gesture recognized: " + e.Gesture.Name; if (e.Gesture == lastGesture_) { lastGestureCount_++; st += " (" + lastGestureCount_ + ")"; } else lastGestureCount_ = 1; lastGesture_ = e.Gesture; StatusText = st; } }
public void Init(Frame frame) { mFrame = frame; //TODO - this should be set properly - as a property mOrientation = Rotation.Zero; mOrientation.Changed += orientation_Changed; mFrame.Changed += (win, args) => ConfigureFromWindow(); mPlaneTopLeft = Vector.Create("PlanePoint", 1f, 1f, 0f); mPlaneNormal = Nui.normalize(Vector.Create("PlaneNormal", 0f, 0f, 1f)); mWorldW = Scalar.Create("WorldW", (float)mFrame.Width); mWorldH = Scalar.Create("WorldH", (float)mFrame.Height); mScreenW = Scalar.Create("ScreenW", mFrame.Monitor.Bounds.Width); mScreenH = Scalar.Create("ScreenH", mFrame.Monitor.Bounds.Height); Vector pointEnd = Nui.joint(Nui.Hand_Right) * SCALE; if (mTest) { mPointStart = Vector.Create("PointStart", 0f, 0f, 5f); mPointDir = Vector.Create("PointDir", 0f, 0f, -1f); } else { mPointStart = Nui.joint(Nui.Elbow_Right) * SCALE; mPointDir = Nui.normalize(mPointStart - pointEnd); } //Calculate the intersection of the plane defined by the point mPlaneTopLeft and the normal mPlaneNormal and the line defined by the point mPointStart and the direction mPointDir. Scalar numerator = Nui.dot(mPointStart - mPlaneTopLeft, mPlaneNormal); Scalar denominator = Nui.dot(mPlaneNormal, mPointDir); mIntersects = denominator != 0f; mIntersection = mPointStart + Nui.scale(mPointDir, Nui.ifScalar(mIntersects, numerator / denominator, 0f)); Vector vertical = Vector.Create(0f, 1f, 0f); // Vertical //Calculate a vector that represents the orientation of the top of the input. mTop = Nui.scale(Nui.cross(vertical, mPlaneNormal), mWorldW); //Calculate a vector that represents the orientation of the side of the input. mSide = Nui.scale(Nui.cross(mPlaneNormal, mTop), mWorldH); //Calculate the vector (running along the plane) between the top left corner and the point of intersection. Vector diff = mIntersection - mPlaneTopLeft; //Project the diff line onto the top and side vectors to get x and y values. Scalar kinectCoordX = Nui.project(diff, mTop); Scalar kinectCoordY = Nui.project(diff, mSide); Scalar x = (mWorldW - kinectCoordX) / mWorldW; Scalar y = (mWorldH - kinectCoordY) / mWorldH; mX = Nui.ifScalar(C.And(mIntersects, C.And(x >= 0f, x <= 1f)), x, -1f); mY = Nui.ifScalar(C.And(mIntersects, C.And(y >= 0f, y <= 1f)), y, -1f); mIntersection.Name = "Intersection"; mTop.Name = "Top"; mSide.Name = "Side"; mX.Name = "X"; mY.Name = "Y"; ConfigureFromWindow(); Nui.Tick += Tick; }
public KinectCursorAxis(bool left, bool x, AxisBinding binding) { mName = MakeName(left, x); mBinding = binding; mLeft = left; mX = x; mPanel = new UserControl(); mSmoothingFactor = Scalar.Create(HAND_SMOOTHING_FRAMES); if (mLeft) { mHand = Nui.smooth(Nui.joint(Nui.Hand_Right), mSmoothingFactor); } else { mHand = Nui.smooth(Nui.joint(Nui.Hand_Left), mSmoothingFactor); } mAnchor = Nui.smooth(Nui.joint(Nui.Hip_Centre), ANCHOR_SMOOTHING_FRAMES); mLeftShift = Scalar.Create("Left Shift", .0f); mUpShift = Scalar.Create("Up Shift", .0f); mWidth = Scalar.Create("Width", .5f); mHeight = Scalar.Create("Height", .5f); mTopLeftX = Nui.x(mAnchor) - (mWidth * mLeftShift); mTopLeftY = Nui.y(mAnchor) + (mHeight * mUpShift); if (mLeft) { if (mX) { mLeftHandShift = Scalar.Create("LeftHandShift", .5f); mNUIRaw = (Nui.x(mHand) + mLeftHandShift) - mTopLeftX; xActiveLeft = C.And(mNUIRaw >= 0f, mNUIRaw <= mWidth); mConstrained = Nui.constrain(mNUIRaw, .01f, mWidth, .10f, false); } else { mNUIRaw = Nui.y(mHand) - mTopLeftY; yActiveLeft = C.And(mNUIRaw >= 0f, mNUIRaw <= mHeight); mConstrained = Nui.constrain(mNUIRaw, .01f, mHeight, .10f, false); } if (xActiveLeft != null && yActiveLeft != null) { mOnScreenConditionLeft = C.And(xActiveLeft, yActiveLeft); } } else { if (mX) { mNUIRaw = Nui.x(mHand) - mTopLeftX; xActiveRight = C.And(mNUIRaw >= 0f, mNUIRaw <= mWidth); mConstrained = Nui.constrain(mNUIRaw, .01f, mWidth, .10f, false); } else { mNUIRaw = Nui.y(mHand) - mTopLeftY; yActiveRight = C.And(mNUIRaw >= 0f, mNUIRaw <= mHeight); mConstrained = Nui.constrain(mNUIRaw, .01f, mHeight, .10f, false); } if (xActiveRight != null && yActiveRight != null) { mOnScreenConditionRight = C.And(xActiveRight, yActiveRight); } } }