コード例 #1
0
    public bool GetJointPosition(NiteWrapper.SkeletonJoint joint, out Vector3 position)
    {
        if (kinectConnect && calibratedUser)
        {
            NiteWrapper.SkeletonJointTransformation trans = new NiteWrapper.SkeletonJointTransformation();
            NiteWrapper.GetJointTransformation(calibratedUserId, joint, ref trans);

            // Nite gives position in mm convert to Unity unit = meters
            position = new Vector3(trans.pos.x / 1000.0F, trans.pos.y / 1000.0F, trans.pos.z / 1000.0F);
            return(trans.pos.confidence > confidenceThreshold);
        }
        else
        {
            position = new Vector3(0.0F, 0.0F, 0.0F);
            return(false);
        }
    }
コード例 #2
0
    public bool GetJointOrientation(NiteWrapper.SkeletonJoint joint, out Quaternion rotation)
    {
        if (kinectConnect && calibratedUser)
        {
            NiteWrapper.SkeletonJointTransformation trans = new NiteWrapper.SkeletonJointTransformation();
            NiteWrapper.GetJointTransformation(calibratedUserId, joint, ref trans);

            Vector3 worldZVec = new Vector3(trans.ori.m02, trans.ori.m12, trans.ori.m22);
            Vector3 worldYVec = new Vector3(trans.ori.m01, trans.ori.m11, trans.ori.m21);
            rotation = Quaternion.LookRotation(worldZVec, worldYVec);
            return(trans.ori.confidence > confidenceThreshold);
        }
        else
        {
            rotation = Quaternion.identity;
            return(false);
        }
    }
コード例 #3
0
ファイル: Nite.cs プロジェクト: masohail/cve-kinect
    void TransformBone(uint userId, NiteWrapper.SkeletonJoint joint, Transform dest)
    {
        NiteWrapper.SkeletonJointTransformation trans = new NiteWrapper.SkeletonJointTransformation();
        NiteWrapper.GetJointTransformation(userId, joint, ref trans);

        // only modify joint if confidence is high enough in this frame
        if (trans.ori.confidence > 0.5)
        {
            // Z coordinate in OpenNI is opposite from Unity. We will create a quat
            // to rotate from OpenNI to Unity (relative to initial rotation)
            Vector3    worldZVec     = new Vector3(trans.ori.m02, -trans.ori.m12, trans.ori.m22);
            Vector3    worldYVec     = new Vector3(-trans.ori.m01, trans.ori.m11, -trans.ori.m21);
            Quaternion jointRotation = Quaternion.LookRotation(worldZVec, worldYVec);

            Quaternion newRotation = jointRotation * initialRotations[(int)joint];

            // Some smoothing
            dest.rotation = Quaternion.Slerp(dest.rotation, newRotation, Time.deltaTime * 20);
        }
    }
コード例 #4
0
	// Rotate the spine of the avatar to the direction of the main fly arm.
	void RotateSpineInFlight(uint userId, NiteWrapper.SkeletonJoint joint) {
		NiteWrapper.SkeletonJointTransformation trans = new NiteWrapper.SkeletonJointTransformation();
        NiteWrapper.GetJointTransformation(userId, joint, ref trans);

		// Smooth spine rotation, but currently results in a buggy avatar.
		//spine.forward = Vector3.SmoothDamp(spine.forward, -mainFlyArm.right, ref velocity, smoothTime);
		// Instant spine rotation to the direction of the main fly arm.
		spine.forward = -mainFlyArm.right;
	}
コード例 #5
0
	// This function moves the avatar around according to the movement of the user relative to the kinect.
	void MoveBone(uint userId, NiteWrapper.SkeletonJoint joint, Transform dest) {
		NiteWrapper.SkeletonJointTransformation trans = new NiteWrapper.SkeletonJointTransformation();
		NiteWrapper.GetJointTransformation(userId, joint, ref trans);

		// Save the first position of the user relative to the kinect once it stopped flying.
		if (firstMoveAfterFlight == true)
			kinectOffsetPosition = new Vector3(trans.pos.x/1000, trans.pos.y/1000 -1, -trans.pos.z/1000);

		// The position of the avatar is based on the characterPosition (i.e. the position where the avatar
		// has flown to) and the movement around the initial position of the user after flight (kinectOffsetPosition)
		// relative to the kinect.
		dest.position = characterPosition - kinectOffsetPosition + new Vector3(trans.pos.x/1000, trans.pos.y/1000 -1, -trans.pos.z/1000);
	}
