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);
        }
 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;
 }
        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);
        }
Exemple #4
0
        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 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);
        }
Exemple #6
0
        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 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);
        }
Exemple #8
0
            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);
            }
Exemple #9
0
        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);
                }
            }
        }
Exemple #10
0
        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;
        }