Now, I’m trying to map kinect motion to 3D model motion using rotations.
I’ve tried the following code to rotate the arm(shoulder) joint based on the old and the new position of the elbow joint.
What I 'me doing is theat:
1- Find the old direction from shoulder to elbow
2- Find the new direction (after the elbow position changed because of the rotation of the shoulder)
3- Find the shoulder rotation that causes the new position of the elbow
The problem:
the model rotated in different direction from what is supposed to be.
My question:
what’s wrong in my code that causes that problem?
Thanks
BTW, _oldJoints is the array of joints of the “previous” kinect frame.
_dataFloats is the array of joints of the “current” kinect frame.
and the indexes used are to access the x, y, and z of the shoulder and elbow kinect joints.
Vector3 L_Arm_oldPosition = new Vector3(_oldJoints[6], _oldJoints[26], _oldJoints[46]);
Vector3 L_ForeArm_oldPosition = new Vector3(_oldJoints[7], _oldJoints[27], _oldJoints[47]);
Vector3 L_ForeArm_newPosition = new Vector3(_dataFloat[7], _dataFloat[27], _dataFloat[47]);
L_Arm_oldPosition.z = -L_Arm_oldPosition.z;
L_ForeArm_oldPosition.z = -L_ForeArm_oldPosition.z;
L_ForeArm_newPosition.z = -L_ForeArm_newPosition.z;
oldDir = (L_Arm_oldPosition - L_ForeArm_oldPosition).normalized;
newDir = (L_Arm_oldPosition - L_ForeArm_newPosition).normalized;
L_Arm.transform.rotation *= Quaternion.FromToRotation(oldDir, newDir);