Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
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);
            }