コード例 #6
0
	// Retrieves the latest rotation information from the kinect.
    void RotateBone(uint userId, NiteWrapper.SkeletonJoint joint, Transform dest) {
        NiteWrapper.SkeletonJointTransformation trans = new NiteWrapper.SkeletonJointTransformation();
        NiteWrapper.GetJointTransformation(userId, joint, ref trans);

        // Only modify joint if confidence is high enough in this frame.
		// We set it to 0 since we always want the latest rotation information.
        if (trans.ori.confidence > 0.0) {
            // Z coordinate in OpenNI is opposite from Unity. We will create a quaternion
            // to rotate from OpenNI to Unity (relative to initial rotation).
            Vector3 worldZVec = new Vector3(-trans.ori.m02, -trans.ori.m12, trans.ori.m22);
            Vector3 worldYVec = new Vector3(trans.ori.m01, trans.ori.m11, -trans.ori.m21);
            Quaternion jointRotation = Quaternion.LookRotation(worldZVec, worldYVec);

			Quaternion newRotation = jointRotation * initialRotations[(int)joint];

            // Smoothing results in a shaky avatar, but might be useful if it is made to work.
			// dest.rotation = Quaternion.Slerp(dest.rotation, newRotation, Time.deltaTime * 20);
			dest.rotation = newRotation;
        }
	}
コード例 #7
0
ファイル: Nite.cs プロジェクト: guozanhua/KinectDressingRoom
	public bool GetJointPosition(NiteWrapper.SkeletonJoint joint, out Vector3 position) {
		if (kinectConnect && calibratedUser) {
			NiteWrapper.SkeletonJointTransformation trans = new NiteWrapper.SkeletonJointTransformation();
        	NiteWrapper.GetJointTransformation(calibratedUserId, joint, ref trans);
			
			// Nite gives position in mm convert to Unity unit = meters
			position = new Vector3(trans.pos.x/1000.0F, trans.pos.y/1000.0F, trans.pos.z/1000.0F);
			return (trans.pos.confidence > confidenceThreshold);
		}
		else {
			position = new Vector3(0.0F, 0.0F, 0.0F);
			return false;
		}
	}
コード例 #8
0
ファイル: Nite.cs プロジェクト: guozanhua/KinectDressingRoom
	public bool GetJointOrientation(NiteWrapper.SkeletonJoint joint, out Quaternion rotation) {
		if (kinectConnect && calibratedUser) {
			NiteWrapper.SkeletonJointTransformation trans = new NiteWrapper.SkeletonJointTransformation();
        	NiteWrapper.GetJointTransformation(calibratedUserId, joint, ref trans);
			
            Vector3 worldZVec = new Vector3(trans.ori.m02, trans.ori.m12, trans.ori.m22);
            Vector3 worldYVec = new Vector3(trans.ori.m01, trans.ori.m11, trans.ori.m21);
            rotation = Quaternion.LookRotation(worldZVec, worldYVec);
			return (trans.ori.confidence > confidenceThreshold);
		}
		else {
			rotation = Quaternion.identity;
			return false;
		}
	}
コード例 #9
0
ファイル: Nite.cs プロジェクト: hongyaoxu/UnityWrapper
    void TransformBone(uint userId, NiteWrapper.SkeletonJoint joint, Transform dest)
    {
        NiteWrapper.SkeletonJointTransformation trans = new NiteWrapper.SkeletonJointTransformation();
        NiteWrapper.GetJointTransformation(userId, joint, ref trans);

        // only modify joint if confidence is high enough in this frame
        if (trans.ori.confidence > 0.5)
        {
            // Z coordinate in OpenNI is opposite from Unity. We will create a quat
            // to rotate from OpenNI to Unity (relative to initial rotation)
            Vector3 worldZVec = new Vector3(-trans.ori.m02, -trans.ori.m12, trans.ori.m22);
            Vector3 worldYVec = new Vector3(trans.ori.m01, trans.ori.m11, -trans.ori.m21);
            Quaternion jointRotation = Quaternion.LookRotation(worldZVec, worldYVec);

            Quaternion newRotation = jointRotation * initialRotations[(int)joint];

            // Some smoothing
            dest.rotation = Quaternion.Slerp(dest.rotation, newRotation, Time.deltaTime * 20);
        }
    }
コード例 #10
0
ファイル: UserBody.cs プロジェクト: loldeepa/vDR
    public Vector3 left, right;     // 3d world positions of hands

    public HandPositions(NiteWrapper.SkeletonJointTransformation leftHand, NiteWrapper.SkeletonJointTransformation rightHand)
    {
        left  = new Vector3(leftHand.pos.x, leftHand.pos.y, leftHand.pos.z);
        right = new Vector3(rightHand.pos.x, rightHand.pos.y, rightHand.pos.z);
    }