Fix for commit from Brecht:
2006/11/19 00:07:32 CET Fix for bug #5250: inaccurate conversion between edit and pose mode bones. Two very bad bugs: - replacing atan() with atan2() should also remove the M_PI correction! This is the equivalent: angle=atan(x/y); if(y<0) angle+=M_PI; angle= atan2(x, y); - the new NormalizedVecAngle2() call was negating an input vector, causing calling code to screw up. All arithb.c calls should not alter input.
This commit is contained in:
@@ -841,7 +841,8 @@ void get_objectspace_bone_matrix (struct Bone* bone, float M_accumulatedMatrix[]
|
||||
*************************************************************************** */
|
||||
/* Computes vector and roll based on a rotation. "mat" must
|
||||
contain only a rotation, and no scaling. */
|
||||
void mat3_to_vec_roll(float mat[][3], float *vec, float *roll) {
|
||||
void mat3_to_vec_roll(float mat[][3], float *vec, float *roll)
|
||||
{
|
||||
if (vec)
|
||||
VecCopyf(vec, mat[1]);
|
||||
|
||||
@@ -873,8 +874,8 @@ void vec_roll_to_mat3(float *vec, float roll, float mat[][3])
|
||||
if (Inpf(axis,axis) > 0.0000000000001) {
|
||||
/* if nor is *not* a multiple of target ... */
|
||||
Normalise (axis);
|
||||
theta=(float) acos (Inpf (target,nor));
|
||||
// theta= NormalizedVecAngle2(target, nor);
|
||||
|
||||
theta= NormalizedVecAngle2(target, nor);
|
||||
|
||||
/* Make Bone matrix*/
|
||||
VecRotToMat3(axis, theta, bMatrix);
|
||||
|
||||
@@ -2418,11 +2418,13 @@ float NormalizedVecAngle2(float *v1, float *v2)
|
||||
{
|
||||
/* this is the same as acos(Inpf(v1, v2)), but more accurate */
|
||||
if (Inpf(v1, v2) < 0.0f) {
|
||||
v2[0]= -v2[0];
|
||||
v2[1]= -v2[1];
|
||||
v2[2]= -v2[2];
|
||||
float vec[3];
|
||||
|
||||
vec[0]= -v2[0];
|
||||
vec[1]= -v2[1];
|
||||
vec[2]= -v2[2];
|
||||
|
||||
return (float)M_PI - 2.0f*saasin(VecLenf(v2, v1)/2.0f);
|
||||
return (float)M_PI - 2.0f*saasin(VecLenf(vec, v1)/2.0f);
|
||||
}
|
||||
else
|
||||
return 2.0f*saasin(VecLenf(v2, v1)/2.0);
|
||||
|
||||
@@ -154,8 +154,7 @@ void make_boneList(ListBase* list, ListBase *bones, EditBone *parent)
|
||||
Mat3Inv(imat, postmat);
|
||||
Mat3MulMat3(difmat, imat, premat);
|
||||
|
||||
eBone->roll = atan(difmat[2][0]/difmat[2][2]);
|
||||
if (difmat[0][0]<0.0) eBone->roll +=M_PI;
|
||||
eBone->roll = atan2(difmat[2][0], difmat[2][2]);
|
||||
|
||||
/* rest of stuff copy */
|
||||
eBone->length= curBone->length;
|
||||
@@ -216,8 +215,7 @@ static void fix_bonelist_roll (ListBase *bonelist, ListBase *editbonelist)
|
||||
printmatrix4 ("difmat", difmat);
|
||||
printf ("Roll = %f\n", (-atan2(difmat[2][0], difmat[2][2]) * (180.0/M_PI)));
|
||||
#endif
|
||||
curBone->roll = -atan(difmat[2][0]/difmat[2][2]);
|
||||
if (difmat[0][0]<0.0) curBone->roll +=M_PI;
|
||||
curBone->roll = -atan2(difmat[2][0], difmat[2][2]);
|
||||
|
||||
/* and set restposition again */
|
||||
where_is_armature_bone(curBone, curBone->parent);
|
||||
@@ -429,10 +427,7 @@ int join_armature(void)
|
||||
Mat4Invert (imat, premat);
|
||||
Mat4MulMat4 (difmat, postmat, imat);
|
||||
|
||||
curbone->roll -=atan(difmat[2][0]/difmat[2][2]);
|
||||
|
||||
if (difmat[0][0]<0)
|
||||
curbone->roll +=M_PI;
|
||||
curbone->roll -= atan2(difmat[2][0], difmat[2][2]);
|
||||
|
||||
}
|
||||
BLI_remlink(&eblist, curbone);
|
||||
@@ -1129,7 +1124,7 @@ void auto_align_armature(void)
|
||||
Mat3Inv(imat, targetmat);
|
||||
Mat3MulMat3(diffmat, imat, curmat);
|
||||
|
||||
ebone->roll = atan(diffmat[2][0]/diffmat[2][2]);
|
||||
ebone->roll = atan2(diffmat[2][0], diffmat[2][2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user