Exemple #1
0
    // Use this for initialization
    void Awake()
    {
        leftHandDetector = new GameObject("LeftHandDetector");
        leftHandDetector.transform.parent = gameObject.transform;
        ZigMapJointToSession leftMap = leftHandDetector.AddComponent <ZigMapJointToSession>();

        leftMap.joint = ZigJointId.LeftHand;

        rightHandDetector = new GameObject("RightHandDetector");
        rightHandDetector.transform.parent = gameObject.transform;
        ZigMapJointToSession rightMap = rightHandDetector.AddComponent <ZigMapJointToSession>();

        rightMap.joint = ZigJointId.RightHand;

        leftHandSteady         = leftHandDetector.AddComponent <ZigSteadyDetector>();
        rightHandSteady        = rightHandDetector.AddComponent <ZigSteadyDetector>();
        leftHandSteady.Steady += delegate(object sender, EventArgs e) {
            ZigInputJoint hand  = trackedUser.Skeleton[(int)ZigJointId.LeftHand];
            ZigInputJoint elbow = trackedUser.Skeleton[(int)ZigJointId.LeftElbow];
            if (IsHandRaise(hand.Position, elbow.Position))
            {
                OnHandRaise(ZigJointId.LeftHand);
            }
        };
        rightHandSteady.Steady += delegate(object sender, EventArgs e) {
            ZigInputJoint hand  = trackedUser.Skeleton[(int)ZigJointId.RightHand];
            ZigInputJoint elbow = trackedUser.Skeleton[(int)ZigJointId.RightElbow];
            if (IsHandRaise(hand.Position, elbow.Position))
            {
                OnHandRaise(ZigJointId.RightHand);
            }
        };
    }
Exemple #2
0
        private void DrawBones(ZigInputJoint[] userSkeleton)
        {
            for (int t = 0; t < userSkeleton.Length; t++)
            {
                ZigJointId    parentId    = CinemaMocapHelper.ParentBoneJoint(userSkeleton[t].Id);
                ZigInputJoint parentJoint = null;

                for (int s = 0; s < userSkeleton.Length; s++)
                {
                    if (userSkeleton[s].Id == parentId)// find parent and leave loop.
                    {
                        parentJoint = userSkeleton[s];
                        break;
                    }
                }

                if (parentJoint != null && parentJoint.Id != ZigJointId.None && userSkeleton[t].GoodPosition && parentJoint.GoodPosition)
                {
                    // parent and child joint coordinates
                    int childX  = textureSize.Width / 2 - (int)(userSkeleton[t].Position.x * 300 / userSkeleton[t].Position.z);
                    int childY  = textureSize.Height / 2 - (int)(userSkeleton[t].Position.y * 300 / userSkeleton[t].Position.z);
                    int parentX = textureSize.Width / 2 - (int)(parentJoint.Position.x * 300 / parentJoint.Position.z);
                    int parentY = textureSize.Height / 2 - (int)(parentJoint.Position.y * 300 / parentJoint.Position.z);

                    // draw lines between joints
                    Color color = (!userSkeleton[t].Inferred) ? Color.cyan : Color.red;
                    CinemaMocapHelper.drawFastLine(outputPixels, textureSize.Width, textureSize.Height, childX, childY, parentX, parentY, color);
                }
            }
        }
    IEnumerator JointUpdate(ulong userId, Kinect.Joint joint)
    {
        string     jointName;
        float      x, y, z;
        Vector3    vec = GetVector3FromJoint(joint);
        Quaternion q   = Quaternion.identity;
        ZigJointId jointId;

        // argStr: user,jointName,x,y,z
        jointName = joint.ToString();

        jointId = _kinectToZigMapping[joint.JointType];
        if (joint.JointType == Kinect.JointType.Head)
        {
            headP = vec;
            headQ = q;
            UpdateLgTrackedUser(userId, headP);
        }
        ZigTrackedUser tUser      = _Bodies[userId];
        ZigInputJoint  inputJoint = new ZigInputJoint(jointId, vec, q, true);

        inputJoint.GoodPosition      = true;
        inputJoint.GoodRotation      = true;
        tUser.Skeleton[(int)jointId] = inputJoint;

        yield return(1);
    }
Exemple #4
0
    static ZgInputJoint ToZgInputJoint(ZigInputJoint aJoint)
    {
        //return new ZgInputJoint (sJointTypeMap[aJoint.Id], aJoint.Position, aJoint.Rotation, aJoint.Inferred);
        //I'm pretty sure this conversion from ZigJointId to ZgJointId is fine
        var r = new ZgInputJoint((ZgJointId)((int)aJoint.Id), aJoint.Position, aJoint.Rotation, aJoint.Inferred);

        r.GoodPosition = aJoint.GoodPosition;
        r.GoodRotation = aJoint.GoodRotation;
        return(r);
    }
Exemple #5
0
    bool IsHandRaise(Vector3 handPosition, Vector3 elbowPosition)
    {
        ZigInputJoint torso = trackedUser.Skeleton[(int)ZigJointId.Torso];
        ZigInputJoint head  = trackedUser.Skeleton[(int)ZigJointId.Head];

        Vector3 armDirection   = (handPosition - elbowPosition).normalized;
        Vector3 torsoDirection = (head.Position - torso.Position).normalized;
        double  angle          = Math.Acos(Vector3.Dot(armDirection, torsoDirection)) * 180 / Math.PI;

        return(angle < angleThreshold);
    }