1
1
extern crate cgt_math;
2
- use cgt_math:: { Plane , Quaternion , Vector3 } ;
2
+ use cgt_math:: { Plane , Quaternion , Vector3 , Axis } ;
3
3
4
4
/// Calculates limb fk chain, hip, shoulder and face rotation.
5
5
/// May uses hip center as pivot.
@@ -57,9 +57,10 @@ fn torso_rotation(data: &[Vector3; 36], rotation_data: &mut [Quaternion; 36]) {
57
57
fn shoulder_rotation ( data : & [ Vector3 ; 36 ] , rotation_data : & mut [ Quaternion ; 36 ] ) {
58
58
// As the torso rotation usually is used to rotate the rig,
59
59
// the torso rotation got to be substracted from the hip rotation
60
- let shoulder_rot =
61
- Quaternion :: from_vec_to_track_quat ( ( data[ 12 ] - data[ 34 ] ) . normalize ( ) . neg ( ) , 2 , 1 ) ; // rotation from center to right shoulder
62
- let hip_rot = Quaternion :: from_vec_to_track_quat ( ( data[ 24 ] - data[ 33 ] ) . normalize ( ) . neg ( ) , 2 , 1 ) ; // rotation from center to right hip
60
+ let shoulder_rot = Quaternion :: rotate_towards ( ( data[ 12 ] -data[ 34 ] ) . normalize ( ) , Axis :: Z , Axis :: Y ) ;
61
+ // Quaternion::from_vec_to_track_quat((data[12] - data[34]).normalize().neg(), 2, 1); // rotation from center to right shoulder
62
+ let hip_rot = Quaternion :: rotate_towards ( ( data[ 24 ] - data[ 33 ] ) . normalize ( ) , Axis :: Z , Axis :: Y ) ; // rotation from center to right hip
63
+ // let hip_rot = Quaternion::from_vec_to_track_quat((data[24] - data[33]).normalize().neg(), 2, 1); // rotation from center to right hip
63
64
rotation_data[ 34 ] = shoulder_rot - hip_rot;
64
65
}
65
66
@@ -68,7 +69,8 @@ fn calc_limb_chain_rotations(data: &[Vector3; 4]) -> [Quaternion; 3] {
68
69
let mut arr: [ Quaternion ; 3 ] = [ Quaternion :: IDENTITY ; 3 ] ;
69
70
for i in 1 ..4 {
70
71
arr[ i - 1 ] =
71
- Quaternion :: from_vec_to_track_quat ( ( data[ i - 1 ] - data[ i] ) . normalize ( ) . neg ( ) , 4 , 2 ) ;
72
+ Quaternion :: rotate_towards ( ( data[ i-1 ] -data[ i] ) . normalize ( ) . neg ( ) , Axis :: X , Axis :: Z ) ;
73
+ // Quaternion::from_vec_to_track_quat((data[i - 1] - data[i]).normalize().neg(), 4, 2);
72
74
}
73
75
return arr;
74
76
}
0 commit comments